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

34 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Derive faction identity/base mappings from local Turtle DBC and Forever DB2 JSON.
The JSON is produced by gameplay_db2_export.cs for the pinned70334 table layout.
No database/network/client writes; no faction-name aliases or invented identities.
"""
import argparse
import hashlib
import json
from pathlib import Path
import struct
p=argparse.ArgumentParser();p.add_argument('forever_json',type=Path);p.add_argument('output',type=Path);p.add_argument('--race',type=int,default=1);p.add_argument('--class-id',type=int,default=1);a=p.parse_args()
root=Path(__file__).resolve().parents[1]
if not a.output.resolve().is_relative_to(root):raise RuntimeError('Output must stay in gateway')
if not 1<=a.race<=12 or not 1<=a.class_id<=11:raise RuntimeError('Race/class bound')
legacy=Path.home()/'Servers/tortoise-docker/data/dbc/Faction.dbc';b=legacy.read_bytes();magic,n,f,size,strings=struct.unpack_from('<4s4I',b)
if magic!=b'WDBC' or f!=37 or size!=148 or len(b)!=20+n*size+strings:raise RuntimeError('Faction DBC schema changed')
modern={row['ID']:row for row in json.loads(a.forever_json.read_text())};rows=[];unsupported=[];names=b[20+n*size:]
signed=lambda v:struct.unpack('<i',struct.pack('<I',v))[0]
race,cls=1<<(a.race-1),1<<(a.class_id-1)
for i in range(n):
v=struct.unpack_from('<37I',b,20+i*size);index=signed(v[1])
if index<0:continue
name=names[v[19]:].split(b'\0')[0].decode();m=modern.get(v[0])
if not m or m['ReputationIndex']<0:unsupported.append({'id':v[0],'index':index,'name':name,'reason':'missing modern faction or reputation index'});continue
old=next((j for j in range(4) if (not v[2+j] or v[2+j]&race) and (not v[6+j] or v[6+j]&cls)),None)
masks=[(int(m['ReputationRaceMasks'+str(j)][0])&0xFFFFFFFF)|((int(m['ReputationRaceMasks'+str(j)][1])&0xFFFFFFFF)<<32) for j in range(4)]
new=next((j for j in range(4) if (not masks[j] or masks[j]&race) and (not m['ReputationClassMask'][j] or m['ReputationClassMask'][j]&cls)),None)
if old is None or new is None:unsupported.append({'id':v[0],'index':index,'name':name,'reason':'no matching base for race/class'});continue
rows.append((index,v[0],m['ReputationIndex'],signed(v[10+old]),m['ReputationBase'][new]))
rows.sort();a.output.parent.mkdir(parents=True,exist_ok=True)
a.output.write_text('# race '+str(a.race)+' class '+str(a.class_id)+'; legacy_index faction_id modern_index legacy_base modern_base\n'+'\n'.join(' '.join(map(str,r)) for r in rows)+'\n')
a.output.with_suffix('.provenance.json').write_text(json.dumps({'race':a.race,'class':a.class_id,'legacy_sha256':hashlib.sha256(b).hexdigest(),'forever_json_sha256':hashlib.sha256(a.forever_json.read_bytes()).hexdigest(),'mapped':len(rows),'unsupported':unsupported},indent=2)+'\n')
print('Mapped',len(rows),'factions; unsupported',len(unsupported),'recorded in provenance. No standings changed.')