play/scripts/extract_ktsl2stbin.py

31 lines
780 B
Python
Raw Normal View History

2024-04-04 04:01:04 +00:00
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3
import struct
import sys
import pathlib
# i don't care about efficiency
data = open(sys.argv[1], "rb").read()
outdir = pathlib.Path(sys.argv[2])
if data[:4] != b"KTSR":
raise Exception("what are you doing")
# there's some more stuff but i don't care, go straight to the entry
off = 0x40
idx = 0
while off < len(data):
if data[off + 0x40 : off + 0x44] != b"KTSS":
raise Exception("oh no offset broken")
(entry_size,) = struct.unpack("<I", data[off + 4 : off + 8])
(size,) = struct.unpack("<I", data[off + 0x44 : off + 0x48])
outfile = (outdir / f"{idx}.ktss").open("wb")
outfile.write(data[off + 0x40 : off + 0x40 + size])
off += entry_size
idx += 1
print(idx, hex(off))