-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
hack.lua
90 lines (80 loc) · 3.61 KB
/
hack.lua
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
-- this hacky mess exists because C_TradeSkill.OpenTradeSkill(skillLineID) is the only method of
-- requesting tradeskill data (like skill levels), and it requires a hardware event. all of this
-- could be prevented by blizzard implementing a way to request the data without a distruptive
-- (as in opening a UI), hardware event requiring trigger.
-- https://github.com/Stanzilla/WoWUIBugs/issues/424
-- how it works:
-- since we're always going to expect the player to hit the Alt key in order to use Molinari
-- we can listen to key events (which are valid hardware events), then open the tradeskill UI
-- ourselves, closing it as soon as it opens. by opening a single profession (even secondary) we
-- have valid data for all professions, even if we unlearn one and learn another. in case the
-- player doesn't have a profession yet we will wait until they do, then listen for key presses.
-- even if the player opens the bags without pressing keys, the OnKeyDown event triggers before
-- Molinari's tooltip handler fires, and the data will be available by then.
-- in case other addons copies this, make sure it never loads multiple times unless there is a
-- newer version of it, in which case we disable it and load anyways
local version = 5
if _G['ForceLoadTradeSkillData'] then
if _G['ForceLoadTradeSkillData'].version < version then
_G['ForceLoadTradeSkillData']:UnregisterAllEvents()
else
return
end
end
local hack = CreateFrame('Frame', 'ForceLoadTradeSkillData')
hack.version = version
hack:SetPropagateKeyboardInput(true) -- make sure we don't own the keyboard
hack:RegisterEvent('PLAYER_LOGIN')
hack:SetScript('OnEvent', function(self, event)
if event == 'PLAYER_LOGIN' or event == 'SKILL_LINES_CHANGED' then
self:UnregisterEvent(event)
local professionID = self:GetAnyProfessionID()
if not professionID then
-- player has no professions, wait for them to learn one
self:RegisterEvent('SKILL_LINES_CHANGED')
elseif not self:HasProfessionData(professionID) then
-- player has profession but the session has no data, listen for key event
self.professionID = professionID
self:SetScript('OnKeyDown', self.OnKeyDown)
end
elseif event == 'TRADE_SKILL_SHOW' then
if not (C_TradeSkillUI.IsTradeSkillLinked() or C_TradeSkillUI.IsTradeSkillGuild()) then
-- we've triggered the tradeskill UI, close it again and bail out
C_Timer.After(0, function()
-- wait for next frame so we can get full data
C_TradeSkillUI.CloseTradeSkill()
end)
self:UnregisterEvent(event)
UIParent:RegisterEvent(event)
-- unmute sounds
UnmuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_OPEN)
UnmuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_CLOSE)
end
end
end)
function hack:OnKeyDown()
-- unregister ourselves first to avoid duplicate queries
self:SetScript('OnKeyDown', nil)
-- be silent
MuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_OPEN)
MuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_CLOSE)
-- listen for tradeskill UI opening then query it
UIParent:UnregisterEvent('TRADE_SKILL_SHOW')
self:RegisterEvent('TRADE_SKILL_SHOW')
C_TradeSkillUI.OpenTradeSkill(self.professionID)
end
function hack:GetAnyProfessionID()
-- any profession except archaeology is valid for requesting data
for index, professionIndex in next, {GetProfessions()} do
if index ~= 3 and professionIndex then
local _, _, _, _, _, _, professionID = GetProfessionInfo(professionIndex)
if professionID then
return professionID
end
end
end
end
function hack:HasProfessionData(professionID)
local skillInfo = C_TradeSkillUI.GetProfessionInfoBySkillLineID(professionID)
return skillInfo and skillInfo.maxSkillLevel and skillInfo.maxSkillLevel > 0
end