Files
WoW-Hybrid-gateway/tests/combat_serializer_fixture.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

58 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Melee bytes match the pinned native writer. Real combat is a separate test."""
from pathlib import Path
import struct
import subprocess
import sys
root=Path(__file__).resolve().parents[1];build=root/'build/forever-schema'
driver=build/'combat-fixture.cpp'
driver.write_text('''#include "gateway/gameplay.hpp"
#include "gateway/object_updates.hpp"
#include "gateway/roster_translation.hpp"
#include <iostream>
int main(){try{gateway::Bytes b;char c;while(std::cin.get(c))b.push_back(uint8_t(c));gateway::Reader r(b);auto realm=r.le(2),map=r.le(4),self=r.le(8);auto d=gateway::turtle_melee_damage(r.take(r.left()));
std::map<uint64_t,gateway::Guid128> targets;for(auto id:{d.attacker,d.victim})targets[id]=id==self?gateway::forever_player_guid(id,realm):gateway::forever_creature_guid(id,uint32_t(id>>24)&0xFFFFFF,realm,map);
auto out=gateway::forever_melee_damage(d,targets);std::cout.write(reinterpret_cast<const char*>(out.data()),out.size());
}catch(const std::exception& e){std::cerr<<e.what();return 1;}}
''')
subprocess.run(['clang++','-std=c++20','-I'+str(root/'include'),str(driver),str(root/'build/libgateway_protocol.a'),'-lcrypto','-lz','-o',str(build/'combat-fixture')],check=True)
P=struct.pack
identity=bytes.fromhex('039d11cb9d110630f1')
cases=[]
for flags,damage,absorb,resist,blocked in [(2,5,0,0,0),(0x82,10,0,0,0),(0x22,5,2,0,0),(0x22,0,7,0,0),(0x42,5,0,2,0),(0x42,0,0,7,0),(2,3,0,0,2),(0x4002,3,0,0,0),(0x12,0,0,0,0)]:
body=P('<I',flags)+identity+P('<IBIfIIiIIII',damage,1,0,1.,damage,absorb,resist,1,0,0,blocked)
cases.append((body,damage,blocked,1))
for blocked in (7,0):
body=P('<I',2)+identity+P('<IBIfIIiIIII',0,1,0,0.,0,0,0,5,0,0,blocked)
cases.append((body,0,blocked,5))
# Tortoise only compares shield block value against subDamage[0]. Full block
# of that first band can leave another band dealing genuine nonzero damage.
for blocked in (2,0):
body=P('<I',2)+identity+P('<IB',3,2)
body+=P('<IfIIi',0,0.,0,0,0)+P('<IfIIi',2,1.,3,0,0)+P('<IIII',5,0,0,blocked)
cases.append((body,3,blocked,5))
def decoded_round(data):
assert data[0]==0 and struct.unpack_from('<I',data,1)[0]==len(data)-5
flags=struct.unpack_from('<I',data,5)[0];position=9
for _ in range(2):
mask=struct.unpack_from('<H',data,position)[0];position+=2+mask.bit_count()
damage,original,overkill=struct.unpack_from('<3i',data,position);position+=12
has_sub=data[position];position+=1
if has_sub:
position+=12
if flags&0x60:position+=4
if flags&0x180:position+=4
victim=data[position];position+=9
blocked=struct.unpack_from('<I',data,position)[0] if flags&0x2000 else None
return flags,damage,original,overkill,victim,blocked
for body,damage,blocked,state in cases:
wire=P('<HIQ',70,0,4509)+body
direct=subprocess.run([str(build/'combat-fixture')],input=wire,capture_output=True,check=True).stdout
native=subprocess.run([sys.argv[1],'--melee-damage'],input=wire,capture_output=True,check=True).stdout
assert direct==native,'Melee bytes differ from pinned native serializer'
flags,actual_damage,original,overkill,victim,actual_block=decoded_round(native)
assert actual_damage==damage and victim==(1 if state==5 else state)
if state==5:
assert flags==0x2002 and actual_block==blocked and original==damage+blocked and overkill==-1, 'Full-block representation must preserve real values and use native HIT1+BLOCK'
print(f'{len(cases)} melee cases match pinned native bytes, including independent full-block HIT1/BLOCK checks with zero and remaining component damage; actual animation requires client evidence.')