-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathHSBatching.lua
More file actions
135 lines (120 loc) · 4.52 KB
/
Copy pathHSBatching.lua
File metadata and controls
135 lines (120 loc) · 4.52 KB
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
local _, addon = ...
-- Allows you to set your hearthstone as you teleport away to your previous location at the end of the hearthstone cast.
-- Only works if the binding confirmation and the HS spell cast are processed in the same batch (<10ms as of patch 1.14)
local HSframe = CreateFrame("Frame");
local currentFPS = GetCVar("maxfps")
local HSstart = 0
local barLabel = "Hearthstone"
local batchingWindow = 0.006
local bindConfirmation = string.gsub(CONFIRM_BINDER,"%%s",".-")
local IsCurrentSpell = C_Spell and C_Spell.IsCurrentSpell or _G.IsCurrentSpell
local GetSpellInfo = C_Spell and C_Spell.GetSpellInfo and addon.GetSpellInfo or _G.GetSpellInfo
local GetItemInfoInstant = C_Item and C_Item.GetItemInfoInstant or _G.GetItemInfoInstant
local GetContainerItemID = C_Container and C_Container.GetContainerItemID or _G.GetContainerItemID
local ConfirmBinder
if C_PlayerInteractionManager and C_PlayerInteractionManager.ConfirmationInteraction and Enum and Enum.PlayerInteractionType and Enum.PlayerInteractionType.Binder then
ConfirmBinder = function()
return C_PlayerInteractionManager.ConfirmationInteraction(Enum.PlayerInteractionType.Binder)
end
else
ConfirmBinder = _G.ConfirmBinder
end
local function StopHSTimer()
HSframe:SetScript("OnUpdate", nil)
SetCVar("maxfps", currentFPS)
HSstart = 0
addon.isCastingHS = false
addon.StopTimer(barLabel)
end
local function SwitchBindLocation()
if GetTime() - HSstart > 10 - batchingWindow then
ConfirmBinder()
StopHSTimer()
elseif GetFramerate() < 20 then
SetCVar("maxfps", currentFPS)
end
addon.isCastingHS = false
end
--[[
hooksecurefunc("SetCVar",function(n,v)
if n == "maxfps" then
print(n,v)--ok
C_Timer.After(1,function()
print(GetCVar("maxfps"))
end)
end
end)
]]
local function StartHSTimer()
if HSstart == 0 and addon.settings.profile.enableHSbatch then
local size = addon.settings.profile.batchSize or 6
batchingWindow = size / 1e3
currentFPS = GetCVar("maxfps")
HSstart = GetTime()
HSframe:SetScript("OnUpdate", SwitchBindLocation)
local text = _G.StaticPopup1 and (_G.StaticPopup1.text or _G.StaticPopup1.Text)
local bind = text and text:GetText() or ""
if bind:find(bindConfirmation) then
SetCVar("maxfps", "300")
addon.isCastingHS = 0.5
addon.StartTimer(10-batchingWindow, barLabel)
end
end
end
HSframe:SetScript("OnEvent", function(self, event, ...)
if event == "UNIT_SPELLCAST_INTERRUPTED" then
local unitTarget, _, spellID = ...
-- Player interrupted Hearthstone cast
if unitTarget == "player" and spellID == 8690 then
if HSstart > 0 then StopHSTimer() end
end
end
end)
HSframe:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
-- Using HS from bags
if _G.C_Container and _G.C_Container.UseContainerItem then -- DF+
hooksecurefunc(C_Container, "UseContainerItem", function(bag, slot)
if GetContainerItemID(bag, slot) == 6948 then StartHSTimer() end
end)
else
hooksecurefunc("UseContainerItem", function(bag, slot)
if GetContainerItemID(bag, slot) == 6948 then StartHSTimer() end
end)
end
-- Using HS from the active item frame
if C_Item and C_Item.UseItemByName then -- DF+
hooksecurefunc(C_Item, "UseItemByName", function(itemInfo)
if GetItemInfoInstant(itemInfo) == 6948 then StartHSTimer() end
end)
else
hooksecurefunc("UseItemByName", function(itemInfo)
if GetItemInfoInstant(itemInfo) == 6948 then StartHSTimer() end
end)
end
-- Astral Recall
hooksecurefunc("CastSpellByName", function(spellName)
if spellName == GetSpellInfo(556) then StartHSTimer() end
end)
-- Astral Recall
hooksecurefunc("CastSpellByID", function(spellID)
if spellID == 556 then StartHSTimer() end
end)
hooksecurefunc("UseAction", function(...)
local event, id = GetActionInfo(...)
if (event == "item" and id == 6948) or (event == "macro" and (IsCurrentSpell(8690) or IsCurrentSpell(556))) or (event == "spell" and id == 556) then
StartHSTimer()
end
end)
local binderPopup = _G.StaticPopupDialogs and _G.StaticPopupDialogs.CONFIRM_BINDER
if binderPopup then
if binderPopup.OnCancel then
hooksecurefunc(binderPopup, "OnCancel", function()
if HSstart > 0 then StopHSTimer() end
end)
end
if binderPopup.OnAccept then
hooksecurefunc(binderPopup, "OnAccept", function()
if HSstart > 0 then StopHSTimer() end
end)
end
end