2026-11-21 12:10:42 -06:00
local root = assert ( arg [ 1 ] , ' Pass the RuenUI directory with a trailing slash ' )
local combat = false
local cursor
function GetCursorInfo ( ) if cursor then return unpack ( cursor ) end end
function ClearCursor ( ) cursor = nil end
function hooksecurefunc ( object , key , fn )
if type ( object ) == ' string ' then return end
local original = object [ key ]
object [ key ] = function ( ... ) local r = { original ( ... ) } ; fn ( ... ) ; return unpack ( r ) end
end
local frames , timers = { } , { }
local function frame ( name , parent )
local f = { name = name , parent = parent , w = 39 , h = 39 , shown = true , attrs = { } , scripts = { } , events = { } }
function f : GetName ( ) return self.name end
function f : GetWidth ( ) return self.w end
function f : GetHeight ( ) return self.h end
function f : GetEffectiveScale ( ) return self.parent and self.parent : GetEffectiveScale ( ) or 1.25 end
function f : SetSize ( w , h ) assert ( not combat ) ; self.w , self.h = w , h end
function f : SetAttribute ( k , v ) assert ( not combat , ' protected attribute write during combat ' ) ; self.attrs [ k ] = v end
function f : ClearAllPoints ( ) assert ( not combat ) ; self.points = { } end
function f : SetPoint ( ... ) assert ( not combat ) ; self.points = self.points or { } ; self.points [ # self.points + 1 ] = { ... } end
function f : SetAllPoints ( ) end
function f : Show ( ) self.shown = true end
function f : Hide ( ) self.shown = false end
function f : SetShown ( v ) self.shown = v end
function f : IsShown ( ) return self.shown and ( not self.parent or self.parent : IsShown ( ) ) end
function f : SetChecked ( v ) self.checked = v end
function f : GetID ( ) return 0 end
function f : SetTexture ( t ) self.texture = t end
function f : GetTexture ( ) return self.texture end
2026-11-21 17:24:50 -06:00
function f : GetAtlas ( ) return self.atlas end
function f : SetAtlas ( v ) self.atlas = v ; self.texture = ' atlas-file- ' .. v end
2026-11-21 16:24:58 -06:00
function f : SetAlpha ( v ) self.alpha = v end
function f : GetBlendMode ( ) return self.blend or ' BLEND ' end
function f : SetBlendMode ( v ) self.blend = v end
function f : GetDrawLayer ( ) return ' OVERLAY ' , 1 end
function f : SetDrawLayer ( a , b ) self.layer = { a , b } end
2026-11-21 12:10:42 -06:00
function f : GetTexCoord ( ) return 0 , 1 , 0 , 1 end
function f : SetTexCoord ( ) end
function f : SetVertexColor ( ... ) self.color = { ... } end
function f : SetText ( t ) self.text = t end
function f : SetTextColor ( ) end
function f : SetScript ( k , v ) self.scripts [ k ] = v end
function f : HookScript ( k , v ) self.scripts [ k ] = v end
function f : RegisterForClicks ( ... ) self.clicks = { ... } end
function f : RegisterForDrag ( ) end
function f : RegisterEvent ( e ) self.events [ e ] = true end
function f : UnregisterEvent ( e ) self.events [ e ] = nil end
function f : CreateTexture ( ) return frame ( nil , self ) end
function f : CreateFontString ( ) return frame ( nil , self ) end
function f : ShowAutoCastEnabled ( v ) self.auto = v end
function f : Clear ( ) self.cd = nil end
function f : SetCooldown ( ... ) self.cd = { ... } end
for _ , kind in ipairs ( { ' Normal ' , ' Pushed ' , ' Highlight ' , ' Checked ' } ) do
f [ ' Get ' .. kind .. ' Texture ' ] = function ( self ) return self [ kind ] end
2026-11-21 16:24:58 -06:00
f [ ' Set ' .. kind .. ' Texture ' ] = function ( self , t ) self [ kind ] = frame ( nil , self ) ; self [ kind ] . texture = t ; self [ kind .. ' Texture ' ] = self [ kind ] end
2026-11-21 17:24:50 -06:00
-- Live buttons expose BOTH setters. Omitting atlas setters hid the bug where
-- a texture-backed native highlight was replaced by the fallback atlas.
f [ ' Set ' .. kind .. ' Atlas ' ] = function ( self , t ) self [ kind ] = frame ( nil , self ) ; self [ kind ] : SetAtlas ( t ) ; self [ kind .. ' Texture ' ] = self [ kind ] end
2026-11-21 12:10:42 -06:00
end
frames [ # frames + 1 ] = f ; if name then _G [ name ] = f end ; return f
end
CreateFrame = function ( _ , name , parent ) return frame ( name , parent ) end
UIParent = frame ( ' UIParent ' ) ; PetActionBar = frame ( ' PetActionBar ' , UIParent ) ; PetActionBar.w = 408
for i = 1 , 10 do frame ( ' PetActionButton ' .. i , PetActionBar ) end
for _ , kind in ipairs ( { ' Normal ' , ' Pushed ' , ' Highlight ' , ' Checked ' } ) do PetActionButton1 [ ' Set ' .. kind .. ' Texture ' ] ( PetActionButton1 , ' native- ' .. kind ) end
2026-11-21 16:24:58 -06:00
PetActionButton1.Flash = frame ( ) ; PetActionButton1.Flash : SetTexture ( ' native-Flash ' )
function UIFrameFlash ( f ) f.flashing = true end
function UIFrameFlashStop ( f ) f.flashing = false end
2026-11-21 12:10:42 -06:00
EditModeManagerFrame = frame ( ' EditModeManagerFrame ' , UIParent )
RuenUIDB = { } ; RuenUICharacter = { }
Enum = { SpellBookSpellBank = { Pet = 1 } , SpellBookItemType = { Spell = 1 , PetAction = 3 } , ActionBarSet = { Mkb = 0 , Gamepad = 1 } }
NUM_PET_ACTION_SLOTS = 10
function InCombatLockdown ( ) return combat end
C_Timer = { After = function ( _ , fn ) timers [ # timers + 1 ] = fn end }
local function flush ( ) local t = timers ; timers = { } ; for _ , fn in ipairs ( t ) do fn ( ) end end
local book , native = { } , { }
local function pet ( prefix , count )
book = { } ; native = { }
for i = 1 , count do book [ i ] = { actionID = 9000 + i , spellID = 9000 + i , name = prefix .. i , iconID = 100 + i , isPassive = false , itemType = 3 } end
book [ count + 1 ] = { actionID = 9900 , spellID = 9900 , name = ' Passive ' , isPassive = true }
book [ count + 2 ] = { actionID = 2 , name = ' Follow ' , itemType = 3 , isPassive = false }
for i = 1 , math.min ( count , 4 ) do native [ i ] = { name = prefix .. i , id = 9000 + i } end
end
function GetPetActionInfo ( i ) local p = native [ i ] ; if p then return p.name , nil , false , nil , nil , nil , p.id end end
C_Spell = { GetSpellInfo = function ( id ) for _ , p in ipairs ( book ) do if p.spellID == id then return p end end end }
local cooldown = { startTime = 10 , duration = 5 , modRate = 1 }
local auto = true
local picked
C_SpellBook = { HasPetSpells = function ( ) return # book end , GetSpellBookItemInfo = function ( i ) return book [ i ] end ,
IsSpellBookItemPassive = function ( i ) return book [ i ] . isPassive end ,
GetSpellBookItemName = function ( i ) return book [ i ] . name end ,
IsSpellBookItemUsable = function ( ) return true end , IsSpellBookItemInRange = function ( ) return true end ,
GetSpellBookItemAutoCast = function ( ) return true , auto end ,
GetSpellBookItemCooldown = function ( ) return cooldown end ,
PickupSpellBookItem = function ( i , b ) assert ( not combat and b == 1 ) ; picked = i ; cursor = { ' petaction ' , book [ i ] . actionID } end }
local locked = false
C_CVar = { GetCVar = function ( ) return locked and ' 1 ' or ' 0 ' end }
function IsModifiedClick ( ) return false end
function GetBindingKey ( action ) return action : find ( ' 11: ' ) and ' - ' or ' = ' end
function GetBindingText ( k ) return k end
local actions = { [ 25 ] = { ' spell ' , 99999 } , [ 1 ] = { ' spell ' , 100 } , [ 37 ] = { ' item ' , 6948 } , [ 145 ] = { ' spell ' , 222 } }
local places , uses , toggles = 0 , { } , 0
2026-11-21 16:24:58 -06:00
local activeStance , activeOrder , attacking
local function activate ( id )
if id >= 100663296 and id <= 100663300 then activeStance = id
elseif id == 117440514 then attacking = true
elseif id == 117440512 or id == 117440513 then activeOrder = id ; attacking = false end
end
2026-11-21 12:10:42 -06:00
local engineActions = { }
local rejectPlacement = false
storedType = ' engine_pet '
local currentPage = 1
function GetActionInfo ( slot ) local a = actions [ slot ] ; if a then if a [ 1 ] == storedType and a [ 2 ] > 100000000 then return ' spell ' , 0 , ' pet ' end return unpack ( a ) end end
function PickupAction ( slot ) assert ( not combat and not cursor ) ; cursor = actions [ slot ] ; actions [ slot ] = nil end
function PlaceAction ( slot )
assert ( not combat and slot >= 13 and slot <= 24 and cursor and cursor [ 1 ] == ' petaction ' )
places = places + 1 ; local old = actions [ slot ] ; actions [ slot ] = { storedType , cursor [ 2 ] } ; cursor = old
end
C_ActionBar = { IsAutoCastPetAction = function ( slot ) local k , id = GetActionInfo ( slot ) ; return k == storedType and id < 100000 end ,
ToggleAutoCastPetAction = function ( slot ) assert ( C_ActionBar.IsAutoCastPetAction ( slot ) ) ; auto = not auto ; toggles = toggles + 1 end ,
2026-11-21 16:24:58 -06:00
IsCurrentAction = function ( slot ) local a = actions [ slot ] ; return a and ( a [ 2 ] == activeStance or a [ 2 ] == activeOrder or ( a [ 2 ] == 117440514 and attacking ) ) or false end ,
2026-11-21 12:10:42 -06:00
GetBonusBarIndexForSlot = function ( ) return nil end ,
GetActionBarPage = function ( ) return currentPage end ,
FindPetActionButtons = function ( id )
if rejectPlacement then return end
local result = { }
for slot , action in pairs ( actions ) do
if action [ 1 ] == storedType and action [ 2 ] % 16777216 == id % 16777216 then result [ # result + 1 ] = slot end
end
return # result > 0 and result or nil
end }
-- Use Blizzard's actual page map, including visible page 3.
for _ , name in ipairs ( { ' MultiBarBottomLeft ' , ' MultiBarBottomRight ' , ' MultiBarLeft ' , ' MultiBarRight ' , ' MultiBar5 ' , ' MultiBar6 ' , ' MultiBar7 ' } ) do frame ( name , UIParent ) end
dofile ( ( assert ( os.getenv ( ' RUEN_NATIVE_UI ' ) ) .. ' /MultiActionBars.lua ' ) )
assert ( MultiActionBar_GetBarForPage ( 3 ) == MultiBarRight and MultiActionBar_GetBarForPage ( 2 ) == nil )
-- Native prototypes can lack texture accessors. Reproduce the reported crash.
PetActionButton1.GetCheckedTexture = nil
PetActionButton1.GetPushedTexture = nil
C_PetInfo = { GetSpellForPetAction = function ( id ) return id % 16777216 end }
local function Copy ( t ) local n = { } ; for k , v in pairs ( t ) do n [ k ] = v end ; return n end
CopyTable = Copy
function GetFrameMetatable ( ) return { __index = { GetParent = function ( f ) return f.parent end , GetAttribute = function ( f , a , n , s )
if not n then return f.attrs [ a ] end
return f.attrs [ a .. n .. s ] or f.attrs [ ' * ' .. n .. s ] or f.attrs [ n .. s ] or f.attrs [ n ]
end } } end
C_PaperDollInfo = { GetInventorySlotInfo = function ( ) return 1 end , IsRangedSlotShown = function ( ) return false end }
function IsShiftKeyDown ( ) return false end
function IsAltKeyDown ( ) return false end
function IsControlKeyDown ( ) return false end
local keyDown = true
function GetCVarBool ( k ) return k == ' ActionButtonUseKeyDown ' and keyDown end
function securecallfunction ( fn , ... ) return fn ( ... ) end
function SpellCanTargetItem ( ) return false end
function SpellCanTargetItemID ( ) return false end
SpellFlyout = { Hide = function ( ) end }
function UseAction ( slot , unit , button , isKeyPress )
assert ( button == ' LeftButton ' ) ; assert ( actions [ slot ] [ 1 ] == storedType , ' no native pet action ' )
uses [ # uses + 1 ] = slot
2026-11-21 16:24:58 -06:00
activate ( actions [ slot ] [ 2 ] )
2026-11-21 12:10:42 -06:00
end
C_Macro = { RunMacroText = function ( ) error ( ' must not use macrotext for pet activation ' ) end }
assert ( loadfile ( ( assert ( os.getenv ( ' RUEN_NATIVE_UI ' ) ) .. ' /SecureTemplates.lua ' ) ) ) ( )
local create = CreateFrame
CreateFrame = function ( kind , name , parent , template )
local f = create ( kind , name , parent )
if template == ' SecureActionButtonTemplate ' then f.CalculateAction = SecureActionButtonMixin.CalculateAction ; f.scripts . OnClick = SecureActionButton_OnClick end
return f
end
local function assertAction ( button , id )
assert ( button.attrs . type1 == ' action ' and button.attrs . action1 and not button.attrs . macrotext1 , ' extra needs a real action ' )
local kind , actual = GetActionInfo ( button.attrs . action1 )
assert ( kind == storedType and C_PetInfo.GetSpellForPetAction ( actual ) == id , ' wrong stored action ' )
end
local function click ( button , mouse )
button.scripts . OnClick ( button , mouse , true ) ; if button.scripts . PostClick then button.scripts . PostClick ( button , mouse , true ) end
button.scripts . OnClick ( button , mouse , false ) ; if button.scripts . PostClick then button.scripts . PostClick ( button , mouse , false ) end
end
local P = { Localized = function ( en ) return en end }
2026-11-21 16:24:58 -06:00
assert ( loadfile ( root .. ' ButtonStyle.lua ' ) ) ( ' RuenUI ' , P )
2026-11-21 12:10:42 -06:00
assert ( loadfile ( root .. ' PetExtras.lua ' ) ) ( ' RuenUI ' , P )
pet ( ' Bear ' , 5 )
local choices = P.PetExtraChoices ( ) ; assert ( # choices == 1 and choices [ 1 ] . id == 9005 , ' missing bear ability was not found ' )
-- Same-name ranks and passive/command entries must not consume extra slots.
book [ # book + 1 ] = { spellID = 9001 , actionID = 9001 , name = ' Bear1 ' , iconID = 101 , isPassive = false }
assert ( # P.PetExtraChoices ( ) == 1 )
P.InitializePetExtras ( function ( ) return true end )
local a , b = RuenPetExtraButton11 , RuenPetExtraButton12
assert ( a and b and a.parent == PetActionBar and NUM_PET_ACTION_SLOTS == 10 )
assert ( a.w == 39 and a.h == 39 and P.PetExtraGeometry ( ) == 39 )
assert ( select ( 3 , P.PetExtraGeometry ( ) ) == 82 and PetActionBar.w + select ( 3 , P.PetExtraGeometry ( ) ) == 490 )
assert ( a.points [ 1 ] [ 2 ] == PetActionButton10 and a.points [ 1 ] [ 4 ] == 2 )
assert ( b.points [ 1 ] [ 2 ] == a and b.points [ 1 ] [ 4 ] == 2 )
assertAction ( a , 9005 )
assert ( not a.attrs . type2 and not a.attrs . macrotext2 )
assert ( not b.attrs . type1 and not b.attrs . macrotext1 )
assert ( a.scripts . OnUpdate and not b.scripts . OnUpdate , ' empty pet slot still polling ' )
assert ( a.HotKey . text == ' - ' and b.HotKey . text == ' = ' )
assert ( a.AutoCastOverlay . auto and a.cooldown . cd [ 2 ] == 5 )
2026-11-21 16:24:58 -06:00
assert ( a.Normal . texture == ' native-Normal ' and a.Checked . texture == ' native-Checked ' , ' missing getter must use native named selected region, not generic glow ' )
assert ( a.Checked . alpha == 1 and a.Checked . blend == PetActionButton1.Checked : GetBlendMode ( ) , ' selected artwork opacity/blending mismatch ' )
assert ( a.Checked . points [ 1 ] [ 1 ] == ' TOPLEFT ' and a.Checked . layer [ 1 ] == ' OVERLAY ' , ' native artwork anchor/layer mismatch ' )
2026-11-21 17:24:50 -06:00
-- A modern atlas remains authoritative too; fallback art is used only when
-- neither a native atlas nor a native file texture exists.
local prototype , probe = frame ( ) , frame ( )
prototype : SetCheckedAtlas ( ' native-selected-atlas ' )
P.StyleActionButton ( probe , prototype )
assert ( probe.Checked : GetAtlas ( ) == ' native-selected-atlas ' , ' native atlas replaced by fallback ' )
P.StyleActionButton ( probe , nil )
assert ( probe.Checked : GetAtlas ( ) == ' UI-HUD-ActionBar-IconFrame-Mouseover ' , ' missing-art fallback unavailable ' )
2026-11-21 12:10:42 -06:00
assert ( a.clicks [ 1 ] == ' AnyDown ' and a.clicks [ 2 ] == ' AnyUp ' )
PetActionBar : Hide ( ) ; assert ( not a : IsShown ( ) and not b : IsShown ( ) , ' petless/vehicle visibility must follow native bar ' ) ; PetActionBar : Show ( )
local listener
for _ , f in ipairs ( frames ) do if f.events . PET_BAR_UPDATE then listener = f end end
assert ( listener )
-- A new pet arrives during combat: no secure writes until combat ends.
combat = true ; pet ( ' Demon ' , 6 )
listener.scripts . OnEvent ( listener , ' UNIT_PET ' , ' player ' ) ; flush ( )
P.RefreshPetExtras ( )
a.scripts . OnUpdate ( a , .25 )
assert ( listener.events . PLAYER_REGEN_ENABLED ) ; assertAction ( a , 9005 )
combat = false ; listener.scripts . OnEvent ( listener , ' PLAYER_REGEN_ENABLED ' ) ; flush ( )
assert ( not listener.events . PLAYER_REGEN_ENABLED )
assertAction ( a , 9005 ) ; assertAction ( b , 9006 )
-- Native rearrangement exposes a different missing ability, never overwrites native slots.
native [ 1 ] = { name = ' Demon5 ' , id = 9005 } ; listener.scripts . OnEvent ( listener , ' PET_BAR_UPDATE ' ) ; flush ( )
assert ( a.item . id == 9001 and b.item . id == 9006 and native [ 1 ] . id == 9005 )
-- Right-click autocast appearance follows the actual spellbook state.
auto = false ; a.scripts . OnUpdate ( a , .2 ) ; assert ( not a.AutoCastOverlay . auto )
picked = nil ; locked = true ; a.scripts . OnDragStart ( a ) ; assert ( not picked )
locked = false ; a.scripts . OnDragStart ( a ) ; assert ( picked == 1 )
picked = nil ; combat = true ; a.scripts . OnDragStart ( a ) ; assert ( not picked ) ; combat = false
-- Localized pet spells store stable action IDs, and petless states clear actions.
ClearCursor ( ) ; pet ( ' Медведь ' , 5 ) ; P.RefreshPetExtras ( ) ; assertAction ( a , 9005 )
book = { } ; native = { } ; P.RefreshPetExtras ( ) ; assert ( not a.attrs . type1 and not a.attrs . type2 and not a.attrs . macrotext2 )
assert ( not a.scripts . OnUpdate and not b.scripts . OnUpdate , ' petless polling ' )
-- A real native ResizeLayout bar includes every visible non-ignored child.
local included = { }
for _ , f in ipairs ( frames ) do if f.parent == PetActionBar and not f.ignoreInLayout then included [ # included + 1 ] = f end end
assert ( # included == 10 and a.ignoreInLayout and b.ignoreInLayout , ' extras enlarged native ten-slot width ' )
pet ( ' Demon ' , 6 ) ; locked = false ; P.RefreshPetExtras ( )
C_SpellBook.PickupSpellBookItem ( 2 , 1 ) ; a.scripts . OnReceiveDrag ( a )
assert ( not cursor and a.item . id == 9002 and RuenUICharacter.petExtraAssignments [ 1 ] . id == 9002 , ' drop did not pin pet spell ' )
assertAction ( a , 9002 )
P.RefreshPetExtras ( ) ; assert ( a.item . id == 9002 , ' pinned assignment did not survive refresh ' )
-- Book commands are valid too; other classes' player spells/passives/items are not.
book [ # book + 1 ] = { actionID = 117440516 , name = ' Move To ' , iconID = 10 , isPassive = false , itemType = 3 }
C_SpellBook.PickupSpellBookItem ( # book , 1 ) ; b.scripts . OnReceiveDrag ( b )
assert ( b.item . command == ' /petmoveto ' and actions [ b.attrs . action1 ] [ 2 ] == 117440516 and not b.attrs . type2 )
local pinned = a.item . id
cursor = { ' item ' , 123 } ; a.scripts . OnReceiveDrag ( a ) ; assert ( a.item . id == pinned and cursor )
cursor = { ' spell ' , 4 , ' spell ' , 99999 } ; a.scripts . OnReceiveDrag ( a ) ; assert ( a.item . id == pinned and cursor )
locked = true ; C_SpellBook.PickupSpellBookItem ( 3 , 1 ) ; a.scripts . OnReceiveDrag ( a ) ; assert ( a.item . id == pinned and cursor )
locked = false ; combat = true ; a.scripts . OnReceiveDrag ( a ) ; assert ( a.item . id == pinned and cursor ) ; combat = false
-- Missing learned abilities cannot leave a command targeting a former demon.
ClearCursor ( ) ; book = { } ; native = { } ; P.RefreshPetExtras ( ) ; assert ( not a.attrs . type1 and not b.attrs . type1 )
pet ( ' Demon ' , 6 ) ; P.RefreshPetExtras ( ) ; assert ( a.item . id == 9002 , ' preference was lost when pet disappeared ' )
P.ResetPetExtras ( ) ; assert ( a.item . id == 9005 and b.item . id == 9006 and not RuenUICharacter.petExtraAssignments )
RuenUIDB.disabled = true ; P.RefreshPetExtras ( ) ; assert ( not a.shown and not b.shown )
print ( ' PASS: ten native slots intact, twelve-button geometry, extra active spells, passive/command filtering, two-key native actions, autocast/cooldowns, pet/class/localization changes, combat deferral, lock-aware copy drag and disabled restore ' )
-- Reproduce restrictions during combat on a populated extra pet button.
RuenUIDB.disabled = false ; pet ( ' Hunter ' , 5 ) ; P.RefreshPetExtras ( )
local restricted = newproxy ( true )
getmetatable ( restricted ) . __lt = function ( ) error ( ' restricted cooldown comparison ' ) end
getmetatable ( restricted ) . __le = function ( ) error ( ' restricted cooldown comparison ' ) end
getmetatable ( restricted ) . __mul = function ( ) error ( ' restricted cooldown arithmetic ' ) end
getmetatable ( restricted ) . __sub = function ( ) error ( ' restricted cooldown arithmetic ' ) end
getmetatable ( restricted ) . __add = function ( ) error ( ' restricted cooldown arithmetic ' ) end
local durationObject = { }
function a . cooldown : SetCooldownFromDurationObject ( object , clearIfZero )
assert ( object == durationObject and clearIfZero == true )
self.durationObject = object
end
C_SpellBook.GetSpellBookItemCooldownDuration = function ( slot , bank )
assert ( slot == a.item . slot and bank == 1 ) ; return durationObject
end
cooldown = { startTime = restricted , duration = restricted , modRate = restricted }
combat = true
for i = 1 , 600 do a.scripts . OnUpdate ( a , .2 ) end
assert ( a.cooldown . durationObject == durationObject , ' native duration renderer not used ' )
C_SpellBook.GetSpellBookItemCooldownDuration = function ( ) return nil end
a.cooldown . cd = { 1 , 5 , 1 } ; a.scripts . OnUpdate ( a , .2 ) ; assert ( not a.cooldown . cd , ' missing duration did not clear stale swipe ' )
-- Older API fallback still hands opaque values straight to the native widget.
C_SpellBook.GetSpellBookItemCooldownDuration = nil
for i = 1 , 600 do a.scripts . OnUpdate ( a , .2 ) end
assert ( rawequal ( a.cooldown . cd [ 1 ] , restricted ) and rawequal ( a.cooldown . cd [ 2 ] , restricted ) )
cooldown = nil ; a.scripts . OnUpdate ( a , .2 ) ; assert ( not a.cooldown . cd )
combat = false
print ( ' PASS: 1200 combat refreshes with opaque cooldown values, native duration object path, nil/finished cleanup, legacy direct-native fallback; no secure attribute changes ' )
-- Execute Blizzard's actual secure dispatcher (mouse and key-down/up settings).
pet ( ' Hunter ' , 6 ) ; P.ResetPetExtras ( ) ; cooldown = nil
for _ , setting in ipairs ( { true , false } ) do
keyDown = setting
for _ , button in ipairs ( { a , b } ) do
local before =# uses ; combat = true ; click ( button , ' LeftButton ' ) ; combat = false
assert ( # uses == before + 1 and uses [ # uses ] == button.actionSlot , ' native activation must execute exactly once ' )
end
local before =# uses ; local toggleBefore = toggles
click ( a , ' RightButton ' ) ; assert ( # uses == before and toggles == toggleBefore + 1 , ' right click must toggle, not cast ' )
end
assert ( actions [ 25 ] [ 1 ] == ' spell ' and actions [ 25 ] [ 2 ] == 99999 and actions [ 1 ] [ 2 ] == 100 and actions [ 37 ] [ 2 ] == 6948 and actions [ 145 ] [ 2 ] == 222 , ' player actions changed ' )
local count = places ; for i = 1 , 200 do P.RefreshPetExtras ( ) end ; assert ( places == count , ' unchanged refresh rewrites action slots ' )
-- Autocast bits can change in a packed pet action without changing the spell.
local slot = a.actionSlot ; actions [ slot ] [ 2 ] = actions [ slot ] [ 2 ] + 2147483648
P.RefreshPetExtras ( ) ; assert ( a.actionSlot == slot and places == count , ' autocast flags leaked a reserved slot ' )
-- Respect a user replacement in a previously owned slot.
actions [ slot ] = { ' spell ' , 55555 } ; P.RefreshPetExtras ( )
assert ( actions [ slot ] [ 2 ] == 55555 and not a.actionSlot , ' user replacement overwritten ' )
P.ResetPetExtras ( )
-- Cursor contents defer background assignment and remain untouched.
cursor = { ' item ' , 777 } ; pet ( ' NewPet ' , 5 ) ; book [ 5 ] . actionID = 12345 ; book [ 5 ] . spellID = 12345
P.RefreshPetExtras ( ) ; assert ( cursor [ 1 ] == ' item ' and cursor [ 2 ] == 777 and not a.attrs . type1 )
ClearCursor ( ) ; listener.scripts . OnEvent ( listener , ' CURSOR_CHANGED ' ) ; flush ( ) ; assertAction ( a , 12345 )
-- Full spare pages are not an excuse to overwrite anything.
RuenUIDB.disabled = true ; P.RefreshPetExtras ( ) ; RuenUIDB.disabled = false
for i = 13 , 36 do actions [ i ] = { ' spell ' , 70000 + i } end
P.RefreshPetExtras ( ) ; assert ( not a.attrs . type1 and a.activationError == ' no unused paging slots ' )
for i = 13 , 36 do assert ( actions [ i ] [ 2 ] == 70000 + i ) end
print ( ' PASS: actual native secure click dispatcher, both click phases, combat, right-click autocast, real action records, packed-ID changes, cursor preservation, occupied-slot preservation, idempotency and graceful full-page handling ' )
-- Exercise the native spellbook's discovery/classification functions too.
for i = 13 , 24 do actions [ i ] = nil end
actions [ 25 ] = { ' spell ' , 99999 }
pet ( ' Hunter ' , 6 ) ; P.ResetPetExtras ( )
MainActionBar = frame ( ' MainActionBar ' , UIParent )
Enum.ActionBarSet = { Mkb = 0 , Gamepad = 1 }
InputUtil = { IsMKBUIEnabled = function ( ) return true end }
function TableIsEmpty ( t ) return next ( t ) == nil end
assert ( MultiActionBar_GetBarForPage ( 3 ) == MultiBarRight )
LE_ACTIONBAR_STATE_MAIN = 0
function ActionBarController_GetCurrentActionBarState ( ) return 0 end
C_ActionBar.GetVehicleBarIndex = function ( ) return 11 end
C_ActionBar.GetOverrideBarIndex = function ( ) return 12 end
C_ActionBar.GetTempShapeshiftBarIndex = function ( ) return 13 end
C_ActionBar.GetBonusBarIndex = function ( ) return 0 end
C_ActionBar.HasBonusActionBar = function ( ) return false end
C_ActionBar.HasOverrideActionBar = function ( ) return false end
C_ActionBar.HasVehicleActionBar = function ( ) return false end
C_ActionBar.HasTempShapeshiftActionBar = function ( ) return false end
C_ActionBar.GetPetActionPetBarIndices = function ( ) end
C_PetInfo.IsPetActionPassive = function ( ) return false end
local source = ( assert ( os.getenv ( ' RUEN_NATIVE_UI ' ) ) .. ' / ' )
dofile ( source .. ' ActionButtonUtil.lua ' ) ; dofile ( source .. ' Blizzard_SpellSearchUtil.lua ' )
for _ , button in ipairs ( { a , b } ) do
local info = book [ button.item . slot ]
assert ( SpellSearchUtil.GetActionbarStatusForSpellBookItemInfo ( info ) == ActionButtonUtil.ActionBarActionStatus . NotMissing , ' native spellbook does not recognize extra ' )
local saved = actions [ button.actionSlot ] ; actions [ button.actionSlot ] = nil
assert ( SpellSearchUtil.GetActionbarStatusForSpellBookItemInfo ( info ) == ActionButtonUtil.ActionBarActionStatus . MissingFromAllBars , ' negative control must be missing ' )
actions [ button.actionSlot ] = saved
end
print ( ' PASS: actual Blizzard spellbook discovery recognizes both extra action slots; removing their backing records reproduces missing-from-bars status ' )
-- Reject after the engine accepted a cursor payload: one write only, even if
-- action/cursor events storm, and even across addon reload (saved failure).
RuenUIDB.disabled = true ; P.RefreshPetExtras ( ) ; RuenUIDB.disabled = false
pet ( ' Reject ' , 5 ) ; rejectPlacement = true
local before = places
P.ResetPetExtras ( )
local failed = RuenUICharacter.petExtraActions [ 1 ]
assert ( failed and failed.failed and failed.payload and not a.attrs . type1 )
for i = 1 , 250 do
listener.scripts . OnEvent ( listener , ' ACTIONBAR_SLOT_CHANGED ' , failed.slot )
listener.scripts . OnEvent ( listener , ' CURSOR_CHANGED ' ) ; flush ( )
P.RefreshPetExtras ( )
end
assert ( places == before + 1 , ' rejected placement wrote more than once ' )
assert ( actions [ 25 ] and actions [ 25 ] [ 1 ] == ' spell ' and actions [ 25 ] [ 2 ] == 99999 , ' visible page 3 changed ' )
local Q = { Localized = P.Localized }
2026-11-21 16:24:58 -06:00
assert ( loadfile ( root .. ' ButtonStyle.lua ' ) ) ( ' RuenUI ' , Q )
2026-11-21 12:10:42 -06:00
assert ( loadfile ( root .. ' PetExtras.lua ' ) ) ( ' RuenUI ' , Q )
Q.InitializePetExtras ( function ( ) return true end )
assert ( places == before + 1 , ' reload retried rejected placement ' )
rejectPlacement = false
-- Active page 2 belongs to the player, not the allocator.
RuenUICharacter.petExtraActions = { } ; currentPage = 2
local snapshotPlaces = places
Q.RefreshPetExtras ( ) ; assert ( places == snapshotPlaces and not RuenPetExtraButton11.attrs . type1 )
print ( ' PASS: actual native page map, absent texture getters, distinct cursor/action types, one persisted attempt through 500 events/reload, no edits to visible/active pages ' )
-- Distinguish commands even though ALL report spell/0/pet to GetActionInfo.
currentPage = 1 ; rejectPlacement = false ; RuenUICharacter.petExtraActions = { }
for i = 13 , 24 do actions [ i ] = nil end
book = { { actionID = 100663300 , name = ' Defensive ' , iconID = 1 , isPassive = false } ,
{ actionID = 100663298 , name = ' Aggressive ' , iconID = 2 , isPassive = false } }
native = { }
RuenUICharacter.petExtraAssignments = { { id = 100663300 } , { id = 100663298 } }
Q.RefreshPetExtras ( )
local c , d = RuenPetExtraButton11 , RuenPetExtraButton12
assert ( c.actionSlot and d.actionSlot and c.actionSlot ~= d.actionSlot )
assert ( GetActionInfo ( c.actionSlot ) == ' spell ' and select ( 2 , GetActionInfo ( c.actionSlot ) ) == 0 and select ( 3 , GetActionInfo ( c.actionSlot ) ) == ' pet ' )
for _ , button in ipairs ( { c , d } ) do
local count =# uses ; click ( button , ' LeftButton ' ) ; assert ( # uses == count + 1 and uses [ # uses ] == button.actionSlot )
end
2026-11-21 16:24:58 -06:00
-- State belongs to the engine, not the last extra button clicked. Native
-- Passive (slot 0), a macro or a pet change must clear a selected extra stance.
click ( c , ' LeftButton ' ) ; c.scripts . OnUpdate ( c , .2 ) ; d.scripts . OnUpdate ( d , .2 )
assert ( c.checked and not d.checked and c.Checked . alpha == 1 )
activate ( 100663296 ) ; c.scripts . OnUpdate ( c , .2 ) ; d.scripts . OnUpdate ( d , .2 )
assert ( not c.checked and not d.checked , ' native Passive did not clear extra stance highlight ' )
click ( d , ' LeftButton ' ) ; c.scripts . OnUpdate ( c , .2 ) ; d.scripts . OnUpdate ( d , .2 )
assert ( not c.checked and d.checked , ' mutually exclusive stance highlights ' )
local startPlaces = places
for i = 1 , 500 do activate ( i % 2 == 0 and 100663300 or 100663296 ) ; c.scripts . OnUpdate ( c , .2 ) end
assert ( places == startPlaces , ' visual refresh altered action assignments ' )
print ( ' PASS: native selected artwork without getters, alpha/blend/layer parity, native/extra mutually exclusive stance state and 500 visual-only transitions ' )
P.SetActionButtonSelected ( c , true , true ) ; assert ( c.Flash . flashing and c.Checked . alpha == .5 , ' attack indication missing ' )
P.SetActionButtonSelected ( c , true , false ) ; assert ( not c.Flash . flashing and c.Checked . alpha == 1 , ' stance inherited attack flashing ' )
2026-11-21 12:10:42 -06:00
local slot = c.actionSlot ; actions [ slot ] = { storedType , 100663298 }
Q.RefreshPetExtras ( ) ; assert ( not c.actionSlot and actions [ slot ] [ 2 ] == 100663298 , ' another command with spell/0/pet was treated as owned ' )
print ( ' PASS: observed spell/0/pet payload activates both stance commands through native dispatcher and cannot confuse ownership of different commands ' )