367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
111 lines
4.2 KiB
Python
111 lines
4.2 KiB
Python
"""Reference native M2s in place of converted doodads that have a 1:1 native equivalent.
|
|
|
|
Policy (Uldaman zone-in bisect, 2026-11-11): swapping the 51 converted doodads
|
|
of WMO 8567809 to their native M2s fixed the client's fatal
|
|
ASSERT(sequenceIndex < sequences.size()). A converted doodad has a native
|
|
equivalent when its internal M2 name (header +8) matches exactly one native
|
|
.m2 listfile basename that the store holds as an M2. For the 51 Uldaman
|
|
doodads this agrees 51/51 with the MODD-placement mapping.
|
|
|
|
Root-cause evidence: every one of 1663 native doodads has a Stand (animation
|
|
0) sequence. 13 converted doodads have none (Uldaman: Crate02 8545442, with
|
|
sequences 146-149 only). Native Crate02 199634 adds a Stand record and makes
|
|
147 an alias (0x40) of it. `missing_stand` flags such models; they need the
|
|
source-default-0 materialisation before they are referenced.
|
|
"""
|
|
import struct
|
|
from collections import defaultdict
|
|
|
|
|
|
def _md20(raw):
|
|
if raw[:4] == b'MD20':
|
|
return raw
|
|
at = 0
|
|
while at + 8 <= len(raw):
|
|
size = struct.unpack_from('<I', raw, at + 4)[0]
|
|
if raw[at:at + 4] == b'MD21':
|
|
return raw[at + 8:at + 8 + size]
|
|
at += 8 + size
|
|
raise ValueError('MD21/MD20 model body required')
|
|
|
|
|
|
def model_name(raw):
|
|
m = _md20(raw); count, offset = struct.unpack_from('<II', m, 8)
|
|
return m[offset:offset + count].split(b'\0')[0].decode('latin1')
|
|
|
|
|
|
def animation_ids(raw):
|
|
m = _md20(raw); count, offset = struct.unpack_from('<II', m, 28)
|
|
return [struct.unpack_from('<H', m, offset + 64 * i)[0] for i in range(count)]
|
|
|
|
|
|
def missing_stand(raw):
|
|
return 0 not in animation_ids(raw)
|
|
|
|
|
|
def listfile_m2_index(lines, *, below):
|
|
index = defaultdict(list)
|
|
for line in lines:
|
|
fdi, _, path = line.rstrip('\n').partition(';')
|
|
if path.lower().endswith('.m2') and fdi.isdigit() and int(fdi) < below:
|
|
index[path.rsplit('/', 1)[-1][:-3].lower()].append(int(fdi))
|
|
return index
|
|
|
|
|
|
def native_equivalents(converted, index, is_native_m2):
|
|
"""converted: {fdi: raw}. Returns (mapping fdi->native fdi, held fdi->reason)."""
|
|
mapping, held = {}, {}
|
|
for fdi, raw in converted.items():
|
|
name = model_name(raw)
|
|
candidates = [n for n in index.get(name.lower(), []) if is_native_m2(n)] if name else []
|
|
if len(candidates) == 1:
|
|
mapping[fdi] = candidates[0]
|
|
else:
|
|
held[fdi] = 'no internal name' if not name else ('no native equivalent' if not candidates else 'ambiguous')
|
|
return mapping, held
|
|
|
|
|
|
def rewrite_doodad_refs(raw, kind, mapping):
|
|
"""Rewrite WMO MODI or ADT MDDF/MLDD FileDataID (flag 0x40) doodad references; other bytes unchanged."""
|
|
out = bytearray(raw); at = 0; changed = 0
|
|
while at + 8 <= len(raw):
|
|
tag = raw[at:at + 4][::-1]; size = struct.unpack_from('<I', raw, at + 4)[0]; body = at + 8
|
|
if kind == 'wmo' and tag == b'MODI':
|
|
slots = range(body, body + size - 3, 4)
|
|
elif kind == 'adt' and tag in (b'MDDF', b'MLDD'):
|
|
slots = [k for k in range(body, body + size - 35, 36) if struct.unpack_from('<H', raw, k + 34)[0] & 0x40]
|
|
else:
|
|
slots = ()
|
|
for k in slots:
|
|
v = struct.unpack_from('<I', raw, k)[0]
|
|
if v in mapping:
|
|
struct.pack_into('<I', out, k, mapping[v]); changed += 1
|
|
at += 8 + size
|
|
return bytes(out), changed
|
|
|
|
|
|
def prepare_unmapped_doodad(raw):
|
|
"""A converted doodad with no native equivalent keeps its FDI; it must have a Stand (animation 0)."""
|
|
from m2_sequence_contract import insert_stand
|
|
return insert_stand(raw)
|
|
|
|
|
|
def listfile_m2_paths(lines, *, below):
|
|
"""Lower-case native .m2 path -> FDI (only FDIs below the converted range)."""
|
|
out = {}
|
|
for line in lines:
|
|
fdi, _, path = line.rstrip('\n').partition(';')
|
|
if path.lower().endswith('.m2') and fdi.isdigit() and int(fdi) < below:
|
|
out[path.lower()] = int(fdi)
|
|
return out
|
|
|
|
|
|
def native_path_bindings(names, paths, is_native_m2):
|
|
"""Source doodad names (.mdx/.mdl/.m2) bound to the native .m2 at the same path."""
|
|
out = {}
|
|
for name in names:
|
|
fdi = paths.get(name.lower().rsplit('.', 1)[0] + '.m2')
|
|
if fdi is not None and is_native_m2(fdi):
|
|
out[name] = fdi
|
|
return out
|