Files
WoW-Hybrid-gateway/tests/windows_current_metadata_check.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

42 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""One Windows matched-module/NEW metadata boundary, outside the game.
Reuses native_display_hotfix_fixture.py's pinned HotfixConnect framing.
"""
import argparse,ctypes as C,json,os,struct
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('--modules',type=Path);p.add_argument('--codec',type=Path);p.add_argument('--expected',type=Path);p.add_argument('--package',type=Path);p.add_argument('--base-rows',type=int);p.add_argument('--report',type=Path,required=True);a=p.parse_args();
if a.expected:
mini=json.loads(a.expected.read_text());total=mini['rows'];base_rows=mini['base_rows'];added=mini['records'];pages=mini['pushes']
else:
package=json.loads(a.package.read_text());rows=package['rows'];total=len(rows);base_rows=a.base_rows;added=rows[base_rows:];pages=[q for q in package['pushes']if q['first']+q['count']>base_rows]
expected={(int(r['table_hash'],0),r['id']):bytes.fromhex(r['wire_hex'])for r in added};assert 0<=base_rows<total and len(expected)==total-base_rows
seen={};modules=a.modules.resolve()if a.modules else None
from contextlib import nullcontext
with os.add_dll_directory(str(modules))if modules else nullcontext():
wire_initialized=False
try:
if modules:
wire=C.WinDLL(str(modules/'GWNativeWire.dll'),winmode=0x1100);wire.gw_wire_initialize.argtypes=[C.c_wchar_p];wire.gw_wire_initialize.restype=C.c_int32;assert wire.gw_wire_initialize(str(modules/'GWNativeBackend.dll'))==0,'Matched backend/PE initialization failed'
wire_initialized=True
codec=C.WinDLL(str(modules/'forever_codec.dll'),winmode=0x1100)if modules else C.CDLL(str(a.codec.resolve()));codec.gw_codec_abi.restype=C.c_uint32;assert codec.gw_codec_abi()==1
serialize=codec.gw_codec_serialize;serialize.argtypes=[C.c_uint32,C.POINTER(C.c_uint8),C.c_uint32,C.c_uint32,C.POINTER(C.c_uint8),C.c_uint32,C.POINTER(C.c_uint32)];serialize.restype=C.c_uint32
for page in pages:
body=struct.pack('<IIII',70334,0,1,page['push_id']);source=(C.c_uint8*len(body)).from_buffer_copy(body);output=(C.c_uint8*1048576)();written=C.c_uint32()
assert serialize(27,source,len(body),0,output,len(output),C.byref(written))==0,'New metadata page serialization failed'
data=bytes(output[:written.value]);count=struct.unpack_from('<I',data)[0];at=4;records=[]
for _ in range(count):
push,unique,table,ident,size,status=struct.unpack_from('<IIIIIB',data,at);at+=21;assert push==page['push_id'] and not status&31;records.append((table,ident,size,status>>5))
size=struct.unpack_from('<I',data,at)[0];at+=4;assert at+size==len(data);offset=at
for table,ident,size,status in records:
value=data[offset:offset+size];offset+=size;key=(table,ident)
if key in expected:assert value==expected[key] and status==1 and key not in seen;seen[key]=True
assert offset==len(data)
finally:
if wire_initialized:
wire.gw_wire_shutdown.argtypes=[];wire.gw_wire_shutdown.restype=C.c_int32
assert wire.gw_wire_shutdown()==0,'Idle owned Wire shutdown failed'
assert set(seen)==set(expected),'New metadata rows absent from compiled codec'
table_counts={hex(table):sum(key[0]==table for key in seen)for table in sorted({key[0]for key in seen})}
a.report.write_text(json.dumps({'status':'PASS','matching_external_PE_backend_initialization':bool(modules),'codec_abi':1,'metadata_rows':total,'base_rows':base_rows,'new_rows_compared':len(seen),'new_rows_by_table_hash':table_counts,'metadata_pages':len(pages),'unchanged_PE_reused':bool(modules),'explicit_Windows_wire_shutdown':bool(modules),'original_client_started':False,'authenticated':False,'gameplay_verified':False,'release_held':True},indent=2)+'\n');print(f'PASS compiled codec all{len(seen)}new{total}metadata rows; original gameplay unverified')