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

329 lines
23 KiB
Python

"""Convert nonmissile cast/impact visuals into source-owned native records.
Source and destination visual numbers occupy different namespaces. Never edit a
shared native visual to remove an expansion-specific event. Allocate a separate
visual and clone only the independently matched cast/impact event templates.
This generates an offline candidate: kit/asset parity and engine acceptance are
separate requirements. It neither installs data nor executes spell effects.
"""
from copy import deepcopy
import hashlib
from octo_client_data import canonical_sha256
from spell_passive_compat import BUILD, SCHEMA, SUPPLEMENTAL_TABLES, encode, integer
POLICY = 'new-source-owned-cast-impact-visual-v1'
TABLES = ('SpellVisual', 'SpellVisualEvent')
EVENT_ZERO = ('StartMinOffsetMs', 'StartMaxOffsetMs', 'EndMinOffsetMs',
'EndMaxOffsetMs', 'Field_10_0_0_44649_008', 'Field_10_0_0_44649_009')
VISUAL_ZERO = dict(MissileCastOffset=[0, 0, 0], MissileImpactOffset=[0, 0, 0],
StateKit=0, AnimEventSoundID=0, Flags=0, MissileCastPositionerID=0,
MissileImpactPositionerID=0, MissileTargetingKit=0, HostileSpellVisualID=0,
CasterSpellVisualID=0, SpellVisualMissileSetID=0, DamageNumberDelay=0,
LowViolenceSpellVisualID=0, RaidSpellVisualMissileSetID=0,
ReducedUnexpectedCameraMovementSpellVisualID=0)
def source_kits(source, kits):
"""Retain exact 35-word kit dependencies; no enum/asset equivalence inferred."""
if not isinstance(kits, list) or not 1 <= len(kits) <= 2:
raise ValueError('Complete bounded source cast/impact kits required')
result = {}
for row in kits:
if (not isinstance(row, (list, tuple)) or len(row) != 35 or
any(type(v) is not int or not 0 <= v <= 0xffffffff for v in row) or
row[0] in result):
raise ValueError('Unique complete source kit rows required')
result[row[0]] = list(row)
if set(result) != {source[2], source[3]}:
raise ValueError('Source visual kit dependencies differ')
return [result[k] for k in sorted(result)]
def new_visual_candidate(source, kits, native_visual, native_events, schemas,
maxima, registry, occupied):
"""Build one visual plus two events without altering any existing records.
Numeric event contracts are copied from positive native equivalents: cast on
caster (3/13/1), impact on target (6/13/2). No channel, area, missile, state,
animation-event sound or flag semantics are discarded to fit this policy.
"""
if (not isinstance(source, (tuple, list)) or len(source) != 16 or
any(type(v) is not int or not 0 <= v <= 0xffffffff for v in source)):
raise ValueError('Complete source visual row required')
ident = integer(source[0], 1, 0x7fffffff, 'source visual ID')
if (not source[2] or not source[3] or
any(source[i] for i in (1, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15))):
raise ValueError('Unreviewed source cast/impact visual family')
# Field9 selects a missile target attachment and is inactive without missile.
# Preserve it in provenance rather than treating it as a modern attachment ID.
kit_rows = source_kits(source, kits)
for table in TABLES:
if (table not in schemas or
canonical_sha256(schemas[table]) != SUPPLEMENTAL_TABLES[table][2]):
raise ValueError('Reviewed native visual schema required')
integer(maxima.get(table), 1, 0x7ffffffe, 'native visual allocation floor')
if (not isinstance(occupied.get(table), set) or
any(type(v) is not int or v <= 0 for v in occupied[table])):
raise ValueError('Explicit occupied native visual IDs required')
if (not isinstance(native_visual, dict) or native_visual.get('ID') != ident or
any(native_visual.get(k) != v for k, v in VISUAL_ZERO.items())):
raise ValueError('Neutral positive native visual template required')
# These inactive fields must still have the known nonmissile template values.
if (native_visual.get('MissileAttachment'),
native_visual.get('MissileDestinationAttachment')) != (-1, 34):
raise ValueError('Unreviewed native nonmissile attachments')
encode(native_visual, schemas['SpellVisual'])
if not isinstance(native_events, list) or not 1 <= len(native_events) <= 32:
raise ValueError('Complete bounded native visual event set required')
selected = {}
seen = set()
roles = {(3, 13, 1, source[2]): 'cast', (6, 13, 2, source[3]): 'impact'}
omitted = []
for row in native_events:
encode(row, schemas['SpellVisualEvent'])
if row['SpellVisualID'] != ident or row['ID'] in seen:
raise ValueError('Native visual event ownership/identity differs')
seen.add(row['ID'])
key = (row['StartEvent'], row['EndEvent'], row['TargetType'], row['SpellVisualKitID'])
if key not in roles:
omitted.append(deepcopy(row))
continue
role = roles[key]
if role in selected or any(row[k] for k in EVENT_ZERO):
raise ValueError('Ambiguous or delayed native cast/impact event')
selected[role] = row
if set(selected) != {'cast', 'impact'}:
raise ValueError('Positive native cast and target-impact events required')
if (not isinstance(registry, dict) or
set(registry) != {'schema_version', 'build', *TABLES} or
registry.get('schema_version') != 1 or registry.get('build') != BUILD):
raise ValueError('Explicit source visual registry required')
result = deepcopy(registry)
for table in TABLES:
entries = result[table]
if not isinstance(entries, dict) or len(entries) > 4096:
raise ValueError('Bounded source visual registry required')
values = set()
for key, value in entries.items():
pieces = key.split(':') if isinstance(key, str) else []
if (len(pieces) != (1 if table == 'SpellVisual' else 2) or
not pieces[0].isdecimal() or str(int(pieces[0])) != pieces[0] or
int(pieces[0]) <= 0 or
(len(pieces) == 2 and pieces[1] not in ('cast', 'impact'))):
raise ValueError('Source visual registry key differs')
integer(value, maxima[table] + 1, 0x7fffffff, 'new native visual ID')
if value in values or value in occupied[table]:
raise ValueError('Source visual allocation collision')
values.add(value)
def allocate(table, key):
entries = result[table]
if key not in entries:
value = integer(max([maxima[table], *entries.values()]) + 1,
1, 0x7fffffff, 'new visual allocation')
if value in occupied[table]:
raise ValueError('Source visual allocation collision')
entries[key] = value
return entries[key]
visual_id = allocate('SpellVisual', str(ident))
rows = [('SpellVisual', dict(deepcopy(native_visual), ID=visual_id))]
for role in ('cast', 'impact'):
row = dict(selected[role], ID=allocate('SpellVisualEvent', str(ident) + ':' + role),
SpellVisualID=visual_id)
rows.append(('SpellVisualEvent', row))
records = []
for table, row in rows:
wire = encode(row, schemas[table])
records.append(dict(table_name=table, table_hash=hex(SUPPLEMENTAL_TABLES[table][0]),
id=row['ID'], record=row, wire_hex=wire.hex(), sha256=hashlib.sha256(wire).hexdigest(),
source_visual_id=ident, baseline_record_sha256=None,
allocation_policy='new-source-owned-cast-impact-visual'))
return dict(kind='source-owned-visual-definition-candidates', definition_policy=POLICY,
build=BUILD, schema=SCHEMA, source_visual_id=ident, native_visual_id=visual_id,
source_visual_row=list(source), source_kit_rows=kit_rows,
native_template=deepcopy(native_visual), native_events=deepcopy(native_events),
native_allocation_floors={t: maxima[t] for t in TABLES},
native_template_sha256=canonical_sha256(native_visual),
native_events_sha256=canonical_sha256(native_events),
omitted_template_events=omitted, records=records, child_id_registry=result,
authoritative_spell_ids_modified=False, existing_records_modified=False,
installable=False, installed=False, dependency_complete=False,
engine_accepted=False, gameplay_verified=False,
limits=['Kit, model, animation and sound parity require independent dependency review.',
'New visual IDs are destination-only mappings; source wire spell IDs are unchanged.',
'No existing visual/event is removed or changed; omitted template events belong only to the original visual.'])
def remap_hand_attachment_kit(source,template,attachments,effects,bindings,schemas,maxima,registry,*,kind='cast'):
"""Clone a simple source-matched native kit with exact resource bindings.
Source Classic SpellVisualKit has35fields: left/right hand effects at6/7,
no animation (-1), no other attachments/procedural behavior. Native positive
templates establish hand attachment21/22 and effect types2(model)/5(sound).
This preserves the template's sound reference; audio parity is unverified.
New destination IDs never replace a shared kit or a source spell identity.
"""
import re
tables=('SpellVisualKit','SpellVisualKitModelAttach','SpellVisualKitEffect')
if not isinstance(source,(list,tuple))or len(source)!=35 or any(type(v)is not int or not 0<=v<=0xffffffff for v in source):raise ValueError('Complete Classic35field kit required')
ident=integer(source[0],1,0x7fffffff,'source kit ID');sentinel=0xffffffff
if kind not in('cast','state'):raise ValueError('Explicit source hand-kit role required')
if source[1]!=(0 if kind=='cast'else 2) or source[2]!=sentinel or any(source[i]!=sentinel for i in(3,4,5,8,9,10,11,15,16,17,18))or source[12]or source[14]or any(source[19:]):raise ValueError('Unreviewed source hand-kit behavior')
expected={21:integer(source[6],1,0x7fffffff,'left hand effect'),22:integer(source[7],1,0x7fffffff,'right hand effect')}
if not isinstance(bindings,dict)or set(bindings)not in(set(expected.values()),{str(v)for v in expected.values()}):raise ValueError('Complete source hand resource bindings required')
bindings={int(k):v for k,v in bindings.items()}
for binding in bindings.values():
if not isinstance(binding,dict)or not isinstance(binding.get('native_effect'),dict):raise ValueError('Positive native effect binding required')
paths=[]
for key in('source_resource','native_resource'):
value=binding.get(key)
if not isinstance(value,str):raise ValueError('Exact source/native effect resources required')
value=value.replace('\\','/').lower()
if not re.fullmatch(r'[a-z0-9_/-]+\.(?:mdx|m2)',value)or '..'in value:raise ValueError('Effect resource path bound')
paths.append(value.rsplit('.',1)[0])
if paths[0]!=paths[1]:raise ValueError('Different source/native effect resource')
integer(binding['native_effect'].get('ID'),1,0x7fffffff,'native effect ID')
integer(binding['native_effect'].get('ModelFileDataID'),1,0x7fffffff,'native model FileDataID')
for table in tables:
if table not in schemas or canonical_sha256(schemas[table])!=SUPPLEMENTAL_TABLES[table][2]:raise ValueError('Pinned native hand-kit schema required')
integer(maxima.get(table),1,0x7ffffffe,'native kit allocation floor')
encode(template,schemas['SpellVisualKit']);parent=integer(template.get('ID'),1,maxima['SpellVisualKit'],'native template kit')
neutral=dict(ClutterLevel=0,FallbackSpellVisualKitID=0,DelayMin=0,DelayMax=0,
MinimumSpellVisualDensityFilterType=0,MinimumSpellVisualDensityFilterParam=0,
ReducedSpellVisualDensityFilterType=0,ReducedSpellVisualDensityFilterParam=0,Flags=[1048576,0])
if template!=dict(neutral,ID=parent):raise ValueError('Unreviewed native kit behavior')
if not isinstance(attachments,list)or len(attachments)!=2 or not isinstance(effects,list)or not 2<=len(effects)<=3:raise ValueError('Complete hand-kit children required')
seen=set();by_id={}
attachment_neutral=dict(Offset=[0,0,0],OffsetVariation=[0,0,0],PositionerID=0,Yaw=0,Pitch=0,Roll=0,
YawVariation=0,PitchVariation=0,RollVariation=0,Scale=1,ScaleVariation=0,StartAnimID=-1,AnimID=-1,
EndAnimID=-1,AnimKitID=0,Flags=4,LowDefModelAttachID=0,StartDelay=0,Field_9_0_1_33978_021=0,Field_11_0_0_54210_022=0)
for row in attachments:
old=integer(row.get('ID'),1,maxima['SpellVisualKitModelAttach'],'native attachment ID');slot=row.get('AttachmentID')
if slot not in expected or slot in seen or old in by_id:raise ValueError('Complete unique hand attachments required')
if row!=dict(attachment_neutral,ID=old,AttachmentID=slot,SpellVisualEffectNameID=row.get('SpellVisualEffectNameID'),ParentSpellVisualKitID=parent):raise ValueError('Unreviewed native hand attachment')
encode(row,schemas['SpellVisualKitModelAttach']);seen.add(slot);by_id[old]=row
model_effects=set();sound=[];effect_ids=set()
for row in effects:
old=integer(row.get('ID'),1,maxima['SpellVisualKitEffect'],'native kit effect ID')
if old in effect_ids or row.get('ParentSpellVisualKitID')!=parent:raise ValueError('Native kit effect ownership differs')
effect_ids.add(old);encode(row,schemas['SpellVisualKitEffect'])
if row['EffectType']==2 and row['Effect']in by_id and row['Effect']not in model_effects:model_effects.add(row['Effect'])
elif row['EffectType']==5:sound.append(row['Effect'])
else:raise ValueError('Unreviewed native kit effect or duplicate model relation')
if model_effects!=set(by_id)or sound!=([source[13]]if source[13]else[]):raise ValueError('Source/native hand kit children or sound reference differ')
if not isinstance(registry,dict)or registry.get('build')!=BUILD or registry.get('schema_version')!=1 or set(registry)!={'build','schema_version',*tables}:raise ValueError('Explicit hand-kit registry required')
result=deepcopy(registry)
for table in tables:
values=result[table]
if not isinstance(values,dict)or len(set(values.values()))!=len(values):raise ValueError('Hand-kit allocation registry collision')
for key,value in values.items():
if not isinstance(key,str)or not key:raise ValueError('Hand-kit registry identity required')
integer(value,maxima[table]+1,0x7fffffff,'destination-only kit ID')
def allocate(table,key):
if key not in result[table]:result[table][key]=max([maxima[table],*result[table].values()])+1
return integer(result[table][key],maxima[table]+1,0x7fffffff,'new hand-kit ID')
kit=allocate(tables[0],str(ident));rows=[(tables[0],dict(template,ID=kit))];replacement={}
for old,row in sorted(by_id.items()):
new=allocate(tables[1],f'{ident}:{old}');replacement[old]=new;binding=bindings[expected[row['AttachmentID']]]
rows.append((tables[1],dict(row,ID=new,ParentSpellVisualKitID=kit,SpellVisualEffectNameID=binding['native_effect']['ID'])))
for row in sorted(effects,key=lambda r:r['ID']):
rows.append((tables[2],dict(row,ID=allocate(tables[2],f'{ident}:{row["ID"]}'),ParentSpellVisualKitID=kit,
Effect=replacement[row['Effect']]if row['EffectType']==2 else row['Effect'])))
records=[]
for table,row in rows:
raw=encode(row,schemas[table]);records.append(dict(table_name=table,table_hash=hex(SUPPLEMENTAL_TABLES[table][0]),id=row['ID'],
record=row,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest(),source_visual_kit_id=ident,baseline_record_sha256=None,
allocation_policy='source-owned-exact-resource-hand-kit'))
return dict(kind='source-owned-hand-kit-candidate',build=BUILD,schema=SCHEMA,source_kit_id=ident,native_kit_id=kit,
records=records,child_id_registry=result,inputs=dict(source=list(source),template=deepcopy(template),attachments=deepcopy(attachments),
effects=deepcopy(effects),bindings={str(k):deepcopy(v)for k,v in bindings.items()},maxima=deepcopy(maxima),kind=kind),existing_records_modified=False,
installed=False,engine_accepted=False,gameplay_verified=False,asset_payloads_verified=False,audio_parity_verified=False)
def review_candidate(candidate, schemas, occupied):
"""Recompute all candidate bytes/allocations before a dependent spell uses it."""
if not isinstance(candidate, dict):
raise ValueError('Explicit source-owned visual candidate required')
if candidate.get('kind')=='source-owned-state-visual-candidate':
rebuilt=new_state_visual_candidate(candidate.get('source_visual_row'),candidate.get('native_template'),
candidate.get('native_events'),candidate.get('kit_candidates'),schemas,candidate.get('native_allocation_floors',{}),
candidate.get('child_id_registry'),occupied)
if any(candidate.get(k)!=v for k,v in rebuilt.items()):raise ValueError('State visual candidate provenance/bytes differ')
return rebuilt
rebuilt = new_visual_candidate(candidate.get('source_visual_row'),
candidate.get('source_kit_rows'), candidate.get('native_template'),
candidate.get('native_events'), schemas,
candidate.get('native_allocation_floors', {}),
candidate.get('child_id_registry'), occupied)
if any(candidate.get(k) != value for k, value in rebuilt.items()):
raise ValueError('Source-owned visual candidate provenance/bytes differ')
return rebuilt
def review_hand_kit(candidate,schemas):
if not isinstance(candidate,dict)or not isinstance(candidate.get('inputs'),dict):raise ValueError('Explicit hand kit candidate required')
values=candidate['inputs'];rebuilt=remap_hand_attachment_kit(values.get('source'),values.get('template'),values.get('attachments'),
values.get('effects'),values.get('bindings'),schemas,values.get('maxima',{}),candidate.get('child_id_registry'),kind=values.get('kind','cast'))
if any(candidate.get(k)!=v for k,v in rebuilt.items()):raise ValueError('Hand kit candidate provenance/bytes differ')
return rebuilt
def new_state_visual_candidate(source,template,events,kit_candidates,schemas,maxima,registry,occupied):
"""Clone a positive cast/state visual graph using checked hand-kit mappings.
No missile/channel/impact/area behavior is admitted by this family. Original
cast and caster/target state events survive; all new kit children accompany
the graph. This remains an offline candidate until asset and engine checks.
"""
if not isinstance(source,(list,tuple))or len(source)!=16 or any(type(v)is not int or not 0<=v<=0xffffffff for v in source):raise ValueError('Complete source16field visual required')
ident=integer(source[0],1,0x7fffffff,'source aura visual')
if any(source[i]for i in range(1,16)if i not in(2,4))or not source[2]or not source[4]or source[2]==source[4]:raise ValueError('Unreviewed source cast/state visual family')
if not isinstance(kit_candidates,dict)or set(kit_candidates)not in({source[2],source[4]},{str(source[2]),str(source[4])}):raise ValueError('Complete cast/state kit candidates required')
kit_candidates={int(k):v for k,v in kit_candidates.items()}
children=[];mapped={};seen=set()
for kit,role in ((source[2],'cast'),(source[4],'state')):
candidate=review_hand_kit(kit_candidates[kit],schemas)
if candidate['source_kit_id']!=kit or candidate['inputs']['template']['ID']!=kit or candidate['inputs']['kind']!=role:raise ValueError('Cast/state kit role or template differs')
mapped[kit]=candidate['native_kit_id']
for row in candidate['records']:
key=(row['table_name'],row['id'])
if key in seen or row['id']in occupied.get(row['table_name'],set()):raise ValueError('Cast/state kit child allocation collision')
seen.add(key);children.append(dict(deepcopy(row),source_visual_id=ident))
for table in TABLES:
if table not in schemas or canonical_sha256(schemas[table])!=SUPPLEMENTAL_TABLES[table][2]:raise ValueError('Pinned aura visual schema required')
integer(maxima.get(table),1,0x7ffffffe,'aura visual allocation floor')
encode(template,schemas['SpellVisual'])
neutral=dict(VISUAL_ZERO,StateKit=source[4])
if template.get('ID')!=ident or any(template.get(k)!=v for k,v in neutral.items()):raise ValueError('Source-matched neutral native state visual required')
if not isinstance(events,list)or len(events)!=3:raise ValueError('Complete cast and caster/target state events required')
event_roles=set();event_ids=set()
for event in events:
integer(event.get('ID'),1,maxima['SpellVisualEvent'],'native aura event ID')
encode(event,schemas['SpellVisualEvent']);key=(event.get('StartEvent'),event.get('EndEvent'),event.get('TargetType'),event.get('SpellVisualKitID'))
if event.get('SpellVisualID')!=ident or event['ID']in event_ids or key in event_roles or any(event.get(k)!=0 for k in EVENT_ZERO):raise ValueError('Ambiguous/conditional native aura event')
event_ids.add(event['ID']);event_roles.add(key)
if event_roles!={(3,13,1,source[2]),(7,8,1,source[4]),(7,8,2,source[4])}:raise ValueError('Positive source-equivalent aura event roles required')
if not isinstance(registry,dict)or registry.get('schema_version')!=1 or registry.get('build')!=BUILD or set(registry)!={'schema_version','build',*TABLES}:raise ValueError('Explicit state visual registry required')
result=deepcopy(registry)
for table in TABLES:
if not isinstance(result[table],dict)or len(set(result[table].values()))!=len(result[table]):raise ValueError('State visual registry collision')
for value in result[table].values():
integer(value,maxima[table]+1,0x7fffffff,'destination-only state visual ID')
if value in occupied.get(table,set()):raise ValueError('State visual allocation collision')
def allocate(table,key):
if key not in result[table]:result[table][key]=max([maxima[table],*result[table].values()])+1
value=integer(result[table][key],maxima[table]+1,0x7fffffff,'new state visual ID')
if value in occupied.get(table,set()):raise ValueError('New state visual allocation collision')
return value
visual=allocate('SpellVisual',str(ident));rows=[('SpellVisual',dict(template,ID=visual,StateKit=mapped[source[4]]))]
for event in sorted(events,key=lambda r:r['ID']):
rows.append(('SpellVisualEvent',dict(event,ID=allocate('SpellVisualEvent',f'{ident}:{event["ID"]}'),SpellVisualID=visual,SpellVisualKitID=mapped[event['SpellVisualKitID']])))
records=list(children)
for table,row in rows:
wire=encode(row,schemas[table]);records.append(dict(table_name=table,table_hash=hex(SUPPLEMENTAL_TABLES[table][0]),id=row['ID'],record=row,
wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest(),source_visual_id=ident,baseline_record_sha256=None,allocation_policy='new-source-owned-state-visual'))
return dict(kind='source-owned-state-visual-candidate',definition_policy='new-source-owned-hand-state-visual-v1',build=BUILD,schema=SCHEMA,
source_visual_id=ident,native_visual_id=visual,source_visual_row=list(source),native_template=deepcopy(template),native_events=deepcopy(events),
kit_candidates={str(k):deepcopy(v)for k,v in kit_candidates.items()},native_allocation_floors={t:maxima[t]for t in TABLES},child_id_registry=result,records=records,
existing_records_modified=False,authoritative_spell_ids_modified=False,installed=False,engine_accepted=False,gameplay_verified=False,
asset_payloads_verified=False,audio_parity_verified=False)