Repository navigation
Expand file tree
/
Copy pathcompat.lua
More file actions
1903 lines (1765 loc) · 77.8 KB
/
Copy pathcompat.lua
File metadata and controls
1903 lines (1765 loc) · 77.8 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
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
--=========================================================================================
-- Cross-client compatibility layer.
--
-- SwedgeTimer ships one build for every WoW client family (Classic Era, TBC, Wrath,
-- Cata, Mists, Retail, WoW Forever, plus legacy/private clients). This is the single
-- place where client API differences are handled.
--
-- Sets:
-- st.family : "ERA" | "TBC" | "WRATH" | "CATA" | "MISTS" | "RETAIL"
-- | "FOREVER" | "UNKNOWN"
-- st.interface_number : the running client's TOC interface version, when knowable
-- st.is_retail : true on the Retail (mainline) client
-- st.is_mainline : true on Mainline-code clients (Retail, WoW Forever): their
-- classic combat log is gone, so the swing engine cannot run
-- st.gcd_probe_spell_id : spell id whose cooldown reading mirrors the global cooldown
-- st.lust_spell_ids : confirmed Bloodlust (2825) / Heroism (32182) spell ids
-- st.lust_supported : true where Bloodlust/Heroism can exist (TBC+; Era: false)
-- st.cleu_supported : true where the classic combat log exists (classic-line;
-- Retail/Forever: false, so CLEU-driven chains stay inert)
-- st.api.* : normalized wrappers for APIs that differ across clients
--
-- On clients where the original global function still exists, each wrapper preserves the
-- global's exact return values, so Titanforge 3.80.2 (the regression baseline) behaves
-- exactly as before. A few wrappers add a secret-value guard on top (see below): where
-- the value is not secret that guard is an exact no-op, and where a restricted read
-- hands back an opaque value it degrades to the documented "unknown" shape instead of
-- raising a Lua error.
-- Retail-only replacements (C_Spell, C_UnitAuras, C_SpecializationInfo) are used only
-- where the globals are gone.
--
-- Rule for the rest of the addon: never call a cross-client API directly - go through
-- st.api. Per-family data (spell IDs, form indices, talent checks) lives with the
-- class modules in classes/.
--=========================================================================================
---@class LibCustomGlow
---@field PixelGlow_Start fun(frame: any, color?: table, N?: number, frequency?: number, length?: number, th?: number, xOffset?: number, yOffset?: number, border?: boolean, key?: any, frameLevel?: number)
---@field PixelGlow_Stop fun(frame: any, key?: any)
---@field ButtonGlow_Start fun(frame: any, color?: table, frequency?: number, frameLevel?: number)
---@field ButtonGlow_Stop fun(frame: any)
---@field AutoCastGlow_Start fun(frame: any, color?: table, N?: number, frequency?: number, scale?: number, xOffset?: number, yOffset?: number, key?: any, frameLevel?: number)
---@field AutoCastGlow_Stop fun(frame: any, key?: any)
local addon_name, st = ...
--------------------------------------------------------------------------------
-- Client family detection
--------------------------------------------------------------------------------
local family = "UNKNOWN"
local interface_number
-- WoW Forever ("Camelot") reports WOW_PROJECT_CAMELOT; fall back to its numeric value
-- so the comparison still works on clients where the global does not exist.
local WOW_PROJECT_FOREVER = WOW_PROJECT_CAMELOT or 18
do
-- Preferred: the WOW_PROJECT_ID constants, present on every official client.
local project_id = WOW_PROJECT_ID
if project_id ~= nil then
if project_id == WOW_PROJECT_CLASSIC then
family = "ERA"
elseif project_id == WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
family = "TBC"
elseif project_id == WOW_PROJECT_WRATH_CLASSIC then
family = "WRATH"
elseif project_id == WOW_PROJECT_CATACLYSM_CLASSIC then
family = "CATA"
elseif project_id == WOW_PROJECT_MISTS_CLASSIC then
family = "MISTS"
elseif project_id == WOW_PROJECT_MAINLINE then
family = "RETAIL"
elseif project_id == WOW_PROJECT_FOREVER then
family = "FOREVER"
end
end
-- Fallback: the TOC interface version. Legacy/private clients have no project id.
local get_build_info = GetBuildInfo
if get_build_info then
local _, _, _, toc = get_build_info()
interface_number = tonumber(toc)
end
if family == "UNKNOWN" and interface_number then
local major = math.floor(interface_number / 10000)
if major == 1 and interface_number >= 16000 then
-- WoW Forever shares Classic Era's major version (1.60.x -> 16000+)
-- but runs Mainline client code: never bucket it as Era.
family = "FOREVER"
elseif major == 1 then
family = "ERA"
elseif major == 2 then
family = "TBC"
elseif major == 3 then
family = "WRATH"
elseif major == 4 then
family = "CATA"
elseif major == 5 then
family = "MISTS"
elseif major >= 10 then
family = "RETAIL"
end
end
-- WoW Forever / Camelot probe: if C_SwingTimer is exposed or Camelot project matches,
-- this client is FOREVER, never Retail, Era, or Unknown.
if rawget(_G, "C_SwingTimer") ~= nil then
family = "FOREVER"
elseif (family == "RETAIL" or family == "UNKNOWN") then
local camelot_id = WOW_PROJECT_CAMELOT or 18
if project_id ~= nil and project_id == camelot_id then
family = "FOREVER"
end
end
end
st.family = family
st.interface_number = interface_number
st.is_retail = (family == "RETAIL")
-- Retail and WoW Forever run Mainline client code; the classic combat log is gone
-- there, so the swing engine (LibClassicSwingTimerAPI) cannot work on them.
st.is_mainline = (family == "RETAIL" or family == "FOREVER")
-- GCD probe spell: a spell that has no cooldown of its own, so its cooldown reading
-- mirrors the global cooldown. 29515 ("TEST Scorch") is a vanilla-era test spell
-- present on every classic client; 61304 ("Global Cooldown") is Blizzard's dummy
-- for the same purpose on Mainline clients.
st.gcd_probe_spell_id = 29515
if st.is_mainline then
st.gcd_probe_spell_id = 61304
end
--------------------------------------------------------------------------------
-- Bloodlust / Heroism (the lust window)
--------------------------------------------------------------------------------
-- Bloodlust (Horde) 2825 and its Alliance twin Heroism 32182 are a first-class
-- haste-window input for the swing tracking (hunter H2, paladin P3). Both ids
-- are CONFIRMED (bench/verify_bank.md §2: Wowhead TBC pages, 40s duration). The
-- spells only exist from TBC onward, so a lust helper must never arm on Classic
-- Era: consumers gate on st.lust_supported, which is derived from st.family
-- (never a version string) and stays false on Era and on the UNKNOWN fallback
-- family - only the confirmed families TBC/WRATH/CATA/MISTS/RETAIL/FOREVER arm.
st.lust_spell_ids = { 2825, 32182 }
st.lust_supported = (family ~= "ERA" and family ~= "UNKNOWN")
-- Post-lust debuff ids, registered for reference only. UNCONFIRMED:
-- bench/verify_bank.md §2 found no primary source for Exhaustion/Sated
-- 57723/57724 (secondary WeakAura mentions only), and the 57723-vs-57724 name
-- mapping is unconfirmed as well. IN-CLIENT CHECK: read the debuff id off the
-- player right after a Bloodlust lands before any caller depends on it. Nothing
-- may hard-depend on these values: matching them must stay on nil-safe paths
-- that degrade to "no debuff" instead of erroring.
st.post_lust_debuff_ids = { 57723, 57724 }
--------------------------------------------------------------------------------
-- Normalized API surface
--------------------------------------------------------------------------------
local api = {}
st.api = api
-- Secret values (Mainline-code clients) ---------------------------------------------------
-- Under the Mainline secret-value regime, restricted reads (cooldowns, power, health,
-- auras, combat stats, casts) can return opaque "secret" values: type() still reports the
-- underlying type, so a type() or "== nil" guard cannot see them, while arithmetic,
-- comparison and table indexing with one raises a Lua error. Feature-detect the probe
-- once; on every classic client it is absent and every guard below is an exact no-op.
local is_secret = issecretvalue or function()
return false
end
-- Spell info -----------------------------------------------------------------------------
-- Classic shape: name, rank, icon, castTime, minRange, maxRange, spellID
-- Retail shape: C_Spell.GetSpellInfo returns a SpellInfo table.
if GetSpellInfo then
api.GetSpellInfo = GetSpellInfo
elseif C_Spell and C_Spell.GetSpellInfo then
api.GetSpellInfo = function(spell)
local info = C_Spell.GetSpellInfo(spell)
if not info then
return nil
end
-- Retail has no "rank"; the remaining units match the classic returns.
return info.name, nil, info.originalIconID, info.castTime, info.minRange, info.maxRange, info.spellID
end
else
-- Unknown client: report a 1.5s cast time so GCD estimation stays sane.
api.GetSpellInfo = function()
return nil, nil, nil, 1500, 0, 0, nil
end
end
-- Spell knowledge ------------------------------------------------------------------------
-- Whether the player knows a spell, used to resolve the highest known rank of a tracked
-- spell family. The probes exist on different client families; the first one that ANSWERS
-- wins (a probe that returns nil declines, and the chain moves on to the next probe).
--
-- CONTRACT (binary, never nil): api.is_spell_known answers true or false and nothing else.
-- true = a probe answered "the player knows this spell".
-- false = a probe answered "the player does not know it" OR no probe could answer at all
-- (no probe on this client, or every probe declined).
-- A false is therefore NOT the claim "the client says the player does not know the spell":
-- on a client that cannot answer it is the fail-closed answer, not a fact about the player.
-- Every caller in the tree treats only true as affirmative knowledge (== true / ~= true),
-- so a false never turns a row on.
--
-- The two cases ARE told apart by api.is_spell_known_state below - the same shape as
-- api.get_family_spell_id_state (the answer first, the state string second): a caller that
-- must not guess (a row that hides when the client cannot answer) reads the state, never
-- the boolean alone.
--
-- Client note (wow-ui-source, per branch): C_SpellBook.IsSpellKnown is documented on every
-- targeted family (classic_era, classic_anniversary, classic_titan, forever, live) and
-- returns a bool; the classic global IsSpellKnown is Blizzard's deprecated shim over
-- C_SpellBook (Blizzard_DeprecatedSpellBook/Deprecated_SpellBook.lua) and exists only while
-- the loadDeprecationFallbacks CVar is on. So no targeted client is probe-less - the
-- no-probe branch below is the defensive path, not a shape the shipped matrix reaches.
local spell_known_probes = {}
-- IsSpellKnown is deprecated on modern clients, so resolve it dynamically; this both
-- dodges the deprecation annotation and tolerates clients that removed the global.
local classic_is_spell_known = rawget(_G, "IsSpellKnown")
if classic_is_spell_known then
spell_known_probes[#spell_known_probes + 1] = classic_is_spell_known
end
-- C_SpellBook.IsSpellKnown (SpellBookDocumentation.lua: "Returns true if a player knows
-- a spell"; sibling IsSpellKnownOrInSpellBook beside it) is the probe on the
-- Mainline-code clients, where the global above is absent. NOTE: C_Spell.IsSpellKnown*
-- exists on NO client (absent on era/anniversary/titan/forever/live alike) - the live
-- namespace is C_SpellBook, so nothing probes C_Spell here. Appended after the global
-- on purpose: a client whose chain already answers (the classic clients, with
-- Blizzard's deprecation fallbacks loaded) keeps the exact same answer source, so
-- nothing changes there.
local spell_book_api = rawget(_G, "C_SpellBook")
if spell_book_api then
if spell_book_api.IsSpellKnown then
spell_known_probes[#spell_known_probes + 1] = spell_book_api.IsSpellKnown
end
if spell_book_api.IsSpellKnownOrInSpellBook then
spell_known_probes[#spell_known_probes + 1] = spell_book_api.IsSpellKnownOrInSpellBook
end
end
-- A spell NAME is not a probe argument on the modern clients. TBC Anniversary's
-- IsSpellKnown global is Blizzard's deprecated shim
-- (Blizzard_DeprecatedSpellBook/Deprecated_SpellBook.lua), which forwards its argument
-- to C_SpellBook.IsSpellInSpellBook - an id-only API that throws on a string:
-- "bad argument #1 to 'IsSpellInSpellBook' (outside of expected range ...)",
-- operator in-client BugGrabber evidence 2026-10-21 (hunter post_init, "Kill Shot").
-- The caller's token is therefore probed AS GIVEN first: on the clients where a name is
-- the query form (operator-confirmed name-vs-id rule) that keeps the exact answer source.
-- Only a THROWING probe triggers the one-time name -> id resolution through the ONE compat
-- spell-info path above (api.GetSpellInfo; its 7th return is the id) - no second
-- resolution path - after which the same probe is retried with the id. A name that
-- resolves to nothing is "unknown": never a guess, never a throw.
local function spell_known_name_id(spell_name)
if type(spell_name) ~= "string" then
return nil
end
local ok, _, _, _, _, _, _, id = pcall(api.GetSpellInfo, spell_name)
if not ok or is_secret(id) or type(id) ~= "number" then
return nil
end
return id
end
-- The state variant of the probe - the tri-state the boolean above folds away:
-- true, "known" a probe answered true
-- false, "not_known" a probe answered false
-- false, "unknown" no probe answered - the client cannot answer the question,
-- or the token did not resolve to a spell id at all
-- Same contract as api.get_family_spell_id_state: the answer first, the state second.
-- Every probe call is pcall-wrapped: a probe that throws is "no answer" (the chain
-- moves on), so a client-side throw costs the answer, never the caller's init. The
-- probe order is unchanged (classic global first, C_SpellBook probes after it).
function api.is_spell_known_state(spell_id, fallback_id)
-- Neither a spell id nor a spell name can be a probe argument: fail closed before any
-- client call. pcall would contain the throw, but there is nothing to resolve either.
if type(spell_id) ~= "number" and type(spell_id) ~= "string" then
if type(fallback_id) == "number" or type(fallback_id) == "string" then
spell_id = fallback_id
fallback_id = nil
else
return false, "unknown"
end
end
local fallback_id = fallback_id
local fallback_resolved = false
for i = 1, #spell_known_probes do
local ok, known = pcall(spell_known_probes[i], spell_id)
if not ok then
if not fallback_resolved then
local resolved_id = spell_known_name_id(spell_id)
if resolved_id ~= nil then
fallback_id = resolved_id
end
fallback_resolved = true
end
if fallback_id ~= nil then
ok, known = pcall(spell_known_probes[i], fallback_id)
end
end
if ok and not is_secret(known) then
if known == true then
return true, "known"
end
if known ~= nil then
return false, "not_known"
end
end
end
return false, "unknown"
end
-- The boolean form: the answer half of the state above, unchanged for every caller
-- (true / false, never nil).
function api.is_spell_known(spell_id, fallback_id)
local known = api.is_spell_known_state(spell_id, fallback_id)
return known
end
-- Spell cooldowns ------------------------------------------------------------------------
-- Classic shape: start, duration, enabled, modRate (enabled is 1/0)
-- Retail shape: C_Spell.GetSpellCooldown returns a SpellCooldownInfo table.
--
-- One wrapper for every family instead of a pass-through of the classic global: that
-- global's annotation declares no return values, and inheriting it would make the
-- wrapper's own returns look redundant to the type checker.
local classic_get_spell_cooldown = GetSpellCooldown
local retail_get_spell_cooldown = C_Spell and C_Spell.GetSpellCooldown
local function raw_query_spell_cooldown(token)
if token == nil then
return 0, 0, 0, 0
end
local start_time, duration, enabled, mod_rate
if classic_get_spell_cooldown then
local ok, s, d, e, m = pcall(classic_get_spell_cooldown, token)
if ok and s and not is_secret(s) then
start_time = s
duration = d
enabled = e
mod_rate = m
end
end
if (not duration or duration == 0) and retail_get_spell_cooldown then
local ok, info = pcall(retail_get_spell_cooldown, token)
if ok and type(info) == "table" and not is_secret(info.startTime) then
local enabled_raw = info.isEnabled
if not is_secret(enabled_raw) then
start_time = info.startTime
duration = info.duration
enabled = enabled_raw and 1 or 0
mod_rate = info.modRate
end
end
end
if is_secret(start_time) or is_secret(duration) or is_secret(enabled) or is_secret(mod_rate) then
return 0, 0, 0, 0
end
return start_time or 0, duration or 0, enabled or 0, mod_rate or 0
end
function api.GetSpellCooldown(spell, fallback_id)
if type(spell) ~= "number" and type(spell) ~= "string" then
if type(fallback_id) == "number" or type(fallback_id) == "string" then
spell = fallback_id
fallback_id = nil
else
return 0, 0, 0, 0
end
end
local start_time, duration, enabled, mod_rate = raw_query_spell_cooldown(spell)
if duration and duration > 0 then
return start_time, duration, enabled, mod_rate
end
if fallback_id and fallback_id ~= spell then
local fb_s, fb_d, fb_e, fb_m = raw_query_spell_cooldown(fallback_id)
if fb_d and fb_d > 0 then
return fb_s, fb_d, fb_e, fb_m
end
if start_time == 0 and fb_s and fb_s > 0 then
return fb_s, fb_d, fb_e, fb_m
end
end
return start_time or 0, duration or 0, enabled or 0, mod_rate or 0
end
-- Spell usability ------------------------------------------------------------------------
-- Whether a spell can be cast right now, and specifically whether it is unusable for lack
-- of resources (mana). Every probe shape returns (usable, insufficientPower): the C_Spell
-- form on Mainline and the newer classic clients, the classic IsSpellUsable global, then
-- the older IsUsableSpell. All three are read through _G: they are not in the annotation
-- set of every client family, where naming them directly would be an undefined-global /
-- undefined-field reference. No probe at all: nil, i.e. unknown - callers must treat
-- unknown as "no tint", never as a usable reading.
local spell_usable_probe
do
local c_spell = rawget(_G, "C_Spell")
if type(c_spell) == "table" and type(c_spell.IsSpellUsable) == "function" then
spell_usable_probe = c_spell.IsSpellUsable
elseif type(rawget(_G, "IsSpellUsable")) == "function" then
spell_usable_probe = rawget(_G, "IsSpellUsable")
elseif type(rawget(_G, "IsUsableSpell")) == "function" then
spell_usable_probe = rawget(_G, "IsUsableSpell")
end
end
function api.IsSpellUsable(spell)
if not spell_usable_probe then
return nil
end
local usable, insufficient = spell_usable_probe(spell)
-- A restricted reading reports unknown (nil), which every caller renders as "no
-- tint", never as a usable/insufficient claim.
if is_secret(usable) or is_secret(insufficient) then
return nil, nil
end
return usable, insufficient
end
-- Spell power costs ----------------------------------------------------------------------
-- Classic and retail both return an array of cost structs; entries have a .cost field.
-- Read through _G: the global, and the classic-only C_Spell fields below, are not in the
-- annotation set of Mainline-code clients, where naming them directly would be an
-- undefined-global / undefined-field reference.
local spell_api = rawget(_G, "C_Spell")
local get_spell_power_cost = _G.GetSpellPowerCost
or (spell_api and spell_api.GetSpellPowerCost)
-- Unknown client: a zero-cost entry of the expected shape instead of an error.
api.GetSpellPowerCost = get_spell_power_cost or function()
return { { cost = 0, minCost = 0 } }
end
-- Spell base cooldowns -------------------------------------------------------------------
-- Classic: GetSpellBaseCooldown(spell) returns the base cooldown in milliseconds.
-- Retail has no replacement; degrade to 0 rather than error.
if GetSpellBaseCooldown then
local raw_get_spell_base_cooldown = GetSpellBaseCooldown
api.GetSpellBaseCooldown = function(spell)
local first, second = raw_get_spell_base_cooldown(spell)
-- A restricted reading reports the absent-client shape (0, 0): callers treat a
-- non-positive base cooldown as "no value" and fall back to their own constant.
if is_secret(first) or is_secret(second) then
return 0, 0
end
return first, second
end
else
api.GetSpellBaseCooldown = function()
return 0, 0
end
end
-- Current spell --------------------------------------------------------------------------
-- Detects on-next-attack abilities queued for the current cast (Maul, Heroic Strike, ...).
-- The classic global is read through _G: it is absent on Mainline-code clients, and
-- naming it directly would be an undefined-global reference there.
local is_current_spell = _G.IsCurrentSpell
api.IsCurrentSpell = is_current_spell or (C_Spell and C_Spell.IsCurrentSpell) or function()
return false
end
-- Resources (rage, mana, energy) ---------------------------------------------------------
-- UnitPower / UnitPowerMax exist on every supported client (the modern ones prefer
-- UnitPowerType but do not remove the globals). Wrapped for the secret regime: a
-- restricted reading reports nil (unknown), which every caller's type() guard already
-- routes to its "cannot claim" branch. An unknown client keeps reporting 0 so a caller
-- can never error while comparing.
local legacy_unit_power = rawget(_G, "UnitPower")
local legacy_unit_power_max = rawget(_G, "UnitPowerMax")
if legacy_unit_power then
api.UnitPower = function(unit, power_type)
local value = legacy_unit_power(unit, power_type)
if is_secret(value) then
return nil
end
return value
end
else
api.UnitPower = function()
return 0
end
end
if legacy_unit_power_max then
api.UnitPowerMax = function(unit, power_type)
local value = legacy_unit_power_max(unit, power_type)
if is_secret(value) then
return nil
end
return value
end
else
api.UnitPowerMax = function()
return 0
end
end
-- Unit power type: UnitPowerType(unit) returns the numeric power-type id (0 mana,
-- 1 rage, 3 energy, ...) and its token. The druid form label maps 3 -> Cat and
-- 1 -> Bear (reference GetDruidFormLabel, SuperSwingTimer_ClassMods.lua:4530-4538) and
-- the energy tick bar only shows for the energy power type. Unknown client: mana (0,
-- "MANA"), the safe default - every mapping then falls through to "Caster" and the
-- energy tick stays hidden. Read through _G for the same undefined-global reason.
local legacy_unit_power_type = rawget(_G, "UnitPowerType")
if legacy_unit_power_type then
api.UnitPowerType = function(unit)
local power_type, token = legacy_unit_power_type(unit)
-- A restricted reading reports unknown (nil), which every mapping falls through
-- as "Caster" / no energy tick - the same shape an absent client gets.
if is_secret(power_type) or is_secret(token) then
return nil
end
return power_type, token
end
else
api.UnitPowerType = function()
return 0, "MANA"
end
end
-- Health ---------------------------------------------------------------------------------
-- UnitHealth / UnitHealthMax exist on every supported client like the power reads above;
-- read through _G for the same undefined-global reason. A client that cannot answer
-- returns nil, which callers read as unknown health - never as zero. A restricted
-- (secret) reading degrades the same way.
local legacy_unit_health = rawget(_G, "UnitHealth")
local legacy_unit_health_max = rawget(_G, "UnitHealthMax")
if legacy_unit_health then
api.UnitHealth = function(unit)
local value = legacy_unit_health(unit)
if is_secret(value) then
return nil
end
return value
end
else
api.UnitHealth = function()
return nil
end
end
if legacy_unit_health_max then
api.UnitHealthMax = function(unit)
local value = legacy_unit_health_max(unit)
if is_secret(value) then
return nil
end
return value
end
else
api.UnitHealthMax = function()
return nil
end
end
-- Auras ----------------------------------------------------------------------------------
-- Classic shape: UnitAura(unit, index, filter) returns
-- name, icon, count, dispelName, duration, expirationTime, sourceUnit, isStealable,
-- nameplateShowPersonal, spellId, ...
-- Retail shape: C_UnitAuras.GetAuraDataByIndex returns an AuraData table. The field
-- order below matches Blizzard's own AuraUtil.UnpackAuraData back-compat mapping.
-- Aura entries are taken whole or not at all: one secret field makes the entry unusable
-- (consumers run arithmetic on durations/expirations, compare names and index spell-id
-- tables), and the existing "name == nil -> stop scanning" loops are the only degrade
-- they can consume, so a secret entry is returned as absent (nil) instead of per-field
-- nils. All three source paths are wrapped, including the classic-global pass-through.
local function aura_entry_is_secret(name, icon, count, dispel_name, duration, expiration,
source, is_stealable, nameplate_show_personal, spell_id)
return is_secret(name) or is_secret(icon) or is_secret(count) or is_secret(dispel_name)
or is_secret(duration) or is_secret(expiration) or is_secret(source)
or is_secret(is_stealable) or is_secret(nameplate_show_personal) or is_secret(spell_id)
end
if UnitAura then
api.UnitAura = function(unit, index, filter)
local name, icon, count, dispel_name, duration, expiration, source, is_stealable,
nameplate_show_personal, spell_id = UnitAura(unit, index, filter)
if aura_entry_is_secret(name, icon, count, dispel_name, duration, expiration,
source, is_stealable, nameplate_show_personal, spell_id) then
return nil
end
return name, icon, count, dispel_name, duration, expiration, source, is_stealable,
nameplate_show_personal, spell_id
end
elseif C_UnitAuras and C_UnitAuras.GetAuraDataByIndex then
api.UnitAura = function(unit, index, filter)
local aura = C_UnitAuras.GetAuraDataByIndex(unit, index, filter)
if not aura then
return nil
end
local name, icon, count, dispel_name, duration, expiration, source, is_stealable,
nameplate_show_personal, spell_id = aura.name, aura.icon, aura.applications,
aura.dispelName, aura.duration, aura.expirationTime, aura.sourceUnit,
aura.isStealable, aura.nameplateShowPersonal, aura.spellId
if aura_entry_is_secret(name, icon, count, dispel_name, duration, expiration,
source, is_stealable, nameplate_show_personal, spell_id) then
return nil
end
return name, icon, count, dispel_name, duration, expiration, source, is_stealable,
nameplate_show_personal, spell_id
end
else
api.UnitAura = function()
return nil
end
end
-- Player aura scan: one predicate over the player's own buffs, normalised into
-- duration_remaining_seconds, stacks = api.scan_player_aura(predicate)
-- CONTRACT FROZEN (hunter H2 / paladin P3 code against this exact shape):
-- * predicate(spell_id, name, stacks) returns truthy for a match; first match
-- wins. spell_id can be nil on a client without numeric ids - an id
-- comparison already treats that safely - and stacks follows the same
-- count convention as the wrapper above.
-- * returns nil, nil when not found, when no aura API exists on the client,
-- or when the predicate is not a function. Callers must treat nil as "no
-- window", never as zero.
-- * remaining seconds come from expirationTime on the api.get_time() axis
-- (the domain the rest of the addon compares in), clamped at 0 once
-- expired; nil remaining with a set stacks means found-but-no-time.
-- * stacks is the count for anything above 1 and nil for a non-stacking aura
-- (classic count nil, retail applications 1) - identical on every family.
-- Family paths, all through this file's own wrappers: the classic global on
-- Era/TBC/Wrath (a consumer may re-poll at a 0.05s cadence - this scan holds no
-- state of its own) and the C_UnitAuras read on the Mainline-code clients. A
-- secret entry degrades to absent in the wrapper above and the walk continues
-- past it (no early break): a restricted row above the buff no longer
-- truncates the scan, so a restricted list still reports not found (nil, nil)
-- only when nothing matches.
local scan_player_aura_index_max = 40
function api.scan_player_aura(predicate)
if type(predicate) ~= "function" then
return nil, nil
end
local now = api.get_time()
for index = 1, scan_player_aura_index_max do
local name, _, count, _, _, expiration, _, _, _, spell_id = api.UnitAura(
"player", index, "HELPFUL")
-- No early break (R2): nil is simply no match at this index. The
-- 40-row cap bounds the walk, so the worst-case cost is the same 40
-- UnitAura calls as before.
if name ~= nil then
if predicate(spell_id, name, count) then
local remaining
if type(expiration) == "number" then
remaining = expiration - now
if remaining < 0 then
remaining = 0
end
end
local stacks
if type(count) == "number" and count > 1 then
stacks = count
end
return remaining, stacks
end
end
end
return nil, nil
end
-- Unit aura scan: the player scan above, generalised to any unit and to either
-- aura list. duration_remaining_seconds, stacks = api.scan_unit_aura(unit, predicate, filter)
-- CONTRACT (the same three-way contract as the player scan above - a caller
-- reads nil as "unknown", never as "absent"):
-- * predicate(spell_id, name, stacks) returns truthy for a match; the first
-- match wins. The arguments are exactly the ones the player scan hands
-- over, in the same order: spell_id can be nil on a client without numeric
-- ids (an id comparison already treats that safely - compare the name
-- first when a client resolves by name), and the third argument is the raw
-- count on the wrapper's convention.
-- * filter selects the aura list: "HARMFUL" (the default - a debuff scan) or
-- "HELPFUL" (a buff scan). Any other value falls back to the debuff
-- filter, so a typo can never silently scan the wrong list.
-- * returns nil, nil when not found, when the unit carries no readable aura,
-- when no aura API exists on the client, when the unit is not a usable
-- unit string, or when the predicate is not a function. Callers must treat
-- nil as "unknown", never as "absent" - a target debuff that could not be
-- read is not a target without that debuff.
-- * the row cap, the no-early-break rule, the api.get_time() axis and the
-- whole-entry secret degrade are the player scan's, unchanged: a restricted
-- row reads absent and the walk continues past it, so a restricted list
-- still reports the match that sits below it.
-- Family paths, all through this file's own wrappers: the classic global on
-- Era/TBC/Wrath and the C_UnitAuras read on the Mainline-code clients.
function api.scan_unit_aura(unit, predicate, filter)
if type(predicate) ~= "function" then
return nil, nil
end
if type(unit) ~= "string" or unit == "" then
return nil, nil
end
if filter ~= "HELPFUL" then
filter = "HARMFUL"
end
local now = api.get_time()
for index = 1, scan_player_aura_index_max do
local name, _, count, _, _, expiration, _, _, _, spell_id = api.UnitAura(
unit, index, filter)
-- No early break (R2), same as the player scan above: nil is simply no
-- match at this index. The 40-row cap bounds the walk, so the worst-case
-- cost is the same 40 UnitAura calls as the player scan.
if name ~= nil then
if predicate(spell_id, name, count) then
local remaining
if type(expiration) == "number" then
remaining = expiration - now
if remaining < 0 then
remaining = 0
end
end
local stacks
if type(count) == "number" and count > 1 then
stacks = count
end
return remaining, stacks
end
end
end
return nil, nil
end
-- Secret-value regime observability (M5): can restricted (secret) AURA rows be
-- hidden from every aura consumer right now? The whole-entry degrade above stays
-- exactly as it is (E2: one secret field -> the entry reads absent); this probe
-- only makes the regime itself readable so a consumer can tell "no lust" from
-- "the aura list may be restricted". true/false only when C_Secrets answers with a
-- boolean; nil when the API/probe is absent or throws (unknown, never "no" - every
-- classic client is the exact no-op nil here).
function api.auras_may_be_secret()
local c_secrets = rawget(_G, "C_Secrets")
if type(c_secrets) ~= "table" then
return nil
end
local probe = rawget(c_secrets, "ShouldAurasBeSecret")
if type(probe) ~= "function" then
return nil
end
local ok, value = pcall(probe)
if ok and type(value) == "boolean" then
return value
end
return nil
end
-- Casting and channels -------------------------------------------------------------------
-- Wrapped rather than passed through: a restricted (secret) cast payload degrades to
-- "no cast is running" (nil), the shape every consumer already handles - the classes
-- pack start/end times into arithmetic and match names/spell ids, none of which a secret
-- value survives. The payloads are NOT identical: UnitCastingInfo returns castID before
-- notInterruptible and the spell id 9th, while UnitChannelInfo has no castID and returns
-- the spell id 8th; callers must unpack each accordingly.
local legacy_unit_casting_info = UnitCastingInfo
local legacy_unit_channel_info = UnitChannelInfo
-- name is compared, start/end times are arithmetic (ms/1000, cast windows) and spell_id
-- is matched against tables: if any of them is secret the payload is not usable.
local function cast_payload_is_secret(name, start_ms, end_ms, spell_id)
return is_secret(name) or is_secret(start_ms) or is_secret(end_ms) or is_secret(spell_id)
end
if legacy_unit_casting_info then
api.UnitCastingInfo = function(unit)
local name, text, texture, start_ms, end_ms, is_trade_skill, cast_id,
not_interruptible, spell_id = legacy_unit_casting_info(unit)
if cast_payload_is_secret(name, start_ms, end_ms, spell_id) then
return nil
end
return name, text, texture, start_ms, end_ms, is_trade_skill, cast_id,
not_interruptible, spell_id
end
else
api.UnitCastingInfo = function() return nil end
end
if legacy_unit_channel_info then
api.UnitChannelInfo = function(unit)
local name, text, texture, start_ms, end_ms, is_trade_skill, not_interruptible,
spell_id = legacy_unit_channel_info(unit)
if cast_payload_is_secret(name, start_ms, end_ms, spell_id) then
return nil
end
return name, text, texture, start_ms, end_ms, is_trade_skill, not_interruptible,
spell_id
end
else
api.UnitChannelInfo = function() return nil end
end
-- Folding caster lookup: a live cast first, a channel second, normalised into
-- name, spell_id, start_seconds, end_seconds
-- in the seconds domain of api.get_time() (the clients report startTimeMs/endTimeMs on
-- the GetTime()*1000 axis). The payload arities differ and are documented here because
-- the two source functions cannot be unpacked the same way:
-- UnitCastingInfo: name, text, texture, startTimeMs, endTimeMs, isTradeSkill,
-- castID, notInterruptible, spellID
-- UnitChannelInfo: name, text, texture, startTimeMs, endTimeMs, isTradeSkill,
-- notInterruptible, spellID (no castID; spellID 8th)
-- spell_id is nil when the payload carries no numeric id (older classic clients), so
-- callers must fall back to matching on the name.
function api.UnitCastingSpell(unit)
if not unit then
return nil
end
local name, _, _, start_ms, end_ms, _, _, _, spell_id = api.UnitCastingInfo(unit)
if not name then
name, _, _, start_ms, end_ms, _, _, spell_id = api.UnitChannelInfo(unit)
end
if not name then
return nil
end
if type(spell_id) ~= "number" then
spell_id = nil
end
local start_seconds
if type(start_ms) == "number" then
start_seconds = start_ms / 1000
end
local end_seconds
if type(end_ms) == "number" then
end_seconds = end_ms / 1000
end
return name, spell_id, start_seconds, end_seconds
end
-- Spell haste ----------------------------------------------------------------------------
-- UnitSpellHaste is the current global where available; GetSpellHaste is the older one,
-- removed from the modern clients entirely, so it is looked up dynamically (never
-- referenced as a bare global) and both return a percentage, or nil where lacking.
local legacy_get_spell_haste = rawget(_G, "GetSpellHaste")
if UnitSpellHaste then
api.UnitSpellHaste = function(unit)
local haste = UnitSpellHaste(unit)
if is_secret(haste) then
return nil
end
return haste
end
else
api.UnitSpellHaste = function() return nil end
end
if legacy_get_spell_haste then
api.GetSpellHaste = function()
local haste = legacy_get_spell_haste()
if is_secret(haste) then
return nil
end
return haste
end
else
api.GetSpellHaste = function() return nil end
end
-- Talents --------------------------------------------------------------------------------
-- Classic (Era/TBC/Wrath/Cata): GetTalentInfo(tab, index) returns
-- name, icon, tier, column, rank, maxRank, ...
-- The global only exists on clients that expose Blizzard's deprecation fallbacks, so
-- mirror Blizzard's own C_SpecializationInfo mapping (see Blizzard_DeprecatedSpecialization).
-- Mists and Retail use different talent systems. The final fallback reports rank 0 so
-- that "has talent" checks all evaluate to false instead of erroring.
if GetTalentInfo then
api.GetTalentInfo = GetTalentInfo
elseif C_SpecializationInfo and C_SpecializationInfo.GetTalentInfo then
api.GetTalentInfo = function(tab, index, isInspect, isPet, groupIndex)
local query = {
specializationIndex = tab,
talentIndex = index,
isInspect = isInspect,
isPet = isPet,
groupIndex = groupIndex,
}
local info = C_SpecializationInfo.GetTalentInfo(query)
if not info then
return nil, nil, nil, nil, 0
end
return info.name, info.icon, info.tier, info.column, info.rank,
info.maxRank, info.meetsPrereq, info.previewRank,
info.meetsPreviewPrereq, info.isExceptional, info.hasGoldBorder,
info.talentID
end
else
api.GetTalentInfo = function()
return nil, nil, nil, nil, 0
end
end
-- Talent groups / specializations --------------------------------------------------------
-- Classic: GetActiveTalentGroup() returns 1 or 2.
-- Retail: C_SpecializationInfo.GetActiveSpecGroup() returns the active spec index.
local getActiveTalentGroup
if GetActiveTalentGroup then
getActiveTalentGroup = GetActiveTalentGroup
elseif C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup then
getActiveTalentGroup = C_SpecializationInfo.GetActiveSpecGroup
else
getActiveTalentGroup = function()
return 1
end
end
api.GetActiveTalentGroup = getActiveTalentGroup
-- Shapeshift form index ------------------------------------------------------------------
-- Classic indices: 1=bear, 3=cat, 4=travel, 5=moonkin/tree/flight, 6=flight.
-- Other families index forms differently; form-dependent visual features will need
-- per-family data with the class modules.
-- Read through _G: the global is not in the annotation set of Mainline-code clients, where
-- naming it directly would be an undefined-global reference. NOTE: there is no
-- C_ShapeshiftForm namespace on any client (absent on era/anniversary/titan/forever/live
-- alike), so no C_ branch is probed here: the bare global answers on the classic-line
-- clients (engine-provided there - RestrictedEnvironment.lua allowlists it on
-- era/anniversary/titan), and every other client reports 0 (unknown form).
local get_shapeshift_form = _G.GetShapeshiftForm
if get_shapeshift_form then
api.GetShapeshiftForm = get_shapeshift_form
else
api.GetShapeshiftForm = function()
return 0
end
end
-- Weapon speeds --------------------------------------------------------------------------
-- Used to detect whether an offhand/ranged weapon exists.
if UnitAttackSpeed then
api.UnitAttackSpeed = function(unit)
local main_speed, off_speed, ranged_speed = UnitAttackSpeed(unit)
-- Any restricted speed fails the whole read (nil): an unknown read must never be
-- mistaken for a weapon reading either way.
if is_secret(main_speed) or is_secret(off_speed) or is_secret(ranged_speed) then
return nil
end
return main_speed, off_speed, ranged_speed
end
else
api.UnitAttackSpeed = function()
return 0, 0
end
end
if UnitRangedDamage then
api.UnitRangedDamage = function(unit)
local damage = UnitRangedDamage(unit)
if is_secret(damage) then
return nil
end
return damage
end
else
api.UnitRangedDamage = function()
return 0
end
end
-- Ranged state and spell range ------------------------------------------------------------
-- Probes for the hunter ranged sync: auto-repeat state (mounted hunters never
-- auto-repeat), mounted state, and spell range. Each degrades to a safe value on a
-- client without the probe.
-- Probe selection: the C_Spell form on Mainline-code clients, the classic global
-- elsewhere; both are pcall-wrapped because their argument forms differ across clients.
-- Neither present -> false. The classic global is read through _G: it is absent on
-- Mainline-code clients, where naming it directly would be an undefined-global
-- reference.
local c_spell_is_auto_repeat = C_Spell and C_Spell.IsAutoRepeatSpell
local classic_is_auto_repeat = rawget(_G, "IsAutoRepeatSpell")
function api.IsAutoRepeatSpell(spell)
local probe = c_spell_is_auto_repeat or classic_is_auto_repeat
if not probe then
return false
end
local ok, is_repeating = pcall(probe, spell)
if ok and is_repeating == true then