Files

284 lines
18 KiB
Python

#!/usr/bin/env python3
"""Offline checks for the optional source-derived serializer; not client compatibility."""
import struct
import math
import os
import subprocess
import sys
P=struct.pack
fields={22:80,28:80,34:1,35:1,36:0x01000101,718:98,719:0x012C012C}
# Health, max health, level and race/class metadata use audited legacy indices.
mask=[0]*23
for index in fields:mask[index//32]|=1<<(index%32)
body=P('<IBB',1,0,3)+bytes.fromhex('039d11')+bytes([4,0x21])+P('<II4fI',0,100,1,2,3,0,0)+P('<6f',2.5,7,4.5,4.72,2.5,3.14)
body+=bytes([len(mask)])+P('<23I',*mask)+b''.join(P('<I',fields[i]) for i in sorted(fields))
header=P('<QHIIIII',4509,70,0x46010046,0,12,2,2)+b'Gatewaytest\0'+bytes([1,1,0])+P('<I',0xA9)
def run(wire):return subprocess.run([sys.argv[1]],input=wire,capture_output=True,timeout=15)
r=run(header+body)
assert r.returncode==0,r.stderr.decode()
packet=r.stdout
map_id,count,flags,block_size=struct.unpack_from('<HIBI',packet)
assert (map_id,count,flags)==(0,2,0x80)
assert block_size==len(packet)-11
def packed_end(at):
mask=int.from_bytes(packet[at:at+2],'little');return at+2+mask.bit_count()
at=11
assert packet[at]==2
at=packed_end(at+1)
assert packet[at]==2, 'Vanilla bank represented as modern container'
at+=1+3+4
size=struct.unpack_from('<I',packet,at)[0];at+=4+size
start=at
assert packet[start]==2 and packet[start+1:start+8]==bytes.fromhex('03e09d11180108')
assert packet[start+8]==7 and packet[start+9:start+12]==bytes([0x8C,0,0x80])
assert packet[start+16:start+23]==bytes.fromhex('03e09d11180108'), 'MovementUpdate requires its mover GUID'
assert struct.unpack_from('<QI4f',packet,start+23)==(0,0,1,2,3,0), 'Initial movement state must preserve backend position'
negative_self=bytearray(body)
struct.pack_into('<f',negative_self,31,-2.39142)
negative_result=run(header+negative_self)
assert negative_result.returncode==0,negative_result.stderr.decode()
negative_wire=negative_result.stdout
self_angle_offset=start+47
self_angle=struct.unpack_from('<f',negative_wire,self_angle_offset)[0]
assert 0<=self_angle<2*math.pi and abs(self_angle-3.891765)<0.00001
assert negative_wire[:self_angle_offset]+negative_wire[self_angle_offset+4:]==packet[:self_angle_offset]+packet[self_angle_offset+4:], 'Negative self facing changed unrelated create fields'
# Far NewWorld is a separate native facing writer; equivalent source angles
# must produce the same destination packet without changing the source state.
source_angle=struct.unpack('<f',P('<f',-2.39142))[0]
turn=struct.unpack('<f',P('<f',2*math.pi))[0]
canonical_angle=struct.unpack('<f',P('<f',source_angle+turn))[0]
def new_world(angle):
return subprocess.run([sys.argv[1],'--world-transfer'],input=bytes([2])+P('<I4fI',0,1.,2.,3.,angle,1),capture_output=True,timeout=15)
negative_transfer=new_world(source_angle)
canonical_transfer=new_world(canonical_angle)
assert negative_transfer.returncode==canonical_transfer.returncode==0
assert negative_transfer.stdout==canonical_transfer.stdout, 'NewWorld facing was not normalized for Forever'
assert packet[start+71:start+73]==bytes(2), 'Movement optional bits'
assert struct.unpack_from('<9f',packet,start+73)[1]==7, 'Authoritative run speed'
assert struct.unpack_from('<I',packet,start+187)[0]==len(packet)-(start+191), 'Typed value section follows complete movement state'
assert len(packet)>19000 and b'Gatewaytest' in packet and b'Turtle bank' in packet
assert bytes.fromhex('620000002c0101002c0100000000') in packet, 'Backend Common skill and ranks preserved'
bad=bytearray(header+body);bad[0]^=1
assert run(bad).returncode!=0
assert run((header+body)[:-1]).returncode!=0
# Server-confirmed control modes are current state, not old input history.
# Their source/native flag values differ; the complete output must otherwise
# remain unchanged, including equipment, ownership and typed values.
mode_flags=((0x1000,0x400),(0x10000000,0x04000000),
(0x20000000,0x08000000),(0x40000000,0x0800000000000000))
for selection in range(16):
source_flags=native_flags=0
for i,(legacy,modern) in enumerate(mode_flags):
if selection&(1<<i):source_flags|=legacy;native_flags|=modern
changed=bytearray(body);struct.pack_into('<I',changed,11,source_flags)
result=run(header+changed);assert result.returncode==0,result.stderr.decode()
expected=bytearray(packet);struct.pack_into('<Q',expected,start+23,native_flags)
assert result.stdout==expected,'Initial source movement modes lost or numerically copied into native flags'
print('16 original self-create mode combinations preserve all unrelated bytes; no actual-client movement claim.')
native_header=P('<QHIIIII',4509,70,0x46010046,0,12,0,0)+b'Gatewaytest\0'+bytes([1,1,0])+P('<I',0xA9)
native=run(native_header+body)
assert native.returncode==0,native.stderr.decode()
assert b'Gatewaytest' in native.stdout and len(native.stdout)>19000
assert native.stdout!=packet,'Absent native account GUIDs must differ from authenticated modern-provider identities'
print('3 optional serializer fixture cases passed; actual world entry unverified.')
# Original ObjectData::WriteCreate is EntryID32, DynamicFlags32, Scale32.
# The self values section has six fragment/visibility bytes before ObjectData.
# Compare the complete output so no unit, item or movement fields can change.
self_baseline=packet
self_dynamic_offset=start+191+6+4
assert self_baseline[self_dynamic_offset:self_dynamic_offset+4]==bytes(4)
self_mask_at=len(body)-(1+23*4+len(fields)*4)
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 legacy,native_flags in dynamic_cases:
changed=dict(fields);changed[143]=legacy
changed_mask=[0]*23
for field in changed:changed_mask[field//32]|=1<<(field%32)
source=body[:self_mask_at]+bytes([23])+P('<23I',*changed_mask)+b''.join(P('<I',changed[i]) for i in sorted(changed))
result=run(header+source)
assert result.returncode==0,result.stderr.decode()
expected=bytearray(self_baseline);struct.pack_into('<I',expected,self_dynamic_offset,native_flags)
assert result.stdout==expected,'Self full-create ObjectData dynamic flag semantics differ or unrelated fields changed'
print('12 self full-create dynamic flag goldens match original ObjectData field order; no client-rendering claim.')
def with_player_flags(flags):
changed=dict(fields);changed[190]=flags;changed_mask=[0]*23
for field in changed:changed_mask[field//32]|=1<<(field%32)
source=body[:self_mask_at]+bytes([23])+P('<23I',*changed_mask)+b''.join(P('<I',changed[i])for i in sorted(changed))
result=run(header+source);assert result.returncode==0,result.stderr.decode()
return result.stdout
ghost=with_player_flags(0x10)
delta=[i for i,(a,b)in enumerate(zip(self_baseline,ghost))if a!=b]
assert len(ghost)==len(self_baseline)and len(delta)==1 and ghost[delta[0]]==0x10 and self_baseline[delta[0]]==0
assert with_player_flags(0x410)==ghost and with_player_flags(0xc40)==self_baseline
assert with_player_flags(0)==self_baseline
print('Full self-create retains genuine ghost PlayerFlags without interpreting source visibility bits as modern War Mode.')
# Original race IDs1..8, Warrior only. Source ChrRaces male/female display IDs
# project to the reviewed native race defaults; these checks do not prove assets
# or customization compatibility in the running client.
race_displays={1:(49,50),2:(51,52),3:(53,54),4:(55,56),5:(57,58),
6:(59,60),7:(1563,1564),8:(1478,1479)}
native_displays={1:(57899,56658),2:(51894,53762),3:(49242,53768),4:(54918,54439),
5:(54041,56327),6:(55077,56316),7:(51877,53291),8:(59071,59223)}
unit_start=start+191+6+12
for race,displays in race_displays.items():
for sex,display in enumerate(displays):
changed=dict(fields);changed[36]=(1<<24)|(sex<<16)|(1<<8)|race;changed[131]=changed[132]=display
changed_mask=[0]*23
for field in changed:changed_mask[field//32]|=1<<(field%32)
source=body[:self_mask_at]+bytes([23])+P('<23I',*changed_mask)+b''.join(P('<I',changed[i]) for i in sorted(changed))
changed_header=bytearray(header);changed_header[-7]=race;changed_header[-5]=sex
result=run(changed_header+source);assert result.returncode==0,result.stderr.decode()
assert struct.unpack_from('<i',result.stdout,unit_start)[0]==native_displays[race][sex],'Native race/gender default display projection differs'
# Original UnitData writer has nine32-bit scalars,12 empty packed GUIDs,
# BattlePetDBID64, UnitChannel20, empower8 and home-realm32 before Race.
assert result.stdout[unit_start+93:unit_start+97]==bytes([race,1,1,sex]),'Native race/class/player-class/sex identity differs'
for race,cls,sex in ((0,1,0),(1,11,0),(10,7,0),(6,2,0),(6,1,2)):
changed_header=bytearray(header);changed_header[-7:-4]=bytes([race,cls,sex])
assert run(changed_header+body).returncode!=0,'Unimplemented race/class/gender profile accepted'
print('16 source-metadata original-race Warrior create variants and five unsupported-profile rejections checked; actual models remain unverified.')
context=header[:-4]+P('<3I',2,12664,16466)+header[-4:]+body
traits=subprocess.run([sys.argv[1],'--self-talents'],input=context,capture_output=True,timeout=15,env=dict(os.environ,GATEWAY_TALENT_EXPERIMENT='1'))
assert traits.returncode==0,traits.stderr.decode()
assert P('<5i',105958,130688,3,0,0) in traits.stdout and P('<5i',105957,130687,5,0,0) in traits.stdout
assert b'Local Turtle' in traits.stdout
assert subprocess.run([sys.argv[1],'--self-talents'],input=context[:-1],capture_output=True,timeout=15).returncode!=0
print('Explicit self-talents entry mode and authoritative rank context serialize; malformed context rejected.')
# Independent legacy creature create with entry 6; no client-derived object state.
fields={3:6,22:80,28:80,34:1,35:1,36:0x01000101,131:19723,132:19723}
mask=[0]*5
for index in fields:mask[index//32]|=1<<(index%32)
npc=P('<IBB',1,0,3)+bytes.fromhex('cb9d110630f1')+bytes([3,0x20])+P('<II4fI',0,100,1,2,3,0,0)+P('<6f',2.5,7,4.5,4.72,2.5,3.14)
npc+=bytes([5])+P('<5I',*mask)+b''.join(P('<I',fields[i]) for i in sorted(fields))
r=subprocess.run([sys.argv[1],'--npcs'],input=header+npc,capture_output=True,timeout=15)
assert r.returncode==0,r.stderr.decode()
assert struct.unpack_from('<HIBI',r.stdout)[:3]==(0,1,0x80)
assert len(r.stdout)==11+struct.unpack_from('<I',r.stdout,7)[0]
packet=r.stdout
at=packed_end(12)
assert packet[at]==5 and packet[at+1:at+4]==bytes.fromhex('840000')
at+=8
at=packed_end(at)
assert struct.unpack_from('<QI4f',packet,at)==(0,100,1,2,3,0), 'NPC movement preserves backend position'
for selection in range(16):
source_flags=native_flags=0
for i,(legacy,modern) in enumerate(mode_flags):
if selection&(1<<i):source_flags|=legacy;native_flags|=modern
changed=bytearray(npc);struct.pack_into('<I',changed,14,source_flags)
result=subprocess.run([sys.argv[1],'--npcs'],input=header+changed,capture_output=True,timeout=15)
assert result.returncode==0,result.stderr.decode()
expected=bytearray(packet);struct.pack_into('<Q',expected,at,native_flags)
assert result.stdout==expected,'Initial creature movement modes differ or unrelated output changed'
print('16 original creature-create mode combinations preserve all unrelated bytes; actual NPC mode behavior unverified.')
at+=48
assert packet[at:at+2]==bytes(2)
at+=2+36+8+68+1
size=struct.unpack_from('<I',packet,at)[0]
assert at+4+size==len(packet), 'NPC fields follow complete movement structure'
print('1 independent NPC serializer fixture passed; actual NPC visibility requires client testing.')
# NPC values have five fragment bytes, then the same original ObjectData.
# Source unit flag143 must never pass raw to native ObjectData::DynamicFlags.
npc_baseline=packet
npc_dynamic_offset=at+4+5+4
assert npc_baseline[npc_dynamic_offset:npc_dynamic_offset+4]==bytes(4)
npc_mask_at=len(npc)-(1+5*4+len(fields)*4)
for legacy,native_flags in dynamic_cases:
changed=dict(fields);changed[143]=legacy
changed_mask=[0]*5
for field in changed:changed_mask[field//32]|=1<<(field%32)
source=npc[:npc_mask_at]+bytes([5])+P('<5I',*changed_mask)+b''.join(P('<I',changed[i]) for i in sorted(changed))
result=subprocess.run([sys.argv[1],'--npcs'],input=header+source,capture_output=True,timeout=15)
assert result.returncode==0,result.stderr.decode()
expected=bytearray(npc_baseline);struct.pack_into('<I',expected,npc_dynamic_offset,native_flags)
assert result.stdout==expected,'NPC full-create dynamic flags or unrelated movement/unit fields differ'
print('12 NPC full-create dynamic flag goldens preserve lootability, own/foreign taps and unknown-bit isolation.')
# Actual Turtle entry38 supplied a negative facing; the Forever create validator
# rejects that representation even though its direction is equivalent modulo 2*pi.
orientation_offset=7+npc[6].bit_count()+2+8+12
for legacy_angle,expected in ((-0.256737,6.0264483),(7.0,0.7168147)):
rotated=bytearray(npc)
struct.pack_into('<f',rotated,orientation_offset,legacy_angle)
result=subprocess.run([sys.argv[1],'--npcs'],input=header+rotated,capture_output=True,timeout=15)
assert result.returncode==0,result.stderr.decode()
packet=result.stdout
mover=packed_end(packed_end(12)+8)
angle=struct.unpack_from('<f',packet,mover+24)[0]
assert abs(angle-expected)<0.000002 and 0<=angle<6.2831854
print('2 NPC orientation regressions passed; real creature visibility remains a separate integration test.')
# Independent legacy static mailbox create: entry144131/display1907, type19.
fields={3:144131,4:0x3f800000,8:1907,13:0x3f800000,14:1,21:19}
mask=0
for index in fields:mask|=1<<index
static=P('<IBB',1,0,3)+bytes.fromhex('fb9d1103330210f1')+bytes([5,0x40])+P('<4f',1,2,3,0)
static+=bytes([1])+P('<I',mask)+b''.join(P('<I',fields[i]) for i in sorted(fields))
r=subprocess.run([sys.argv[1],'--gameobjects'],input=header+static,capture_output=True,timeout=15)
assert r.returncode==0,r.stderr.decode()
packet=r.stdout
assert struct.unpack_from('<HIBI',packet)[:3]==(0,1,0x80)
assert len(packet)==11+struct.unpack_from('<I',packet,7)[0]
at=packed_end(12)
assert packet[at]==8 and packet[at+1:at+4]==bytes.fromhex('810800')
at+=8
assert struct.unpack_from('<4f',packet,at)==(1,2,3,0)
rotated_static=bytearray(static)
struct.pack_into('<f',rotated_static,28,-2.39142)
rotated_result=subprocess.run([sys.argv[1],'--gameobjects'],input=header+rotated_static,capture_output=True,timeout=15)
assert rotated_result.returncode==0,rotated_result.stderr.decode()
rotated_angle=struct.unpack_from('<f',rotated_result.stdout,at+12)[0]
assert 0<=rotated_angle<2*math.pi and abs(rotated_angle-3.891765)<0.00001
assert rotated_result.stdout[:at+12]==packet[:at+12] and rotated_result.stdout[at+24:]==packet[at+24:], 'Game-object facing changed unrelated fields'
at+=16
assert struct.unpack_from('<Q',packet,at)[0]==0, 'Identity quaternion packs to zero'
at+=8
size=struct.unpack_from('<I',packet,at)[0];at+=4
assert at+size==len(packet) and packet[at:at+5]==bytes([0,3,206,255,1]), 'Game-object fragment/value section'
assert subprocess.run([sys.argv[1],'--gameobjects'],input=(header+static)[:-1],capture_output=True,timeout=15).returncode!=0
# Same static source framing, no fabricated models: a null-display trap must
# not reach Forever's CGameObject assertion; null-display spell focus is allowed.
def go_variant(typ,display):
f=dict(fields);f[8]=display;f[21]=typ
raw=P('<IBB',1,0,3)+bytes.fromhex('fb9d1103330210f1')+bytes([5,0x40])+P('<4f',1,2,3,0)+bytes([1])+P('<I',mask)+b''.join(P('<I',f[i]) for i in sorted(f))
result=subprocess.run([sys.argv[1],'--gameobjects'],input=header+raw,capture_output=True,check=True)
return struct.unpack_from('<I',result.stdout,2)[0]
assert go_variant(6,0)==0 and go_variant(19,0)==0 and go_variant(8,0)==1 and go_variant(6,1907)==1
assert go_variant(2,0)==0
for display in (6425,6426,6427,1907):assert go_variant(2,display)==1
print('2 independent game-object serializer fixture cases passed; actual visibility requires client testing.')
# Live-template population profile: exactly the same native field schema, with
# authoritative humanoid/beast/critter type and explicit generation-valid GUIDs.
# Decode the independent packed64 fixture.
mask=npc[6];raw=bytearray(8);at=7
for bit in range(8):
if mask & (1<<bit):raw[bit]=npc[at];at+=1
legacy_guid=int.from_bytes(raw,'little')
original=subprocess.run([sys.argv[1],'--npcs'],input=header+npc,capture_output=True,timeout=15).stdout
for typ in (7,1,8):
typed_header=header[:-4]+P('<IIBIQ',1,6,typ,1,legacy_guid)+header[-4:]
result=subprocess.run([sys.argv[1],'--npcs-types'],input=typed_header+npc,capture_output=True,timeout=15)
assert result.returncode==0,result.stderr.decode()
if typ==7:assert result.stdout==original, 'Expanded profile preserves working humanoid bytes'
else:
differences=[i for i,(a,b) in enumerate(zip(original,result.stdout)) if a!=b]
assert len(result.stdout)==len(original) and len(differences)==1
i=differences[0];assert original[i]==7 and result.stdout[i]==typ, 'Only native CreatureType changes'
excluded=header[:-4]+P('<IIBI',1,6,1,0)+header[-4:]
result=subprocess.run([sys.argv[1],'--npcs-types'],input=excluded+npc,capture_output=True,timeout=15)
assert result.returncode==0 and struct.unpack_from('<I',result.stdout,2)[0]==0, 'Removed pending actor cannot resurrect'
duplicate=header[:-4]+P('<IIBIQQ',1,6,1,2,legacy_guid,legacy_guid)+header[-4:]
assert subprocess.run([sys.argv[1],'--npcs-types'],input=duplicate+npc,capture_output=True,timeout=15).returncode!=0
print('5 general-population serializer checks passed (type identity and stale-create exclusion).')
# Static GO types observed in the real session. Moving transports retain a
# different protocol and must not silently pass through this stationary profile.
for typ in (2,3,5,6,7,8,9,19,15):
changed=bytearray(static)
struct.pack_into('<I',changed,len(changed)-4,typ)
result=subprocess.run([sys.argv[1],'--gameobjects'],input=header+changed,capture_output=True,timeout=15)
assert result.returncode==0,result.stderr.decode()
assert struct.unpack_from('<I',result.stdout,2)[0]==(0 if typ==15 else 1)
print('9 static game-object type coverage checks passed; live visuals require review.')