31 lines
1.9 KiB
Python
31 lines
1.9 KiB
Python
"""Source fixups for Turtle custom item models before m2_equipment_convert (2026-11-23).
|
|
- type 2 (item replaceable) slots keep a modder's local file name (c:\\users\\...): the name is never read (the display
|
|
supplies the texture), so clear it (length 0), as native replaceable slots do.
|
|
- type 1 (character skin) on an item model that names an existing Octo file: the author meant that file; make it a
|
|
hardcoded type 0 slot. A type-1 slot whose file is missing on Octo too is left (model stays held).
|
|
Writes models/src3/<sha>.m2 + manifest.json (all 40 models; unchanged ones byte-identical)."""
|
|
import json, struct, hashlib, sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, '/mnt/Games/@project/gateway/ops/maps14-20261122'); import octo_mpq
|
|
W = Path(__file__).resolve().parent
|
|
src = json.load(open(W / 'models/src/manifest.json'))['matches']
|
|
out = W / 'models/src3'; out.mkdir(exist_ok=True)
|
|
def exists(p):
|
|
try: return bool(octo_mpq.read(p))
|
|
except Exception: return False
|
|
rows = []; log = []
|
|
for m in src:
|
|
raw = bytearray((W / 'models/src' / m['file']).read_bytes())
|
|
n, o = struct.unpack_from('<II', raw, 92)
|
|
for i in range(n):
|
|
k, f, ln, at = struct.unpack_from('<4I', raw, o + 16 * i)
|
|
name = bytes(raw[at:at + ln]).rstrip(b'\0').decode('latin1') if ln else ''
|
|
if k == 2 and ln and (':' in name or name.startswith(('\\', '/'))):
|
|
struct.pack_into('<I', raw, o + 16 * i + 8, 0); log.append((m['member'], i, 'type2 name cleared', name))
|
|
elif k == 1 and name and exists(name):
|
|
struct.pack_into('<I', raw, o + 16 * i, 0); log.append((m['member'], i, 'type1 -> hardcoded', name))
|
|
sha = hashlib.sha256(raw).hexdigest(); (out / f'{sha}.m2').write_bytes(raw)
|
|
rows.append(dict(m, sha256=sha, file=f'{sha}.m2', fixups=[l[2:] for l in log if l[0] == m['member']]))
|
|
json.dump(dict(matches=rows), open(out / 'manifest.json', 'w'), indent=1)
|
|
for l in log: print(l)
|