-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaux-addon.lua
312 lines (291 loc) · 8.25 KB
/
aux-addon.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
module 'aux'
include 'T'
local info = require 'aux.util.info'
local money = require 'aux.util.money'
local cache = require 'aux.core.cache'
local history = require 'aux.core.history'
local stack = require 'aux.core.stack'
local post = require 'aux.core.post'
local scan = require 'aux.core.scan'
local search_tab = require 'aux.tabs.search'
_G.aux_scale = 1
_G.aux = {
character = {},
faction = {},
realm = {},
account = {},
}
M.print = vararg-function(arg)
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. '<aux> ' .. join(map(arg, tostring), ' '))
end
local event_frame = CreateFrame'Frame'
for event in pairs(temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED')) do
event_frame:RegisterEvent(event)
end
do
local handlers, handlers2 = {}, {}
function M.set_LOAD(f)
tinsert(handlers, f)
end
function M.set_LOAD2(f)
tinsert(handlers2, f)
end
event_frame:SetScript('OnEvent', function()
if event == 'ADDON_LOADED' then
if arg1 == 'Blizzard_AuctionUI' then
Blizzard_AuctionUI()
elseif arg1 == 'Blizzard_CraftUI' then
Blizzard_CraftUI()
elseif arg1 == 'Blizzard_TradeSkillUI' then
Blizzard_TradeSkillUI()
end
elseif event == 'VARIABLES_LOADED' then
for _, f in pairs(handlers) do f() end
elseif event == 'PLAYER_LOGIN' then
for _, f in pairs(handlers2) do f() end
print('loaded - /aux')
else
_M[event]()
end
end)
end
do
local cache = {}
function LOAD()
cache.account = aux.account
do
local key = format('%s|%s', GetCVar'realmName', UnitName'player')
aux.character[key] = aux.character[key] or {}
cache.character = aux.character[key]
end
do
local key = GetCVar'realmName'
aux.realm[key] = aux.realm[key] or {}
cache.realm = aux.realm[key]
end
end
function LOAD2()
do
local key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player')
aux.faction[key] = aux.faction[key] or {}
cache.faction = aux.faction[key]
end
end
for scope in pairs(temp-S('character', 'faction', 'realm', 'account')) do
local scope = scope
M[scope .. '_data'] = function(key, init)
if not cache[scope]
then error('Cache not ready', 2)
end
cache[scope][key] = cache[scope][key] or {}
for k, v in pairs(init or empty) do
if cache[scope][key][k] == nil then
cache[scope][key][k] = v
end
end
return cache[scope][key]
end
end
end
tab_info = {}
function M.TAB(name)
local tab = O('name', name)
local env = getfenv(2)
function env.set_OPEN(f) tab.OPEN = f end
function env.set_CLOSE(f) tab.CLOSE = f end
function env.set_USE_ITEM(f) tab.USE_ITEM = f end
function env.set_CLICK_LINK(f) tab.CLICK_LINK = f end
tinsert(tab_info, tab)
end
do
local index
function get_active_tab() return tab_info[index] end
function on_tab_click(i)
CloseDropDownMenus()
do (index and active_tab.CLOSE or nop)() end
index = i
do (index and active_tab.OPEN or nop)() end
end
end
SetItemRef = vararg-function(arg)
if arg[3] ~= 'RightButton' or not index(active_tab, 'CLICK_LINK') or not strfind(arg[1], '^item:%d+') then
return orig.SetItemRef(unpack(arg))
end
local item_info = info.item(tonumber(select(3, strfind(arg[1], '^item:(%d+)'))))
if item_info then
return active_tab.CLICK_LINK(item_info)
end
end
HandleModifiedItemClick = vararg-function(arg)
if IsAltKeyDown() and active_tab and active_tab.USE_ITEM then
active_tab.USE_ITEM(info.parse_link(arg[1]))
end
end
M.orig = setmetatable({[_G]=T}, {__index=function(self, key) return self[_G][key] end})
M.hook = vararg-function(arg)
local name, object, handler
if arg.n == 3 then
name, object, handler = unpack(arg)
else
object, name, handler = _G, unpack(arg)
end
handler = handler or getfenv(3)[name]
orig[object] = orig[object] or T
assert(not orig[object][name], '"' .. name .. '" is already hooked into.')
orig[object][name], object[name] = object[name], handler
return hook
end
do
local locked
function M.get_bid_in_progress() return locked end
function M.place_bid(type, index, amount, on_success)
if locked then return end
local money = GetMoney()
PlaceAuctionBid(type, index, amount)
if money >= amount then
locked = true
local send_signal, signal_received = signal()
thread(when, signal_received, function()
do (on_success or nop)() end
locked = false
end)
thread(when, later(5), send_signal)
event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_BID_PLACED then
send_signal()
kill()
end
end)
end
end
end
do
local locked
function M.get_cancel_in_progress() return locked end
function M.cancel_auction(index, on_success)
if locked then return end
locked = true
CancelAuction(index)
local send_signal, signal_received = signal()
thread(when, signal_received, function()
do (on_success or nop)() end
locked = false
end)
thread(when, later(5), send_signal)
event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_REMOVED then
send_signal()
kill()
end
end)
end
end
function LOAD2()
AuxFrame:SetScale(aux_scale)
end
function AUCTION_HOUSE_SHOW()
AuctionFrame:Hide()
AuxFrame:Show()
tab = 1
end
function AUCTION_HOUSE_CLOSED()
post.stop()
stack.stop()
scan.abort()
tab = nil
AuxFrame:Hide()
end
function Blizzard_AuctionUI()
AuctionFrame:UnregisterEvent('AUCTION_HOUSE_SHOW')
AuctionFrame:SetScript('OnHide', nil)
hook('ShowUIPanel', vararg-function(arg)
if arg[1] == AuctionFrame then
return AuctionFrame:Show()
end
return orig.ShowUIPanel(unpack(arg))
end)
hook 'SetItemRef' 'AuctionFrameAuctions_OnEvent'
hooksecurefunc('HandleModifiedItemClick', HandleModifiedItemClick)
end
do
local function cost_label(cost)
local label = LIGHTYELLOW_FONT_COLOR_CODE .. '(Total Cost: ' .. FONT_COLOR_CODE_CLOSE
label = label .. (cost and money.to_string2(cost, nil, LIGHTYELLOW_FONT_COLOR_CODE) or GRAY_FONT_COLOR_CODE .. '---' .. FONT_COLOR_CODE_CLOSE)
label = label .. LIGHTYELLOW_FONT_COLOR_CODE .. ')' .. FONT_COLOR_CODE_CLOSE
return label
end
local function hook_quest_item(f)
f:SetScript('OnMouseUp', function()
if arg1 == 'RightButton' then
if active_tab then
tab = 1
search_tab.filter = _G[this:GetName() .. 'Name']:GetText() .. '/exact'
search_tab.execute(nil, false)
end
end
end)
end
function Blizzard_CraftUI()
hook('CraftFrame_SetSelection', vararg-function(arg)
local ret = temp-A(orig.CraftFrame_SetSelection(unpack(arg)))
local id = GetCraftSelectionIndex()
local total_cost = 0
for i = 1, GetCraftNumReagents(id) do
local link = GetCraftReagentItemLink(id, i)
if not link then
total_cost = nil
break
end
local item_id, suffix_id = info.parse_link(link)
local count = select(3, GetCraftReagentInfo(id, i))
local _, price, limited = cache.merchant_info(item_id)
local value = price and not limited and price or history.value(item_id .. ':' .. suffix_id)
if not value then
total_cost = nil
break
else
total_cost = total_cost + value * count
end
end
CraftReagentLabel:SetText(SPELL_REAGENTS .. ' ' .. cost_label(total_cost))
return unpack(ret)
end)
for i = 1, 8 do
hook_quest_item(_G['CraftReagent' .. i])
end
end
function Blizzard_TradeSkillUI()
hook('TradeSkillFrame_SetSelection', vararg-function(arg)
local ret = temp-A(orig.TradeSkillFrame_SetSelection(unpack(arg)))
local id = GetTradeSkillSelectionIndex()
local total_cost = 0
for i = 1, GetTradeSkillNumReagents(id) do
local link = GetTradeSkillReagentItemLink(id, i)
if not link then
total_cost = nil
break
end
local item_id, suffix_id = info.parse_link(link)
local count = select(3, GetTradeSkillReagentInfo(id, i))
local _, price, limited = cache.merchant_info(item_id)
local value = price and not limited and price or history.value(item_id .. ':' .. suffix_id)
if not value then
total_cost = nil
break
else
total_cost = total_cost + value * count
end
end
TradeSkillReagentLabel:SetText(SPELL_REAGENTS .. ' ' .. cost_label(total_cost))
return unpack(ret)
end)
for i = 1, 8 do
hook_quest_item(_G['TradeSkillReagent' .. i])
end
end
end
AuctionFrameAuctions_OnEvent = vararg-function(arg)
if AuctionFrameAuctions:IsVisible() then
return orig.AuctionFrameAuctions_OnEvent(unpack(arg))
end
end