1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
local BLOCK_SIZE = 4
local BLOCK_COUNT = 7
local RANGE_SPELL = "Shadow Bolt"
local isSpellInRange = C_Spell and C_Spell.IsSpellInRange or IsSpellInRange
local FACING_ERROR_SECONDS = 1
local FACING_ERRORS = {
[ERR_BADATTACKFACING] = true,
[SPELL_FAILED_UNIT_NOT_INFRONT] = true,
}
local facingErrorAt = 0
local UPDATE_SECONDS = 0.05
local ATTACK_SPELL_ID = 6603
local WAND_SPELL = "Shoot"
local isCurrentSpell = C_Spell and C_Spell.IsCurrentSpell or IsCurrentSpell
local isAutoRepeatSpell = C_Spell and C_Spell.IsAutoRepeatSpell or IsAutoRepeatSpell
local frame = CreateFrame("Frame", "PixelStateFrame", UIParent)
frame:SetIgnoreParentScale(true)
frame:SetFrameStrata("TOOLTIP")
frame:SetPoint("TOPLEFT")
frame:SetSize(BLOCK_SIZE * BLOCK_COUNT, BLOCK_SIZE)
local blocks = {}
for i = 0, BLOCK_COUNT - 1 do
local texture = frame:CreateTexture(nil, "OVERLAY")
texture:SetSize(BLOCK_SIZE, BLOCK_SIZE)
texture:SetPoint("TOPLEFT", i * BLOCK_SIZE, 0)
blocks[i] = texture
end
local function setBlock(index, red, green, blue)
blocks[index]:SetColorTexture(red / 255, green / 255, blue / 255)
end
local isSecret = issecretvalue or function() return false end
local function plain(value)
if isSecret(value) then
return 0
end
return value
end
local function splitBytes(value)
return math.floor(value / 256), value % 256
end
local function percentByte(current, maximum)
current, maximum = plain(current), plain(maximum)
if maximum == 0 then
return 0
end
return math.floor(current / maximum * 255)
end
local function readPosition()
local mapID = C_Map.GetBestMapForUnit("player")
if not mapID then
return 0, 0, 0
end
local position = C_Map.GetPlayerMapPosition(mapID, "player")
if not position then
return mapID, 0, 0
end
return mapID, math.floor(plain(position.x) * 65535), math.floor(plain(position.y) * 65535)
end
local function readFlags()
local flags = 0
if UnitAffectingCombat("player") then
flags = flags + 1
end
if UnitExists("target") then
flags = flags + 2
if UnitIsDead("target") then
flags = flags + 4
end
local inRange = isSpellInRange(RANGE_SPELL, "target")
if inRange == true or inRange == 1 then
flags = flags + 16
end
if GetTime() - facingErrorAt < FACING_ERROR_SECONDS then
flags = flags + 32
end
end
if UnitIsDeadOrGhost("player") then
flags = flags + 8
end
if isCurrentSpell(ATTACK_SPELL_ID) or isAutoRepeatSpell(WAND_SPELL) then
flags = flags + 64
end
if UnitCastingInfo("player") or UnitChannelInfo("player") then
flags = flags + 128
end
return flags
end
local function matchPhysicalPixels()
local _, screenHeight = GetPhysicalScreenSize()
frame:SetScale(768 / screenHeight)
end
local function update()
local mapID, x, y = readPosition()
local facing = math.floor(plain(GetPlayerFacing() or 0) / (2 * math.pi) * 255)
local flags = readFlags()
local health = percentByte(UnitHealth("player"), UnitHealthMax("player"))
local power = percentByte(UnitPower("player"), UnitPowerMax("player"))
local targetHealth = percentByte(UnitHealth("target"), UnitHealthMax("target"))
local level = plain(UnitLevel("player"))
local targetLevel = 0
local flags2 = 0
if plain(GetUnitSpeed("player")) > 0 then
flags2 = flags2 + 4
end
if UnitExists("target") then
targetLevel = plain(UnitLevel("target"))
if targetLevel < 1 then
targetLevel = 255
end
if CheckInteractDistance("target", 3) then
flags2 = flags2 + 1
end
if UnitCanAttack("player", "target") then
flags2 = flags2 + 2
end
end
local xHigh, xLow = splitBytes(x)
local yHigh, yLow = splitBytes(y)
local mapHigh, mapLow = splitBytes(mapID)
local checksum = (xHigh + xLow + facing + yHigh + yLow + flags + mapHigh + mapLow
+ health + power + targetHealth + level + targetLevel + flags2) % 256
setBlock(1, xHigh, xLow, facing)
setBlock(2, yHigh, yLow, flags)
setBlock(3, mapHigh, mapLow, health)
setBlock(4, power, targetHealth, checksum)
setBlock(5, level, targetLevel, flags2)
if GetCurrentKeyBoardFocus() then
setBlock(6, 255, 255, 255)
else
setBlock(6, 0, 0, 0)
end
end
local sinceUpdate = UPDATE_SECONDS
local function onUpdate(_, elapsed)
sinceUpdate = sinceUpdate + elapsed
if sinceUpdate >= UPDATE_SECONDS then
sinceUpdate = 0
update()
end
end
local function onEvent(_, event, _, message)
if event == "UI_ERROR_MESSAGE" then
if FACING_ERRORS[message] then
facingErrorAt = GetTime()
end
return
end
matchPhysicalPixels()
end
setBlock(0, 255, 0, 255)
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("DISPLAY_SIZE_CHANGED")
frame:RegisterEvent("UI_ERROR_MESSAGE")
frame:SetScript("OnEvent", onEvent)
frame:SetScript("OnUpdate", onUpdate)