-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogSkipper.lua
More file actions
142 lines (109 loc) · 4.61 KB
/
Copy pathDialogSkipper.lua
File metadata and controls
142 lines (109 loc) · 4.61 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
136
137
138
local folderName, addon = ...
-- Automate Auction House confirmation and pet charm buy confirmation.
local isHooked = false
local eventFrame = CreateFrame("Frame")
local function EventFrameScript(self, event, ...)
if event == "EQUIP_BIND_CONFIRM" then
local slot = ...
-- Cannot do this while in combat.
if not InCombatLockdown() then
EquipPendingItem(slot)
end
-- Note: USE_BIND cannot be auto-skipped. Its OnAccept calls the protected
-- function C_Item.ConfirmBindOnUse(), which requires a genuine hardware event
-- with no addon code in the call stack. Any addon-initiated call (via the
-- USE_BIND_CONFIRM event handler or a programmatic Button1:Click()) triggers
-- ADDON_ACTION_FORBIDDEN. Unlike EQUIP_BIND, which uses the unprotected
-- EquipPendingItem(), there is no addon-accessible way to confirm use-bind.
elseif event == "ADDON_LOADED" then
local addonName = ...
if addonName == "LudiusPlus" then
self:UnregisterEvent("ADDON_LOADED")
addon.SetupOrTeardownDialogSkipper()
end
end
end
local function SetupDialogSkipper()
-- print("SetupDialogSkipper")
eventFrame:SetScript("OnEvent", EventFrameScript)
-- Only register EQUIP_BIND_CONFIRM if skipEquipBind is enabled.
if LP_config.dialogSkipper_skipEquipBind then
eventFrame:RegisterEvent("EQUIP_BIND_CONFIRM")
else
-- If skipEquipBind is disabled, ensure the event is unregistered.
eventFrame:UnregisterEvent("EQUIP_BIND_CONFIRM")
end
-- Hook StaticPopup_Show only once
if not isHooked then
hooksecurefunc("StaticPopup_Show", function(which, args)
if not LP_config or not LP_config.dialogSkipper_enabled then return end
if InCombatLockdown() then return end
local ok = false
if which == "BUYOUT_AUCTION" and LP_config.dialogSkipper_skipAuction then
ok = true
elseif which == "EQUIP_BIND_REFUNDABLE" and LP_config.dialogSkipper_skipEquipBind then
ok = true
elseif which == "CONFIRM_PURCHASE_NONREFUNDABLE_ITEM" and LP_config.dialogSkipper_skipPetCharm then
local polishedPetCharmName = GetItemInfo(163036)
if type(args) == "string" and polishedPetCharmName and string.find(args, polishedPetCharmName) then
ok = true
end
elseif which == "CONFIRM_PURCHASE_TOKEN_ITEM" then
if LP_config.dialogSkipper_skipOrderResources then
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(1220)
local currencyName = currencyInfo and currencyInfo.name
if type(args) == "string" and currencyName and string.find(args, currencyName) then
ok = true
end
end
if not ok and LP_config.dialogSkipper_skipOrderResources then
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(3363)
local currencyName = currencyInfo and currencyInfo.name
if type(args) == "string" and currencyName and string.find(args, currencyName) then
ok = true
end
end
if not ok and LP_config.dialogSkipper_skipDragonIslesSupplies then
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(2003)
local currencyName = currencyInfo and currencyInfo.name
if type(args) == "string" and currencyName and string.find(args, currencyName) then
ok = true
end
end
end
if not ok then return end
for i = 1, 10 do
local frame = _G["StaticPopup" .. i]
if frame and frame:IsShown() and frame.which and frame.which == which then
-- Only confirm when price is below limit.
if which == "BUYOUT_AUCTION" then
local money = _G["StaticPopup" .. i .. "MoneyFrame"].staticMoney
if money > LP_config.dialogSkipper_auctionPriceLimit then return end
end
-- Confirm the popup.
_G["StaticPopup" .. i .. "Button1"]:Click("LeftButton")
-- Also click the back button to return to the overview of items to buy.
if LP_config.dialogSkipper_auctionBackButton and AuctionHouseFrame then
AuctionHouseFrame.ItemBuyFrame.BackButton:Click("LeftButton")
end
end
end
end)
isHooked = true
end
end
local function TeardownDialogSkipper()
-- print("TeardownDialogSkipper")
eventFrame:UnregisterEvent("EQUIP_BIND_CONFIRM")
eventFrame:SetScript("OnEvent", nil)
end
function addon.SetupOrTeardownDialogSkipper()
if LP_config and LP_config.dialogSkipper_enabled then
SetupDialogSkipper()
else
TeardownDialogSkipper()
end
end
-- Initialize when addon loads
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", EventFrameScript)