Files

226 lines
14 KiB
Python

#!/usr/bin/env python3
"""Independent goldens for ongoing Classic unit/owned values; no live-client claim."""
import struct
import subprocess
import sys
P=struct.pack
body=P('<IBB',1,0,0)+bytes.fromhex('039d11')+bytes([1])+P('<II',1<<22,55)
wire=P('<HIQI',70,0,4509,0xA9)+body
expected=bytes.fromhex('00000100000080210000000003e09d1118010815000000010003200000000200000041003700000000000000')
r=subprocess.run([sys.argv[1],'--unit-values'],input=wire,capture_output=True,check=True)
assert r.stdout==expected,'Classic unit mask, ownership, fragment contents and health bytes differ'
for n in range(len(wire)):
r=subprocess.run([sys.argv[1],'--unit-values'],input=wire[:n],capture_output=True)
assert r.returncode!=0,'Truncated unit update accepted'
# An unimplemented legacy field must not invent a modern change or replace the unit.
body=P('<IBB',1,0,0)+bytes.fromhex('039d11')+bytes([1])+P('<II',1<<10,123)
r=subprocess.run([sys.argv[1],'--unit-values'],input=P('<HIQI',70,0,4509,0xA9)+body,capture_output=True,check=True)
assert r.stdout==P('<HIBI',0,0,0x80,0)
print('Classic unit-health golden, truncation and unsupported-field isolation checks passed.')
def power(cls,index,maximum=False):
field=23+index+(6 if maximum else 0);n=field//32+1
body=P('<IBB',1,0,0)+bytes.fromhex('039d11')+bytes([n])+b''.join(P('<I',(1<<(field%32)) if i==field//32 else 0) for i in range(n))+P('<I',123)
wire=P('<HIQBH',70,0,4509,cls,0)+P('<I',0xA9)+body
return subprocess.run([sys.argv[1],'--unit-values-profile'],input=wire,capture_output=True,check=True).stdout
# Same source value in native slot0 must be identical, regardless of legacy index.
assert power(1,1)==power(2,0)==power(4,3),'Warrior rage, Paladin mana and Rogue energy must use native slot0'
assert power(1,1,True)==power(2,0,True)==power(4,3,True),'Maximum resource uses the same data-derived slot'
assert power(11,1)!=power(1,1),'Druid rage is slot1 after mana, unlike Warrior rage'
assert power(1,0)==P('<HIBI',0,0,0x80,0),'Warrior has no mana slot in the actual class-power table'
assert power(1,4)==P('<HIBI',0,0,0x80,0),'Legacy happiness must not populate modern Warrior combo points'
assert power(1,1)!=P('<HIBI',0,0,0x80,0)
print('Actual class-power profile maps primary resources and isolates legacy happiness from combo points.')
# Source Unit.h GetShapeshiftForm = BYTES_1 byte2; destination UF bit90.
# Form transitions, including explicit zero, must survive sparse updates;
# unrelated bytes must not leak into the stance identity.
def form(value):
field=138;n=field//32+1
body=P('<IBB',1,0,0)+bytes.fromhex('039d11')+bytes([n])+b''.join(P('<I',(1<<(field%32)) if i==field//32 else 0) for i in range(n))+P('<I',value)
return subprocess.run([sys.argv[1],'--unit-values'],input=P('<HIQI',70,0,4509,0xA9)+body,capture_output=True,check=True).stdout
normal=form(0)
for value in (0,1,16,17,18,19,28,31):
out=form(value<<16)
assert out[:-1]==normal[:-1] and out[-1]==value,'Actual source form byte must occupy native ShapeshiftForm, including clear0'
assert form(17<<16 | 0xab<<8 | 0xcd<<24)==form(17<<16),'Other BYTES_1 fields must not leak into form'
assert form(17<<16 | 1)!=form(17<<16),'StandState remains independently represented'
print('Source form byte2 persists through native UF ShapeshiftForm with independent stand and explicit clear0.')
# Genuine PLAYER_GUILDID191 is a guild128 in UnitData, whereas guild rank192
# belongs to PlayerData. Clearing membership/rank must explicitly serialize0.
def guild_field(index,value):
n=index//32+1
body=P('<IBB',1,0,0)+bytes.fromhex('039d11')+bytes([n])+b''.join(P('<I',(1<<(index%32)) if i==index//32 else 0) for i in range(n))+P('<I',value)
return subprocess.run([sys.argv[1],'--unit-values'],input=P('<HIQI',70,0,4509,0xA9)+body,capture_output=True)
# Original PlayerData bit14/group0 is independent of UnitData health/flags.
# Ghost clears and source hide-helm/cloak must not enable retail War Mode.
player_zero=guild_field(190,0);assert player_zero.returncode==0
for flags in (0,1,2,4,8,16,32,0x100,0x200,0x1000,0x2000,0x20000,0x40000,0xffffffff):
r=guild_field(190,flags);assert r.returncode==0
assert r.stdout[:-4]==player_zero.stdout[:-4] and r.stdout[-4:]==P('<I',flags&0x6333f)
assert guild_field(190,0x410).stdout==guild_field(190,0x10).stdout
assert guild_field(190,0xcc0).stdout==player_zero.stdout
print('Source PlayerFlags ghost/status transitions and explicit clear0 survive sparse updates; foreign modern capabilities excluded.')
# Pinned Turtle UNIT_FIELD_BYTES_2=164, byte0 -> native SheatheState.
# The original explicit-mask writer remaps retail bit87 to Classic bit90.
# Keep explicit UNARMED0 clears and isolate the unrelated three source bytes.
sheath_zero=guild_field(164,0)
assert sheath_zero.returncode==0 and sheath_zero.stdout[-1]==0
for state in (0,1,2):
r=guild_field(164,state)
assert r.returncode==0 and r.stdout[:-1]==sheath_zero.stdout[:-1] and r.stdout[-1]==state
other=guild_field(164,0xabcd1200|state)
assert other.returncode==0 and other.stdout==r.stdout,'Unrelated BYTES_2 bytes leaked into SheatheState'
print('Genuine sparse sheath states map to original native UnitData with explicit clear and high-byte isolation.')
for rank in (0,1,4,9):
r=guild_field(192,rank);assert r.returncode==0 and struct.unpack_from('<I',r.stdout,2)[0]==1
assert r.stdout[-4:]==P('<I',rank),'Guild rank is actual sparse PlayerData, including rank0'
assert guild_field(192,10).returncode!=0,'Out-of-range legacy guild rank accepted'
member=guild_field(191,21);cleared=guild_field(191,0)
assert member.returncode==cleared.returncode==0 and member.stdout!=cleared.stdout
assert bytes.fromhex('15000000000000000000180100000070') not in member.stdout,'Guild GUID should use packed wire encoding, not raw128'
# Membership writes both the packed Unit GuildGUID and Player ClubMemberID.
# Trinity's member ID is character4509 | (realm70 << 48), not guild21.
assert member.stdout==bytes.fromhex(
'000001000000802e0000000003e09d111801082200000001000360000000100000001100'
'01e01518017000002000020020')+P('<Q',4509|(70<<48)), 'Guild/member field ownership or identity differs'
assert cleared.stdout==bytes.fromhex(
'000001000000802a0000000003e09d111801081e00000001000360000000100000001100'
'000000002000020020')+bytes(8), 'Membership clear must clear both guild and club member identities'
print('Guild identity/rank sparse updates preserve source IDs, Guild high-type, field ownership and clear0.')
# Player bytes2 byte1 owns the native ActivePlayer AuraVision field. Other
# source bits and bytes cannot invent extra presentation capabilities.
zero=guild_field(1260,0);assert zero.returncode==0
for bits in (0,0x20,0x40,0x60):
r=guild_field(1260,bits<<8);assert r.returncode==0 and r.stdout[-1]==bits
other=guild_field(1260,(bits<<8)|0xab0000cd|(0x1f<<8))
assert other.stdout==r.stdout,'Unreviewed source bytes/flags leaked into AuraVision'
assert guild_field(1260,0x4000).stdout!=zero.stdout,'Invisibility presentation must survive a sparse player update'
print('Source-backed AuraVision flags are sparse ActivePlayer values with explicit clear and unrelated-byte isolation.')
# Independent ObjectData writer contract: source UNIT_DYNAMIC_FLAGS=143 is
# a unit field, but native DynamicFlags belongs to ObjectData, mask bits0/2.
# Tortoise Object::BuildValuesUpdate has already filtered these for the viewer;
# native TAPPED means a foreign tap, not source TAPPED_BY_PLAYER.
def packed(raw):
return P('<H',sum(1<<i for i,b in enumerate(raw) if b))+bytes(b for b in raw if b)
def packed64(value):
raw=value.to_bytes(8,'little')
return bytes([sum(1<<i for i,b in enumerate(raw) if b)])+bytes(b for b in raw if b)
dynamic_cases=((0,0),(1,4),(2,8),(4,16),(8,0),(12,0),(5,20),(13,4),
(16,32),(32,0),(31,44),(0xffffffff,44))
for owner,high in ((4509,(2<<58)|(70<<42)),
((0xF130<<48)|(6<<24)|4509,(8<<58)|(70<<42)|(6<<6))):
modern=P('<QQ',4509,high)
for legacy,native in dynamic_cases:
source=P('<IBB',1,0,0)+packed64(owner)+bytes([5])+P('<5I',0,0,0,0,1<<15)+P('<I',legacy)
actual=subprocess.run([sys.argv[1],'--unit-values'],input=P('<HIQI',70,0,4509,0xA9)+source,capture_output=True,check=True).stdout
# UF::ObjectData DynamicFlags is UpdateField<uint32,0,2>: group0 plus
# child2 give mask0b0101, not0b0110. Original WriteBits(mask,4) emits
# that nibble MSB-first as0x50, then FlushBits and DynamicFlags uint32.
values=bytes([int(owner==4509),0,3])+P('<I',1)+bytes([0x50])+P('<I',native)
block=bytes([0])+packed(modern)+P('<I',len(values))+values
expected=P('<HIBI',0,1,0x80,len(block))+block
assert actual==expected,'Unit dynamic semantics or original ObjectData ownership/mask differ'
print('24 independent self/NPC sparse dynamic flag goldens preserve explicit clear and viewer tap ownership.')
# Pinned original SkillInfo::WriteUpdate, not the adapter's source-triple loop:
# ActivePlayer.Skill is group32/bit63 (unchanged by Classic remapping). Its
# nested2101-bit mask has root0 and seven300-element arrays at the offsets below.
# The original writer emits two LE32 blocks masks, two extra mask bits, each
# present32-bit block MSB-first, flushes, then changed fields in slot/array order.
skill_arrays=(('id',1),('step',301),('rank',601),('starting',901),
('maximum',1201),('temporary',1501),('permanent',1801))
def written_bits(fields):
bits=''.join(format(value,'0%db'%width) for value,width in fields)
bits+='0'*((-len(bits))%8)
return int(bits,2).to_bytes(len(bits)//8,'big')
def skill_golden(slots):
mask=1
for slot,fields in slots.items():
for name,offset in skill_arrays:
if name in fields:mask|=1<<(offset+slot)
blocks=[(mask>>(32*index))&0xffffffff for index in range(66)]
present=sum(1<<index for index,block in enumerate(blocks) if block)
nested=P('<II',present&0xffffffff,(present>>32)&0xffffffff)
nested+=written_bits([((present>>64)&3,2)]+[(block,32) for block in blocks if block])
for slot,fields in sorted(slots.items()):
for name,_ in skill_arrays:
if name in fields:nested+=P('<h' if name=='temporary' else '<H',fields[name])
active=written_bits([(2,14),(0x80000001,32)])+nested
values=bytes([1,0,3])+P('<I',1<<7)+active
modern=P('<QQ',4509,(2<<58)|(70<<42))
block=bytes([0])+packed(modern)+P('<I',len(values))+values
return P('<HIBI',0,1,0x80,len(block))+block
def skill_source(fields,owner=4509,mode='--unit-values-profile',self_class=1):
words=max(fields)//32+1
mask=[0]*words
for field in fields:mask[field//32]|=1<<(field%32)
body=P('<IBB',1,0,0)+packed64(owner)+bytes([words])+P('<%dI'%words,*mask)
body+=b''.join(P('<I',value) for _,value in sorted(fields.items()))
header=P('<HIQ',70,0,4509)+(P('<BH',self_class,0) if mode=='--unit-values-profile' else b'')+P('<I',0xa9)
return subprocess.run([sys.argv[1],mode],input=header+body,capture_output=True)
# Manual destination expectations cover both endpoints, each source word,
# explicit zero, maximum unsigned rank/step, and signed bonus bit preservation.
skill_cases=(
({718:0x1234002b},{0:{'id':43,'step':0x1234,'starting':1}}),
({718:0},{0:{'id':0,'step':0,'starting':0}}),
({718:0xffff0000},{0:{'id':0,'step':65535,'starting':0}}),
({719:0xffff012c},{0:{'rank':300,'maximum':65535}}),
({719:0},{0:{'rank':0,'maximum':0}}),
({720:0xfffdfff9},{0:{'temporary':-7,'permanent':65533}}),
({720:0x00030000},{0:{'temporary':0,'permanent':3}}),
({720:0},{0:{'temporary':0,'permanent':0}}),
({1099:0xffff0036},{127:{'id':54,'step':65535,'starting':1}}),
({1099:0},{127:{'id':0,'step':0,'starting':0}}),
({1100:0x012cffff},{127:{'rank':65535,'maximum':300}}),
({1100:0},{127:{'rank':0,'maximum':0}}),
({1101:0x80008000},{127:{'temporary':-32768,'permanent':32768}}),
({1101:0},{127:{'temporary':0,'permanent':0}}),
({718:43,719:0x012c012b,720:0x00030000,1099:0,1100:0,1101:0},
{0:{'id':43,'step':0,'rank':299,'starting':1,'maximum':300,'temporary':0,'permanent':3},
127:{'id':0,'step':0,'rank':0,'starting':0,'maximum':0,'temporary':0,'permanent':0}}),
)
for mode in ('--unit-values','--unit-values-profile'):
for source,expected_slots in skill_cases:
result=skill_source(source,mode=mode)
assert result.returncode==0,result.stderr.decode()
assert result.stdout==skill_golden(expected_slots),'Sparse skill source halves, original nested masks or changed-field payload differ'
for owner in (4510,(0xf130<<48)|(6<<24)|4509):
result=skill_source({718:43,719:0x012c012c,720:0x00030000},owner=owner,mode=mode)
assert result.returncode==0 and result.stdout==P('<HIBI',0,0,0x80,0),'Foreign/nonplayer skill fields leaked into the owned SkillInfo'
result=skill_source({1103:0xffffffff},mode=mode)
assert result.returncode==0 and result.stdout==P('<HIBI',0,0,0x80,0),'Unsupported following field expanded the skill range'
print('30 independent sparse skill goldens preserve native nested masks, first/last slot, clears and signed bonus bits; foreign fields remain isolated.')
# Pinned source PLAYER_FIELD_BYTES1222 byte0 -> original ActivePlayerData
# LocalFlags bit101/group70. Native <=107 mask bits are unchanged. Derive
# the full independent original mask/frame, including explicit zero clears.
def local_flags_golden(value,source,cls):
# PLAYER_FIELD_BYTES also owns lifetime rank (byte3) and class combo power
# (byte1). Assert those real sibling fields rather than calling them unrelated.
active=written_bits([(12,14),(1<<6,32),((1<<5)|(1<<6)|(1<<9),32)])+P('<IB',value,source>>24)
combo_slot={4:1,11:3}.get(cls)
unit=b''
if combo_slot is not None:
unit=written_bits([(1<<4,8),((1<<21)|(1<<(22+combo_slot)),32),(0,1)])+P('<I',(source>>8)&255)
values=bytes([1,0,3])+P('<I',(1<<7)|((1<<5) if unit else 0))+unit+active
modern=P('<QQ',4509,(2<<58)|(70<<42))
block=bytes([0])+packed(modern)+P('<I',len(values))+values
return P('<HIBI',0,1,0x80,len(block))+block
for cls in (1,2,3,4,5,7,8,9,11):
for bits in range(8):
value=sum(flag for i,flag in enumerate((2,8,16)) if bits&(1<<i))
for unrelated in (0,0xffff00e5):
result=skill_source({1222:value|unrelated},self_class=cls)
assert result.returncode==0 and result.stdout==local_flags_golden(value,value|unrelated,cls),('Source LocalFlags/rank/combo differ',cls,value|unrelated,result.stdout.hex(),local_flags_golden(value,value|unrelated,cls).hex())
for cls in (4,11):
for points in (0,1,5):
source=(14<<24)|(points<<8)|0x1a
result=skill_source({1222:source},self_class=cls)
assert result.returncode==0 and result.stdout==local_flags_golden(0x1a,source,cls), 'Combo points or lifetime rank lost beside LocalFlags'
assert skill_source({1222:0x1a},owner=0xf130000001000001).stdout==P('<HIBI',0,0,0x80,0)
print('144 whole-packet LocalFlags goldens across nine classes retain lifetime rank and class combo siblings; unrelated low bits and foreign owners stay excluded.')