-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcurtracker.lua
More file actions
404 lines (370 loc) · 11.1 KB
/
curtracker.lua
File metadata and controls
404 lines (370 loc) · 11.1 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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
--Currency Tracker by erupt@asura.
--After you load the lua for the first time just edit the settings.xml from /data and reload the lua
--to have your new fields displayed. Curlines dictates how many fields you would like per line on your box.
--
-- ** Commands **
-- //curt on|off
-- //curt add <search term>
-- //curt del <search term>
-- //curt field_color <red> <green> <blue>
-- //curt value_color <red> <green> <blue>
-- //curt size <text size>
-- //curt refresh <Seconds to refresh currencies>
-- //curt alpha <background transparency> 0-255
-- //curt profile <Add Profile>
-- Profiles will add multiple fields at once. Refer to the profiles.lua file
-- to view options.
--
-- ex. //curt add Snowdim
-- Returns that this matched multiple results
-- //curt add Snowdim 2
-- ex. //curt add Snowdim *
-- Adds multiple entries matching Snowdim
--
-- ** Version History **
-- v1.3 - Added profiles
-- v1.2 - Again changed how config saves to avoid conflicts with alts.
-- v1.1 - Fixed some issues with character specific settings.
-- v1.0 - Rewrote the saving and loading of currency types to just use whatever is found
-- in the packets library so no updates are needed.
-- v0.4 - Add commands to disable refresh, search and change fields from addon command
-- v0.3 - Add all fields to a table which can just be enabled/disabled through settings.xml
-- v0.2 - Fix Windower fields.lua to correct Unity Accolades memory location
-- v0.1 - Initial Test Release
_addon.author = 'Erupt'
_addon.commands = {'curtracker','curt'}
_addon.name = 'CurTracker'
_addon.version = '1.3.080920'
require('logger')
require('tables')
require('sets')
files = require('files')
texts = require('texts')
config = require('config')
res = require('resources')
packets = require('packets')
profiles = require('profiles')
curfields = {}
for i,v in ipairs(T(packets.raw_fields.incoming[0x118])) do
v = v['label']
curfields[v:lower()] = v
end
for i,v in ipairs(T(packets.raw_fields.incoming[0x113])) do
v = v['label']
curfields[v:lower()] = v
end
default = {
text = {
size = 10,
},
curtracking = true,
curlines = 2,
currefresh = 60,
curfields = S{},
field_color = {
red = 0,
green = 255,
blue = 255,
},
value_color = {
red = 255,
green = 255,
blue = 255,
},
pos = {
x = 0,
y = 0,
}
}
settings = config.load(default)
cur1packet = {}
cur2packet = {}
cursearches = {}
curpackettype = 0
thread_name = ''
last_player = ''
cur_box = function()
local str = '[\\cs(255,215,0)Currency Tracker\\cr]:\\cs(200,200,200):.\\cr\\cs(150,150,150)..\\cr\\cs(50,50,50). .\\cr \\cs(10,10,10).\\cr\n'
if not cur2packet['Coalition Imprimaturs'] then return end
curlinecnt = 0
for v in settings.curfields:it() do
if v ~= '' then
if curlinecnt >= settings.curlines then
str = str..'\n'
curlinecnt = 0
end
v = curfields[v:lower()]
if not cur1packet[v] then
str = str..'[\\cs('..settings.field_color.red..','..settings.field_color.green..','..settings.field_color.blue..')'..v..'\\cr] = \\cs('..settings.value_color.red..','..settings.value_color.green..','..settings.value_color.blue..')'..cur2packet[v]..' \\cr'
curlinecnt = curlinecnt+1
else
str = str..'[\\cs('..settings.field_color.red..','..settings.field_color.green..','..settings.field_color.blue..')'..v..'\\cr] = \\cs('..settings.value_color.red..','..settings.value_color.green..','..settings.value_color.blue..')'..cur1packet[v]..' \\cr'
curlinecnt = curlinecnt+1
end
end
end
curpackettype = 0
return str
end
cur_trackbox = texts.new(settings)
search_data = {}
function search_curs(curs)
local search = string.gsub(curs," ",".*")
search_data = {}
local search_cnt = 0
search = string.lower(".*"..search..".*")
for l,u in pairs(curfields) do
if string.match(l,search) then
table.insert(search_data,u)
search_cnt = search_cnt+1
end
end
return search_cnt
end
function log(str)
windower.add_to_chat(207, _addon.name..': '..str)
end
function cur_command(cmd,...)
if not cmd then --do help when I stop being lazy
return
else
cmd = cmd:lower()
end
local commands = T{...}
local commands_joined = string.gsub(table.concat(commands," "),'*','')
if cmd == "on" then
log('Set to on')
if not settings.curtracking then
settings.curtracking = true
send_request()
else
log('Already Enabled')
end
return
elseif cmd == "off" then
log('Set to off')
settings.curtracking = false
cur_trackbox:hide()
return
elseif cmd == 'refresh' then
if not commands[1] then
log('Missing Refresh Number')
return
end
settings.currefresh = tonumber(commands[1])
log('Changed Refresh time to '..settings.currefresh..'s')
config.save(settings,'all')
elseif cmd == 'alpha' then
if not commands[1] then
log('Missing Alpha Number')
return
end
settings.bg_alpha = tonumber(commands[1])
texts.bg_alpha(cur_trackbox,settings.bg_alpha)
config.save(settings,'all')
cur_trackbox:text(cur_box())
cur_trackbox:show()
elseif cmd == 'size' then
if not commands[1] then
log('Missing Text Size Number')
return
end
settings.text.size = tonumber(commands[1])
texts.size(cur_trackbox,settings.text.size)
config.save(settings,'all')
cur_trackbox:text(cur_box())
cur_trackbox:show()
elseif cmd == 'value_color' then
if #commands < 3 then
log('Missing a Color')
return
end
settings.value_color.red = tonumber(commands[1])
settings.value_color.green = tonumber(commands[2])
settings.value_color.blue = tonumber(commands[3])
config.save(settings,'all')
cur_trackbox:text(cur_box())
cur_trackbox:show()
elseif cmd == 'field_color' then
if #commands < 3 then
log('Missing a Color')
return
end
settings.field_color.red = tonumber(commands[1])
settings.field_color.green = tonumber(commands[2])
settings.field_color.blue = tonumber(commands[3])
config.save(settings,'all')
cur_trackbox:text(cur_box())
cur_trackbox:show()
elseif cmd == 'profile' then
if not commands[1] then
log(' Usage: //curt profile Profile_Name')
log(' Options: '..string.sub(table.concat(profiles:keyset(),','),1,-2))
return
end
if profiles[commands[1]] then
settings.curfields = S{}
for v in profiles[commands[1]]:it() do
settings.curfields:add(v:lower())
end
log('Set to: '..string.sub(table.concat(profiles[commands[1]],','),1,-2))
config.save(settings,'all')
cur_trackbox:text(cur_box())
cur_trackbox:show()
return
else
log(commands[1]..' Not a valid option')
log(' Options: '..string.sub(table.concat(profiles:keyset(),','),1,-2))
return
end
elseif cmd == "add" then
if not commands[1] then
log(' Usage: //curt add Currency Name')
return
end
local search_result = search_curs(commands_joined)
if search_result>0 then
if search_result == 1 then
if settings.curfields:contains(search_data[1]) then
log(search_data[1]..' Already added to tracker')
return
end
log('Adding: '..search_data[1])
settings.curfields:add(search_data[1]:lower())
config.save(settings,'all')
return
elseif search_result > 1 then
if search_result > 5 then
log(' Too many results matched your pattern, narrow it down')
return
end
local results = ''
for k,v in pairs(search_data) do
if k > 1 then results = results..', ' end
results = results..v
end
if commands[#commands] == '*' then
for k,v in pairs(search_data) do
settings.curfields:add(v:lower())
end
log(' Added: '..results)
config.save(settings,'all')
return
else
log('Multiple Results: '..results)
log('** To add all these results append search with "*"')
return
end
end
else
log('Did not match any known currencies')
return
end
elseif cmd == 'del' then
if not commands[1] then
log(' Usage: //curt del Currency Name')
return
end
local search_result = search_curs(commands_joined)
if search_result>0 then
if search_result == 1 then
log('Deleting: '..search_data[1])
settings.curfields:remove(search_data[1]:lower())
config.save(settings,'all')
return
elseif search_result > 1 then
if search_result > 5 then
log(' Too many results matched your pattern, narrow it down')
return
end
local results = ''
for k,v in pairs(search_data) do
if k > 1 then results = results..', ' end
results = results..v
end
if commands[#commands] == '*' then
for k,v in pairs(search_data) do
settings.curfields:remove(v:lower())
end
log(' Deleted: '..results)
config.save(settings,'all')
return
else
log('Multiple Results: '..results)
log('** To delete all these results append search with "*"')
return
end
end
else
log('Did not match any known currencies')
return
end
end
end
function check_incoming_chunk(id,original,modified,injected,blocked)
if settings.curtracking == false then return end
if id == 0x118 then
cur2packet = packets.parse('incoming', original)
end
if id == 0x113 then
cur1packet = packets.parse('incoming',original)
-- print(original)
return
end
if curpackettype == 2 then
cur_trackbox:text(cur_box())
cur_trackbox:show()
pos_x,pos_y = texts.pos(cur_trackbox)
settings.pos.x = pos_x
settings.pos.y = pos_y
config.save(settings)
thread_name = coroutine.schedule(send_request,settings.currefresh or 120)
end
end
function check_outgoing_chunk(id,data)
if id == 0x115 then
local packet = packets.parse('outgoing',data)
--print(packet)
end
end
function send_request()
if curpackettype == 0 then
local packet = packets.new('outgoing',0x10F)
curpackettype = 1
packets.inject(packet)
coroutine.schedule(send_request,5)
return
end
if curpackettype == 1 then
local packet = packets.new('outgoing',0x115)
curpackettype = 2
packets.inject(packet)
return
end
end
incoming_chunk = windower.register_event('incoming chunk', check_incoming_chunk)
outgoing_chunk = windower.register_event('outgoing chunk', check_outgoing_chunk)
windower.register_event('login', function()
if windower.ffxi.get_info().logged_in then
last_player = windower.ffxi.get_player().name
settings = config.load('data/'..last_player..'.xml',default)
cur_trackbox:pos(settings.pos.x,settings.pos.y)
if thread_name == '' then
coroutine.schedule(send_request,60)
end
end
end)
windower.register_event('logout', function()
config.save(settings)
settings.curtracking = false
send_command('lua r curtracker')
end)
windower.register_event('load', function()
if windower.ffxi.get_info().logged_in then
last_player = windower.ffxi.get_player().name
settings = config.load('data/'..last_player..'.xml',default)
cur_trackbox:pos(settings.pos.x,settings.pos.y)
coroutine.schedule(send_request,60)
end
end)
windower.register_event('addon command', cur_command)