Files
WoW-Hybrid-gateway/ops/merchant_opcode_profile.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

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

33 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Generate fixed70334 merchant opcodes from naturally observed getter code.
The original source writer defines bodies, not proof of destination opcode IDs.
No automatic family-wide offset: actual native getters independently pin routes.
"""
import argparse,json,re,struct
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
PROFILE=ROOT/'docs/evidence/protocol/merchant-opcodes-70334.json'
HEADER=ROOT/'include/gateway/merchant_opcode_profile.hpp'
def generate(profile,source):
if profile['build']!='1.60.1.70334' or profile['code_bytes_modified'] or profile['engine_calls_made']:raise ValueError('Unreviewed client opcode evidence')
names={'SellResponse':'SMSG_SELL_RESPONSE','BuySucceeded':'SMSG_BUY_SUCCEEDED','BuyFailed':'SMSG_BUY_FAILED'};rows={}
for row in profile['routes']:
name=row['name'];code=bytes.fromhex(row['getter_code'])
if name not in names or name in rows or len(code)!=10 or code[:2]!=b'\xc7\x02' or code[6:]!=b'\x48\x8b\xc2\xc3':raise ValueError('Native opcode getter contract differs')
native=struct.unpack_from('<I',code,2)[0]
canonical=re.search(r'\b'+names[name]+r'\s*=\s*(0x[0-9A-Fa-f]+)',source)
if not canonical or int(canonical[1],16)!=int(row['source_opcode'],16) or native>>16!=0x47:raise ValueError('Merchant source/native opcode identity differs')
rows[name]=native
if set(rows)!=set(names) or len(set(rows.values()))!=3:raise ValueError('Incomplete/duplicate merchant routes')
return '// Generated by ops/merchant_opcode_profile.py from real70334 code getters.\n#pragma once\nnamespace gateway::merchant_opcodes {\n'+''.join(f'inline constexpr unsigned {n}=0x{v:06x};\n' for n,v in rows.items())+'}\n'
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--check',action='store_true');p.add_argument('--source',type=Path,default=Path.home()/'Projects/WoW-Hybrid/servers/trinity-forever/src/server/game/Server/Protocol/Opcodes.h');a=p.parse_args()
data=generate(json.loads(PROFILE.read_text()),a.source.read_text())
if a.check:
if HEADER.read_text()!=data:raise ValueError('Merchant native opcode profile drift')
else:HEADER.write_text(data)
print('Native merchant routes match observed70334 code and original source semantics.')