-
-
Save mnml/4c5b53ccb4fbb48a7ce12fa3174cda49 to your computer and use it in GitHub Desktop.
patch PCM sections in Wii VC ROMs with original data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import io | |
import re | |
import sys | |
import Wii # https://pypi.org/project/Wii.py/ | |
import lzss3 # https://github.com/magical/nlzss | |
import lzh83 # https://gist.github.com/mnml/1b61ddf0e8141a99018d327dc9e5f21b | |
if len(sys.argv) <= 2: | |
sys.exit(f"usage: {sys.argv[0]} <WAD> <original ROM> <output>") | |
filename, rom = next(f for f in Wii.U8.load(Wii.WAD.loadFile(sys.argv[1])[5]).files if f[0].endswith(b".rom")) | |
if filename.startswith(b"LZ77"): | |
rom = lzss3.decompress(rom) | |
elif filename.startswith(b"LZH8"): | |
rom = lzh83.decompress(io.BytesIO(rom)) | |
rom = bytearray(rom) | |
with open(sys.argv[2], "rb") as origf: | |
orig = origf.read() | |
for m in re.finditer(rb"PCMF.{5}", rom, re.DOTALL): | |
rom[slice(*m.span())] = orig[slice(*m.span())] | |
with open(sys.argv[3], "wb") as outf: | |
outf.write(rom) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment