883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
106 lines
4.9 KiB
Python
106 lines
4.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Decode genuine native writer output; no client, database, socket or UI access."""
|
|
import struct
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0,str(Path(__file__).resolve().parent))
|
|
from native_codec_driver import load,serialize,MODES,ROOT
|
|
|
|
if not Path(os.environ.get('GW_TEST_CODEC_PATH',ROOT/'build/forever-schema/libforever_codec.so')).is_file():sys.exit(77)
|
|
library=load()
|
|
mode=MODES.index('--inventory-objects')
|
|
|
|
def packed_end(data,at):
|
|
mask=struct.unpack_from('<H',data,at)[0]
|
|
return at+2+mask.bit_count()
|
|
|
|
def packet(flags,kind=2,item_type=1):
|
|
# Source UpdateFields.h: entry3, owner6, contained8, stack14,
|
|
# ITEM_FIELD_FLAGS21, CONTAINER_FIELD_NUM_SLOTS48.
|
|
fields={3:25,6:42,8:42,14:2}
|
|
if flags is not None:fields[21]=flags
|
|
if item_type==2:fields[48]=0
|
|
payload=struct.pack('<QHII',42,70,0,1)
|
|
payload+=struct.pack('<QBBH',(0x4000<<48)|75,item_type,kind,len(fields))
|
|
payload+=b''.join(struct.pack('<HI',index,value)for index,value in sorted(fields.items()))
|
|
return serialize(library,mode,payload)
|
|
|
|
def item_values(wire,kind,item_type):
|
|
map_id,count,marker,size=struct.unpack_from('<HIBI',wire)
|
|
assert (map_id,count,marker)==(0,1,128) and len(wire)==11+size
|
|
assert wire[11]==(2 if kind in(2,3)else 0)
|
|
at=packed_end(wire,12)
|
|
if kind in(2,3):
|
|
assert wire[at]==item_type
|
|
at+=8
|
|
size=struct.unpack_from('<I',wire,at)[0];at+=4
|
|
assert at+size==len(wire)
|
|
return wire[at:]
|
|
|
|
def flags_from_create(wire,item_type):
|
|
data=item_values(wire,2,item_type)
|
|
# Owner visibility + type-ID list + ObjectData create (entry/flags/scale).
|
|
at=5+(item_type==2)+12
|
|
for _ in range(4):at=packed_end(data,at) # owner/contained/creator/gift
|
|
at+=4+4+5*4 # stack, expiration, charges
|
|
return struct.unpack_from('<I',data,at)[0]
|
|
|
|
def flags_from_update(wire,item_type):
|
|
data=item_values(wire,0,item_type)
|
|
assert data[:3]==bytes([1,0,3])
|
|
assert struct.unpack_from('<I',data,3)[0]&(1<<1)
|
|
at=7
|
|
object_mask=data[at]>>4;at+=1
|
|
at+=4*sum(bool(object_mask&(1<<i))for i in(1,2,3))
|
|
# ItemData mask: two presence bits followed by each nonzero32-bit block,
|
|
# all MSB-first; then FlushBits before the field values.
|
|
bits=''.join(f'{byte:08b}'for byte in data[at:at+9])
|
|
presence=int(bits[:2],2);offset=2;masks=[]
|
|
for i in range(2):
|
|
masks.append(int(bits[offset:offset+32],2)if presence&(1<<i)else 0)
|
|
if presence&(1<<i):offset+=32
|
|
at+=(offset+7)//8
|
|
mask=masks[0]
|
|
assert mask&1 and not mask&6 # No artifact/gem dynamic updates in fixture.
|
|
for index in(3,4,5,6):
|
|
if mask&(1<<index):at=packed_end(data,at)
|
|
for index in(7,8):
|
|
if mask&(1<<index):at+=4
|
|
return struct.unpack_from('<I',data,at)[0]if mask&(1<<9)else None
|
|
|
|
reviewed=0x1|0x4|0x8|0x200
|
|
for item_type in(1,2):
|
|
for value in [0,reviewed,0xffffffff]+[1<<bit for bit in range(32)]:
|
|
assert flags_from_create(packet(value,item_type=item_type),item_type)==value&reviewed
|
|
assert flags_from_update(packet(value,kind=0,item_type=item_type),item_type)==value&reviewed
|
|
# Explicit clears must reach the engine; an absent update field is not a clear.
|
|
assert flags_from_update(packet(0,kind=0,item_type=item_type),item_type)==0
|
|
assert flags_from_update(packet(None,kind=0,item_type=item_type),item_type)is None
|
|
assert flags_from_create(packet(None,item_type=item_type),item_type)==0
|
|
|
|
# The initial SELF path has a separate append_item writer. Exercise it with a
|
|
# real source object-mask fixture, not just the later inventory opcode path.
|
|
def initial_item(flags):
|
|
fields={22:80,28:80,34:60,35:1,36:0x01000101,718:98,719:0x012c012c}
|
|
mask=[0]*23
|
|
for index in fields:mask[index//32]|=1<<(index%32)
|
|
body=struct.pack('<IBB',2,0,3)+bytes.fromhex('039d11')+bytes([4,0x21])
|
|
body+=struct.pack('<II4fI',0,100,1,2,3,0,0)+struct.pack('<6f',2.5,7,4.5,4.72,2.5,3.14)
|
|
body+=bytes([len(mask)])+struct.pack('<23I',*mask)
|
|
body+=b''.join(struct.pack('<I',fields[i])for i in sorted(fields))
|
|
item={3:25,6:4509,8:4509,14:2,21:flags}
|
|
body+=bytes([2,0x81,75,0x40,1,0,1])+struct.pack('<I',sum(1<<i for i in item))
|
|
body+=b''.join(struct.pack('<I',item[i])for i in sorted(item))
|
|
header=struct.pack('<QHIIIII',4509,70,0x46010046,0,12,0,0)
|
|
header+=b'Fixture\0'+bytes([1,1,0])+struct.pack('<I',0xa9)
|
|
wire=serialize(library,0,header+body)
|
|
assert struct.unpack_from('<I',wire,2)[0]==3 # item, virtual bank, self
|
|
at=packed_end(wire,12)+8
|
|
end=at+4+struct.unpack_from('<I',wire,at)[0]
|
|
first=struct.pack('<HIBI',0,1,128,end-11)+wire[11:end]
|
|
return flags_from_create(first,1)
|
|
for value in(0,1,reviewed,0x40,0x40000,0xffffffff):assert initial_item(value)==value&reviewed
|
|
print('PASS: native item/container create and update writers preserve four reviewed instance flags, explicit clears, absent-field semantics and all32 single-bit boundaries. Offline serialization only; real-client behavior remains unverified.')
|