Files
WoW-Hybrid-gateway/ops/qualify_shop_illusion_aura.py
2026-11-23 03:28:32 +02:00

195 lines
8.7 KiB
Python

#!/usr/bin/env python3
"""Qualify old-client shop illusion auras against the effective native codec.
The source list is the official old client Spell.dbc extraction. The optional
eight-row extension is a separate, unpublished Source411 hotfix component.
This tool creates an evidence receipt and a small, exact-ID aura mask profile;
it never changes a client or a codec.
"""
from __future__ import annotations
import argparse
import hashlib
import importlib.util
import json
import struct
from collections import defaultdict
from pathlib import Path
CURRENT_HEADER_SHA = "06d3311ebf26d6a5b4510e1b63681fd4d8a71545def320b71a3229f2a44ec279"
OFFICIAL_SHA = "a96099e39a8617ddb8f7521529b241a2fffcB85b3e622f8d13667b55a0e36f5b".lower()
PENDING_SHA = "990a31e06ba80c339d5d80d0221772edb4a04c196483dd0a62dfd44d9d889092"
TABLES = {
"SpellName": 0x46C66698,
"Spell": 0xE111669E,
"SpellMisc": 0xC603EE28,
"SpellEffect": 0xF04238A5,
}
HELD = (19937, 31961, 31965)
PENDING = (21570, 21571, 21572, 21573, 21574, 30282, 30283, 30284)
def sha(raw: bytes) -> str:
return hashlib.sha256(raw).hexdigest()
def require_spell_name(body: bytes, expected: str) -> None:
assert body.endswith(b"\0") and body[:-1].decode("utf-8") == expected
def require_effect(body: bytes, spell: int) -> None:
assert len(body) == 136 and struct.unpack_from("<I", body, 132)[0] == spell
assert struct.unpack_from("<H", body, 0)[0] == 56 # TRANSFORM
assert struct.unpack_from("<I", body, 4)[0] == 0 # only effect index zero
assert struct.unpack_from("<I", body, 8)[0] == 6 # APPLY_AURA
def require_misc(body: bytes, spell: int) -> int:
assert len(body) == 119 and struct.unpack_from("<I", body, 115)[0] == spell
assert struct.unpack_from("<I", body, 0)[0] == 0 # visible, positive, cancelable
assert struct.unpack_from("<H", body, 72)[0] == 21 # old-client illusion duration
icon = struct.unpack_from("<I", body, 91)[0]
assert icon > 0
return icon
def profile(existing: list[int], pending: list[int]) -> str:
def values(rows: list[int]) -> str:
return ",".join(str(v) for v in rows)
return (
"// Generated by ops/qualify_shop_illusion_aura.py from the pinned old-client Spell.dbc\n"
"// and the effective Windows codec. Pending spells require their paired hotfix.\n"
"#pragma once\n#include <algorithm>\n#include <cstdint>\n#include <iterator>\n"
"namespace gateway::shop_illusion_aura_profile {\n"
f"inline constexpr uint32_t Existing[]={{ {values(existing)} }};\n"
f"inline constexpr uint32_t PendingCodec[]={{ {values(pending)} }};\n"
"inline uint32_t mask(uint32_t spell){\n"
" return (std::binary_search(std::begin(Existing),std::end(Existing),spell) ||\n"
" std::binary_search(std::begin(PendingCodec),std::end(PendingCodec),spell))?1u:0u;\n"
"}\n}\n"
)
def main() -> None:
p = argparse.ArgumentParser()
for name in ("official", "current-header", "pending-component", "header-parser", "receipt", "profile"):
p.add_argument("--" + name, type=Path, required=True)
args = p.parse_args()
official_raw = args.official.read_bytes()
pending_raw = args.pending_component.read_bytes()
assert sha(official_raw) == OFFICIAL_SHA
assert sha(pending_raw) == PENDING_SHA
official = json.loads(official_raw)
old = {row["id"]: row for row in official if row["name"].startswith("Illusion: ")}
assert len(old) == 57 and len(set(old)) == 57
spec = importlib.util.spec_from_file_location("hotfix_header_parser", args.header_parser)
assert spec and spec.loader
parser = importlib.util.module_from_spec(spec)
spec.loader.exec_module(parser)
current = parser.parse(args.current_header)
assert current["file_sha256"] == CURRENT_HEADER_SHA
assert parser.identity(current["rows"]) == current["push_id"]
names = {}
parents = {}
effects: dict[int, list[tuple[int, bytes]]] = defaultdict(list)
misc: dict[int, list[tuple[int, bytes]]] = defaultdict(list)
for table, ident, status, _offset, body in current["rows"]:
if status != 1:
continue
if table == TABLES["SpellName"] and ident in old:
names[ident] = body
elif table == TABLES["Spell"] and ident in old:
parents[ident] = body
elif table == TABLES["SpellEffect"] and len(body) == 136:
spell = struct.unpack_from("<I", body, 132)[0]
if spell in old:
effects[spell].append((ident, body))
elif table == TABLES["SpellMisc"] and len(body) == 119:
spell = struct.unpack_from("<I", body, 115)[0]
if spell in old:
misc[spell].append((ident, body))
pending_component = json.loads(pending_raw)
assert pending_component["current_windows_header_sha256"] == CURRENT_HEADER_SHA
assert set(map(int, pending_component["spells"])) == set(PENDING)
pending_by_spell: dict[int, dict[str, tuple[int, bytes]]] = defaultdict(dict)
assert len(pending_component["rows"]) == 32
for row in pending_component["rows"]:
assert row["record_status"] == "valid"
table = row["table_name"]
assert int(row["table_hash"], 16) == TABLES[table]
spell = int(row["record"]["spell_id"])
assert spell in PENDING and table not in pending_by_spell[spell]
body = bytes.fromhex(row["wire_hex"])
assert sha(body) == row["sha256"]
pending_by_spell[spell][table] = (int(row["id"]), body)
assert set(pending_by_spell) == set(PENDING)
admitted = []
existing, pending = [], []
for spell, source in sorted(old.items()):
simple = (source["effects"] == [6, 0, 0] and
source["auras"] == ["56:TRANSFORM", 0, 0] and
source["attributes"] == "0x00000000" and
not any(source["flags"][flag] for flag in
("passive_0x40", "hidden_clientside_0x80", "cant_cancel_0x80000000")))
if spell in HELD:
assert not simple
continue
assert simple, spell
if spell in PENDING:
assert spell not in names and spell not in parents
assert not effects[spell] and not misc[spell]
record = pending_by_spell[spell]
assert set(record) == set(TABLES)
require_spell_name(record["SpellName"][1], source["name"])
require_effect(record["SpellEffect"][1], spell)
icon = require_misc(record["SpellMisc"][1], spell)
status = "pending_paired_codec"
pending.append(spell)
else:
require_spell_name(names[spell], source["name"])
assert parents[spell] and len(effects[spell]) == len(misc[spell]) == 1
record = {"SpellName": (spell, names[spell]), "Spell": (spell, parents[spell]),
"SpellMisc": misc[spell][0], "SpellEffect": effects[spell][0]}
require_effect(record["SpellEffect"][1], spell)
icon = require_misc(record["SpellMisc"][1], spell)
status = "current_codec"
existing.append(spell)
admitted.append({"spell": spell, "name": source["name"], "status": status,
"native_icon_fdid": icon,
"rows": {table: {"id": row[0], "sha256": sha(row[1])}
for table, row in record.items()}})
assert len(existing) == 46 and len(pending) == 8
assert sorted(existing) == existing and sorted(pending) == pending
assert sorted(set(old) - set(existing) - set(pending)) == list(HELD)
generated = profile(existing, pending)
receipt = {
"policy": "source-attested-same-ID-shop-illusion-single-transform-aura-v1",
"publication": "HOLD",
"native_accepted": False,
"inputs_sha256": {
"official_old_spell_dbc_extraction": OFFICIAL_SHA,
"current_windows_codec_header": CURRENT_HEADER_SHA,
"pending_source411_hotfix_component": PENDING_SHA,
},
"counts": {"current_codec": len(existing), "pending_paired_codec": len(pending), "held": len(HELD)},
"held_spell_ids": list(HELD),
"deployment_condition": "Build and stage this native profile with the eight-spell hotfix component; do not ship the pending IDs against the old codec.",
"profile_sha256": sha(generated.encode()),
"admitted": admitted,
}
args.receipt.parent.mkdir(parents=True, exist_ok=True)
args.profile.parent.mkdir(parents=True, exist_ok=True)
args.receipt.write_text(json.dumps(receipt, indent=2) + "\n", encoding="utf-8")
args.profile.write_text(generated, encoding="utf-8")
print(f"Qualified {len(existing)} current and {len(pending)} paired-codec illusions; held {len(HELD)}")
if __name__ == "__main__":
main()