Files
WoW-Hybrid-gateway/ops/octo_spell_presentation.py

167 lines
9.2 KiB
Python

#!/usr/bin/env python3
"""#12 (2026-11-25): native client rows for Octo spells the 70334 client has no SpellName row for.
Octo (current client) Spell.dbc 1.12 layout -> SpellName, Spell (texts), SpellMisc, SpellEffect, SpellAuraOptions, SpellAuraRestrictions, plus
SpellDuration / SpellCastTimes / SpellRange rows for Octo indices the client lacks. Field rules are the ones the
already-ported spells follow (checked over 24k SpellMisc / 30k SpellEffect rows): attributes 0-4 copied, cast/duration/
range indices copied, SchoolMask = 1 << school, icon = listfile FDID of the Octo SpellIcon path, EffectBasePointsF =
BasePoints + BaseDice, effect/aura/targets/misc/trigger/period/radius/chain/amplitude copied. New row IDs from 2600000
(codec-allocated rows live in 1000000-1501282). Presentation only: server stays authoritative for every mechanic. Missing restrictions are also backfilled
for already-present spell names; unreviewed source aura states are reported separately, never numerically aliased.
usage: octo_spell_presentation.py <client-csv-dir> <out-dir>
client-csv-dir holds Db2Bake dumps (SpellName.csv, SpellMisc.csv, SpellDuration.csv, SpellCastTimes.csv, SpellRange.csv, SpellAuraRestrictions.csv)
"""
import json
import struct
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent / 'maps14-20261122'))
import octo_mpq # noqa: E402
BASE = 2600000
QUESTION_MARK_ICON = 134400
def dbc(name, signed=False):
raw = octo_mpq.read('DBFilesClient\\' + name)
n, f, rs, ss = struct.unpack_from('<4I', raw, 4)
rows = [struct.unpack_from('<%d%s' % (f, 'i' if signed else 'I'), raw, 20 + i * rs) for i in range(n)]
strings = raw[20 + n * rs:]
return rows, lambda o: strings[o:strings.index(b'\0', o)].decode('utf-8', 'replace')
def ids(csv):
return {int(line.split('\t', 1)[0]) for line in open(csv) if line.strip()}
def aura_restriction_rows(spells, presented, native_dump):
"""Restore missing source conditions using the reviewed codec state map.
DEFENSE, HEALTHLESS_20, FROZEN and HEALTHLESS_35 are the named routes
in src/aura_state.cpp. Other ordinals remain explicit holds, never aliases.
Existing native restrictions (including additional fields) are preserved.
"""
routes = {0: 0, 1: 1, 2: 2, 4: 4, 12: 13}
existing = set()
next_id = BASE
for line in Path(native_dump).read_text().splitlines():
if not line.strip():
continue
parts = line.split('\t')
ident = int(parts[0])
values = dict(part.split('=', 1) for part in parts[1:] if '=' in part)
next_id = max(next_id, ident + 1)
if int(values.get('DifficultyID', '0')) == 0:
existing.add(int(values['SpellID']))
rows, holds = [], []
for source in sorted(spells, key=lambda row: row[0]):
spell, caster, target = source[0], source[16], source[17]
if spell not in presented or spell in existing or not (caster or target):
continue
if caster not in routes or target not in routes:
holds.append(dict(SpellID=spell, CasterAuraState=caster, TargetAuraState=target,
reason='source aura state has no reviewed native route'))
continue
rows.append(dict(ID=next_id, SpellID=spell, DifficultyID=0,
CasterAuraState=routes[caster], TargetAuraState=routes[target],
ExcludeCasterAuraState=0, ExcludeTargetAuraState=0,
CasterAuraSpell=0, TargetAuraSpell=0,
ExcludeCasterAuraSpell=0, ExcludeTargetAuraSpell=0,
CasterAuraType=0, TargetAuraType=0,
ExcludeCasterAuraType=0, ExcludeTargetAuraType=0))
next_id += 1
existing.add(spell)
return rows, holds
def presentation_rows(r, text, icon, next_id):
"""Use the existing Octo presentation field rules for one explicit Source row."""
sid=r[0]
as_float=lambda v: struct.unpack('<f',struct.pack('<i',v))[0]
tables={t:[] for t in ('SpellName','Spell','SpellMisc','SpellEffect','SpellAuraOptions')}
tables['SpellName'].append(dict(ID=sid,Name_lang=text(r[120])))
tables['Spell'].append(dict(ID=sid,NameSubtext_lang=text(r[129]),Description_lang=text(r[138]),AuraDescription_lang=text(r[147])))
tables['SpellMisc'].append(dict(ID=next_id['SpellMisc'], Attributes=list(r[6:11]) + [0] * 12, DifficultyID=0, CastingTimeIndex=r[18],
DurationIndex=r[30], RangeIndex=r[36], SchoolMask=1 << r[1] if 0 <= r[1] < 7 else 1,
Speed=as_float(r[37]), SpellIconFileDataID=icon, SpellID=sid))
next_id['SpellMisc'] += 1
for e in range(3):
if not r[61 + e]:
continue
tables['SpellEffect'].append(dict(ID=next_id['SpellEffect'], EffectAura=r[91 + e], DifficultyID=0, EffectIndex=e, Effect=r[61 + e],
EffectAmplitude=as_float(r[97 + e]), EffectAuraPeriod=r[94 + e], EffectChainAmplitude=1.0,
EffectChainTargets=r[100 + e], EffectItemType=r[103 + e], EffectMechanic=r[79 + e],
EffectPointsPerResource=as_float(r[112 + e]), EffectRealPointsPerLevel=as_float(r[73 + e]),
EffectTriggerSpell=r[109 + e], PvpMultiplier=1.0, GroupSizeBasePointsCoefficient=1.0,
EffectBasePointsF=float(r[76 + e] + r[67 + e]), EffectMiscValue=[r[106 + e], 0],
EffectRadiusIndex=[r[88 + e], 0], ImplicitTarget=[r[82 + e], r[85 + e]], SpellID=sid))
next_id['SpellEffect'] += 1
if r[39] or r[25] not in (0, 101) or r[26]:
tables['SpellAuraOptions'].append(dict(ID=next_id['SpellAuraOptions'], DifficultyID=0, CumulativeAura=r[39], ProcChance=r[25],
ProcCharges=r[26], ProcTypeMask=[r[24], 0], SpellID=sid))
next_id['SpellAuraOptions'] += 1
return tables
def main(csv_dir, out_dir):
csv_dir, out = Path(csv_dir), Path(out_dir)
out.mkdir(parents=True, exist_ok=True)
present = ids(csv_dir / 'SpellName.csv')
spells, text = dbc('Spell.dbc', signed=True)
icons_raw, icon_text = dbc('SpellIcon.dbc')
icon_path = {r[0]: icon_text(r[1]).lower().replace('\\', '/') + '.blp' for r in icons_raw}
listfile = {}
for line in open('/mnt/Games/@project/listfiles/community-listfile.csv', errors='replace'):
i, _, p = line.rstrip('\n').partition(';')
listfile.setdefault(p.lower(), int(i))
as_float = lambda v: struct.unpack('<f', struct.pack('<i', v))[0]
have = {t: ids(csv_dir / f'{t}.csv') for t in ('SpellDuration', 'SpellCastTimes', 'SpellRange')}
octo_tables = {}
dur, _ = dbc('SpellDuration.dbc', signed=True)
octo_tables['SpellDuration'] = {r[0]: dict(ID=r[0], Duration=r[1], MaxDuration=r[3], DurationPerResource=r[2]) for r in dur}
cast, _ = dbc('SpellCastTimes.dbc', signed=True)
octo_tables['SpellCastTimes'] = {r[0]: dict(ID=r[0], Base=r[1], Minimum=r[3]) for r in cast}
rng, rng_text = dbc('SpellRange.dbc')
octo_tables['SpellRange'] = {r[0]: dict(ID=r[0], DisplayName_lang=rng_text(r[4]), DisplayNameShort_lang=rng_text(r[13]), Flags=r[3],
RangeMin=[as_float(r[1] - (1 << 32) if r[1] >= 1 << 31 else r[1])] * 2,
RangeMax=[as_float(r[2] - (1 << 32) if r[2] >= 1 << 31 else r[2])] * 2) for r in rng}
tables = {t: [] for t in ('SpellName', 'Spell', 'SpellMisc', 'SpellEffect', 'SpellAuraOptions', 'SpellDuration', 'SpellCastTimes', 'SpellRange')}
needed = {t: set() for t in have}
next_id = {'SpellMisc': BASE, 'SpellEffect': BASE, 'SpellAuraOptions': BASE}
missing_icon = 0
for r in spells:
sid = r[0]
if sid in present or not text(r[120]):
continue
icon = listfile.get(icon_path.get(r[117], ''), 0)
if not icon:
missing_icon += 1
icon = QUESTION_MARK_ICON
for table, index in (('SpellCastTimes', r[18]), ('SpellDuration', r[30]), ('SpellRange', r[36])):
if index and index not in have[table]:
needed[table].add(index)
for table, rows in presentation_rows(r,text,icon,next_id).items():tables[table].extend(rows)
# Backfill names imported by earlier runs as well as this run's new spells.
presented = present | {row['ID'] for row in tables['SpellName']}
tables['SpellAuraRestrictions'], aura_holds = aura_restriction_rows(
[row for row in spells if text(row[120])], presented, csv_dir / 'SpellAuraRestrictions.csv')
(out / 'SpellAuraRestrictions.holds.json').write_text(json.dumps(aura_holds, indent=2) + '\n')
for table, wanted in needed.items():
tables[table] = [octo_tables[table][i] for i in sorted(wanted) if i in octo_tables[table]]
for table, rows in tables.items():
(out / f'{table}.json').write_text(json.dumps(rows, ensure_ascii=False))
summary = {t: len(v) for t, v in tables.items()}
summary['missing_icon_fallback'] = missing_icon
summary['aura_restriction_holds'] = len(aura_holds)
(out / 'summary.json').write_text(json.dumps(summary, indent=1) + '\n')
print(summary)
if __name__ == '__main__':
main(*sys.argv[1:3])