Files
WoW-Hybrid-gateway/ops/spell_result_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

41 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Generate named Turtle -> Forever cast failure mappings from local sources.
No numeric reason-offset assumption. Missing semantic names remain unsupported.
Versioned header allows ordinary offline builds; --check catches source drift.
"""
import argparse,hashlib,json,re
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
TURTLE=Path.home()/'Servers/tortoise-wow/src/game/Spells/SpellDefines.h'
FOREVER=Path.home()/'Projects/WoW-Hybrid/servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h'
def enum(path,enum_name="SpellCastResult"):
data=path.read_bytes();text=re.sub(r'/\*.*?\*/|//[^\n]*','',data.decode(),flags=re.S)
body=text.split('enum '+enum_name,1)[1].split('{',1)[1].split('}',1)[0]
result={};value=-1
for row in body.split(','):
row=row.strip()
if not row:continue
m=re.fullmatch(r'(\w+)(?:\s*=\s*(0x[0-9A-Fa-f]+|[0-9]+|[A-Z_]+))?',row)
if not m:raise ValueError('Unreviewed enum expression: '+row)
name,literal=m.groups()
value=(result[literal] if literal in result else int(literal,0)) if literal else value+1
if name in result:raise ValueError('Duplicate enum name')
result[name]=value
return result,hashlib.sha256(data).hexdigest()
def generate():
old,oh=enum(TURTLE);new,nh=enum(FOREVER)
rows=[{'name':n,'turtle':v,'forever':new[n]} for n,v in old.items() if n.startswith('SPELL_FAILED_') and n in new]
if len({r['turtle'] for r in rows})!=len(rows) or any(not 0<=r['turtle']<255 for r in rows):raise ValueError('Ambiguous legacy failure index')
header='// Generated by ops/spell_result_profile.py; semantic enum names, not numeric offsets.\n#pragma once\n#include <cstdint>\nnamespace gateway::spell_results {\ninline int32_t forever(uint8_t legacy){switch(legacy){\n'
header+=''.join(f"case {r['turtle']}:return {r['forever']}; // {r['name']}\n" for r in rows)+'default:return -1;}}\n}\n'
report={'turtle_source':'src/game/Spells/SpellDefines.h','turtle_sha256':oh,'forever_source':'src/server/game/Miscellaneous/SharedDefines.h','forever_sha256':nh,'mappings':rows,'unsupported':[{'name':n,'value':v} for n,v in old.items() if n.startswith('SPELL_FAILED_') and n not in new],'limitation':'Matching enum names establishes error identity; extra argument and UI behavior require separate packet/runtime validation.'}
return header,json.dumps(report,indent=2)+'\n'
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('--check',action='store_true');a=p.parse_args();header,report=generate()
for path,text in ((ROOT/'include/gateway/spell_result_profile.hpp',header),(ROOT/'docs/evidence/data/spell-result-profile.json',report)):
if a.check:
if path.read_text()!=text:raise ValueError('Cast-result source/profile drift; review regeneration')
else:path.write_text(text)
print('Named cast-result source profile matches.' if a.check else 'Generated reviewed-name cast-result profile; original sources unchanged.')