Files

77 lines
3.2 KiB
Python

"""#56 follow-up (2026-11-25): bccb5019 put anim 211 into the lookup by linear probing; the client probes i += p*p,
so Tauren (968705), Gnome (900914) and the Undead skel did not find it. Move each 211 lookup entry onto the client's
probe path. Reads the parent (bccb) store; writes inputs/out."""
import struct
import sys
from pathlib import Path
H = Path(__file__).resolve().parent
sys.path[:0] = [str(H.parent), str(H)]
import frozen_store as fs
store = fs.Store(); root = store.root; lay = store.layout
cells = {}
for g in lay['groups']:
f = 0
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
f += d
if f in (968705, 900914, 1022938, 959310, 1100087, 2140228, 1838675):
cells.setdefault(f, []).append((g['flags1'], root[g['ckeys_offset'] + i * 16:g['ckeys_offset'] + i * 16 + 16].hex()))
f += 1
OUT = H / 'out'; NAT = H / 'nat'; NAT.mkdir(exist_ok=True)
def chunks(b):
at, out = 0, []
while at + 8 <= len(b):
t, n = struct.unpack_from('<4sI', b, at); out.append([t, bytearray(b[at + 8:at + 8 + n])]); at += 8 + n
assert at == len(b); return out
def probe(D, so, lo, lc, aid, idx_at):
"""Return (found index via client probe, slot)."""
s, p = aid % lc, 0
while True:
v = struct.unpack_from('<h', D, lo + 2 * s)[0]
if v == -1:
return None, s
if struct.unpack_from('<H', D, so + 64 * v)[0] == aid:
return v, s
p += 1; s = (s + p * p) % lc
def relocate(D, seqoff, lookoff, aid=211):
K, so = struct.unpack_from('<II', D, seqoff); lc, lo = struct.unpack_from('<II', D, lookoff)
ids = [struct.unpack_from('<H', D, so + 64 * i)[0] for i in range(K)]
first = ids.index(aid)
found, _ = probe(D, so, lo, lc, aid, None)
if found == first:
return 'ok'
slots = [i for i in range(lc) if struct.unpack_from('<h', D, lo + 2 * i)[0] == first]
assert len(slots) == 1, slots
struct.pack_into('<h', D, lo + 2 * slots[0], -1)
found, s = probe(D, so, lo, lc, aid, None); assert found is None
struct.pack_into('<h', D, lo + 2 * s, first)
assert probe(D, so, lo, lc, aid, None)[0] == first
return f'moved {slots[0]}->{s}'
def one(ck):
r = store.read(ck); assert r, ck; return r[2]
for fid, off in ((968705, 'm2'), (900914, 'm2'), (1022938, 'm2'), (1100087, None), (2140228, 'skel'), (1838675, 'skel')):
(fl, ck), = cells[fid]
raw = one(ck); (NAT / f'{fid}.bin').write_bytes(raw)
parts = chunks(raw)
if off == 'm2':
D = next(p[1] for p in parts if p[0] == b'MD21'); res = relocate(D, 0x1C, 0x24)
elif off == 'skel':
D = next(p[1] for p in parts if p[0] == b'SKS1'); res = relocate(D, 8, 16)
else:
print(fid, 'skel-driven m2, no lookup'); continue
print(fid, ck[:8], res)
if res != 'ok':
(OUT / f'{fid}.{"m2" if off == "m2" else "skel"}').write_bytes(b''.join(struct.pack('<4sI', t, len(d)) + bytes(d) for t, d in parts))
# The other 959310 ROOT cell (flags1 0) is an older self-contained model (v272, own sequences); the current skel-based
# model and its only .skel cell both carry flags1 0x80, which the client loads, so nothing else to patch.