85 lines
5.2 KiB
Python
85 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Class trainer/spell updates vs pinned original writers, no gameplay claim."""
|
|
from pathlib import Path
|
|
import struct,subprocess,sys
|
|
root=Path(__file__).resolve().parents[1]
|
|
protocol_build=Path(sys.argv[2]).resolve() if len(sys.argv)>2 else root/'build'
|
|
references=[sys.argv[1],*sys.argv[3:]]
|
|
build=protocol_build/'forever-schema';build.mkdir(exist_ok=True);driver=build/'trainer-fixture.cpp'
|
|
driver.write_text('''#include "gateway/gameplay.hpp"
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
int main(int argc,char**argv){try{gateway::Bytes b;char c;while(std::cin.get(c))b.push_back(uint8_t(c));gateway::Reader r(b);gateway::Bytes out;
|
|
if(argc==2 && std::string(argv[1])=="trainer"){auto raw=r.take(16);gateway::Guid128 guid{};std::copy(raw.begin(),raw.end(),guid.begin());auto list=gateway::turtle_trainer_list(r.take(r.left()));if(!gateway::prepare_trainer_offers(list))return 1;out=gateway::forever_trainer_list(list,guid);}
|
|
else{auto opcode=r.le(2);out=gateway::forever_spell_learning(opcode,r.take(r.left()));}
|
|
std::cout.write(reinterpret_cast<const char*>(out.data()),out.size());}catch(const std::exception&){return 1;}}
|
|
''')
|
|
subprocess.run(['clang++','-std=c++20','-I'+str(root/'include'),str(driver),str(protocol_build/'libgateway_protocol.a'),'-lcrypto','-lz','-o',str(build/'trainer-fixture')],check=True)
|
|
vendor=(0xf130<<48)|(9010<<24)|99;modern=struct.pack('<QQ',99,(8<<58)|(70<<42))
|
|
cases=[]
|
|
for count,greeting in ((0,b''),(1,b'Class training'),(17,'Authentic é'.encode()),(1,b'x'*2047)):
|
|
body=struct.pack('<QII',vendor,0,count)
|
|
for i in range(count):body+=struct.pack('<IBIIIBIIIII',1234+i,i%3,71+i,0,0,14,26,5,78,0,0)
|
|
cases.append(('trainer','--trainer-list',modern+body+greeting+b'\0'))
|
|
def profession(entry, lessons):
|
|
npc=(0xf130<<48)|(entry<<24)|99
|
|
rows=b''.join(struct.pack('<IBIIIBIIIII',*lesson,0,0,0) for lesson in lessons)
|
|
return modern+struct.pack('<QII',npc,2,len(lessons))+rows+b'Training\0'
|
|
|
|
def rank(service, state, cost, skill=0, required=0, level=5):
|
|
primary=int(skill==0)
|
|
return (service,state,cost,primary,primary,level,skill,required)
|
|
|
|
def recipe(service, state, cost, skill, required):
|
|
return (service,state,cost,0,0,0,skill,required)
|
|
|
|
apprentice=rank(2275,0,10)
|
|
known=rank(2275,2,10)
|
|
copper=recipe(3184,1,50,171,15)
|
|
mana=recipe(2339,0,100,171,25)
|
|
smith=rank(2020,2,9)
|
|
journeyman=rank(2021,0,450,164,50,10)
|
|
known_journeyman=rank(2021,2,450,164,50,10)
|
|
breastplate=recipe(2753,0,900,164,145)
|
|
# The rank must occupy published slot zero, even when Source mixes it into the recipes.
|
|
# Expected rows name both the display ID and the authoritative Source service fields.
|
|
professions=[
|
|
(1215,[copper,apprentice,recipe(2339,1,100,171,25)],[(2275,apprentice),(3170,copper),(2331,recipe(2339,1,100,171,25))]),
|
|
(1215,[mana,copper,known],[(2275,known),(2331,mana),(3170,copper)]),
|
|
(1383,[smith,recipe(2753,1,900,164,145),journeyman],[(2021,journeyman),(2675,recipe(2753,1,900,164,145))]),
|
|
(1383,[breastplate,known_journeyman,smith],[(2021,known_journeyman),(2675,breastplate)]),
|
|
]
|
|
expected={}
|
|
for entry, lessons, order in professions:
|
|
body=profession(entry,lessons)
|
|
cases.append(('trainer','--trainer-list',body))
|
|
expected[body]=(1000000+entry,order)
|
|
for opcode,body in ((0x12b,struct.pack('<I',78)),(0x12b,struct.pack('<I',50001)),(0x203,struct.pack('<H',78)),(0x203,struct.pack('<H',50001)),(0x12c,struct.pack('<HH',78,284))):cases.append(('learn','--spell-learning',struct.pack('<H',opcode)+body))
|
|
for kind,mode,body in cases:
|
|
ours=subprocess.run([str(build/'trainer-fixture'),kind],input=body,capture_output=True,check=True).stdout
|
|
for reference in references:
|
|
original=subprocess.run([reference,mode],input=body,capture_output=True,check=True).stdout
|
|
assert ours==original,'Native trainer/spell update differs from original writer'
|
|
if body in expected:
|
|
trainer,order=expected[body]
|
|
offset=2+int.from_bytes(ours[:2],'little').bit_count()
|
|
# Raw codec mode 30 has no selected character or authoritative skill snapshot.
|
|
assert struct.unpack_from('<BII',ours,offset)==(0,trainer,len(order))
|
|
offset+=9
|
|
for display,(_,_,cost,_,_,level,skill,required) in order:
|
|
assert struct.unpack_from('<IIIBIIIII',ours,offset)==(display,0,cost,level,skill,required,0,0,0)
|
|
offset+=33
|
|
for kind,mode,body in cases[:2]+cases[4:]:
|
|
for bad in (body[:-1],body+b'\0'):
|
|
assert subprocess.run([str(build/'trainer-fixture'),kind],input=bad,capture_output=True).returncode!=0
|
|
for reference in references:
|
|
assert subprocess.run([reference,mode],input=bad,capture_output=True).returncode!=0
|
|
for lessons in ([],[mana],[rank(2155,0,10),mana]):
|
|
body=profession(1215,lessons)
|
|
for writer in [[str(build/'trainer-fixture'),'trainer'],*[[ref,'--trainer-list'] for ref in references]]:
|
|
result=subprocess.run(writer,input=body,capture_output=True)
|
|
assert result.returncode!=0 and not result.stdout,'A list without a qualified rank produced output'
|
|
print(f'{len(cases)} class, profession and spell events match the pinned writer. '
|
|
f'Checked generic presentation, first-slot rank and recipe fields in {len(professions)} stateless lists. '
|
|
f'The direct writer and {len(references)} reference adapter(s) withheld three unresolved lists.')
|