Files
2026-11-23 03:28:32 +02:00

120 lines
8.6 KiB
Python

"""Octo-authoritative profession recipe hotfix rows for the 14 profession lines + quarantine archive of every removed/overwritten client row.
Writes recipe-component.json (rows: table, table_hash, id, wire_hex ('' = delete), action, reason) and
quarantine/recipes-removed-20261122.json (exact prior client rows, decoded + wire hex)."""
import json,struct,sys,collections,hashlib
sys.path.insert(0,'.')
import effective as E, audit as A
LINES={129,142,164,165,171,182,185,186,197,202,333,356,393,755}
NEWBASE=8_900_000
def encode(layout,d):
out=bytearray()
for f in layout:
if 'noninline' in f['ann']:continue
vals=d[f['name']] if f['arr']>1 else [d[f['name']]]
for v in vals:
if f['size'] is None and (f['name'].endswith('_lang') or f['name']=='NeutralDisplayName'):
out+=(v if isinstance(v,str) else '').encode('utf8')+b'\0'
elif f['size'] is None: out+=struct.pack('<f',float(v or 0))
else:
n=int(f['size'].strip('<>u'));signed=not f['size'].startswith('<u')
out+=(int(v or 0)&((1<<n)-1)).to_bytes(n//8,'little')
return bytes(out)
tabs={n:E.table(n) for n in ('SkillLineAbility','SpellReagents','SpellTotems','SpellCastingRequirements','SpellEffect','SpellName')}
def lay(n): return tabs[n]['table']['layout']
def th(n): return tabs[n]['table']['header']['table_hash']
rows=[];quar=[];nextid=collections.defaultdict(lambda:NEWBASE)
def emit(n,rid,d,action,reason,prior=None):
wire=encode(lay(n),d) if d is not None else b''
if d is not None:
rest=E.decode(lay(n),wire)[1]; assert rest==0
rel=[f['name'] for f in lay(n) if 'relation' in f['ann'] and 'noninline' in f['ann']]
if d is not None and rel: wire+=int(d[rel[0]]).to_bytes(4,'little')
rows.append(dict(table=n,table_hash=f'0x{th(n):08x}',id=rid,wire_hex=wire.hex(),action=action,reason=reason))
if prior is not None:
pw=encode(lay(n),prior)+(int(prior[rel[0]]).to_bytes(4,'little') if rel and prior.get(rel[0]) is not None else b'')
quar.append(dict(table=n,id=rid,action=action,reason=reason,prior_source=prior.get('_src'),prior=dict((k,v) for k,v in prior.items() if not k.startswith('_')),prior_wire_hex=pw.hex()))
def newid(n):
nextid[n]+=1; return nextid[n]
sla=tabs['SkillLineAbility']['rows']
by_line=collections.defaultdict(dict)
for r in sla.values():
if r['SkillLine'] in LINES: by_line[r['SkillLine']][r['Spell']]=r
octo=A.octo
OSLA={r[0]:r for r in A.osla}
recipe_spells=set()
for line in sorted(LINES):
o=octo[line]; c=by_line[line]
tmpl=next(iter(c.values()),None)
cat=collections.Counter(r['TradeSkillCategoryID'] for r in c.values() if r['Spell'] in o).most_common(1)
for sid,r in c.items():
if sid not in o: emit('SkillLineAbility',r['ID'],None,'delete',f'extra recipe on line {line}: spell {sid} not an Octo recipe of this line',prior=r)
for sid,a in o.items():
recipe_spells.add(sid)
if sid in c:
r=c[sid]; d=dict(r); d.update(MinSkillLineRank=a['min'],TrivialSkillLineRankHigh=a['high'],TrivialSkillLineRankLow=a['low'])
if (d['MinSkillLineRank'],d['TrivialSkillLineRankHigh'],d['TrivialSkillLineRankLow'])!=(r['MinSkillLineRank'],r['TrivialSkillLineRankHigh'],r['TrivialSkillLineRankLow']):
emit('SkillLineAbility',r['ID'],d,'rewrite',f'Octo ranks for spell {sid}',prior=r)
else:
base=dict(tmpl) if tmpl else {f['name']:([0]*f['arr'] if f['arr']>1 else 0) for f in lay('SkillLineAbility')}
nid=newid('SkillLineAbility')
base.update(AbilityVerb_lang='',AbilityAllVerb_lang='',ID=nid,SkillLine=line,Spell=sid,MinSkillLineRank=a['min'],ClassMask=0,SupercedesSpell=0,
AcquireMethod=a['acq'],TrivialSkillLineRankHigh=a['high'],TrivialSkillLineRankLow=a['low'],Flags=0,NumSkillUps=1,UniqueBit=0,
TradeSkillCategoryID=cat[0][0] if cat else 0)
orow=OSLA[a['sla']]
base.update(ClassMask=orow[4],RaceMasks=[orow[3],0],SupercedesSpell=orow[8],SkillupSkillLineID=base.get('SkillupSkillLineID') if base.get('SkillupSkillLineID') in (0,line) else 0,
Field_5_5_4_67090_014=[0,0])
emit('SkillLineAbility',nid,base,'add',f'missing Octo recipe {sid} on line {line}')
# spell data
def group(n,key='SpellID'):
g=collections.defaultdict(list)
for r in tabs[n]['rows'].values():
if r.get(key) is not None: g[r[key]].append(r)
return g
RG,TT,CR,EF=group('SpellReagents'),group('SpellTotems'),group('SpellCastingRequirements'),group('SpellEffect')
NM=tabs['SpellName']['rows']; stats=collections.Counter()
for sid in sorted(recipe_spells):
o=A.o_recipe(sid)
if not o: stats['no-octo-spell']+=1; continue
raw=A.ospell[sid]; reag=[(raw[42+i],raw[50+i]) for i in range(8) if raw[42+i]] # Octo's own order
have=RG[sid]; want_items=[i for i,_ in reag]+[0]*(8-len(reag)); want_cnt=[c for _,c in reag]+[0]*(8-len(reag))
if reag:
if have:
r=have[0]; d=dict(r,Reagent=want_items,ReagentCount=want_cnt,ReagentReCraftCount=[0]*8,ReagentSource=[0]*8)
if [r['Reagent'],r['ReagentCount']]!=[want_items,want_cnt] or any(r['ReagentReCraftCount']) or any(r['ReagentSource']): emit('SpellReagents',r['ID'],d,'rewrite',f'Octo reagents for {sid}',prior=r); stats['reagent-rewrite']+=1
for x in have[1:]: emit('SpellReagents',x['ID'],None,'delete',f'duplicate reagent row for {sid}',prior=x)
else:
nid=newid('SpellReagents'); emit('SpellReagents',nid,dict(ID=nid,SpellID=sid,Reagent=want_items,ReagentCount=want_cnt,ReagentReCraftCount=[0]*8,ReagentSource=[0]*8),'add',f'Octo reagents for {sid}'); stats['reagent-add']+=1
else:
for x in have: emit('SpellReagents',x['ID'],None,'delete',f'Octo recipe {sid} has no reagents',prior=x); stats['reagent-delete']+=1
tots=o['totems']+[0]*(2-len(o['totems'])); have=TT[sid]
if o['totems']:
if have:
r=have[0]; d=dict(r,Totem=tots,RequiredTotemCategoryID=[0,0])
if r['Totem']!=tots or any(r['RequiredTotemCategoryID']): emit('SpellTotems',r['ID'],d,'rewrite',f'Octo tools for {sid}',prior=r); stats['tool-rewrite']+=1
for x in have[1:]: emit('SpellTotems',x['ID'],None,'delete',f'duplicate tool row for {sid}',prior=x)
else:
nid=newid('SpellTotems'); emit('SpellTotems',nid,dict(ID=nid,SpellID=sid,Totem=tots,RequiredTotemCategoryID=[0,0]),'add',f'Octo tools for {sid}'); stats['tool-add']+=1
else:
for x in have: emit('SpellTotems',x['ID'],None,'delete',f'Octo recipe {sid} needs no tool',prior=x); stats['tool-delete']+=1
have=CR[sid]
for r in have:
if r['RequiresSpellFocus']!=o['focus']:
emit('SpellCastingRequirements',r['ID'],dict(r,RequiresSpellFocus=o['focus']),'rewrite',f'Octo spell focus {o["focus"]} for {sid} (was {r["RequiresSpellFocus"]})',prior=r); stats['focus-rewrite']+=1
if not have and o['focus']:
nid=newid('SpellCastingRequirements'); emit('SpellCastingRequirements',nid,dict(ID=nid,SpellID=sid,FacingCasterFlags=0,MinFactionID=0,MinReputation=0,RequiredAreasID=0,RequiredAuraVision=0,RequiresSpellFocus=o['focus']),'add',f'Octo spell focus for {sid}'); stats['focus-add']+=1
ce=sorted([r for r in EF[sid] if r.get('Effect')==24 and r.get('DifficultyID',0)==0],key=lambda r:r['EffectIndex'])
if o['creates'] and ce and len(ce)==len(o['creates']):
for r,item in zip(ce,o['creates']):
if r['EffectItemType']!=item: emit('SpellEffect',r['ID'],dict(r,EffectItemType=item),'rewrite',f'Octo crafted item {item} for {sid}',prior=r); stats['create-rewrite']+=1
elif o['creates'] and len(ce)!=len(o['creates']): stats['create-shape-differs(held)']+=1
n=NM.get(sid)
if n and n['Name_lang']!=o['name']:
emit('SpellName',sid,dict(n,Name_lang=o['name']),'rewrite',f'Octo name for {sid}',prior=n); stats['name-rewrite']+=1
comp=dict(kind='octo-profession-recipe-hotfix-component',schema_version=1,build=70334,lines=sorted(LINES),new_id_base=NEWBASE,
source='Octo client patch-5 DBCs (patch-O empty)',client_basis='installed cb30/cf2c DB2 + 5d4af6b3 item_sparse_compat hotfixes',rows=rows)
json.dump(comp,open('recipe-component.json','w'),indent=1)
import os; os.makedirs('quarantine',exist_ok=True)
json.dump(dict(kind='removed-or-overwritten-client-rows',note='Rows removed from or overwritten in the client so it matches Octo exactly; kept for reference/restore.',rows=quar),open('quarantine/recipes-removed-20261122.json','w'),indent=1)
print('rows',len(rows),collections.Counter((r['table'],r['action']) for r in rows)); print(dict(stats)); print('quarantined',len(quar))