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

52 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""Export actual70334 table schemas and compare with installed Turtle records.
Reports raw differences with explicit semantic limits; never fabricates mappings.
"""
import hashlib
import json
from pathlib import Path
import subprocess
from turtle_data import ROOT,DBC,CLIENT,spell_layout
FOREVER=Path.home()/'Projects/WoW-Hybrid/servers/trinity-forever/install/bin/dbc/enUS'
DBD=Path.home()/'Projects/WoW-Hybrid/tools/WoWDBDefs/definitions'
TABLES=('Spell','SpellName','SpellEffect','SpellMisc','SpellCategories','SpellClassOptions','SpellAuraOptions','SpellPower','SpellLevels','SpellCooldowns','SpellCastTimes','SpellDuration','SpellRange','SpellRadius','SpellItemEnchantment','SkillLine','SkillLineAbility','ChrRaces','ChrClasses','Talent','TalentTab','TraitNode','TraitNodeEntry','TraitDefinition','TraitNodeXTraitNodeEntry','TraitCond','TraitNodeXTraitCond','TraitEdge','TraitTree','TraitTreeLoadout')
def digest(path):return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
output=ROOT/'build/data-comparison';output.mkdir(parents=True,exist_ok=True)
executable=ROOT/'build/db2-gameplay/DB2Gameplay.dll';manifest={};modern={}
for table in TABLES:
source=FOREVER/(table+'.db2');schema=DBD/(table+'.dbd');target=output/(table+'.json');cache=target.with_suffix('.cache.json')
if not source.exists() or not schema.exists():manifest[table]={'status':'missing source table or schema'};continue
key={'db2_sha256':digest(source),'dbd_sha256':digest(schema),'reader_sha256':digest(executable)}
if not (cache.exists() and target.exists() and json.loads(cache.read_text())==key):
result=subprocess.run(['dotnet',str(executable),str(FOREVER),str(DBD),table,str(target),'*'],capture_output=True,text=True)
if result.returncode:
manifest[table]={'status':'schema export failed; review actual DBD layout',**key};continue
cache.write_text(json.dumps(key,sort_keys=True))
rows=json.loads(target.read_text());modern[table]=rows
manifest[table]={'status':'exported','rows':len(rows),'fields':list(rows[0]) if rows else [],**key}
spells=DBC(CLIENT/'Spell.dbc',173);names={r['ID']:r['Name_lang'] for r in modern.get('SpellName',[])}
effects={}
for r in modern.get('SpellEffect',[]):
if r['DifficultyID']==0:effects.setdefault((r['SpellID'],r['EffectIndex']),[]).append(r)
layout=spell_layout();differences=[]
for s in spells.rows:
if s[0] not in names:continue
for i in range(3):
if not s[61+i]:continue
rows=effects.get((s[0],i),[])
legacy={'effect':s[layout['Effect']+i],'aura':s[layout['EffectAura']+i],'trigger':s[layout['EffectTriggerSpell']+i],'targets':[s[layout['ImplicitTargetA']+i],s[layout['ImplicitTargetB']+i]],'base_points_encoded':s[layout['EffectBasePoints']+i]}
# Compare only reviewed raw identity fields. Do not equate enum values,
# scaling coefficients or differently encoded base-point semantics.
native=[{'effect':r['Effect'],'aura':r['EffectAura'],'trigger':r['EffectTriggerSpell'],'targets':r['ImplicitTarget'],'base_points_float':r['EffectBasePointsF']} for r in rows]
if len(native)!=1 or any(legacy[k]!=native[0][k] for k in ('effect','aura','trigger','targets')):
differences.append({'spell':s[0],'effect_index':i,'turtle':legacy,'forever':native})
talents=DBC(CLIENT/'Talent.dbc',21);other={r['ID']:r for r in modern.get('Talent',[])};collisions=[]
for t in talents.rows:
m=other.get(t[0])
if m and m.get('SpellRank',[None])[0]!=t[4]:collisions.append({'talent_id':t[0],'turtle_spell':t[4],'forever_spell':m.get('SpellRank',[None])[0]})
report={'schema_version':1,'turtle_spell_sha256':spells.digest(),'forever_tables':manifest,'missing_forever_spell_names':sorted(set(spells.by_id)-set(names)),'raw_effect_identity_differences':differences,'talent_id_collisions':collisions,'semantic_limits':['Raw enum/target mismatches require source-name/engine semantics review.','Equal raw fields or SpellName presence are not complete spell compatibility.','Legacy encoded base points and modern float/scaling fields are not directly interchangeable.','MPQ patch-order provenance and native Turtle GUI comparison remain separate validation tasks.']}
(output/'compatibility.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
print('Actual schema exports:',sum(t['status']=='exported' for t in manifest.values()),'/',len(TABLES),'; missing spell-name records:',len(report['missing_forever_spell_names']),'; raw effect identity differences:',len(differences),'; talent ID collisions:',len(collisions))
if __name__=='__main__':main()