Files

58 lines
2.7 KiB
Python

"""Native 70334 sequence lookup for converted M2 bodies (2026-11-25, #34 GO freeze).
1.12 (MD20 v256) indexes the animation lookup directly by animation ID: lookup[id] = sequence or -1, size max_id+1.
70334 (v272+) reads the same M2Array (header 0x24, `sequenceIdxHashById`) as an open-addressing HASH table:
slot = id % size, then cumulative squared steps (+1^2, +2^2, ...) until the slot's sequence has that ID or is -1.
Pinned 70334 reader: RVA 0x1df4d40, probe update 0x1df4f7e..0x1df5040. A copied 1.12 table
without any -1 (e.g. [0] or [0,1,2] for Stand variations) makes every lookup of an animation the model lacks probe
forever: the client's model thread soft-locks (ERROR #109) as soon as a game object asks for its open/close/spawn
animation (Thalassian Mailbox, High Elf banners). Native layout, verified on humanmalewarriorlight (43 seqs, 37 IDs,
79 slots) and wolf (89 slots): size = next prime >= 2 * unique IDs, value = first sequence index of the ID.
Single-ID models get [index, -1] (size 2). The pinned lookup's empty-hash branch searches the sequence array
linearly; an empty hash alone does not prove that this lookup cannot find Stand. Native one-ID models often
ship [0] (87 of 111 sampled), but such a table has no terminator for a request for an absent animation.
"""
import struct
def _next_prime(n):
n = max(2, n)
while any(n % d == 0 for d in range(2, int(n ** 0.5) + 1)):
n += 1
return n
def native_sequence_hash(body):
"""Return (body, changed) with the 0x24 lookup rebuilt as the native hash table. `body` is MD20 bytes."""
body = bytearray(body)
assert body[:4] == b'MD20'
count, offset = struct.unpack_from('<II', body, 0x1C)
ids = [struct.unpack_from('<H', body, offset + 64 * i)[0] for i in range(count)]
first = {}
for index, ident in enumerate(ids):
first.setdefault(ident, index)
if not first:
new = b''
else:
size = _next_prime(2 * len(first)); table = [-1] * size
for ident, index in first.items():
slot = ident % size
step = 1
while table[slot] != -1:
slot = ((slot + step * step) & 0xffffffff) % size
step += 1
table[slot] = index
new = struct.pack('<%dh' % size, *table)
old_count, old_offset = struct.unpack_from('<II', body, 0x24)
old = bytes(body[old_offset:old_offset + 2 * old_count]) if old_count else b''
if old == new:
return bytes(body), False
if not new:
struct.pack_into('<II', body, 0x24, 0, 0)
else:
while len(body) % 16:
body.append(0)
at = len(body); body += new
struct.pack_into('<II', body, 0x24, len(new) // 2, at)
return bytes(body), True