Created
September 7, 2021 07:31
-
-
Save NWPlayer123/bfc341c465ae573d3cbd48a14656b590 to your computer and use it in GitHub Desktop.
for WarioWare: Get It Together!, Python 2, no warranty if it breaks on some file
This file contains hidden or 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
from struct import unpack | |
import sys | |
def align(value): | |
return value + (0x10 - (value % 0x10)) | |
def full(f): | |
return unpack("<I", f.read(4))[0] | |
def LBL1(f): | |
start = f.tell() | |
count = full(f) | |
table = [] | |
for i in range(count): | |
table.append(unpack("<2I", f.read(8))) | |
assert table == sorted(table, key=lambda x: x[1]) #can read strings in-place | |
returnme = [] | |
for entry in table: | |
f.seek(start + entry[1]) | |
addme = [] | |
for i in range(entry[0]): | |
size = ord(f.read(1)) | |
string = f.read(size) | |
index = full(f) | |
addme.append([string, index]) | |
returnme.append(addme) | |
return returnme | |
def TXTW(f, fullsize): | |
start = f.tell() | |
count = full(f) | |
table = [] | |
for i in range(count): | |
table.append(full(f)) | |
table.append(fullsize) #so we don't get an off-by-one | |
returnme = [] | |
for i in range(count): | |
f.seek(start + table[i]) | |
string = f.read(table[i+1] - table[i] - 2) #null byte terminator | |
returnme.append(string) | |
return returnme | |
with open(sys.argv[1], "rb") as f: | |
with open(".".join(sys.argv[1].split(".")[:-1]) + ".txt", "wb") as o: | |
header = unpack("<8sH2xBBB3xH12x", f.read(0x20)) | |
assert header[0] == "MsgStdBn" | |
assert header[1] == 0xFEFF | |
for i in range(header[4] - 1): | |
header2 = unpack("<4sI8x", f.read(0x10)) | |
start = f.tell() | |
if header2[0] == "LBL1": | |
labels = LBL1(f) | |
elif header2[0] == "TXTW": #custom section | |
strings = TXTW(f, header2[1]) | |
f.seek(start + header2[1]) | |
f.seek(align(f.tell())) | |
for entry in strings: | |
o.write(entry + "\r\n".encode("UTF-16-LE")) | |
o.write("----------------------------------------\r\n".encode("UTF-16-LE")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment