View Single Post
10-04-11, 08:34 AM   #18
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
If you make an addon in-game that creates a 1x1 pixel (or larger if it fancies you) then make that addon change the color of the texture you are showing to white, red, green, yellow or what ever you wish it to; then you can can read the color from the pixel at position x,y on screen with a program -for example AutoIT3 has simple to use API for pixel color reading.

Then it is a mater of making the script running on the machine send those signals to your hardware, dunno what interface you use.

The lua code I wrote explained:
Code:
-- I just use the UIParent frame since I then have to write less code :P
local t = UIParent:CreateTexture(nil, "BACKGROUND")
-- the top-left side of the screen
t:SetPoint("TOPLEFT")
-- this is 8x8 but you can set it to 1x1 to make it less visible
t:SetSize(8, 8)
-- default color at login (gray = no threat)
t:SetTexture(GetThreatStatusColor(nil))
-- we need to know: when you change your target to the new target threat levels
UIParent:RegisterEvent("PLAYER_TARGET_CHANGED")
-- we need to know: when you overaggro tank, or loose aggro and other threat level changes
UIParent:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
-- hook the UIParent events so we can read off the data and change the texture color
UIParent:HookScript("OnEvent", function(_, event)
  if event == "PLAYER_TARGET_CHANGED" or event == "UNIT_THREAT_LIST_UPDATE" then
    -- nil/0 = no threat (gray), 1 = has threat but safe zone (yellow), 2 = has high threat (orange), 3 = tanking (red)
    local status = UnitThreatSituation("player", "target")
    -- we fetch the default game coloring system using the status value
    local r, g, b = GetThreatStatusColor(status)
    -- we apply the color to the texture
    t:SetTexture(r, g, b)
  end
end)
The AutoIT3 code I wrote to test it out, but not so much explained in details:
Code:
; pattern to match the game window
Local $title = "[TITLE:World of Warcraft; Class:GxWindowClass]"

; simple check to not waste our time
If Not WinExists($title) Then
	MsgBox(48, "Where is World of Warcraft?", "Run me when the game is running, bye!")
	Exit
EndIf

; set the handle to the window in focus
Local $game = WinGetHandle($title)

; this is called when reporting a threat level change
Func ThreatChange($status)
	; TODO: do your magic here, and to help you get started:
	; http://www.autoitscript.com/autoit3/docs/functions.htm
EndFunc

; check pixel at topleft location each 1/4th second
Local $pos = WinGetPos($title)
Local $x = $pos[0] + 10 ; change this (have to find where the in-game pixel is on the x-axis)
Local $y = $pos[1] + 34 ; change this (have to find where the in-game pixel is on the y-axis)
;~ MouseMove($x, $y) ; uncomment to see where the mouse movies, should be on top of the pixel, if not, keep trying!
;~ Exit ; should uncomment this too if working on finding the in-game texture
Local $color, $r, $g, $b, $rgb, $status, $laststatus
While 1
	Sleep(0.25)
	$color = PixelGetColor($x, $y, $game)
	$b = BitAND($color, 0xFF)
	$g = BitAND(BitShift($color, 8), 0xFF)
	$r = BitAND(BitShift($color, 16), 0xFF)
	$rgb = $r + $g + $b
	Switch $rgb
		Case 528
			$status = 0
		Case 629
			$status = 1
		Case 408
			$status = 2
		Case 255
			$status = 3
	EndSwitch
	If $laststatus <> $status Then
		$laststatus = $status
		ThreatChange($status)
	EndIf
WEnd

#cs

can use to test the pixel in-game (all the macros create the "addon") -have to /reloadui first if you want to change the function tough...
/run local t = UIParent:CreateTexture(nil, "BACKGROUND") _G.t=t
/run t:SetPoint("TOPLEFT")
/run t:SetSize(8, 8)
/run t:SetTexture(GetThreatStatusColor(nil))
/run UIParent:RegisterEvent("PLAYER_TARGET_CHANGED")
/run UIParent:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
/run UIParent:HookScript("OnEvent", function(_, event) if event == "PLAYER_TARGET_CHANGED" or event == "UNIT_THREAT_LIST_UPDATE" then t:SetTexture(GetThreatStatusColor(UnitThreatSituation("player", "target"))) end end)

can use these to change the colors by force and check if the program responds
/run t:SetTexture(GetThreatStatusColor(0))
/run t:SetTexture(GetThreatStatusColor(1))
/run t:SetTexture(GetThreatStatusColor(2))
/run t:SetTexture(GetThreatStatusColor(3))

#ce
At the bottom of the au3 code there is a macro version of the "addon" for easier testing, hehe.

Last edited by Vlad : 10-04-11 at 09:48 AM.
  Reply With Quote