52 lines
2.4 KiB
Python
52 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Gossip byte comparisons against the pinned native writer; no client claim."""
|
|
from pathlib import Path
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
root=Path(__file__).resolve().parents[1]
|
|
build=root/'build/forever-schema'
|
|
driver=build/'gossip-fixture.cpp'
|
|
driver.write_text('''#include "gateway/gameplay.hpp"
|
|
#include "gateway/object_updates.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);
|
|
auto v=gateway::codec_gossip_menu(r.take(r.left()));
|
|
auto out=gateway::forever_gossip_menu(v,gateway::forever_creature_guid(v.guid,uint32_t(v.guid>>24)&0xFFFFFF,realm,map));
|
|
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/'gossip-fixture')],check=True)
|
|
P=struct.pack
|
|
guid=0xF130000098000001
|
|
cases=[]
|
|
for count in [0,1,2]:
|
|
body=P('<QII',guid,123,count)
|
|
for i in range(count):body+=P('<IBB',i,i,i%2)+('Option '+str(i)).encode()+b'\0'
|
|
body+=P('<I',1)+P('<IIi',33,2,1)+b'A quest\0'
|
|
cases.append(body)
|
|
cases.append(P('<QIII',guid,0,0,0))
|
|
def check_writers(body):
|
|
wire = P('<HI', 70, 0) + body
|
|
direct = subprocess.run([str(build/'gossip-fixture')], input=wire, capture_output=True, check=True).stdout
|
|
native = subprocess.run([sys.argv[1], '--gossip-menu'], input=wire, capture_output=True, check=True).stdout
|
|
assert direct == native, 'Gossip bytes differ from pinned native serializer'
|
|
return native
|
|
|
|
|
|
for body in cases:
|
|
unresolved = check_writers(body)
|
|
assert unresolved[-1:] == b'\0', 'Unresolved menu must omit both native text fields'
|
|
assert check_writers(P('<QI', 0, 0) + body) == unresolved
|
|
if struct.unpack_from('<I', body, 8)[0]:
|
|
resolved = check_writers(P('<QI', 0, 2821) + body)
|
|
assert resolved == unresolved[:-1] + P('<BI', 0x40, 2821), 'Expected only BroadcastTextID 2821'
|
|
|
|
# A resolved title cannot appear without a source text record to resolve.
|
|
bad = P('<HIQI', 70, 0, 0, 2821) + cases[-1]
|
|
for invocation in ([str(build/'gossip-fixture')], [sys.argv[1], '--gossip-menu']):
|
|
assert subprocess.run(invocation, input=bad, capture_output=True).returncode != 0
|
|
|
|
print(len(cases), 'gossip menus match pinned native bytes across unresolved and resolved title cases.')
|