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

58 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Generate the complete effect-95 admission profile from two retained catalogues.
Uses the shared bounded DBC reader and reviewed 1.12 disk layout. No DB access.
"""
import argparse
import json
from pathlib import Path
from turtle_data import DBC, spell_layout
def catalogue(path, layout):
dbc = DBC(path, 173)
effect = layout['Effect']
if effect != 61:
raise ValueError('Reviewed effect columns changed')
rows = []
for row in dbc.rows:
effects = list(row[effect:effect + 3])
if 95 not in effects:
continue
# Spell::handle_immediate sends GO before effects except instakill/spawn.
# A projectile could apply later; this profile requires the reviewed
# immediate, unchanneled skinning contract for every selected row.
if row[layout['Speed']] or 1 in effects or 46 in effects or row[layout['AttributesEx']] & 0x44:
raise ValueError('Skinning GO/effect ordering requires new review')
rows.append(dict(id=row[0], effects=effects, speed_word=row[layout['Speed']],
attributes_ex=row[layout['AttributesEx']]))
if not rows:
raise ValueError('Empty skinning catalogue')
return dict(path=str(path), sha256=dbc.digest(), rows_scanned=dbc.count,
selected=sorted(rows, key=lambda row: row['id']))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('server', type=Path)
parser.add_argument('client', type=Path)
parser.add_argument('--layout', type=Path)
parser.add_argument('--header', required=True, type=Path)
parser.add_argument('--receipt', required=True, type=Path)
args = parser.parse_args()
layout = spell_layout(args.layout)
sources = [catalogue(path, layout) for path in (args.server, args.client)]
if sources[0]['selected'] != sources[1]['selected']:
raise ValueError('Skinning catalogues disagree')
ids = ', '.join(str(row['id']) for row in sources[0]['selected'])
args.header.write_text('// Generated by ops/source_skinning_profile.py; complete effect-95 catalogues.\n'
'#pragma once\n#include <algorithm>\n#include <cstdint>\n#include <iterator>\n'
'namespace gateway::source_skinning_spells {\n'
'inline constexpr std::uint32_t Spells[] = {' + ids + '};\n'
'inline bool contains(std::uint32_t spell) {\n'
' return std::binary_search(std::begin(Spells), std::end(Spells), spell);\n}\n}\n')
args.receipt.write_text(json.dumps(dict(effect=95, sources=sources), indent=2) + '\n')
if __name__ == '__main__':
main()