367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
131 lines
11 KiB
Python
131 lines
11 KiB
Python
#!/usr/bin/env python3
|
|
"""Source-authoritative ItemSet/ItemSetSpell components for Forever70334.
|
|
|
|
Pure conversion using the existing schema encoders and package format. Source
|
|
set/spell/item IDs stay intact; only child record IDs are target allocations.
|
|
Components remain uninstalled and dependency-incomplete until linked spell,
|
|
skill, item definitions and actual engine acceptance have been verified.
|
|
"""
|
|
import argparse,copy,hashlib,json,struct
|
|
from pathlib import Path
|
|
from item_sparse_compat import ROOT,encode,fields,check_db2
|
|
|
|
TABLES={'ItemSet':(0x8e741a98,0xf79068a4,5),'ItemSetSpell':(0x8645bb79,0x2666a73f,5)}
|
|
REMOVAL_POLICY='source-authoritative-per-set-bonus-link-replacement'
|
|
|
|
def integer(value,low,high,label):
|
|
if type(value)is not int or not low<=value<=high:raise ValueError('Item set integer bound: '+label)
|
|
return value
|
|
|
|
def source_set(row):
|
|
ident=integer(row['id'],1,0x7fffffff,'set ID')
|
|
names=row['names'];items=row['item_ids'];spells=row['spell_ids'];thresholds=row['thresholds']
|
|
if not isinstance(names,list)or len(names)!=8 or not isinstance(names[0],str)or not names[0]or '\0'in names[0]:raise ValueError('Item set enUS name required')
|
|
if not isinstance(items,list)or len(items)!=17 or not isinstance(spells,list)or len(spells)!=8 or not isinstance(thresholds,list)or len(thresholds)!=8:raise ValueError('Item set source array shape differs')
|
|
for value in items:integer(value,0,0x7fffffff,'item reference')
|
|
if len({v for v in items if v})!=sum(bool(v)for v in items):raise ValueError('Duplicate source set member')
|
|
skill=integer(row['required_skill'],0,0xffffffff,'required skill');rank=integer(row['required_skill_rank'],0,65535,'required rank')
|
|
if rank and not skill:raise ValueError('Item set rank without skill')
|
|
bonuses=[];seen=set()
|
|
for slot,(spell,threshold)in enumerate(zip(spells,thresholds)):
|
|
integer(spell,0,0x7fffffff,'spell reference');integer(threshold,0,0xffffffff,'source threshold')
|
|
# AddItemsSetItem skips unused spell slots regardless of threshold.
|
|
if not spell:continue
|
|
if spell in seen:raise ValueError('Ambiguous repeated set spell')
|
|
seen.add(spell);integer(threshold,1,17,'piece threshold');bonuses.append((slot,spell,threshold))
|
|
return dict(ID=ident,Name_lang=names[0],SetFlags=0,RequiredSkill=skill,RequiredSkillRank=rank,ItemID=list(items)),bonuses
|
|
|
|
def extract_sets(path):
|
|
"""Batch the authoritative45-column Classic table, preserving exceptions."""
|
|
from turtle_data import DBC
|
|
dbc=DBC(Path(path),45);records=[];exceptions=[]
|
|
for raw in dbc.rows:
|
|
row=dict(id=raw[0],names=[dbc.string(v)for v in raw[1:9]],item_ids=list(raw[10:27]),
|
|
spell_ids=list(raw[27:35]),thresholds=list(raw[35:43]),required_skill=raw[43],required_skill_rank=raw[44])
|
|
try:source_set(row);records.append(row)
|
|
except ValueError as error:exceptions.append(dict(id=raw[0],error=str(error),raw_source=row))
|
|
return records,exceptions
|
|
|
|
def generate(source,native_sets,native_children,schemas,native_max,registry,*,replace_existing=False):
|
|
if type(replace_existing)is not bool:raise ValueError('Explicit set relationship replacement policy required')
|
|
if not isinstance(source,list)or not 1<=len(source)<=4096 or len({r['id']for r in source})!=len(source):raise ValueError('Source item set identity/count bound')
|
|
integer(native_max,0,0x7fffffff,'native child maximum')
|
|
bases={r['ID']:r for r in native_sets};children={r['ID']:r for r in native_children}
|
|
if len(bases)!=len(native_sets)or len(children)!=len(native_children):raise ValueError('Duplicate native set/child identity')
|
|
for row in native_sets:encode(row,schemas['ItemSet'])
|
|
for ident,row in children.items():
|
|
integer(ident,1,native_max,'native child ID');encode(row,schemas['ItemSetSpell'])
|
|
reg=copy.deepcopy(registry)
|
|
if reg.get('version')!=1 or not isinstance(reg.get('slots'),dict):raise ValueError('Unknown set child registry')
|
|
slots=reg['slots'];allocated=list(slots.values())
|
|
for ident in allocated:integer(ident,native_max+1,0x7fffffff,'allocated child ID')
|
|
if len(set(allocated))!=len(allocated):raise ValueError('Duplicate set child allocation')
|
|
next_id=max([native_max,*allocated]);used=set();records=[];dependencies=[]
|
|
children_by_set={}
|
|
for row in native_children:
|
|
children_by_set.setdefault(row['ItemSetID'],[]).append(row)
|
|
for rows in children_by_set.values():rows.sort(key=lambda row:row['ID'])
|
|
def record(table,ident,row,source_id):
|
|
raw=encode(row,schemas[table]);return dict(table_name=table,table_hash=hex(TABLES[table][0]),id=ident,record=row,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest(),source_set=source_id)
|
|
for original in sorted(source,key=lambda r:r['id']):
|
|
parent,bonuses=source_set(original);ident=parent['ID'];existing=children_by_set.get(ident,[])
|
|
wanted=sorted((spell,threshold,0,0)for _,spell,threshold in bonuses)
|
|
actual=sorted((r['SpellID'],r['Threshold'],r['ChrSpecID'],r['TraitSubTreeID'])for r in existing)
|
|
if existing and actual!=wanted and not replace_existing:raise ValueError('Native set bonuses differ; explicit per-set replacement required')
|
|
row=record('ItemSet',ident,parent,ident);row['baseline_observed']=ident in bases;row['complete_native_absence_verified']=False;records.append(row)
|
|
# Existing exact child semantics can remain untouched. A replacement
|
|
# removes only these set-owned links, never a shared Spell definition.
|
|
if existing and actual==wanted:continue
|
|
for old in existing:
|
|
raw=encode(old,schemas['ItemSetSpell'])
|
|
records.append(dict(table_name='ItemSetSpell',table_hash=hex(TABLES['ItemSetSpell'][0]),id=old['ID'],record_status='removed',record=None,wire_hex='',sha256=hashlib.sha256(b'').hexdigest(),source_set=ident,baseline_record=copy.deepcopy(old),baseline_record_sha256=hashlib.sha256(raw).hexdigest(),policy=REMOVAL_POLICY))
|
|
for slot,spell,threshold in bonuses:
|
|
key=f'{ident}:{slot}';used.add(key)
|
|
if key not in slots:next_id+=1;integer(next_id,1,0x7fffffff,'new child ID');slots[key]=next_id
|
|
child=dict(ChrSpecID=0,SpellID=spell,TraitSubTreeID=0,Threshold=threshold,ItemSetID=ident)
|
|
records.append(record('ItemSetSpell',slots[key],child,ident))
|
|
dependencies.append(dict(set_id=ident,spell_ids=[spell for _,spell,_ in bonuses],item_ids=[v for v in parent['ItemID']if v],skill_id=parent['RequiredSkill']))
|
|
if set(slots)-used:raise ValueError('Previously allocated set children removed; reviewed migration required')
|
|
# Include references for preserved children too; equal IDs do not attest
|
|
# source/destination spell semantics or grant a set bonus to the character.
|
|
dependency_ids={row['set_id']for row in dependencies}
|
|
for original in source:
|
|
if original['id'] not in dependency_ids:
|
|
_,bonuses=source_set(original);dependencies.append(dict(set_id=original['id'],spell_ids=[s for _,s,_ in bonuses],item_ids=[v for v in original['item_ids']if v],skill_id=original['required_skill']))
|
|
return dict(build='1.60.1.70334',kind='source-item-set-components',locale='enUS',records=records,registry=reg,dependencies=sorted(dependencies,key=lambda r:r['set_id']),dependency_complete=False,installable=False,installed=False,engine_loaded=False,gameplay_verified=False,
|
|
limits=['Source set, spell and member IDs retained; only destination child record IDs allocated.',
|
|
'Equal native bonus identities do not prove full spell behavior parity.',
|
|
'Caller must verify source selection and linked spell/skill/item definitions before installation.',
|
|
'Native RecordRemoved cache behavior and real set bonuses remain unverified.'])
|
|
|
|
if __name__=='__main__':
|
|
from item_package_preflight import read_public_json
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
for name in('source','native-sets','native-children','registry','output'):p.add_argument('--'+name,type=Path,required=True)
|
|
p.add_argument('--replace-existing',action='store_true',help='Replace only source-owned per-set bonus relations, with pinned removal baselines')
|
|
a=p.parse_args();inputs={key:getattr(a,key)for key in('source','native_sets','native_children')}
|
|
if not all(path.resolve().is_relative_to(ROOT)for path in(a.registry,a.output)) or len({path.resolve()for path in(*inputs.values(),a.registry,a.output)})!=5:p.error('Separate input, registry and output paths; generated files must stay inside gateway')
|
|
values={};pins={}
|
|
source_exceptions=[]
|
|
for key,path in inputs.items():
|
|
if key=='source'and path.suffix.lower()=='.dbc':
|
|
values[key],source_exceptions=extract_sets(path);pins[key]=hashlib.sha256(path.read_bytes()).hexdigest()
|
|
else:values[key],pins[key]=read_public_json(path)
|
|
registry=read_public_json(a.registry)[0]if a.registry.exists()else dict(version=1,slots={})
|
|
native=Path.home()/'Projects/WoW-Hybrid/servers/trinity-forever/install/bin/dbc/enUS';dbd=Path.home()/'Projects/WoW-Hybrid/tools/WoWDBDefs/definitions';schemas={};meta={}
|
|
sha=lambda path:hashlib.sha256(path.read_bytes()).hexdigest()
|
|
for name,(table,layout,count)in TABLES.items():
|
|
file=native/(name+'.db2');definition=dbd/(name+'.dbd');check_db2(file,table,layout);schemas[name]=fields(definition,layout,count)
|
|
with file.open('rb')as f:header=f.read(168)
|
|
meta[name]=dict(table_hash=hex(table),layout_hash=hex(layout),native_max_id=struct.unpack_from('<I',header,164)[0],db2_sha256=sha(file),dbd_sha256=sha(definition))
|
|
r=generate(values['source'],values['native_sets'],values['native_children'],schemas,meta['ItemSetSpell']['native_max_id'],registry,replace_existing=a.replace_existing)
|
|
if pins!={key:hashlib.sha256(path.read_bytes()).hexdigest()for key,path in inputs.items()}:raise ValueError('Set conversion inputs changed')
|
|
for name in TABLES:
|
|
if sha(native/(name+'.db2'))!=meta[name]['db2_sha256']or sha(dbd/(name+'.dbd'))!=meta[name]['dbd_sha256']:raise ValueError('Native set schema/data changed during conversion')
|
|
r.update(input_sha256=pins,native_tables=meta,converter_sha256=sha(Path(__file__)),source_exceptions=source_exceptions)
|
|
for path,value in((a.registry,r['registry']),(a.output,r)):
|
|
path.parent.mkdir(parents=True,exist_ok=True);temp=path.with_name(path.name+'.new')
|
|
if temp.exists()or temp.is_symlink():raise ValueError('Existing set conversion temporary preserved')
|
|
temp.write_text(json.dumps(value,sort_keys=True,ensure_ascii=False,indent=2,allow_nan=False)+'\n');temp.replace(path)
|
|
print('Generated',len(r['records']),'set component records; no client installation, character grants or gameplay claim.')
|