Files
WoW-Hybrid-gateway/tests/native_loot_roll_wire_test.lua

84 lines
4.5 KiB
Lua

-- Actual codec packets -> modeled engine cache/events -> actual native Lua.
-- Roll tokens are host-only opaque handles, not claimed to match live engine IDs.
local function read(path) local f=assert(io.open(path,'rb'));local b=f:read('*a');f:close();return b end
local bytes, at = read(arg[1]), 1
local function uint(n)
assert(at+n-1<=#bytes);local value=0
for i=0,n-1 do value=value+bytes:byte(at+i)*256^i end
at=at+n;return value
end
local rolls, identities = {}, {}
local count=uint(4);assert(count==16)
for token=1,count do
assert(uint(4)==0x4700c7);local size=uint(4);local finish=at+size
local guidStart=at;local mask=uint(2)
for bit=0,15 do if math.floor(mask/2^bit)%2==1 then uint(1) end end
local guid=bytes:sub(guidStart,at-1);assert(#guid>2)
assert(uint(4)==1) -- MapID
assert(uint(1)==8 and uint(4)==1 and uint(1)==0) -- LootItem type/count/UIType
local slot=uint(1);local item=uint(4);assert(slot==token-1 and item==99)
assert(uint(2)==0) -- ItemInstance optional-data flags
local duration=uint(4);assert(duration>0 and duration<=60000)
assert(uint(1)==7);for i=1,20 do assert(uint(1)==0) end
local method=uint(1);assert(method==3 or method==4);assert(uint(4)==0 and at==finish)
local identity=guid..string.char(slot);assert(not identities[identity]);identities[identity]=token
rolls[token]={item=item,duration=duration,slot=slot,deadline=duration/1000}
end
assert(at==#bytes+1)
local now,timers,listener=0,{},nil
max=math.max
InputUtil={IsGamepadUIEnabled=function() return false end}
FrameUtil={RegisterFrameForEvents=function() end}
ColorManager={GetAtlasDataForLootBorderItemQuality=function() return 'test' end,GetColorDataForItemQuality=function() return nil end}
Enum={ItemQuality={Uncommon=2}}
function issecure() return true end -- Host model only: no engine taint claim.
function GetTime() return now end
function GetLootRollItemInfo(id)
local r=assert(rolls[id]);return 1,r.cached and ('Item '..r.item) or nil,1,2,false,true,true,false,0,0,0,0,false
end
function GetLootRollTimeLeft(id) return math.max(0,(assert(rolls[id]).deadline-now)*1000) end
function RollOnLoot() end
function hooksecurefunc() end
C_Timer={After=function(_,cb) timers[#timers+1]=cb end}
function CreateFrame()
return {RegisterEvent=function() end,SetScript=function(_,_,cb) listener=cb end}
end
local function noop() end
local function widget()
return {SetTexture=noop,SetAtlas=noop,SetText=noop,SetVertexColor=noop,Show=noop,Hide=noop,
Enable=noop,Disable=noop,SetAlpha=noop,SetDesaturated=noop,SetFrameLevel=noop,SetMinMaxValues=noop,
GetNormalTexture=function(self) return self end}
end
local layoutCalls=0
GroupLootContainer={rollFrames={},waitingRolls={},maxIndex=0,reservedSize=100,
SetHeight=noop,Show=noop,Hide=noop,layoutParent={Layout=function() layoutCalls=layoutCalls+1 end}}
for i=1,4 do
local f={shown=false,Timer=widget(),Name=widget(),Border=widget(),IconFrame={Icon=widget(),Border=widget(),Count=widget()},
LootButtonContainer={NeedButton=widget(),GreedButton=widget(),TransmogButton=widget()},
ClearAllPoints=noop,SetPoint=noop,GetFrameLevel=function() return 10 end}
function f:IsShown() return self.shown end
function f:Show() self.shown=true;GroupLootFrame_OnShow(self) end
function f:Hide() self.shown=false end -- Rendering/OnHide animation are outside this host model.
_G['GroupLootFrame'..i]=f
end
-- Execute the pinned original functions, then the native-only appended helper.
dofile(arg[2]);dofile(arg[3]);assert(listener)
for id,r in ipairs(rolls) do
GroupLootContainer_AddRoll(id,r.duration) -- Engine's normal START_LOOT_ROLL UI consumer.
listener(nil,'START_LOOT_ROLL',id,r.duration)
end
assert(GroupLootContainer.maxIndex==0 and #GroupLootContainer.waitingRolls==0)
for _,r in ipairs(rolls) do r.cached=true end
listener(nil,'GET_ITEM_INFO_RECEIVED',99,true)
now=.25;local run=timers;timers={};for _,cb in ipairs(run) do cb() end
assert(GroupLootContainer.maxIndex==4 and #GroupLootContainer.waitingRolls==12)
local seen={}
while GroupLootContainer.maxIndex>0 do
local _,f=next(GroupLootContainer.rollFrames);assert(f and f:IsShown() and not seen[f.rollID])
assert(f.rollTime>0 and f.rollTime<=rolls[f.rollID].duration-250)
seen[f.rollID]=true;GroupLootContainer_RemoveFrame(GroupLootContainer,f)
end
for id in ipairs(rolls) do assert(seen[id]) end
assert(#GroupLootContainer.waitingRolls==0 and #timers==0 and layoutCalls>0)
print('real codec -> host engine model -> original native Lua: 16 cache misses recovered, 4 visible + 12 queued, each shown once PASS')