367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
530 lines
40 KiB
Python
530 lines
40 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate reviewed source aura masks from local SQL and native DB2 rows.
|
|
|
|
Ordinary holders require a reviewed persistent effect. The explicit mounted
|
|
family projects only a matched mounted effect with a real source mount display;
|
|
its companion effects and other multi-effect/area/scripted cases remain unknown.
|
|
The opt-in homogeneous caster ModStat category uses a separate pinned core proof.
|
|
No runtime SQL, unrelated spell IDs, caster guesses or invented duration values.
|
|
"""
|
|
import argparse,hashlib,json
|
|
from pathlib import Path
|
|
from item_template_snapshot import identities
|
|
from local_tortoise import ROOT,db
|
|
|
|
def _caster_modstat_rejection(spell,effects,indices):
|
|
"""Pinned core source mask category; native rows are checked separately.
|
|
|
|
See docs/evidence/gameplay/homogeneous-caster-modstat-20261023/assessment.json.
|
|
"""
|
|
if any(value not in (0,6) for value in effects):
|
|
return 'caster ModStat category has another source effect type'
|
|
if spell.get('script_name')!='':
|
|
return 'caster ModStat requires an explicit empty source script binding'
|
|
if spell['entry'] in (12566,12567,12568):
|
|
return 'source core has per-index Plainsrunning application/removal policy'
|
|
mechanic=spell.get('mechanic')
|
|
if type(mechanic) is not int or not 0<=mechanic<32:
|
|
return 'caster ModStat source mechanic is unavailable or invalid'
|
|
vectors=[]
|
|
for index in indices:
|
|
suffix=str(index+1)
|
|
required=('effectApplyAuraName','effectMechanic','effectBasePoints',
|
|
'effectBaseDice','effectImplicitTargetA','effectImplicitTargetB',
|
|
'effectRadiusIndex','effectChainTarget','effectAmplitude',
|
|
'effectTriggerSpell','effectMiscValue')
|
|
values={key:spell.get(key+suffix) for key in required}
|
|
if any(type(value) is not int for value in values.values()):
|
|
return 'caster ModStat requires complete numeric source effect fields'
|
|
if values['effectApplyAuraName']!=29:
|
|
return 'multiple source aura kinds are not a coupled ModStat holder'
|
|
if (values['effectImplicitTargetA'],values['effectImplicitTargetB'])!=(1,0):
|
|
return 'multiple source effects do not use the reviewed direct caster target'
|
|
if not -2<=values['effectMiscValue']<=4:
|
|
return 'caster ModStat selector is outside the original handler range'
|
|
if any(values[key]!=0 for key in ('effectRadiusIndex','effectChainTarget',
|
|
'effectAmplitude','effectTriggerSpell')):
|
|
return 'caster ModStat requires the reviewed nonperiodic unchained target path'
|
|
effect_mechanic=values['effectMechanic']
|
|
if not 0<=effect_mechanic<32 or (effect_mechanic and effect_mechanic!=mechanic):
|
|
return 'caster ModStat has an independent per-effect resistance predicate'
|
|
if any(not -(1<<31)<=values[key]<(1<<31) for key in ('effectBasePoints','effectBaseDice')):
|
|
return 'caster ModStat simple value input is outside the original integer range'
|
|
vectors.append((effect_mechanic,
|
|
values['effectBasePoints']+values['effectBaseDice']<0))
|
|
if any(vector!=vectors[0] for vector in vectors[1:]):
|
|
return 'caster ModStat indexed immunity or positivity predicates differ'
|
|
return None
|
|
|
|
|
|
def generate(source,native,*,instant_companions=False,homogeneous_modstat_caster=False):
|
|
if not isinstance(source,list) or not isinstance(native,list):raise ValueError('Require source/native row arrays')
|
|
if type(instant_companions)is not bool or type(homogeneous_modstat_caster)is not bool or len(source)>100000 or len(native)>500000:raise ValueError('Bounded aura source/native family required')
|
|
native_index={}
|
|
for row in native:
|
|
if any(type(row.get(k)) is not int for k in ('SpellID','EffectIndex','DifficultyID','Effect','EffectAura')):raise ValueError('Invalid native effect metadata')
|
|
native_index.setdefault((row['SpellID'],row['EffectIndex'],row['DifficultyID']),[]).append(row)
|
|
rows=[];excluded=[];seen=set()
|
|
for spell in sorted(source,key=lambda r:r['entry']):
|
|
ident=spell['entry']
|
|
if type(ident) is not int or not 0<ident<=0x7fffffff or ident in seen:raise ValueError('Invalid/duplicate source spell')
|
|
seen.add(ident);effects=[spell['effect'+str(i)] for i in range(1,4)]
|
|
if any(type(v) is not int or not 0<=v<=0xffffffff for v in effects):raise ValueError('Invalid source effect metadata')
|
|
indices=[i for i,v in enumerate(effects) if v==6]
|
|
# One persistent aura still has an unambiguous source holder mask when an
|
|
# immediate damage/heal/energize effect accompanies it. Multiple persistent,
|
|
# periodic trigger chains and area-aura holders are deliberately not inferred.
|
|
allowed=(0,2,6,10,30)if instant_companions else(0,6)
|
|
if homogeneous_modstat_caster and len(indices)>1:
|
|
reason=_caster_modstat_rejection(spell,effects,indices)
|
|
if reason:
|
|
excluded.append(dict(spell=ident,reason=reason));continue
|
|
native_matches=[native_index.get((ident,index,0),[]) for index in indices]
|
|
if any(len(matches)!=1 or matches[0]['Effect']!=6 or matches[0]['EffectAura']!=29
|
|
for matches in native_matches):
|
|
excluded.append(dict(spell=ident,reason='no unambiguous accessible native ModStat effect at every genuine source index'));continue
|
|
rows.append(dict(spell=ident,effect_indices=indices,aura_type=29,
|
|
active_flags=sum(1<<index for index in indices),
|
|
reviewed_family='homogeneous-direct-caster-ModStat'))
|
|
continue
|
|
if len(indices)!=1 or any(v not in allowed for v in effects):excluded.append(dict(spell=ident,reason='not a single reviewed APPLY_AURA holder'));continue
|
|
index=indices[0];kind=spell['effectApplyAuraName'+str(index+1)]
|
|
if type(kind) is not int or not 0<=kind<=0xffff:raise ValueError('Invalid source aura kind')
|
|
if not kind and not instant_companions:raise ValueError('Invalid source aura kind')
|
|
# Pinned source/destination enum meanings agree for STUN12, STAT29,
|
|
# DECREASE_SPEED33 and MELEE_HASTE138. This is not a blanket numeric mapping.
|
|
if instant_companions and kind not in(12,29,33,138):excluded.append(dict(spell=ident,reason='aura semantic family not reviewed for instant companions'));continue
|
|
matches=native_index.get((ident,index,0),[])
|
|
if len(matches)!=1 or matches[0]['Effect']!=6 or matches[0]['EffectAura']!=kind:excluded.append(dict(spell=ident,reason='no unambiguous accessible native effect at genuine index/type'));continue
|
|
rows.append(dict(spell=ident,effect_index=index,aura_type=kind,active_flags=1<<index))
|
|
return dict(definitions=rows,excluded=excluded,limits=[
|
|
'One source APPLY_AURA in reviewed stun/stat/slow/melee-haste family; immediate damage/heal/energize companions allowed. No server execution is synthesized.'if instant_companions else('Observed single-effect holders and the opt-in reviewed homogeneous direct-caster ModStat category.' if homogeneous_modstat_caster else 'Only observed holders whose source definition has exactly one nonzero APPLY_AURA effect.'),
|
|
'Positive accessible same-ID/index/type native row is verified; no claim that other encoded rows do not exist.',
|
|
'Mask eligibility only: native effect amounts, targets, UI, asset loading and actual mechanics require separate verification.',
|
|
('No inferred caster, cast ID, visual, maximum duration or effect amount. Only the opt-in pinned source direct-caster ModStat category has a multiple-aura mask; other multiple-aura families remain held. Actual Octo fork and native UI acceptance are unverified.' if homogeneous_modstat_caster else 'No inferred caster, cast ID, visual, maximum duration, effect amount or multi-aura application mask.')])
|
|
|
|
# Static numeric corrections only. Aura Points and talent modifiers are separate
|
|
# runtime state; this deliberately does not synthesize either of them.
|
|
SCALAR_POLICY='named-source-attack-power-scalar-overlay-v1'
|
|
SCALAR_HEADER_PINS={
|
|
'source_defines':'fd1c65c0266b77a310c066bc3ccce86fe39f73a6cd10f67192d419009f95ead1',
|
|
'source_auras':'ed7f67babe916cbbf91f7a1f1a9a9af694a2469d2e07eb10e94f0ae883678cb8',
|
|
'target_defines':'9b0e2ad90eea77c961b00f1fc482e9d9e521aa85c58b63863a35d3a338a31799',
|
|
'target_auras':'1784b495ea9704bbe12223c2ad42d9d5fea7d320f0dc6c0055cd090cb7e5498b'}
|
|
|
|
def scalar_namespace(paths):
|
|
import re
|
|
if not isinstance(paths,dict)or set(paths)!=set(SCALAR_HEADER_PINS):raise ValueError('Four pinned source/target enum headers required')
|
|
for role,path in paths.items():
|
|
raw=Path(path).read_bytes()
|
|
if hashlib.sha256(raw).hexdigest()!=SCALAR_HEADER_PINS[role]:raise ValueError('Reviewed scalar enum changed: '+role)
|
|
names={'SPELL_AURA_MOD_ATTACK_POWER':99,'SPELL_AURA_MOD_LANGUAGE':75,'SPELL_AURA_MOD_SKILL':30}if role.endswith('auras')else{'SPELL_EFFECT_APPLY_AURA':6,'SPELL_EFFECT_ADD_EXTRA_ATTACKS':19,'SPELL_EFFECT_ENCHANT_ITEM':53}
|
|
if role=='source_defines':names['SPELL_ATTR_LEVEL_DAMAGE_CALCULATION']=0x80000
|
|
text=re.sub(r'/\*.*?\*/|//[^\n]*','',raw.decode(),flags=re.S)
|
|
for name,value in names.items():
|
|
m=re.search(r'\b'+name+r'\s*=\s*(0x[0-9A-Fa-f]+|[0-9]+)\s*,',text)
|
|
if not m or int(m[1],0)!=value:raise ValueError('Named scalar semantics differ: '+name)
|
|
return dict(policy=SCALAR_POLICY,header_sha256=dict(SCALAR_HEADER_PINS))
|
|
|
|
def attack_power_scalar_rows(source,native_effects,native_levels,published_rows,schema,proof,level_schema):
|
|
"""Overlay two scalar fields on existing compatible same-ID aura99 records.
|
|
|
|
Source integer level arithmetic must be exactly representable by the native
|
|
float curve for every level1..255. Fractional source steps are deferred until
|
|
client rounding is verified. Preserve all references, flags and child IDs.
|
|
"""
|
|
from copy import deepcopy
|
|
import math
|
|
from octo_client_data import canonical_sha256
|
|
from spell_passive_compat import TABLES,SUPPLEMENTAL_TABLES,encode
|
|
if proof!=dict(policy=SCALAR_POLICY,header_sha256=SCALAR_HEADER_PINS):raise ValueError('Pinned named scalar namespace required')
|
|
if canonical_sha256(schema)!=TABLES['SpellEffect'][2]or canonical_sha256(level_schema)!=SUPPLEMENTAL_TABLES['SpellLevels'][2]:raise ValueError('Reviewed SpellEffect/SpellLevels schemas required')
|
|
if not isinstance(source,list)or not 1<=len(source)<=100000:raise ValueError('Bounded source scalar definitions required')
|
|
def index(rows):
|
|
out={}
|
|
for r in rows:
|
|
if type(r.get('ID'))is not int or not 0<r['ID']<2**31 or r['ID']in out:raise ValueError('Invalid/duplicate native scalar identity')
|
|
out[r['ID']]=deepcopy(r)
|
|
return out
|
|
effects=index(native_effects);levels=index(native_levels)
|
|
for row in published_rows:
|
|
table=row.get('table_name')
|
|
if table not in('SpellEffect','SpellLevels'):continue
|
|
if row.get('record_status','valid')!='valid':continue
|
|
target=effects if table=='SpellEffect'else levels
|
|
if row['id']not in target:continue
|
|
r=row.get('record')
|
|
if not isinstance(r,dict)or r.get('ID')!=row['id']:raise ValueError('Published scalar row identity differs')
|
|
wire=encode(r,schema if table=='SpellEffect'else level_schema)
|
|
metadata=(TABLES|SUPPLEMENTAL_TABLES)[table]
|
|
if row.get('table_hash')!=hex(metadata[0])or row.get('wire_hex')!=wire.hex()or row.get('sha256')!=hashlib.sha256(wire).hexdigest():raise ValueError('Published scalar bytes differ')
|
|
target[row['id']]=deepcopy(r)
|
|
rows=[];blocked=[];unchanged=[];seen=set()
|
|
for s in sorted(source,key=lambda r:r['entry']):
|
|
ident=s['entry']
|
|
if type(ident)is not int or not 0<ident<2**31 or ident in seen:raise ValueError('Duplicate/invalid source scalar identity')
|
|
seen.add(ident)
|
|
for name in ('attributes','baseLevel','spellLevel','maxLevel','effectBaseDice1','effectBasePoints1','effectDieSides1'):
|
|
if type(s.get(name))is not int:raise ValueError('Source scalar integer required: '+name)
|
|
if any(not 0<=s[k]<=255 for k in ('baseLevel','spellLevel','maxLevel'))or (s['maxLevel']and s['maxLevel']<s['baseLevel']):raise ValueError('Source scalar level bounds')
|
|
def reject(reason):blocked.append(dict(spell=ident,reason=reason))
|
|
if [s['effect'+str(i)]for i in(1,2,3)]!=[6,0,0]or s['effectApplyAuraName1']!=99:
|
|
reject('not one named attack-power APPLY_AURA effect');continue
|
|
if s.get('script_name')or s['attributes']&0x80000 or s['effectDieSides1']not in(0,1)or any(s[k]for k in('effectDicePerLevel1','effectPointsPerComboPoint1','effectBonusCoefficient1','effectTriggerSpell1')):
|
|
reject('scripted, exponential, random, resource or triggered amount');continue
|
|
e=[r for r in effects.values()if(r.get('SpellID'),r.get('EffectIndex'),r.get('DifficultyID'))==(ident,0,0)]
|
|
l=[r for r in levels.values()if(r.get('SpellID'),r.get('DifficultyID'))==(ident,0)]
|
|
if len(e)!=1 or len(l)!=1:
|
|
reject('accessible native effect/level relation absent or ambiguous');continue
|
|
e,l=e[0],l[0]
|
|
encode(e,schema);encode(l,level_schema)
|
|
if(e['Effect'],e['EffectAura'])!=(6,99)or any(e[k]for k in('EffectAttributes','EffectPointsPerResource','EffectTriggerSpell','EffectBonusCoefficient','BonusCoefficientFromAP','Coefficient','Variance','ResourceCoefficient','ScalingClass')):
|
|
reject('native semantic or non-neutral scaling family differs');continue
|
|
if e['GroupSizeBasePointsCoefficient']!=1 or e['PvpMultiplier']!=1 or e['EffectChainAmplitude']!=1 or e['Node__Field_12_0_0_63534_001']!=0:
|
|
reject('native multiplicative or unknown scaling differs');continue
|
|
if(s['baseLevel']!=s['spellLevel']or (l['BaseLevel'],l['SpellLevel'],l['MaxLevel'])!=(s['baseLevel'],s['spellLevel'],s['maxLevel'])):
|
|
reject('source/native caster-level bounds differ');continue
|
|
base=s['effectBasePoints1']+s['effectBaseDice1'];per=s['effectRealPointsPerLevel1']
|
|
if any(type(v)not in(int,float)or not math.isfinite(v)for v in(base,per))or type(s['effectBaseDice1'])is not int:
|
|
raise ValueError('Invalid source scalar values')
|
|
if int(base)!=base or int(per)!=per:
|
|
reject('fractional source integer-step versus native float rounding unresolved');continue
|
|
if any(abs(base+max(0,min(level,s['maxLevel']or level)-s['spellLevel'])*per)>=2**24 for level in range(1,256)):
|
|
reject('source level arithmetic exceeds exact native float integer range');continue
|
|
new=deepcopy(e);new['EffectBasePointsF']=base;new['EffectRealPointsPerLevel']=per
|
|
changed=[k for k in('EffectBasePointsF','EffectRealPointsPerLevel')if new[k]!=e[k]]
|
|
if not changed:unchanged.append(ident);continue
|
|
raw=encode(new,schema)
|
|
rows.append(dict(table_name='SpellEffect',table_hash=hex(TABLES['SpellEffect'][0]),id=new['ID'],record=new,
|
|
wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest(),policy=SCALAR_POLICY,
|
|
source_spell_id=ident,source_effect_index=0,source_record_sha256=canonical_sha256(s),
|
|
baseline_record_sha256=canonical_sha256(e),changed_fields=changed))
|
|
return dict(kind='source-aura-static-scalar-candidates',policy=SCALAR_POLICY,rows=rows,blocked=blocked,unchanged=unchanged,
|
|
source_records=len(source),installed=False,engine_accepted=False,limits=[
|
|
'Existing same-ID/type/index records and exact caster-level bounds only; no new definitions, altered references, spell learning or server execution.',
|
|
'Static base/level values only. Aura Points/caster information and talent-modifier routing require independent runtime synchronization and actual-client tests.',
|
|
'Fractional integer-step scaling, random/scripted effects, non-neutral native scaling and missing metadata remain explicit blockers.'])
|
|
|
|
def extend_with_package(base,source,package,schema):
|
|
from copy import deepcopy
|
|
from octo_client_data import canonical_sha256
|
|
from spell_passive_compat import BUILD,SCHEMA,TABLES,encode
|
|
table,_,fieldsha=TABLES['SpellEffect']
|
|
if canonical_sha256(schema)!=fieldsha or (package.get('build'),package.get('schema'))!=(BUILD,SCHEMA):raise ValueError('Reviewed package aura schema required')
|
|
if not isinstance(source,list)or not 1<=len(source)<=256:raise ValueError('Bounded package aura source required')
|
|
wanted={r.get('entry')for r in source};native=[]
|
|
for row in package.get('rows',[]):
|
|
if row.get('table_name')!='SpellEffect'or row.get('source_spell_id')not in wanted:continue
|
|
record=row.get('record',{});wire=encode(record,schema)
|
|
if (row.get('record_status','valid')!='valid'or row.get('table_hash')!=hex(table)or row.get('id')!=record.get('ID')or
|
|
row.get('source_spell_id')!=record.get('SpellID')or row.get('source_effect_index')!=record.get('EffectIndex')or
|
|
row.get('wire_hex')!=wire.hex()or row.get('sha256')!=hashlib.sha256(wire).hexdigest()):raise ValueError('Package aura effect identity/wire differs')
|
|
native.append(record)
|
|
extra=generate(source,native)
|
|
if extra['excluded']or len(extra['definitions'])!=len(source):raise ValueError('Complete single-effect package aura definitions required')
|
|
rows=deepcopy(base);known={r['spell']:r for r in rows}
|
|
if len(known)!=len(rows):raise ValueError('Duplicate base aura identity')
|
|
for row in extra['definitions']:
|
|
if row['spell']in known:
|
|
if known[row['spell']]!=row:raise ValueError('Conflicting base aura definition')
|
|
else:rows.append(row);known[row['spell']]=row
|
|
return sorted(rows,key=lambda r:r['spell'])
|
|
|
|
def extend_composite_with_package(base,candidates,package,schema):
|
|
"""One persistent aura plus a reviewed instantaneous extra attack.
|
|
|
|
Tortoise EffectAddExtraAttacks updates extra attacks; EffectApplyAura and
|
|
SpellAuraHolder::AddAura retain the aura's actual effect index. This opt-in
|
|
does not infer masks for multiple auras, area effects or scripted spells.
|
|
"""
|
|
from copy import deepcopy
|
|
from octo_client_data import canonical_sha256
|
|
from spell_passive_compat import BUILD,SCHEMA,TABLES,encode
|
|
from spell_timed_buff_compat import EXTRA_DAMAGE_POLICY,validate_source
|
|
from item_sparse_compat import package_payloads
|
|
table,_,fieldsha=TABLES['SpellEffect']
|
|
if canonical_sha256(schema)!=fieldsha or(package.get('build'),package.get('schema'))!=(BUILD,SCHEMA)or package.get('push_id')!=package_payloads(package.get('rows'))[0]:
|
|
raise ValueError('Reviewed composite aura package/schema required')
|
|
if not isinstance(base,list)or not isinstance(candidates,list)or not 1<=len(candidates)<=16:raise ValueError('Bounded composite aura candidates required')
|
|
rows=deepcopy(base);known={r['spell']:r for r in rows}
|
|
if len(known)!=len(rows):raise ValueError('Duplicate base aura identity')
|
|
seen=set()
|
|
for candidate in candidates:
|
|
if (not isinstance(candidate,dict)or candidate.get('kind')!='source-timed-self-buff-definition-candidates'
|
|
or candidate.get('definition_policy')!=EXTRA_DAMAGE_POLICY or not isinstance(candidate.get('spells'),list)
|
|
or not 1<=len(candidate['spells'])<=256):raise ValueError('Explicit typed composite source required')
|
|
for spell in candidate['spells']:
|
|
src=spell.get('source_definition');ident=spell.get('spell_id')
|
|
if not isinstance(src,dict)or src.get('entry')!=ident or canonical_sha256(src)!=spell.get('source_record_sha256')or ident in seen:raise ValueError('Composite aura source identity/hash differs')
|
|
seen.add(ident);indices=validate_source(src,visual_link=candidate.get('visual_link'),extra_damage=True)
|
|
if spell.get('effect_indices')!=indices:raise ValueError('Composite source effect coverage differs')
|
|
expected=[r for r in candidate.get('records',[])if r.get('table_name')=='SpellEffect'and r.get('source_spell_id')==ident]
|
|
actual=[r for r in package['rows']if r.get('table_name')=='SpellEffect'and r.get('source_spell_id')==ident]
|
|
if (len(expected)!=2 or actual!=expected or {r.get('record',{}).get('EffectIndex')for r in actual}!=set(indices)
|
|
or not all(any(r.get('table_name')==name and r.get('id')==ident and r.get('record_status','valid')=='valid'for r in package['rows'])for name in('Spell','SpellName'))):
|
|
raise ValueError('Complete reviewed composite package effects/parents required')
|
|
for record in actual:
|
|
r=record.get('record',{});wire=encode(r,schema);i=r.get('EffectIndex')
|
|
if (record.get('record_status','valid')!='valid'or record.get('table_hash')!=hex(table)or record.get('id')!=r.get('ID')
|
|
or r.get('SpellID')!=ident or type(i)is not int or i not in indices or record.get('source_effect_index')!=i
|
|
or record.get('wire_hex')!=wire.hex()or record.get('sha256')!=hashlib.sha256(wire).hexdigest()
|
|
or(r['Effect'],r['EffectAura'],r['EffectBasePointsF'],r['EffectMiscValue'])!=(src['effects'][i][0],src['effects'][i][1],src['effects'][i][2]+1,[src['effects'][i][7],0])):
|
|
raise ValueError('Composite aura effect/source/serialization differs')
|
|
auras=[i for i in indices if src['effects'][i][0]==6]
|
|
if len(auras)!=1:raise ValueError('Exactly one persistent composite aura required')
|
|
i=auras[0];row=dict(spell=ident,effect_index=i,aura_type=src['effects'][i][1],active_flags=1<<i)
|
|
if ident in known:
|
|
if known[ident]!=row:raise ValueError('Conflicting base composite aura definition')
|
|
else:rows.append(row);known[ident]=row
|
|
return sorted(rows,key=lambda r:r['spell'])
|
|
|
|
MOUNT_POLICY='source-mounted-holder-projection-v1'
|
|
def mount_namespace(paths):
|
|
import re
|
|
scalar_namespace(paths) # Keep the same reviewed four source/target headers.
|
|
for role in ('source_auras','target_auras'):
|
|
text=re.sub(r'/\*.*?\*/|//[^\n]*','',Path(paths[role]).read_text(),flags=re.S)
|
|
match=re.search(r'\bSPELL_AURA_MOUNTED\s*=\s*(0x[0-9a-fA-F]+|[0-9]+)\s*,',text)
|
|
if not match or int(match[1],0)!=78:raise ValueError('Mounted aura semantic namespace differs')
|
|
return dict(policy=MOUNT_POLICY,header_sha256=dict(SCALAR_HEADER_PINS))
|
|
|
|
def _holder_rows(source,native,aura_kind):
|
|
"""Shared structural match; caller must verify the named aura namespace."""
|
|
if not isinstance(source,list)or not isinstance(native,list)or len(source)>100000 or len(native)>500000:raise ValueError('Bounded source/native holder inventories required')
|
|
index={}
|
|
for row in native:
|
|
if any(type(row.get(k))is not int for k in('SpellID','EffectIndex','DifficultyID','Effect','EffectAura')):raise ValueError('Invalid native projected effect metadata')
|
|
index.setdefault((row['SpellID'],row['EffectIndex'],row['DifficultyID']),[]).append(row)
|
|
rows=[];excluded=[];seen=set()
|
|
for spell in sorted(source,key=lambda r:r['entry']):
|
|
ident=spell['entry']
|
|
if type(ident)is not int or not 0<ident<2**31 or ident in seen:raise ValueError('Invalid/duplicate source holder spell')
|
|
seen.add(ident);effects=[spell['effect'+str(i)]for i in range(1,4)];auras=[spell['effectApplyAuraName'+str(i)]for i in range(1,4)]
|
|
if any(type(v)is not int or not 0<=v<=0xffffffff for v in effects+auras):raise ValueError('Invalid source holder effect metadata')
|
|
projected=[i for i in range(3)if effects[i]==6 and auras[i]==aura_kind]
|
|
if len(projected)!=1 or any(v not in(0,6)for v in effects):
|
|
excluded.append(dict(spell=ident,reason='not one projected effect in reviewed aura-only holder'));continue
|
|
i=projected[0];matches=index.get((ident,i,0),[])
|
|
if len(matches)!=1 or matches[0]['Effect']!=6 or matches[0]['EffectAura']!=aura_kind:
|
|
excluded.append(dict(spell=ident,reason='missing/conflicting native same-ID/index projected effect'));continue
|
|
rows.append(dict(spell=ident,effect_index=i,aura_type=aura_kind,active_flags=1<<i))
|
|
return rows,excluded
|
|
|
|
def generate_mounts(source,native,proof):
|
|
"""Project only the reviewed mounted effect; runtime requires mount display."""
|
|
if proof!=dict(policy=MOUNT_POLICY,header_sha256=SCALAR_HEADER_PINS):raise ValueError('Reviewed mounted semantic namespace required')
|
|
rows,excluded=_holder_rows(source,native,78)
|
|
return dict(policy=MOUNT_POLICY,namespace=proof,definitions=rows,excluded=excluded,
|
|
requires_nonzero_source_mount_display=True,projection='mounted-effect-only',limits=[
|
|
'A genuine source holder and nonzero source mount display are required at runtime.',
|
|
'Only the mounted effect is projected; companion speed/flight/swim effects are not inferred.',
|
|
'Speed values and acknowledgements remain genuine separate server protocol messages.',
|
|
'Spell definitions, names/icons, mount models and actual toggle behavior require separate verification.'])
|
|
|
|
GHOST_POLICY='source-ghost-holder-projection-v1'
|
|
|
|
def generate_defensive_component(component,schemas,*,native,source_tables,visual_links):
|
|
"""Project every reviewed effect of a source-owned finite defensive holder.
|
|
|
|
Reuse the proc converter's complete trigger review rather than inferring a
|
|
multi-aura mask from numeric aura IDs or a partially imported definition.
|
|
"""
|
|
from octo_client_data import canonical_sha256
|
|
from spell_item_proc_compat import review_trigger
|
|
from spell_timed_buff_compat import DEFENSIVE_POLICY
|
|
if (not isinstance(component,dict)or component.get('kind')!='source-timed-self-buff-definition-candidates'
|
|
or component.get('definition_policy')!=DEFENSIVE_POLICY
|
|
or any(component.get(k)is not False for k in('installed','engine_accepted','gameplay_verified'))):
|
|
raise ValueError('Reviewed source-owned defensive component required')
|
|
spells=component.get('spells');records=component.get('records')
|
|
if not isinstance(spells,list)or not 1<=len(spells)<=4096 or not isinstance(records,list):
|
|
raise ValueError('Bounded defensive holder definitions required')
|
|
rows=[];seen=set()
|
|
for row in spells:
|
|
source=row.get('source_definition');ident=row.get('spell_id')
|
|
if (type(ident)is not int or ident in seen or not isinstance(source,dict)
|
|
or source.get('entry')!=ident or row.get('source_record_sha256')!=canonical_sha256(source)):
|
|
raise ValueError('Defensive holder source identity changed')
|
|
seen.add(ident)
|
|
reviewed=review_trigger(ident,source,records,schemas,native=native,
|
|
source_tables=source_tables,visual_links=visual_links)
|
|
if reviewed['definition_family']!='finite-self-physical-reduction-defense':
|
|
raise ValueError('Distinct defensive holder family required')
|
|
indices=[i for i,e in enumerate(source['effects'])if e[0]]
|
|
if row.get('effect_indices')!=indices:raise ValueError('Complete defensive holder effect indices required')
|
|
rows.append(dict(spell=ident,effect_indices=indices,active_flags=sum(1<<i for i in indices),
|
|
source_record_sha256=canonical_sha256(source),trigger_review=reviewed))
|
|
return dict(kind='reviewed-source-defensive-holder-projections',definitions=sorted(rows,key=lambda r:r['spell']),
|
|
limits=['Only complete source-owned constant finite physical-reduction/Defense definitions are projected.',
|
|
'A genuine server aura holder is still required; no application, proc outcome, caster or duration is synthesized.'])
|
|
|
|
def ghost_namespace(paths):
|
|
import re
|
|
scalar_namespace(paths)
|
|
for role in ('source_auras','target_auras'):
|
|
text=re.sub(r'/\*.*?\*/|//[^\n]*','',Path(paths[role]).read_text(),flags=re.S)
|
|
match=re.search(r'\bSPELL_AURA_GHOST\s*=\s*(0x[0-9a-fA-F]+|[0-9]+)\s*,',text)
|
|
if not match or int(match[1],0)!=95:raise ValueError('Ghost aura semantic namespace differs')
|
|
return dict(policy=GHOST_POLICY,header_sha256=dict(SCALAR_HEADER_PINS))
|
|
|
|
def generate_ghosts(source,native,proof):
|
|
"""Project genuine GHOST only; companion speed/breathing are not inferred."""
|
|
if proof!=dict(policy=GHOST_POLICY,header_sha256=SCALAR_HEADER_PINS):raise ValueError('Reviewed ghost semantic namespace required')
|
|
rows,excluded=_holder_rows(source,native,95)
|
|
return dict(policy=GHOST_POLICY,namespace=proof,definitions=rows,excluded=excluded,
|
|
projection='ghost-effect-only',limits=[
|
|
'A genuine source holder and bound unit are required. No ghost aura is synthesized.',
|
|
'Only GHOST is projected. Companion speed/water-breathing effects are not inferred.',
|
|
'Object flags, corpse identity, reclaim and actual model alpha require separate verification.'])
|
|
|
|
CATALOGUE_POLICY='source-native-aura-index-catalogue-v1'
|
|
# Pinned enum values (tortoise SpellDefines.h / trinity-forever SharedDefines.h):
|
|
# every effect that installs an aura on a unit. Source 132/133 are tortoise's
|
|
# RAID/OWNER area auras; native RAID/OWNER are 65/143.
|
|
SOURCE_AURA_EFFECTS=frozenset((6,27,35,119,128,129,132,133))
|
|
NATIVE_AURA_EFFECTS=frozenset((6,27,35,65,119,128,129,143,174,202,271))
|
|
VISUAL_CONDITIONS=('CasterPlayerConditionID','CasterUnitConditionID','ViewerPlayerConditionID','ViewerUnitConditionID')
|
|
|
|
def _overlay(base,package,table):
|
|
"""Native local rows with the installed package's same-ID overrides/removals."""
|
|
rows={r['ID']:r for r in base}
|
|
for row in package:
|
|
if row.get('table_name')!=table:continue
|
|
if row.get('record_status','valid')=='removed':rows.pop(row['id'],None);continue
|
|
record=row.get('record')
|
|
if not isinstance(record,dict)or record.get('ID')!=row.get('id'):raise ValueError('Package row identity differs: '+table)
|
|
rows[row['id']]=record
|
|
return rows
|
|
|
|
def generate_catalogue(sources,native_effects,native_names,native_visuals,package,*,reserved=()):
|
|
"""Admit every source aura whose native definition has the same aura indices.
|
|
|
|
sources: {'server':{id:(name,[effect x3],[aura x3])},'dbc':{...}}. A source
|
|
aura is admissible when a native (local DB2 + package) SpellName and effect set
|
|
exist for the same ID and the native aura-installing effect indices equal the
|
|
source aura-installing effect indices; mask = those indices. Server and client
|
|
DBC must agree where both define the spell. Visual = the unique default
|
|
(DifficultyID 0, unconditional) native SpellXSpellVisual of that spell, else 0.
|
|
Reserved (mount/ghost/self-applied special-case) spells are never added here.
|
|
"""
|
|
effects=_overlay(native_effects,package,'SpellEffect')
|
|
names=_overlay(native_names,package,'SpellName')
|
|
visuals=_overlay(native_visuals,package,'SpellXSpellVisual')
|
|
by_spell={}
|
|
for r in effects.values():
|
|
if r.get('DifficultyID')!=0:continue
|
|
if any(type(r.get(k))is not int for k in('SpellID','EffectIndex','Effect')):raise ValueError('Invalid native effect metadata')
|
|
by_spell.setdefault(r['SpellID'],{}).setdefault(r['EffectIndex'],[]).append(r)
|
|
vis_by_spell={}
|
|
for r in visuals.values():
|
|
if r.get('DifficultyID')==0 and not any(r.get(k)for k in VISUAL_CONDITIONS):vis_by_spell.setdefault(r.get('SpellID'),[]).append(r)
|
|
server,dbc=sources.get('server',{}),sources.get('dbc',{})
|
|
definitions=[];held=[];links=[];link_held=[];stats=dict(type_mismatch=0,name_mismatch=0)
|
|
for ident in sorted(set(server)|set(dbc)):
|
|
views=[v for v in(server.get(ident),dbc.get(ident))if v]
|
|
sets=[tuple(i for i in range(3)if v[1][i]in SOURCE_AURA_EFFECTS)for v in views]
|
|
if not any(sets):continue
|
|
def hold(reason):held.append(dict(spell=ident,reason=reason))
|
|
if len(set(sets))!=1:hold('server spell_template and client Spell.dbc aura indices differ');continue
|
|
indices=sets[0];kinds=[views[0][2][i]for i in indices]
|
|
if ident in reserved:hold('reserved special-case profile (mount/ghost/self-applied) retained');continue
|
|
native=by_spell.get(ident)
|
|
if not native or ident not in names:hold('no native definition (local DB2 or package)');continue
|
|
if any(len(v)!=1 for v in native.values()):hold('ambiguous native effect index');continue
|
|
nidx=tuple(sorted(i for i,v in native.items()if v[0]['Effect']in NATIVE_AURA_EFFECTS))
|
|
if nidx!=indices:hold('native aura effect indices differ');continue
|
|
if [native[i][0].get('EffectAura')for i in indices]!=kinds:stats['type_mismatch']+=1
|
|
if (names[ident].get('Name_lang')or'').strip().lower()!=views[0][0].strip().lower():stats['name_mismatch']+=1
|
|
definitions.append(dict(spell=ident,active_flags=sum(1<<i for i in indices)))
|
|
v=vis_by_spell.get(ident,[])
|
|
if len(v)==1:links.append(dict(spell=ident,spell_x_spell_visual=v[0]['ID'],visual=v[0].get('SpellVisualID')))
|
|
else:link_held.append(dict(spell=ident,reason='no default native visual' if not v else 'multiple default native visuals'))
|
|
return dict(policy=CATALOGUE_POLICY,definitions=definitions,held=held,visual_links=links,visual_held=link_held,
|
|
informational=stats,limits=[
|
|
'Index equality only: native effect amounts/aura types are the native definition; the source server remains authoritative for application.',
|
|
'Native = local DB2 export plus the class-spells package; official hotfix cache rows are not included.',
|
|
'Offline catalogue; buff-bar presentation requires actual-client acceptance.'])
|
|
|
|
def merge_catalogue(baseline,rows,key):
|
|
"""Baseline reviewed rows win; catalogue only adds new spell IDs."""
|
|
out={r['spell']:r for r in baseline}
|
|
for r in rows:out.setdefault(r['spell'],r)
|
|
return [out[k]for k in sorted(out)]
|
|
|
|
def parse_header_rows(text,value):
|
|
import re
|
|
return [dict(spell=int(a),**{value:int(b)})for a,b in re.findall(r'\{(\d+),(\d+)\}',text.split('Rows[]=',1)[1].split(';',1)[0])]
|
|
|
|
def load_catalogue_inputs(server_rows,dbc_path):
|
|
"""Source views from tortoise spell_template rows and Octo client Spell.dbc."""
|
|
from turtle_data import spell_layout,DBC
|
|
o=spell_layout();d=DBC(Path(dbc_path),173)
|
|
server={r['entry']:(r['name'],[r['effect'+str(i)]for i in(1,2,3)],[r['effectApplyAuraName'+str(i)]for i in(1,2,3)])for r in server_rows}
|
|
dbc={r[0]:(d.string(r[o['Name_lang']]),list(r[o['Effect']:o['Effect']+3]),list(r[o['EffectAura']:o['EffectAura']+3]))for r in d.rows}
|
|
return dict(server=server,dbc=dbc)
|
|
|
|
def header(data,*,namespace='aura_definition_profile'):
|
|
if not data:raise ValueError('No verified aura definitions')
|
|
if namespace not in('aura_definition_profile','source_mount_aura_profile','source_ghost_aura_profile'):raise ValueError('Owned aura namespace required')
|
|
return '// Generated from reviewed local SQL and native same-ID aura effect rows.\n#pragma once\n#include <algorithm>\n#include <cstdint>\n#include <iterator>\nnamespace gateway::'+namespace+' {\nstruct Definition {uint32_t spell,active_flags;};\ninline constexpr Definition Rows[]={'+','.join('{'+str(r['spell'])+','+str(r['active_flags'])+'}' for r in data)+'};\ninline uint32_t mask(uint32_t spell){auto it=std::lower_bound(std::begin(Rows),std::end(Rows),spell,[](const auto& r,uint32_t s){return r.spell<s;});return it!=std::end(Rows)&&it->spell==spell?it->active_flags:0;}\n}\n'
|
|
|
|
def catalogue_main(argv):
|
|
import aura_visual_profile
|
|
p=argparse.ArgumentParser(prog='aura_definition_profile.py generate-catalogue')
|
|
for k in('dbc','native_effects','native_names','native_visuals','package','baseline','report'):p.add_argument('--'+k.replace('_','-'),type=Path,required=True)
|
|
a=p.parse_args(argv)
|
|
if not a.report.resolve().is_relative_to(ROOT)or a.report.exists():p.error('Require new workspace report')
|
|
cols=['entry','name']+['effect'+str(i)for i in(1,2,3)]+['effectApplyAuraName'+str(i)for i in(1,2,3)]
|
|
raw=db('SELECT HEX(JSON_OBJECT('+','.join("'"+v+"',`"+v+'`'for v in cols)+')) FROM tw_world.spell_template WHERE '+' OR '.join('effect%d IN (%s)'%(i,','.join(map(str,sorted(SOURCE_AURA_EFFECTS))))for i in(1,2,3))+' ORDER BY entry;')
|
|
server=[json.loads(bytes.fromhex(v))for v in raw.splitlines()]
|
|
sources=load_catalogue_inputs(server,a.dbc)
|
|
baseline=json.loads(a.baseline.read_text())
|
|
reserved=set()
|
|
for name in('source_mount_aura_profile','source_ghost_aura_profile'):reserved|={r['spell']for r in parse_header_rows((ROOT/'include/gateway'/(name+'.hpp')).read_text(),'active_flags')}
|
|
import re
|
|
reserved|={int(v)for v in re.findall(r'\d+',(ROOT/'include/gateway/source_self_applied_aura_profile.hpp').read_text().split('Spells[]={',1)[1].split('}',1)[0])}
|
|
package=json.loads(a.package.read_text())['rows']
|
|
result=generate_catalogue(sources,json.loads(a.native_effects.read_text()),json.loads(a.native_names.read_text()),json.loads(a.native_visuals.read_text()),package,reserved=reserved)
|
|
base_def={r['spell']for r in baseline['definitions']}
|
|
definitions=merge_catalogue(baseline['definitions'],result['definitions'],'active_flags')
|
|
visuals=merge_catalogue(baseline['visual_links'],[r for r in result['visual_links']],'spell_x_spell_visual')
|
|
(ROOT/'include/gateway/aura_definition_profile.hpp').write_text(header(definitions))
|
|
(ROOT/'include/gateway/aura_visual_profile.hpp').write_text(aura_visual_profile.header(visuals))
|
|
source_auras=sum(1 for i in set(sources['server'])|set(sources['dbc'])if any(e in SOURCE_AURA_EFFECTS for v in(sources['server'].get(i),sources['dbc'].get(i))if v for e in v[1]))
|
|
from collections import Counter
|
|
result.update(input_sha256={k:hashlib.sha256(getattr(a,k).read_bytes()).hexdigest()for k in('dbc','native_effects','native_names','native_visuals','package','baseline')},
|
|
denominators=dict(source_auras=source_auras,server_auras=len(server),catalogue_admitted=len(result['definitions']),
|
|
baseline_retained=len(base_def),profile_rows=len(definitions),newly_admitted=len({r['spell']for r in result['definitions']}-base_def),
|
|
held=len(result['held']),held_by_reason=dict(Counter(r['reason']for r in result['held'])),
|
|
visual_rows=len(visuals),visual_held_by_reason=dict(Counter(r['reason']for r in result['visual_held']))))
|
|
a.report.parent.mkdir(parents=True,exist_ok=True);a.report.write_text(json.dumps(result,indent=1)+'\n')
|
|
print('Catalogue: %d profile rows (%d new), %d held, %d visual links.'%(len(definitions),result['denominators']['newly_admitted'],len(result['held']),len(visuals)))
|
|
|
|
if __name__=='__main__':
|
|
import sys
|
|
if sys.argv[1:2]==['generate-catalogue']:catalogue_main(sys.argv[2:]);raise SystemExit
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('action',choices=['snapshot','generate','generate-mounts','generate-ghosts']);p.add_argument('--ids');p.add_argument('--mounted-only',action='store_true');p.add_argument('--source',type=Path);p.add_argument('--native',type=Path);p.add_argument('--header',type=Path);p.add_argument('--instant-companions',action='store_true',help='Opt into reviewed one-aura stun/stat/slow/haste holders with immediate damage/heal/energize companions');p.add_argument('--output',type=Path,required=True);a=p.parse_args()
|
|
if not a.output.resolve().is_relative_to(ROOT) or a.output.exists():p.error('Require new workspace output')
|
|
if a.action=='snapshot':
|
|
if a.instant_companions:p.error('Companion policy applies only to offline generation')
|
|
if a.mounted_only and a.ids:p.error('Use complete mounted family or explicit IDs, not both')
|
|
if not a.mounted_only and not a.ids:p.error('Snapshot requires bounded source spell IDs or --mounted-only')
|
|
ids=None if a.mounted_only else identities(a.ids)
|
|
columns=['entry','name']+['effect'+str(i)for i in range(1,4)]+['effectApplyAuraName'+str(i)for i in range(1,4)]
|
|
where='('+' OR '.join('effectApplyAuraName'+str(i)+'=78'for i in range(1,4))+')'if a.mounted_only else'entry IN ('+','.join(map(str,ids))+')'
|
|
raw=db('SELECT HEX(JSON_OBJECT('+','.join("'"+v+"',`"+v+'`'for v in columns)+')) FROM tw_world.spell_template WHERE '+where+' ORDER BY entry;')
|
|
result=[json.loads(bytes.fromhex(v))for v in raw.splitlines()]
|
|
if len(result)>100000 or len({r['entry']for r in result})!=len(result):raise ValueError('Source aura snapshot bound/identity differs')
|
|
if ids is not None and [r['entry']for r in result]!=ids:raise ValueError('Missing requested source spell; no incomplete profile')
|
|
else:
|
|
if not a.source or not a.native or not a.header or not a.header.resolve().is_relative_to(ROOT):p.error('Generation requires source/native/header in workspace')
|
|
if a.action in('generate-mounts','generate-ghosts'):
|
|
if a.instant_companions:p.error('Mount and instant-companion policies are distinct')
|
|
server=Path.home()/'Servers/tortoise-wow';target=ROOT.parent/'servers/trinity-forever'
|
|
proof=(mount_namespace if a.action=='generate-mounts'else ghost_namespace)(dict(source_defines=server/'src/game/Spells/SpellDefines.h',source_auras=server/'src/game/Spells/SpellAuraDefines.h',target_defines=target/'src/server/game/Miscellaneous/SharedDefines.h',target_auras=target/'src/server/game/Spells/Auras/SpellAuraDefines.h'))
|
|
result=(generate_mounts if a.action=='generate-mounts'else generate_ghosts)(json.loads(a.source.read_text()),json.loads(a.native.read_text()),proof)
|
|
else:result=generate(json.loads(a.source.read_text()),json.loads(a.native.read_text()),instant_companions=a.instant_companions)
|
|
result['input_sha256']={k:hashlib.sha256(getattr(a,k).read_bytes()).hexdigest()for k in('source','native')}
|
|
a.header.write_text(header(result['definitions'],namespace='source_mount_aura_profile'if a.action=='generate-mounts'else'source_ghost_aura_profile'if a.action=='generate-ghosts'else'aura_definition_profile'))
|
|
a.output.parent.mkdir(parents=True,exist_ok=True);a.output.write_text(json.dumps(result,indent=2)+'\n');print('Public source aura snapshot read.' if a.action=='snapshot' else 'Generated '+str(len(result['definitions']))+(' reviewed holder-effect projections; no gameplay verification.'if a.action in('generate-mounts','generate-ghosts')else' verified simple aura definitions; no gameplay verification.'))
|