Files
2026-11-23 03:28:32 +02:00

29 lines
1.5 KiB
Python

"""Convert the Source (Octo) doodad M2s the Turtle maps need but the client lacks."""
import sys, json, struct
sys.path.insert(0, '.'); sys.path.insert(0, '/mnt/Games/@project/gateway/ops')
import octo_mpq as O
from m2_equipment_convert import convert_equipment
def source_model(p):
for q in (p, p.rsplit('.', 1)[0] + '.mdx'):
raw = O.read(q.replace('/', '\\'))
if raw is not None: return raw
def textures(raw):
n, off = struct.unpack_from('<II', raw, 80); out = []
for i in range(n):
typ, fl, ln, no = struct.unpack_from('<IIII', raw, off + 16 * i)
out.append((typ, raw[no:no + ln].rstrip(b'\0').decode('latin1').replace('\\', '/').lower() if typ == 0 and ln else ''))
return out
def convert(p):
raw = source_model(p)
if raw is None: return None, 'no source'
if raw[:4] == b'MD20' and int.from_bytes(raw[4:8], 'little') == 257: raw = raw[:4] + (256).to_bytes(4, 'little') + raw[8:]
body, skins, checks = convert_equipment(raw, allow_qualified_cutout_shader16=True, paired_single_texture_rule=True, convert_ribbons=True, convert_particles=True)
return dict(body=body, skins=skins, textures=textures(body)), None
if __name__ == '__main__':
inv = json.load(open('inventory.json'))
for p in sorted({p for v in inv.values() for p in v['missing']['m2']}):
try:
r, err = convert(p)
print(p, err or dict(bytes=len(r['body']), skins=len(r['skins']), textures=r['textures']))
except Exception as e: print(p, 'ERROR', type(e).__name__, str(e)[:150])