120 lines
6.8 KiB
Python
120 lines
6.8 KiB
Python
"""Original-frame posthooks, source PvE baselines, and secret-value boundaries."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
lua=r'''
|
|
local hooks, lines = {}, {}
|
|
local secret, mounted, onLoad = {}, false, nil
|
|
function issecretvalue(value)return value==secret end
|
|
function IsMounted()return mounted end
|
|
function CreateFrame()
|
|
local frame={}
|
|
function frame:RegisterEvent()end
|
|
function frame:UnregisterEvent()end
|
|
function frame:SetScript(_,fn)onLoad=fn end
|
|
return frame
|
|
end
|
|
function MovementSpeed_OnUpdate(frame)frame.Label:SetText('Movement Speed:')end
|
|
function MovementSpeed_OnEnter()end
|
|
function PaperDollFrame_SetDefense()end
|
|
function CharacterDefenseFrame_OnEnter()end
|
|
local original=MovementSpeed_OnUpdate
|
|
function hooksecurefunc(name,fn)assert(not hooks[name]);hooks[name]=fn end
|
|
GameTooltip={AddLine=function(_,text)lines[#lines+1]={text}end,
|
|
AddDoubleLine=function(_,a,b)lines[#lines+1]={a,b}end,Show=function()end}
|
|
GameTooltipTextLeft1={SetText=function(_,text)GameTooltipTextLeft1.text=text end}
|
|
function UnitLevel()return 60 end
|
|
function GetDodgeChance()return 15 end
|
|
function GetParryChance()return 10 end
|
|
function GetBlockChance()return 5 end
|
|
function UnitArmor()return 5500,5500 end
|
|
local offType='INVTYPE_WEAPONOFFHAND'
|
|
function GetInventoryItemID(_,slot)return slot end
|
|
local durability,maximum=100,100
|
|
function GetInventoryItemDurability()return durability,maximum end
|
|
C_Item={GetItemInfoInstant=function(id)return id,nil,nil,id==16 and 'INVTYPE_WEAPONMAINHAND'or offType end}
|
|
dofile(arg[1]);local info=WoWHybridUI.characterStats
|
|
assert(info.installed and MovementSpeed_OnUpdate==original)
|
|
local function close(a,b)assert(math.abs(a-b)<0.00001,tostring(a)..' vs '..tostring(b))end
|
|
local normal=info.DefenseComparison(60,300,15,10,5,60,5500)
|
|
assert(normal.miss==5 and normal.baseCrit==5 and normal.crushingEntry==0)
|
|
assert(normal.dodge==15 and normal.parry==10 and normal.block==5)
|
|
close(normal.armorReduction,50)
|
|
local boss=info.DefenseComparison(60,300,15,10,5,63,5500)
|
|
close(boss.miss,4.4);close(boss.baseCrit,5.6);close(boss.crushingEntry,15)
|
|
close(boss.dodge,14.4);close(boss.parry,9.4);close(boss.block,4.4)
|
|
assert(boss.armorReduction<normal.armorReduction)
|
|
local geared=info.DefenseComparison(60,440,20.6,15.6,0,63,50000)
|
|
assert(geared.baseCrit==0 and geared.block==0 and geared.crushingEntry==15)
|
|
assert(geared.armorReduction==75)
|
|
close(geared.dodge,20);close(geared.parry,15)
|
|
assert(info.DefenseComparison(60,285,5,0,0,60).crushingEntry==15)
|
|
assert(not info.DefenseComparison(60,nil,5,5,5,63))
|
|
assert(not info.DefenseComparison(60,secret,5,5,5,63))
|
|
assert(not info.DefenseComparison(60,300,0/0,5,5,63))
|
|
assert(not info.DefenseComparison(61,305,5,5,5,64))
|
|
local frame={unit='player',speed=200,runSpeed=200,effectiveDefenseSkill=300,
|
|
Label={SetText=function(self,text)self.text=text end}}
|
|
mounted=true;original(frame);hooks.MovementSpeed_OnUpdate(frame)
|
|
assert(frame.Label.text=='Mounted Speed')
|
|
hooks.MovementSpeed_OnEnter(frame)
|
|
assert(GameTooltipTextLeft1.text=='Mounted Movement Speed: 200%')
|
|
assert(lines[3][1]=='Bonus over normal running'and lines[3][2]=='+100%')
|
|
mounted=false;original(frame);hooks.MovementSpeed_OnUpdate(frame)
|
|
assert(frame.Label.text=='Movement Speed:')
|
|
local count=#lines;frame.runSpeed=secret;hooks.MovementSpeed_OnEnter(frame);assert(#lines==count)
|
|
hooks.PaperDollFrame_SetDefense(frame,'player');hooks.CharacterDefenseFrame_OnEnter(frame)
|
|
local same,higher=false,false
|
|
for _,line in ipairs(lines)do
|
|
same=same or line[1]=='Same-level enemy (level 60)'
|
|
higher=higher or line[1]=='Boss baseline (level 63)'
|
|
end
|
|
assert(same and higher)
|
|
assert(lines[#lines-4][1]=='Block'and lines[#lines-4][2]=='0.00%')
|
|
offType='INVTYPE_SHIELD';hooks.CharacterDefenseFrame_OnEnter(frame)
|
|
assert(lines[#lines-4][1]=='Block'and lines[#lines-4][2]=='4.40%')
|
|
durability=0;hooks.CharacterDefenseFrame_OnEnter(frame)
|
|
assert(lines[#lines-4][2]=='0.00%')
|
|
maximum=0;hooks.CharacterDefenseFrame_OnEnter(frame) -- Indestructible is not broken.
|
|
assert(lines[#lines-4][2]=='4.40%')
|
|
hooks.PaperDollFrame_SetDefense(frame,'pet');count=#lines;hooks.CharacterDefenseFrame_OnEnter(frame);assert(count==#lines)
|
|
-- The addon may read equipment-limited avoidance without modifying Camelot's
|
|
-- native stat registry or its scroll-box categories.
|
|
local nativeArmor=function()return 4600 end
|
|
local nativeDefense=function()return 327 end
|
|
local defense={unit='player',stats={{stat='DEFENSE'},{stat='DODGE',hideAt=0},
|
|
{stat='BLOCK',hideAt=0},{stat='PARRY',hideAt=0},{stat='ARMOR'}}}
|
|
local pet={unit='pet',stats={{stat='DODGE',hideAt=0}}}
|
|
PAPERDOLL_STATCATEGORIES={defense,pet}
|
|
PAPERDOLL_STATINFO={ARMOR={updateFunc=nativeArmor},DEFENSE={updateFunc=nativeDefense}}
|
|
local nativeCategories,nativeInfo=PAPERDOLL_STATCATEGORIES,PAPERDOLL_STATINFO
|
|
onLoad();onLoad()
|
|
assert(PAPERDOLL_STATCATEGORIES==nativeCategories and PAPERDOLL_STATINFO==nativeInfo)
|
|
assert(#defense.stats==5 and defense.stats[3].stat=='BLOCK' and defense.stats[3].hideAt==0)
|
|
assert(pet.stats[1].stat=='DODGE' and pet.stats[1].hideAt==0)
|
|
assert(nativeInfo.ARMOR.updateFunc==nativeArmor and nativeInfo.DEFENSE.updateFunc==nativeDefense)
|
|
local main,off=16,17;function GetInventoryItemID(_,slot)if slot==16 then return main end;return off end
|
|
durability,maximum=100,100;offType='INVTYPE_SHIELD'
|
|
assert(info.ReadAvoidanceChance('BLOCK')==5 and info.ReadAvoidanceChance('PARRY')==10)
|
|
off=nil;assert(info.ReadAvoidanceChance('BLOCK')==0)
|
|
main=nil;assert(info.ReadAvoidanceChance('PARRY')==0)
|
|
main,off=16,17;durability=0
|
|
assert(info.ReadAvoidanceChance('BLOCK')==0 and info.ReadAvoidanceChance('PARRY')==0)
|
|
durability=secret
|
|
assert(info.ReadAvoidanceChance('BLOCK')==nil and info.ReadAvoidanceChance('PARRY')==nil)
|
|
GetBlockChance=function()return 0 end;assert(info.ReadAvoidanceChance('BLOCK')==0)
|
|
GetBlockChance=nil;assert(info.ReadAvoidanceChance('BLOCK')==nil)
|
|
assert(PAPERDOLL_STATCATEGORIES==nativeCategories and PAPERDOLL_STATINFO==nativeInfo)
|
|
dofile(arg[1]);assert(WoWHybridUI.characterStats==info and MovementSpeed_OnUpdate==original)
|
|
'''
|
|
subprocess.run(['lua','-',str(ROOT/'client_addons/WoWHybridUI/NativeCharacterStats.lua')],input=lua.encode(),check=True)
|
|
print('Native movement and defense tooltips, addon avoidance reads, native registry isolation and missing/secret values PASS.')
|
|
|
|
# Exercise the Camelot instance/ModeTabs controls and Statistics tree after a late load.
|
|
toc = (ROOT/'client_addons/WoWHybridUI/WoWHybridUI.toc').read_text().splitlines()
|
|
assert '## SavedVariablesPerCharacter: WoWHybridCharacterStatistics' in toc
|
|
assert all('WoWHybridCharacterStatistics' not in line for line in toc if line.startswith('## SavedVariables:'))
|
|
extras = (ROOT / 'tests/fixtures/character_addon_panel_contract.lua').read_text()
|
|
subprocess.run(['lua', '-', str(ROOT/'client_addons/WoWHybridUI/NativeCharacterExtras.lua')], input=extras.encode(), check=True)
|
|
print('Character addon panel contract passed.')
|