-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathgen_option_values.lua
1466 lines (1373 loc) · 42.7 KB
/
gen_option_values.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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Script to parse boss module files and output ability=>color/sound mappings
local loadstring = loadstring or load -- 5.2 compat
local opt = {}
local modules = {}
local modules_bosses = {}
local modules_locale = {}
local module_colors = {}
local module_sounds = {}
local default_options = {
altpower = {ALTPOWER = true},
infobox = {INFOBOX = true},
proximity = {PROXIMITY = true},
}
local valid_colors = {
green = true,
blue = true,
yellow = true,
orange = true,
red = true,
cyan = true,
purple = true,
}
local valid_sounds = {
info = true,
alert = true,
alarm = true,
long = true,
warning = true,
underyou = true,
}
local color_methods = {
MessageOld = 2,
Message = 2,
TargetMessageOld = 3,
TargetMessage = 2,
TargetsMessageOld = 2,
TargetsMessage = 2,
StackMessageOld = 4,
StackMessage = 2,
DelayedMessage = 3,
}
local sound_methods = {
PlaySound = 2,
MessageOld = 3,
SetPrivateAuraSound = 3,
TargetMessageOld = 4,
StackMessageOld = 5,
DelayedMessage = 6,
}
local icon_methods = {
MessageOld = 5,
Message = 4,
TargetMessageOld = 6,
TargetMessage = 5,
TargetsMessageOld = 6,
TargetsMessage = 6,
StackMessageOld = 7,
StackMessage = 7,
PersonalMessage = 4,
Bar = 4,
CDBar = 4,
CastBar = 4,
TargetBar = 5,
Flash = 2,
}
local removed_methods = {
Message2 = true,
TargetMessage2 = true,
Yell2 = true,
NameplateBar = true,
NameplateCDBar = true,
StopNameplateBar = true,
SetPrivateAuraSound = true,
}
local valid_methods = {
CastBar = "CASTBAR",
PrimaryIcon = "ICON",
SecondaryIcon = "ICON",
Flash = "FLASH",
Say = "SAY",
SayCountdown = "SAY_COUNTDOWN",
CancelSayCountdown = "SAY_COUNTDOWN",
Yell = "SAY",
YellCountdown = "SAY_COUNTDOWN",
CancelYellCountdown = "SAY_COUNTDOWN",
OpenAltPower = "ALTPOWER",
CloseAltPower = "ALTPOWER",
OpenProximity = "PROXIMITY",
CloseProximity = "PROXIMITY",
OpenInfo = "INFOBOX",
SetInfoByTable = "INFOBOX",
SetInfoTitle = "INFOBOX",
SetInfo = "INFOBOX",
SetInfoBar = "INFOBOX",
CloseInfo = "INFOBOX",
Nameplate = "NAMEPLATE",
StopNameplate = "NAMEPLATE",
PauseBar = true,
ResumeBar = true,
}
local tracked_bitflags = {
["CASTBAR"] = true,
["ICON"] = true,
["FLASH"] = true,
["SAY"] = true,
["SAY_COUNTDOWN"] = true,
["ALTPOWER"] = true,
["PROXIMITY"] = true,
["INFOBOX"] = true,
["NAMEPLATE"] = true,
}
local function add_valid_methods(t)
for k in next, t do
if not valid_methods[k] then
valid_methods[k] = true
end
end
end
add_valid_methods(color_methods)
add_valid_methods(sound_methods)
add_valid_methods(icon_methods)
add_valid_methods(removed_methods)
local log_events = {
["SWING_DAMAGE"] = true,
["SWING_MISSED"] = true,
["RANGE_DAMAGE"] = true,
["RANGE_MISSED"] = true,
["SPELL_ABSORBED"] = true,
["SPELL_AURA_APPLIED"] = true,
["SPELL_AURA_APPLIED_DOSE"] = true,
["SPELL_AURA_BROKEN"] = true,
["SPELL_AURA_BROKEN_SPELL"] = true,
["SPELL_AURA_REFRESH"] = true,
["SPELL_AURA_REMOVED"] = true,
["SPELL_AURA_REMOVED_DOSE"] = true,
["SPELL_CAST_FAILED"] = true,
["SPELL_CAST_START"] = true,
["SPELL_CAST_SUCCESS"] = true,
["SPELL_CREATE"] = true,
["SPELL_DAMAGE"] = true,
["SPELL_DISPEL"] = true,
["SPELL_DISPEL_FAILED"] = true,
["SPELL_DRAIN"] = true,
["SPELL_DURABILITY_DAMAGE"] = true,
["SPELL_DURABILITY_DAMAGE_ALL"] = true,
["SPELL_ENERGIZE"] = true,
["SPELL_EXTRA_ATTACKS"] = true,
["SPELL_HEAL"] = true,
["SPELL_INSTAKILL"] = true,
["SPELL_INTERRUPT"] = true,
["SPELL_LEECH"] = true,
["SPELL_MISSED"] = true,
["SPELL_RESURRECT"] = true,
["SPELL_STOLEN"] = true,
["SPELL_SUMMON"] = true,
["SPELL_PERIODIC_DAMAGE"] = true,
["SPELL_PERIODIC_DRAIN"] = true,
["SPELL_PERIODIC_ENERGIZE"] = true,
["SPELL_PERIODIC_HEAL"] = true,
["SPELL_PERIODIC_LEECH"] = true,
["SPELL_PERIODIC_MISSED"] = true,
["SPELL_BUILDING_DAMAGE"] = true,
["SPELL_BUILDING_HEAL"] = true,
["SPELL_EMPOWER_START"] = true,
["SPELL_EMPOWER_END"] = true,
["SPELL_EMPOWER_INTERRUPT"] = true,
["ENVIRONMENTAL_DAMAGE"] = true,
["DAMAGE_SHIELD"] = true,
["DAMAGE_SHIELD_MISSED"] = true,
["DAMAGE_SPLIT"] = true,
["PARTY_KILL"] = true,
["UNIT_DIED"] = true,
["UNIT_DESTROYED"] = true,
["UNIT_DISSIPATES"] = true,
}
local standard_args_keys = {
time = true,
sourceGUID = true,
sourceName = true,
sourceFlags = true,
sourceRaidFlags = true,
destGUID = true,
destName = true,
destFlags = true,
destRaidFlags = true,
spellId = true,
spellName = true,
spellSchool = true,
extraSpellId = true,
extraSpellName = true,
amount = true,
}
local unit_died_args_keys = {
mobId = true,
destGUID = true,
destName = true,
destFlags = true,
destRaidFlags = true,
time = true,
}
-- Set an exit code if we show an error.
local exit_code = 0
local error, warn, info
if os.execute("tput colors >/dev/null 2>&1") then
function error(msg)
print("\27[31m" .. msg .. "\27[0m") -- red
exit_code = 1
end
function warn(msg)
print("\27[33m" .. msg .. "\27[0m") -- orange
end
function info(msg)
print("\27[36m" .. msg .. "\27[0m") -- cyan
end
else
function error(msg)
print(msg)
exit_code = 1
end
warn = print
info = print
end
local function print(...)
if opt.quiet then return end
_G.print(...)
end
-- Return a table containing the value if value is not a table.
local function tablize(value)
if type(value) ~= "table" then
value = { value }
end
return value
end
-- Remove outer quotes.
local function unquote(str)
if type(str) == "string" then
return str:match("^%s*\"(.-)\"%s*$") or str
end
return str
end
-- Break apart and/or assignments and return the conditional results.
local function unternary(str, pattern, validate_table)
if type(str) == "string" then
local matches = {}
for m in str:gmatch(" and "..pattern) do
if not validate_table or validate_table[m] then
matches[#matches+1] = m
end
end
for m in str:gmatch(" or "..pattern) do
if not validate_table or validate_table[m] then
matches[#matches+1] = m
end
end
if #matches > 0 then
return matches
end
end
return str
end
local function contains(t, v)
for _, value in next, t do
if value == v then
return true
end
end
return false
end
-- Removes some things that break simple comma splitting.
local function clean(str)
-- :Dispeller() || :format() || UnitIsUnit()
str = str:gsub("(:?%a+)%b()", "%1")
return str
end
-- Strip whitespace from the start and end of a string.
local function strtrim(str)
return str:match("^%s*(.-)%s*$")
end
-- Split a string at commas and return a table with the results.
local function strsplit(str)
local t = {}
str:gsub("([^,]+)", function(s) t[#t+1] = strtrim(s) end)
return t
end
local function cmp(a, b)
if type(a) == "number" and type(b) == "number" then
return a < b
end
return string.lower(a) < string.lower(b)
end
local function sortKeys(keys)
local t = {}
for key in next, keys do
t[#t+1] = key
end
table.sort(t, cmp)
return t
end
-- Write out a module option values to [module dir]/Options/[value].lua
local function dumpValues(path, name, modules_table, options_table)
local file = path .. name .. ".lua"
local old_data = ""
local f = io.open(file, "r")
if f then
old_data = f:read("*all")
f:close()
end
local data = ""
for _, mod in ipairs(modules_table) do
local options = options_table[mod] or {}
data = data .. string.format("\r\nBigWigs:Add%s(%q, {\r\n", name, mod)
for _, key in ipairs(sortKeys(options)) do
local values = options[key]
if type(key) == "string" then key = string.format("%q", key) end
if #values == 1 then
data = data .. string.format("\t[%s] = %q,\r\n", key, values[1])
else
table.sort(values, cmp)
for i = 1, #values do
values[i] = string.format("%q", values[i])
end
data = data .. string.format("\t[%s] = {%s},\r\n", key, table.concat(values, ","))
end
end
data = data .. "})\r\n"
end
if data == "" then
data = "-- Don't error because I'm empty, please.\r\n"
end
if data:gsub("\r", "") ~= old_data:gsub("\r", "") then
if not opt.dryrun then
f = io.open(file, "wb")
if not f then
error(string.format(" %s: File not found!", file))
else
f:write(data)
f:close()
info(" Updated " .. file)
end
else
info(" Updated " .. file .. " (skipped)")
end
end
end
local function add(module_name, option_table, keys, value)
if not option_table[module_name] then
option_table[module_name] = {}
end
for _, key in next, tablize(keys) do
key = tonumber(key) or key
if not option_table[module_name][key] then
option_table[module_name][key] = {}
end
-- Only add once per key.
local found = nil
for _, v in next, option_table[module_name][key] do
if value == v then
found = true
break
end
end
if not found then
table.insert(option_table[module_name][key], value)
end
end
end
local function findCalls(lines, start, local_func, options)
local keys = {}
local func, if_key = nil, nil
for i = start+1, #lines do
local line = lines[i]:gsub("%s*%-%-.+$", "") -- strip out comments
local res = line:match("^%s*function%s+[%w_]+[.:]([%w_]+)%s*%(")
if res then
func = res
if_key = nil
end
res = line:match("^%s*local function%s+([%w_]+)%s*%(")
if res then
func = nil
if_key = nil
if res == local_func then
-- redefined?! we shouldn't be here...
break
end
end
res = line:match("if (.+) then")
if res and line:match("spellId == %d+") then
if_key = {}
for m in res:gmatch("spellId == (%d+)") do
if_key[#if_key+1] = m
end
end
if func then -- make sure we're out of the local function
if line:match(":ScheduleTimer%(%s*"..local_func.."%s*,") or
line:match(":ScheduleRepeatingTimer%(%s*"..local_func.."%s*,") or
line:match("^%s*"..local_func.."%s*%(")
then
if func and options[func] then
for _, k in next, options[func] do
keys[#keys+1] = k
end
end
if if_key then
for _, k in next, if_key do
keys[#keys+1] = k
end
end
func, if_key = nil, nil
end
end
end
return #keys > 0 and keys or nil
end
local function parseGetOptions(file_name, lines, start, special_options)
local chunk = nil
for i = start, #lines do
if i == start and lines[i]:match("^%s*return {.+}%s*$") then
-- old style one line options
chunk = lines[i]
break
end
-- if lines[i]:match("^%s*},%s*{") or lines[i]:match("^%s*},%s*nil,%s*{") then
-- -- we don't want to parse headers or altnames (to avoid setfenv) so stop here
-- chunk = table.concat(lines, "\n", start, i-1) .. "\n}"
-- -- TODO string parse the other tables for duplicates
-- break
-- -- end
-- if lines[i]:match("^%s*end") then
-- chunk = table.concat(lines, "\n", start, i-1) -- no headers, so we need to back up to the }
-- break
-- end
if lines[i]:match("^%s*}%s*$") then
chunk = table.concat(lines, "\n", start, i)
break
end
end
if not chunk or chunk == "" then
return false, "Something is wrong."
end
local chunk_func
do
-- sigh.
local s = setmetatable({}, { __index = function(t, k) return tostring(k) end })
local mod = {
SpellName = function(k) return tostring(k) end
}
local options_env = setmetatable({
CL = s,
L = s,
self = mod,
mod = mod,
}, {
__index = function(t, k)
if special_options[k] then return "custom_off_" .. k end
return k
end
})
if setfenv then
local f, err = loadstring(chunk, "optionstable")
if err then
return false, err
end
setfenv(f, options_env)
chunk_func = f
else
local f, err = load(chunk, "optionstable", "t", options_env)
if err then
return false, err
end
chunk_func = f
end
end
local success, toggles, headers, altNames = pcall(chunk_func)
if not success then
return success, toggles
end
local options, option_flags = {}, {}
for _, opt in next, toggles do
local flags = true
if type(opt) == "table" then
flags = {}
for i=2, #opt do
flags[opt[i]] = true
end
opt = opt[1]
end
if opt then -- marker option vars will be nil
if default_options[opt] then
flags = default_options[opt]
end
if options[opt] then
error(string.format(" %s:%d: Duplicate option key %q", file_name, start, tostring(opt)))
else
options[opt] = flags
end
end
end
if headers then
for key in next, headers do
if not options[key] then
error(string.format(" %s:%d: Invalid option header key %q", file_name, start, tostring(key)))
end
end
end
if altNames then
for key, name in next, altNames do
if not options[key] then
error(string.format(" %s:%d: Invalid option alt name key %q", file_name, start, tostring(key)))
end
end
end
return options
end
local function checkForAPI(line)
for method in next, valid_methods do
if line:find(method, nil, true) then
return true
end
end
return false
end
-- Read boss module file and parse it for colors and sounds.
local function parseLua(file)
local file_name = file:match(".*/(.*)$") or file
if opt.quiet then
file_name = file
end
local f = io.open(file, "r")
if not f then
error(string.format(" \"%s\" not found!", file_name))
return
end
local data = f:read("*all")
f:close()
-- First, check to make sure this is actually a boss module file.
local module_name, module_args = data:match("\nlocal mod.*= BigWigs:NewBoss%(\"(.-)\",?%s*([^)]*)")
if not module_name then
return
end
if module_args ~= "" then
local args = strsplit(module_args)
local ej_id = tonumber(args[2])
if ej_id and ej_id > 0 then
if modules_bosses[ej_id] then
error(string.format(" %s:%d: Module \"%s\" is using journal id %d, which is already used by module \"%s\"", file_name, 1, module_name, ej_id, modules_bosses[ej_id]))
else -- execution isn't stopped, don't overwrite the original module name
modules_bosses[ej_id] = module_name
end
end
end
-- `modules` is used output the boss modules in the order they were parsed.
table.insert(modules, module_name)
modules_locale[module_name] = {}
-- Split the file into a table
local lines = {}
for line in data:gmatch("(.-)\r?\n") do
lines[#lines+1] = line
end
local module_encounter_id, module_set_stage = nil, nil
local locale, common_locale = modules_locale[module_name], modules_locale["BigWigs: Common"]
local options, option_keys, option_key_used, bitflag_used = {}, {}, {}, {}
local options_block_start = 0
local special_options = {}
local methods, registered_methods, unit_died_methods, mob_engaged_methods = {Win=true,Disable=true}, {}, {}, {}
local event_callbacks = {}
local current_func = nil
local args_keys = standard_args_keys
local rep = {} -- key replacements
for n, line in ipairs(lines) do
-- save and strip comment
local comment = ""
if line:match("^%s*%-%-") then -- shortcut for full line comments
comment = line:gsub("^%s*%-%-%s*", "")
line = ""
else
-- pop off comments from the end (trying to protect strings)
while line:gsub('%b""', ''):match("%-%-") do
local new_line = line:reverse()
local start, stop = new_line:find("--", nil, true)
comment = comment .. new_line:sub(1, stop):reverse()
line = new_line:sub(stop + 1):reverse()
end
end
-- set some module flags
if line:match("^mod:SetEncounterID") then
module_encounter_id = true
end
if line:match("^mod:SetStage") then
module_set_stage = true
else
local method = line:match(":([GS]etStage)%(")
if method and not module_set_stage then
error(string.format(" %s:%d: %s: Missing initial mod:SetStage!", file_name, n, method))
module_set_stage = true
end
end
-- save marker and autotalk options
do
local var = line:match("(%w+) = .*:AddMarkerOption%(")
if var then
special_options[var] = true
end
var = line:match("(%w+) = .*:AddAutoTalkOption%(")
if var then
special_options[var] = true
end
end
-- locale checking
do
-- save module locale
-- multiple definitions on one line
if line:match("^%sL%.[%w_]+%s*,.+=.+") then -- we're setting things, right?
for locale_key in line:gmatch("L%.([%w_]+)%s*,%s*") do
locale[locale_key] = true
end
end
local locale_key, locale_value = line:match("L%.([%w_]+)%s*=%s*(.*)")
if not locale_key then
locale_key, locale_value = line:match("L%[\"(.+)\"%]%s*=%s*(.*)")
end
if locale_key and locale[locale_key] == nil then
locale_value = strtrim(locale_value)
-- check if we're all replacement tokens
local v = locale_value:gsub("%b{}", ""):gsub("\\n", "")
if v == '""' then locale_value = "" end
locale[locale_key] = locale_value:sub(1,1) == "{" or locale_value ~= unquote(locale_value)
end
end
-- check usage
for locale_type, locale_key, extra in line:gsub("L%[\"([%w_]+)\"%]", "L.%1"):gmatch("(C?L)%.([%w_]+)(%(?)") do
if locale_type == "CL" then
-- CL is only set in the main project
if common_locale and not common_locale[locale_key] then
error(string.format(" %s:%d: Invalid locale string \"CL.%s\"", file_name, n, locale_key))
end
elseif locale_type == "L" and locale[locale_key] == nil then
error(string.format(" %s:%d: Invalid locale string \"L.%s\"", file_name, n, locale_key))
end
-- trying to invoke the string (missing :format)
if extra == "(" then
error(string.format(" %s:%d: Missing locale string format \"%s.%s(\"", file_name, n, locale_type, locale_key))
end
end
--- loadstring the options table
if line:find("function mod:GetOptions(", nil, true) then
local opts, err = parseGetOptions(file_name, lines, n+1, special_options)
if not opts then
-- rip keys
error(string.format(" %s:%d: Error parsing GetOptions! %s", file_name, n, err))
return
else
if not next(option_keys) then
option_keys = opts
options_block_start = n + 1
else -- merge multiple :GetOptions
for key, flags in next, opts do
if type(option_keys[key]) == "table" and type(flags) == "table" then
for flag, v in next, flags do
option_keys[key][flag] = v
end
elseif not option_keys[key] or type(flags) == "table" then
option_keys[key] = flags
end
end
end
-- check string keys
local custom_options = {
berserk = true,
altpower = true,
infobox = true,
proximity = true,
stages = true,
warmup = true,
adds = true,
health = true,
}
for key in next, option_keys do
if type(key) == "string" and not custom_options[key] and not key:find("^custom_") and locale[key] == nil then
error(string.format(" %s:%d: Missing option key locale for \"%s\"", file_name, options_block_start, key))
end
end
end
end
local toggle_options = line:match("^mod%.toggleOptions = ({.+})")
if toggle_options then
local success, result = pcall(loadstring("return " .. toggle_options))
if success then
for _, opt in next, result do
local flags = true
if type(opt) == "table" then
flags = {}
for i=2, #opt do
flags[opt[i]] = true
end
opt = opt[1]
end
if opt then -- marker option vars will be nil
if default_options[opt] then
flags = default_options[opt]
end
option_keys[opt] = flags
end
end
end
end
--- Build the callback map.
-- Parse :Log calls and save the callback => spellId association so we can
-- replace args.spellId with the actual spellId(s) based on the last function
-- that was entered when a message function is called.
local event, callback, spells = line:match("self:Log%(\"(.-)\"%s*,%s*(.-)%s*,%s*([^)]*)%)")
if event then
if not log_events[event] then
error(string.format(" %s:%d: Invalid Log event \"%s\"", file_name, n, event))
end
if callback ~= "nil" then
callback = unquote(callback)
else
callback = event
end
if not options[callback] then
options[callback] = {}
end
if not event_callbacks[event] then
event_callbacks[event] = {}
end
for _, v in next, strsplit(spells) do
v = tonumber(v)
if not contains(options[callback], v) then
table.insert(options[callback], v)
end
if not contains(event_callbacks[event], v) then
table.insert(event_callbacks[event], v)
else
error(string.format(" %s:%d: Registered Log event \"%s\" with spell id \"%d\" multiple times", file_name, n, event, v))
end
end
if not next(options[callback]) then
options[callback] = nil
end
registered_methods[callback] = n
end
-- Record other registered events to check at the end
event, callback = line:match(":RegisterUnitEvent%(\"(.-)\"%s*,%s*(.-)%s*,.-%)")
-- if not event then
-- -- XXX need to filter proto methods for this
-- event, callback = line:match(":RegisterEvent%(\"(.-)\"%s*,?%s*(.*)%)")
-- end
if event then
if callback == "" or callback == "nil" then
callback = event
else
callback = unquote(callback)
end
registered_methods[callback] = n
end
event = line:match(":Death%(\"(.-)\"%s*,.*")
if event then
callback = event
registered_methods[callback] = n
unit_died_methods[callback] = true
end
event = line:match(":RegisterEngageMob%(\"(.-)\"%s*,.*")
if event then
callback = event
registered_methods[callback] = n
mob_engaged_methods[callback] = true
end
--- Set spellId replacement values.
-- Record the function that was declared and use the callback map that was
-- created earlier to set the associated spellId(s).
local res, params = line:match("^%s*function%s+([%w_]+:[%w_]+)%s*(%b())")
if res then
current_func = res
local name = res:match(":(.+)")
methods[name] = true
rep = {}
rep.func_key = options[name]
if params ~= "(args)" then
args_keys = {}
elseif unit_died_methods[name] then
args_keys = unit_died_args_keys
elseif mob_engaged_methods[name] then
args_keys = {}
else
args_keys = standard_args_keys
end
end
-- For local functions, look ahead and record the key for the first function
-- that calls it.
res = line:match("^%s*local function%s+([%w_]+)%s*%(") or line:match("^%s*function%s+([%w_]+)%s*%(")
if res then
current_func = res
methods[res] = true
rep = {}
rep.local_func_key = findCalls(lines, n, current_func, options)
args_keys = {}
end
-- For UNIT functions, record the last spellId checked to use as the key.
res = line:match("if (.+) then")
if res then
if line:match("spellId == %d+") then
rep.if_key = {}
for m in res:gmatch("spellId == (%d+)") do
rep.if_key[#rep.if_key+1] = m
end
end
end
-- For expression keys used multiple times
res = line:match("%s*local spellId%s*=%s*(.+)")
if res then
-- fuck off Elerethe
local set_key = comment:match("SetOption:(.-):")
if set_key and set_key ~= "" then
rep.if_key = {}
for k, v in next, strsplit(set_key) do
rep.if_key[#rep.if_key+1] = tonumber(v) or string.format("%q", unquote(v)) -- string keys are expected to be quoted
end
else
if res == "args.spellId" then
rep.if_key = rep.func_key
else
rep.if_key = unternary(res, "(-?%d+)") -- XXX doesn't allow for string keys
end
end
else
res = line:match("%s*local spellId,.+=%s*(.+),")
if res then
local set_key = comment:match("SetOption:(.-):")
if set_key and set_key ~= "" then
rep.if_key = {}
for k, v in next, strsplit(set_key) do
rep.if_key[#rep.if_key+1] = tonumber(v) or string.format("%q", unquote(v)) -- string keys are expected to be quoted
end
else
rep.if_key = unternary(res, "(-?%d+)") -- XXX doesn't allow for string keys
end
end
end
--- Check callback args
for key in string.gmatch(line, "[^%w]*args%.([%w]+)[^%w]*") do
if not args_keys[key] then
error(string.format(" %s:%d: func=%s, Invalid args key \"%s\"", file_name, n, tostring(current_func), key))
end
end
--- Check timer args (callback, timer)
local method, args = line:match(":(%a+Timer)(%b())")
if method == "ScheduleTimer" or method == "ScheduleRepeatingTimer" or method == "SimpleTimer" then
args = strsplit(args:sub(2, -2))
if tonumber(args[1]) then
error(string.format(" %s:%d: Invalid args for \":%s\" callback=%s, delay=%s", file_name, n, method, tostring(args[1]), tostring(args[2])))
end
end
-- Check :Me args
local args = line:match(":Me(%b())")
if args then
args = args:sub(2, -2)
if not string.find(string.lower(args), "guid", nil, true) then
error(string.format(" %s:%d: Me: Invalid guid(1)! guid=%s", file_name, n, args))
end
end
-- Check :CheckOption
local args = line:match(":CheckOption(%b())")
if args then
args = strsplit(clean(args:sub(2, -2)))
local f = tostring(current_func)
if rep.func_key then f = string.format("%s(%s)", f, table.concat(rep.func_key, ",")) end
local key = tonumber(args[1]) or unquote(args[1])
if key == "args.spellId" then
if rep.func_key and #rep.func_key == 1 then
key = rep.func_key[1]
else
error(string.format(" %s:%d: CheckOption: Invalid key! func=%s, key=%s", file_name, n, f, key))
key = nil
end
end
if key then
if not option_keys[key] then
error(string.format(" %s:%d: CheckOption: Invalid key! func=%s, key=%s", file_name, n, f, key))
end
local bitflag = unquote(args[2])
if tracked_bitflags[bitflag] and option_keys[key] and option_keys[key][bitflag] then
if not bitflag_used[key] then
bitflag_used[key] = {}
end
bitflag_used[key][bitflag] = true
end
option_key_used[key] = true
end
end
-- Check :Berserk
local args = line:match(":Berserk(%b())")
if args then
args = strsplit(clean(args:sub(2, -2)))
local f = tostring(current_func)
if rep.func_key then f = string.format("%s(%s)", f, table.concat(rep.func_key, ",")) end
local key = tonumber(args[4]) -- only numbers are used as a replacement key
if not key then
key = unquote(args[4])
if key == "args.spellId" then
if rep.func_key and #rep.func_key == 1 then
key = rep.func_key[1]
else
error(string.format(" %s:%d: Berserk: Invalid key! func=%s, key=%s", file_name, n, f, key))
key = nil
end
else -- arg is a string to use as the name
key = "berserk"
end
end
if key then
if not option_keys[key] then
error(string.format(" %s:%d: Berserk: Missing option key! func=%s, key=%s", file_name, n, f, key))
end
option_key_used[key] = true
end
end
-- Check registering IEEU when it could overwrite the encounter start handler
if line:match(":RegisterEvent%(\"INSTANCE_ENCOUNTER_ENGAGE_UNIT\"") and current_func == "mod:OnBossEnable" then
if module_encounter_id and not line:match(":RegisterEvent%(\"INSTANCE_ENCOUNTER_ENGAGE_UNIT\", \"CheckBossStatus\"%)") then
error(string.format(" %s:%d: Overwriting IEEU handler! Register in OnEngage instead. func=%s", file_name, n, tostring(current_func)))
end
end
--- Parse toggle option API calls.
if checkForAPI(line) then
local key, sound, color, bitflag = nil, nil, nil, nil
local obj, sugar, method, args = line:gsub("^.* = ", ""):match("(%w+)([.:])(.-)(%b())")
if args then args = args:sub(2, -2) end
local offset = 0
if method == "ScheduleTimer" or method == "ScheduleRepeatingTimer" then
method = args:match("^\"(.-)\"")
offset = 2
end
if removed_methods[method] then
error(string.format(" %s:%d: Invalid API method! func=%s, method=%s", file_name, n, tostring(current_func), method))
elseif valid_methods[method] then
args = strsplit(clean(args))
key = unternary(args[1+offset], "(-?%d+)") -- XXX doesn't allow for string keys
local sound_index = sound_methods[method]
if sound_index then
sound = unternary(args[sound_index+offset], "\"(.-)\"", valid_sounds)
if method == "SetPrivateAuraSound" and not sound then
sound = "warning"