-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPolyfills.lua
More file actions
2660 lines (2323 loc) · 92.6 KB
/
Polyfills.lua
File metadata and controls
2660 lines (2323 loc) · 92.6 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
local addonName, ns = ...
-- Use a single global Cell table for everything
_G.Cell = _G.Cell or ns or {}
local Cell = _G.Cell
-------------------------------------------------
-- securecallfunction polyfill
-- Some 3.3.5 builds lack this helper; Ace libraries expect it.
-------------------------------------------------
if type(securecallfunction) ~= "function" then
function securecallfunction(func, ...)
if type(func) ~= "function" then return end
local ok, r1, r2, r3, r4, r5 = pcall(func, ...)
if ok then
return r1, r2, r3, r4, r5
end
-- Swallow errors to mimic securecallfunction behavior in newer clients
end
end
-------------------------------------------------
-- PROJECT / FLAVOR SHIM FOR 3.3.5a
-------------------------------------------------
-- On real Retail/Classic, WOW_PROJECT_ID is a number.
-- On 3.3.5a private clients, it's usually nil, which breaks addons
-- that rely on it. So we fake the constants and pretend to be Wrath Classic.
if type(WOW_PROJECT_ID) ~= "number" then
-- Fake Blizzard project constants
WOW_PROJECT_MAINLINE = 1
WOW_PROJECT_CLASSIC = 2
WOW_PROJECT_WRATH_CLASSIC = 11
WOW_PROJECT_CATACLYSM_CLASSIC = 12
WOW_PROJECT_MISTS_CLASSIC = 13
-- Tell the addon we're Wrath Classic
WOW_PROJECT_ID = WOW_PROJECT_WRATH_CLASSIC
end
-- Initialize flavor + flags once based on WOW_PROJECT_ID
if not Cell.flavor then
if WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC then
Cell.flavor = "wrath"
elseif WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
Cell.flavor = "retail"
elseif WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
Cell.flavor = "vanilla"
elseif WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC then
Cell.flavor = "cata"
elseif WOW_PROJECT_ID == WOW_PROJECT_MISTS_CLASSIC then
Cell.flavor = "mists"
else
Cell.flavor = "retail"
end
end
Cell.isRetail = (Cell.flavor == "retail")
Cell.isWrath = (Cell.flavor == "wrath")
Cell.isVanilla = (Cell.flavor == "vanilla")
Cell.isCata = (Cell.flavor == "cata")
Cell.isMists = (Cell.flavor == "mists")
Cell.isTWW = false -- definitely not TWW on 3.3.5a
-------------------------------------------------
if not IsMetaKeyDown then
function IsMetaKeyDown() return false end
end
if not CreateVector2D then
function CreateVector2D(x, y)
return {
x = x or 0,
y = y or 0,
GetXY = function(self) return self.x, self.y end,
SetXY = function(self, x, y) self.x = x; self.y = y end
}
end
end
-- Initialize supporters tables if not present
Cell.supporters1 = Cell.supporters1 or {}
Cell.supporters2 = Cell.supporters2 or {}
-------------------------------------------------
-- Polyfills for WotLK 3.3.5a
-------------------------------------------------
-------------------------------------------------
-- Screen size polyfill for WotLK
-------------------------------------------------
if not GetPhysicalScreenSize then
-- WotLK uses GetScreenWidth() and GetScreenHeight() instead
function GetPhysicalScreenSize()
return GetScreenWidth(), GetScreenHeight()
end
end
-------------------------------------------------
-- PixelUtil polyfill (doesn't exist in WotLK)
-------------------------------------------------
if not PixelUtil then
PixelUtil = {}
-- Polyfill for GetNearestPixelSize
-- Returns a pixel-perfect size based on the desired size and scale
function PixelUtil.GetNearestPixelSize(desiredSize, scale)
if not desiredSize or desiredSize == 0 then
return 0
end
-- Handle nil or zero scale
if not scale or scale == 0 then
scale = 1
end
-- Round to nearest pixel
local pixelSize = desiredSize * scale
if pixelSize >= 0 then
pixelSize = math.floor(pixelSize + 0.5)
else
pixelSize = math.ceil(pixelSize - 0.5)
end
-- Ensure minimum size of 1 pixel
if desiredSize > 0 and pixelSize < 1 then
pixelSize = 1
elseif desiredSize < 0 and pixelSize > -1 then
pixelSize = -1
end
return pixelSize / scale
end
-- Polyfill for SetPoint
-- Just wraps the standard SetPoint method
function PixelUtil.SetPoint(frame, ...)
if frame and frame.SetPoint then
frame:SetPoint(...)
end
end
-- Polyfill for GetPixelToUIUnitFactor (used in some addons)
function PixelUtil.GetPixelToUIUnitFactor()
local scale = UIParent:GetEffectiveScale()
return 1 / (768 / GetScreenHeight()) / scale
end
end
if not CreateVector2D then
function CreateVector2D(x, y)
return {
x = x or 0,
y = y or 0,
GetXY = function(self) return self.x, self.y end,
SetXY = function(self, x, y) self.x = x; self.y = y end
}
end
end
-------------------------------------------------
-- CellDropdownList shim
-- Retail has a shared dropdown list frame; Wrath port just needs a dummy to hide.
-------------------------------------------------
if not CellDropdownList then
local f = CreateFrame("Frame", "CellDropdownList", UIParent)
f:Hide()
_G.CellDropdownList = f
end
-- Texture:SetGradient polyfill to support CreateColor tables on 3.3.5a
do
local tex = UIParent:CreateTexture()
local mt = getmetatable(tex)
if mt and mt.__index then
local origSetGradient = mt.__index.SetGradient
local origSetGradientAlpha = mt.__index.SetGradientAlpha
local function unpackColor(c)
if type(c) ~= "table" then return end
if c.GetRGBA then
return c:GetRGBA()
end
return c.r, c.g, c.b, c.a or 1
end
-- accept either (orientation, color1, color2) or the classic numeric signature
if origSetGradient and not mt.__index._CellSetGradientPolyfill then
function mt.__index:SetGradient(orientation, ...)
local c1, c2 = ...
if type(c1) == "table" and type(c2) == "table" then
local r1, g1, b1, a1 = unpackColor(c1)
local r2, g2, b2, a2 = unpackColor(c2)
if origSetGradientAlpha then
return origSetGradientAlpha(self, orientation, r1, g1, b1, a1, r2, g2, b2, a2)
end
end
return origSetGradient(self, orientation, ...)
end
mt.__index._CellSetGradientPolyfill = true
end
if origSetGradientAlpha and not mt.__index._CellSetGradientAlphaPolyfill then
function mt.__index:SetGradientAlpha(orientation, ...)
local args = {...}
if #args == 2 and type(args[1]) == "table" and type(args[2]) == "table" then
local r1, g1, b1, a1 = unpackColor(args[1])
local r2, g2, b2, a2 = unpackColor(args[2])
return origSetGradientAlpha(self, orientation, r1, g1, b1, a1, r2, g2, b2, a2)
end
return origSetGradientAlpha(self, orientation, ...)
end
mt.__index._CellSetGradientAlphaPolyfill = true
end
-- Texture:SetColorTexture polyfill for WotLK 3.3.5
-- In retail, SetColorTexture(r, g, b, a) creates a solid color texture
-- In WotLK, we use SetTexture with the RGBA values directly
if not mt.__index.SetColorTexture then
function mt.__index:SetColorTexture(r, g, b, a)
-- In WotLK, SetTexture with 4 numeric args creates a solid color
self:SetTexture(r or 1, g or 1, b or 1, a or 1)
end
end
-- Wrap Texture:SetAtlas to handle missing atlases in WotLK 3.3.5
-- WotLK has fewer atlases than retail, so we need to gracefully handle missing ones
if mt.__index.SetAtlas and not mt.__index._CellSetAtlasWrapped then
local originalSetAtlas = mt.__index.SetAtlas
function mt.__index:SetAtlas(atlasName, useAtlasSize, filterMode)
-- Try to call the original SetAtlas
local success = pcall(originalSetAtlas, self, atlasName, useAtlasSize, filterMode)
if not success then
-- Atlas doesn't exist in WotLK, use a fallback
-- Set to a blank/transparent texture to avoid errors
self:SetTexture(nil)
end
end
mt.__index._CellSetAtlasWrapped = true
end
end
end
-- Mouse click / motion polyfill for Wrath
do
local region = CreateFrame("Frame")
local mt = getmetatable(region)
if not mt or not mt.__index then return end
local idx = mt.__index
-- Retail: ScriptRegion:SetMouseClickEnabled(bool)
if not idx.SetMouseClickEnabled then
function idx:SetMouseClickEnabled(enabled)
-- Wrath only has EnableMouse(bool) for both hover+click
if self.EnableMouse then
self:EnableMouse(not not enabled)
end
end
end
-- Retail: ScriptRegion:SetMouseMotionEnabled(bool)
if not idx.SetMouseMotionEnabled then
function idx:SetMouseMotionEnabled(enabled)
if self.EnableMouse then
self:EnableMouse(not not enabled)
end
end
end
end
-- FontString IsTruncated polyfill for WotLK
do
local fs = UIParent:CreateFontString()
local mt = getmetatable(fs)
if mt and mt.__index and not mt.__index.IsTruncated then
function mt.__index:IsTruncated()
-- Check if text width exceeds the font string's width
local stringWidth = self:GetStringWidth()
local frameWidth = self:GetWidth()
-- If width is 0, assume not truncated
if frameWidth == 0 then
return false
end
-- Check if string width exceeds available width
return stringWidth > frameWidth
end
end
end
-------------------------------------------------
-- FontString SetRotation polyfill for WotLK
-- Text rotation doesn't exist in WotLK, so this is a no-op
-------------------------------------------------
do
local fs = UIParent:CreateFontString()
local mt = getmetatable(fs)
if mt and mt.__index and not mt.__index.SetRotation then
function mt.__index:SetRotation(angle)
-- WotLK doesn't support text rotation, no-op to prevent errors
-- Alternative: use vertical text with newlines at the call site
end
end
end
-------------------------------------------------
-- CreateColor polyfill for WotLK
-- In retail, CreateColor creates a Color object with helper methods
-- In WotLK, we need to create a table with the same interface
-------------------------------------------------
if not CreateColor then
function CreateColor(r, g, b, a)
local color = {r = r or 1, g = g or 1, b = b or 1, a = a or 1}
function color:GetRGB()
return self.r, self.g, self.b
end
function color:GetRGBA()
return self.r, self.g, self.b, self.a
end
function color:WrapTextInColorCode(text)
-- Format: |cAARRGGBB + text + |r
-- AA = alpha (255 for opaque), RR = red, GG = green, BB = blue
local a = math.floor((self.a or 1) * 255)
local r = math.floor(self.r * 255)
local g = math.floor(self.g * 255)
local b = math.floor(self.b * 255)
return string.format("|c%02x%02x%02x%02x%s|r", a, r, g, b, text)
end
return color
end
else
-- CreateColor exists, but WrapTextInColorCode might not
-- Add WrapTextInColorCode to existing Color objects if missing
local testColor = CreateColor(1, 1, 1, 1)
if testColor and not testColor.WrapTextInColorCode then
local mt = getmetatable(testColor)
if mt and mt.__index then
function mt.__index:WrapTextInColorCode(text)
local a = math.floor((self.a or 1) * 255)
local r = math.floor(self.r * 255)
local g = math.floor(self.g * 255)
local b = math.floor(self.b * 255)
return string.format("|c%02x%02x%02x%02x%s|r", a, r, g, b, text)
end
end
end
end
-------------------------------------------------
-- Frame CreateFontString polyfill for WotLK
-- Ensures all created font strings have a default font set
-- This prevents "Font not set" errors when calling SetText
-------------------------------------------------
do
local frame = CreateFrame("Frame")
local mt = getmetatable(frame)
if mt and mt.__index and not mt.__index._CellFontStringCreationPolyfill then
local origCreateFontString = mt.__index.CreateFontString
if origCreateFontString then
function mt.__index:CreateFontString(name, layer, inheritsFrom)
local fontString = origCreateFontString(self, name, layer, inheritsFrom)
-- WotLK Fix: If no font object was inherited, set a default font to prevent errors
-- Check if font is already set (from inheritsFrom)
local currentFont, currentSize, currentFlags = fontString:GetFont()
if not currentFont then
-- Set a safe default font
fontString:SetFont(STANDARD_TEXT_FONT, 12, "")
end
return fontString
end
mt.__index._CellFontStringCreationPolyfill = true
end
end
end
-- SmoothStatusBarMixin polyfill for WotLK
if not SmoothStatusBarMixin then
SmoothStatusBarMixin = {}
function SmoothStatusBarMixin:OnLoad()
-- no-op on 3.3.5
end
function SmoothStatusBarMixin:SetSmoothedValue(value)
if self.SetValue then
self:SetValue(value)
end
end
function SmoothStatusBarMixin:SetMinMaxSmoothedValue(minVal, maxVal)
if self.SetMinMaxValues then
self:SetMinMaxValues(minVal, maxVal)
end
end
-- Retail uses this to reset the smoothing state; on 3.3.5 we just snap to current value.
function SmoothStatusBarMixin:ResetSmoothedValue()
if self.GetValue and self.SetValue then
self:SetValue(self:GetValue())
end
end
end
-------------------------------------------------
-- StatusBar GetStatusBarTexture polyfill for WotLK
-- In WotLK, GetStatusBarTexture() can return nil immediately after SetStatusBarTexture
-- We wrap it to ensure it always returns a valid texture
-------------------------------------------------
do
local sb = CreateFrame("StatusBar")
local mt = getmetatable(sb)
if mt and mt.__index then
local origGetStatusBarTexture = mt.__index.GetStatusBarTexture
local origSetStatusBarTexture = mt.__index.SetStatusBarTexture
-- Wrap SetStatusBarTexture to cache the texture path
if origSetStatusBarTexture then
function mt.__index:SetStatusBarTexture(texture, layer, sublayer)
self._cellCachedTexturePath = texture
return origSetStatusBarTexture(self, texture, layer, sublayer)
end
end
-- Wrap GetStatusBarTexture to ensure it returns a texture
if origGetStatusBarTexture then
function mt.__index:GetStatusBarTexture()
local tex = origGetStatusBarTexture(self)
-- If texture is nil but we have a cached path, try setting it again
if not tex and self._cellCachedTexturePath then
origSetStatusBarTexture(self, self._cellCachedTexturePath)
tex = origGetStatusBarTexture(self)
end
return tex
end
end
end
end
-------------------------------------------------
-- Retail unit API polyfills
-------------------------------------------------
if not UnitInOtherParty then
-- Retail API: returns true if unit is in a different party/instance group.
-- WotLK/Ascension doesn't have that concept, so just say "no".
function UnitInOtherParty(unit)
return false
end
end
-- UnitHasIncomingResurrection
if not UnitHasIncomingResurrection then
-- Retail API: returns true if unit has an incoming resurrection (like Battle Res)
-- WotLK doesn't have this API, always return false
function UnitHasIncomingResurrection(unit)
return false
end
end
-- UnitInPhase
if not UnitInPhase then
-- Retail API: returns true if unit is in the same phase as player
-- WotLK doesn't have this API or handles phasing differently, assume always in phase
function UnitInPhase(unit)
return true
end
end
-- UnitGroupRolesAssigned
if not UnitGroupRolesAssigned then
-- WotLK 3.3.5a NATIVE API: returns THREE BOOLEANS (isTank, isHealer, isDamage)
-- This is DIFFERENT from Retail which returns a single string
-- WotLK has role detection through GetRaidRosterInfo and LFG system
-- Debug flag for role detection (toggle with /cell debug role)
local roleDebugEnabled = false
function UnitGroupRolesAssigned(unit)
if not unit then return false, false, false end
local isTank, isHealer, isDamage = false, false, false
local roleSource = "none"
-- For raid members, get role from GetRaidRosterInfo
if UnitInRaid(unit) then
for i = 1, GetNumRaidMembers() do
-- GetRaidRosterInfo returns: name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML, combatRole
local name, _, _, _, _, _, _, _, _, role = GetRaidRosterInfo(i)
local raidUnit = "raid" .. i
if UnitIsUnit(unit, raidUnit) then
-- role is returned from GetRaidRosterInfo (from LFG/Dungeon Finder system or raid assignments)
if role and role ~= "NONE" and role ~= "" then
roleSource = "GetRaidRosterInfo"
-- Convert WotLK role format to booleans
if role == "MAINTANK" or role == "TANK" then
isTank = true
elseif role == "HEALER" then
isHealer = true
elseif role == "MAINASSIST" or role == "DAMAGER" or role == "DPS" then
isDamage = true
end
end
break
end
end
end
-- Fallback: Check party assignments (Main Tank/Main Assist)
if not isTank and not isHealer and not isDamage then
if GetPartyAssignment("MAINTANK", unit) then
isTank = true
roleSource = "MainTank assignment"
elseif GetPartyAssignment("MAINASSIST", unit) then
isDamage = true
roleSource = "MainAssist assignment"
end
end
-- Fallback: Use spec-based detection via LibGroupInfo
if not isTank and not isHealer and not isDamage then
local LibGroupInfo = LibStub and LibStub:GetLibrary("LibGroupInfo", true)
if LibGroupInfo then
local guid = UnitGUID(unit)
if guid then
local cachedInfo = LibGroupInfo:GetCachedInfo(guid)
if cachedInfo then
-- GetCachedInfo returns a table with assignedRole and specRole fields
local specRole = cachedInfo.assignedRole or cachedInfo.specRole
if specRole and specRole ~= "NONE" then
roleSource = "LibGroupInfo (spec-based)"
if specRole == "TANK" then
isTank = true
elseif specRole == "HEALER" then
isHealer = true
elseif specRole == "DAMAGER" or specRole == "MELEE" or specRole == "RANGED" then
isDamage = true
end
end
end
end
end
end
-- Final fallback: Default to DAMAGER if still no role detected
-- This helps on custom servers like Ascension where spec detection may not work
if not isTank and not isHealer and not isDamage then
isDamage = true
roleSource = "default fallback"
end
-- Debug output
if roleDebugEnabled then
local roleName = isTank and "TANK" or isHealer and "HEALER" or "DAMAGER"
print(string.format("[Role Debug] %s -> %s (source: %s)",
UnitName(unit) or unit, roleName, roleSource))
end
return isTank, isHealer, isDamage
end
-- Debug command toggle - create sFuncs table if needed
if _G.Cell then
_G.Cell.sFuncs = _G.Cell.sFuncs or {}
_G.Cell.sFuncs.ToggleRoleDebug = function()
roleDebugEnabled = not roleDebugEnabled
print(string.format("[Cell] Role debug: %s", roleDebugEnabled and "enabled" or "disabled"))
end
end
end
-- UnitClassBase
if not UnitClassBase then
-- Retail API: returns the class filename (e.g. "WARRIOR")
-- WotLK: UnitClass returns (localizedName, fileName, classIndex)
function UnitClassBase(unit)
return select(2, UnitClass(unit))
end
end
-- GetSpellBookItemName (doesn't exist in WotLK 3.3.5)
-- In WotLK, use GetSpellInfo(index, bookType) which returns name as first value
if not GetSpellBookItemName then
function GetSpellBookItemName(index, bookType)
local spellName = GetSpellInfo(index, bookType)
return spellName
end
end
-- Ambiguate (doesn't exist in WotLK 3.3.5)
-- In retail, Ambiguate formats player names by removing/keeping realm suffixes
-- In WotLK, we implement a simple version
if not Ambiguate then
function Ambiguate(fullName, context)
if not fullName then return "" end
-- context values: "none", "short", "mail", "guild"
-- For WotLK, we'll implement basic realm removal
if context == "none" or context == "short" or context == "mail" then
-- Remove realm suffix (everything after the hyphen)
local name = string.match(fullName, "^([^%-]+)")
return name or fullName
end
-- Default: return full name with realm
return fullName
end
end
-------------------------------------------------
-- StatusBar smoothing helpers polyfill
-------------------------------------------------
do
local sb = CreateFrame("StatusBar")
local mt = getmetatable(sb)
if mt and mt.__index then
if not mt.__index.SetSmoothedValue then
function mt.__index:SetSmoothedValue(value)
if self.SetValue then
self:SetValue(value)
end
end
end
if not mt.__index.SetMinMaxSmoothedValue then
function mt.__index:SetMinMaxSmoothedValue(minVal, maxVal)
if self.SetMinMaxValues then
self:SetMinMaxValues(minVal, maxVal)
end
end
end
if not mt.__index.ResetSmoothedValue then
function mt.__index:ResetSmoothedValue()
if self.GetValue and self.SetValue then
self:SetValue(self:GetValue())
end
end
end
end
end
-- Alpha animation SetFromAlpha / SetToAlpha polyfill for 3.3.5a
do
-- create a sample alpha animation to grab its metatable
local f = CreateFrame("Frame")
local ag = f:CreateAnimationGroup()
local a = ag:CreateAnimation("Alpha")
local mt = getmetatable(a)
if mt and mt.__index and not mt.__index.SetFromAlpha then
-- weak tables to remember from/to per animation
local alphaFrom = setmetatable({}, { __mode = "k" })
local alphaTo = setmetatable({}, { __mode = "k" })
function mt.__index:SetFromAlpha(value)
alphaFrom[self] = value
local to = alphaTo[self]
-- On WotLK, Alpha uses SetChange; approximate from/to with delta
if to ~= nil and self.SetChange then
self:SetChange(to - value)
end
end
function mt.__index:SetToAlpha(value)
alphaTo[self] = value
local from = alphaFrom[self]
if from ~= nil and self.SetChange then
self:SetChange(value - from)
end
end
end
end
-- HookScript polyfill for 3.3.5a
-- 1) Real hook for Frames (they have GetScript/SetScript)
do
local f = CreateFrame("Frame")
local mt = getmetatable(f)
if mt and mt.__index and not mt.__index.HookScript then
function mt.__index:HookScript(scriptType, handler)
if not self or type(scriptType) ~= "string" or type(handler) ~= "function" then
return
end
-- Only makes sense if this object actually supports scripts
local getScript = self.GetScript
local setScript = self.SetScript
if type(getScript) ~= "function" or type(setScript) ~= "function" then
return
end
local prev = getScript(self, scriptType)
if prev then
setScript(self, scriptType, function(...)
prev(...)
handler(...)
end)
else
setScript(self, scriptType, handler)
end
end
end
end
-- 2) Delegate Texture:HookScript to its parent frame
do
local tex = UIParent:CreateTexture()
local mt = getmetatable(tex)
if mt and mt.__index and not mt.__index.HookScript then
function mt.__index:HookScript(scriptType, handler)
if type(scriptType) ~= "string" or type(handler) ~= "function" then
return
end
local parent = self:GetParent()
if parent then
-- If parent already has a proper HookScript (either native or from the frame polyfill), use it
if type(parent.HookScript) == "function" then
parent:HookScript(scriptType, handler)
return
end
-- If parent only has SetScript/GetScript, hook manually
local getScript = parent.GetScript
local setScript = parent.SetScript
if type(getScript) == "function" and type(setScript) == "function" then
local prev = getScript(parent, scriptType)
if prev then
setScript(parent, scriptType, function(...)
prev(...)
handler(...)
end)
else
setScript(parent, scriptType, handler)
end
return
end
end
-- Worst case: no scripts anywhere, just fire once so stuff like blink:Play() runs at least once
handler(self)
end
end
end
-------------------------------------------------
-- SecureHandler_SetFrameRef polyfill
-- Ignore invalid/nil reference frames instead of erroring.
-------------------------------------------------
do
if type(SecureHandler_SetFrameRef) == "function" and not _G._CellOrigSecureHandlerSetFrameRef then
_G._CellOrigSecureHandlerSetFrameRef = SecureHandler_SetFrameRef
function SecureHandler_SetFrameRef(self, refKey, refFrame)
-- If refFrame is missing or not a frame-like table, just skip.
if not refFrame or type(refFrame) ~= "table" or type(refFrame.GetName) ~= "function" then
-- silently ignore bad refs
return
end
return _G._CellOrigSecureHandlerSetFrameRef(self, refKey, refFrame)
end
end
end
-- Cooldown swipe API polyfill for 3.3.5a (no-op)
do
local cd = CreateFrame("Cooldown")
local mt = getmetatable(cd)
if mt and mt.__index then
if not mt.__index.SetSwipeTexture then
function mt.__index:SetSwipeTexture(texture)
-- No swipe layer in WotLK, ignore
end
end
if not mt.__index.SetSwipeColor then
function mt.__index:SetSwipeColor(r, g, b, a)
-- Ignore
end
end
if not mt.__index.SetDrawEdge then
function mt.__index:SetDrawEdge(flag)
-- Ignore
end
end
if not mt.__index.SetDrawBling then
function mt.__index:SetDrawBling(flag)
-- Ignore
end
end
if not mt.__index.SetHideCountdownNumbers then
function mt.__index:SetHideCountdownNumbers(flag)
-- Just ignore; WotLK cooldown text is separate anyway
end
end
end
end
-- Cooldown OnCooldownDone polyfill for 3.3.5a (ignore unsupported script type)
do
local cd = CreateFrame("Cooldown")
local mt = getmetatable(cd)
if mt and mt.__index and not mt.__index._CellOnCooldownDoneShim then
local origSetScript = mt.__index.SetScript
function mt.__index:SetScript(scriptType, handler)
-- Retail-only script type; WotLK cooldowns don't support it
if scriptType == "OnCooldownDone" then
-- No native support in 3.3.5a; safely ignore
return
end
return origSetScript(self, scriptType, handler)
end
mt.__index._CellOnCooldownDoneShim = true
end
end
-- StatusBar:SetReverseFill polyfill for 3.3.5a (no-op)
do
local f = CreateFrame("StatusBar")
local mt = getmetatable(f)
if mt and mt.__index and not mt.__index.SetReverseFill then
function mt.__index:SetReverseFill(reverse)
-- 3.3.5 has no reverse fill; ignore request
end
end
end
-------------------------------------------------
-- FlipBook / ParentKey / ChildKey polyfills
-------------------------------------------------
-- Textures: SetParentKey is Retail-only
do
local tex = UIParent:CreateTexture()
local mt = getmetatable(tex)
if mt and mt.__index and not mt.__index.SetParentKey then
function mt.__index:SetParentKey(key)
-- Retail uses this to bind the texture to a named child
-- of a flipbook animation. WotLK has no concept of this,
-- so just ignore it.
end
end
end
-- Animations: ChildKey + FlipBook-specific methods
do
local f = CreateFrame("Frame")
local ag = f:CreateAnimationGroup()
local a = ag:CreateAnimation("Alpha")
local mt = getmetatable(a)
if mt and mt.__index then
if not mt.__index.SetChildKey then
function mt.__index:SetChildKey(key)
-- No child-key routing in WotLK. Ignore.
end
end
if not mt.__index.SetFlipBookFrames then
function mt.__index:SetFlipBookFrames(frames)
-- No flipbook system; ignore.
end
end
if not mt.__index.SetFlipBookFrameWidth then
function mt.__index:SetFlipBookFrameWidth(width)
-- Ignore.
end
end
if not mt.__index.SetFlipBookFrameHeight then
function mt.__index:SetFlipBookFrameHeight(height)
-- Ignore.
end
end
if not mt.__index.SetFlipBookRows then
function mt.__index:SetFlipBookRows(rows)
-- Ignore; 3.3.5 doesn't know rows/columns.
end
end
if not mt.__index.SetFlipBookColumns then
function mt.__index:SetFlipBookColumns(columns)
-- Ignore.
end
end
end
end
-- AnimationGroup: map "FlipBook" → "Alpha" so CreateAnimation doesn't explode
do
local f = CreateFrame("Frame")
local ag = f:CreateAnimationGroup()
local mt = getmetatable(ag)
if mt and mt.__index and type(mt.__index.CreateAnimation) == "function"
and not mt.__index._CellFlipBookShim
then
local origCreateAnimation = mt.__index.CreateAnimation
function mt.__index:CreateAnimation(animType, ...)
if animType == "FlipBook" then
-- 3.3.5 only knows Alpha/Translation/Scale/Rotation.
animType = "Alpha"
end
return origCreateAnimation(self, animType, ...)
end
mt.__index._CellFlipBookShim = true
end
end
-- CreateMaskTexture polyfill for 3.3.5a (Frame / StatusBar / Cooldown / Texture)
do
local function addCreateMaskTexture(obj)
local mt = getmetatable(obj)
if not mt or type(mt.__index) ~= "table" then
return
end
if not mt.__index.CreateMaskTexture then
function mt.__index:CreateMaskTexture()
-- 3.3.5a has no real mask textures; fake it with a hidden Frame (empty)
-- We use a Frame instead of Texture to avoid the "white box" issue if SetTexture is called.
local mask = CreateFrame("Frame", nil, self)
mask:SetAllPoints(self)
mask:EnableMouse(false) -- Ensure it doesn't block clicks
-- Add dummy methods that Actions.lua expects on a Texture/Mask
mask.SetTexture = function() end
mask.SetRotated = function() end
return mask
end
end
end
-- Patch the types we care about
addCreateMaskTexture(CreateFrame("Frame"))
addCreateMaskTexture(CreateFrame("StatusBar"))
addCreateMaskTexture(CreateFrame("Cooldown"))
addCreateMaskTexture(UIParent:CreateTexture())
end
-- Texture:AddMaskTexture polyfill for 3.3.5a (no-op)
do
local t = UIParent:CreateTexture()