Skip to content

Instantly share code, notes, and snippets.

View NWPlayer123's full-sized avatar

NWPlayer123 NWPlayer123

View GitHub Profile
@NWPlayer123
NWPlayer123 / sprite1.py
Created September 1, 2017 22:29
Sonic Mania Sprite Extractor (WIP, breaks on some stuff)
from struct import unpack
from binascii import hexlify, unhexlify
from os import getcwd, mkdir
from os.path import exists
from PIL import Image
import sys
#sys.argv.append("Sonic.bin")
do_extract = 1
with open(sys.argv[1], "rb") as f:
@NWPlayer123
NWPlayer123 / parse_btxt.py
Last active August 22, 2021 21:02
Metroid Samus Returns text
def getstr(f):
ret = "";char = f.read(1)
while char != "\x00":
ret += char
char = f.read(1)
return ret
def getustr(f):
ret = "";char = f.read(2)
while char != "\x00\x00":
@NWPlayer123
NWPlayer123 / parse_pkg.py
Created September 13, 2017 01:55
Metroid Samus Returns pkg files
# -------------------------------------
# data is aligned to nearest 0x80
# header size is normally 0x7C aka
# 0x80 aligned, minus 4
# (doesn't include 4 bytes for the header size)
# then data size starting at [header_size + 4]
# then number of files, read 12 bytes each and seek
# 12 = hash(?), start pos, end pos (from start of file)
# then just seek to [header_size + 4] and extract files
from struct import pack, unpack
from struct import pack, unpack
from os import remove, rename
import sys
do_replace = 1
with open(sys.argv[1], "rb") as f:
name = sys.argv[1].split(".")
name = ".".join(name[:-1]) + ".dec." + name[-1]
with open(name, "wb+") as o:
@NWPlayer123
NWPlayer123 / SARCExtractR.py
Created January 16, 2018 22:25
Recursive SARCExtract (goes through all ones in a directory, but not subdirectories)
from struct import pack, unpack
from os import mkdir, makedirs, listdir
from os.path import exists
import sys
def half(en, f):
return unpack("%sH" % en, f.read(2))[0]
def full(en, f):
return unpack("%sI" % en, f.read(4))[0]
@NWPlayer123
NWPlayer123 / parse_tpl.py
Last active March 22, 2018 02:50
extracts TPL files (only tested on Monkey Ball 2, missing a few formats)
from struct import unpack
from PIL import Image
from os import mkdir
from os.path import exists
import sys
class I4_Texture:
def __init__(self, width, height, color):
self.image = Image.new("RGB", (width, height))
self.img = self.image.load()
@NWPlayer123
NWPlayer123 / extract_preview.py
Created March 14, 2018 07:18
for use with parse_tpl.py for Super Monkey Ball 2's Preview TPLs
from parse_tpl import *
from os import mkdir
from os.path import exists
name = "banner"
width = 96
height = 32
if not exists(name):
mkdir(name)
@NWPlayer123
NWPlayer123 / zlib_bruteforce.py
Created March 19, 2018 01:45
For bruteforce decompressing files that have multiple zlib chunks
#Very slow, loads whole file into memory to try decompression
from zlib import decompress
import sys
size = 0
with open(sys.argv[1], "rb") as f:
compressed = f.read()
total_size = f.tell()
output = ""
for i in range(total_size):
@NWPlayer123
NWPlayer123 / zlib_bruteforce2.py
Last active March 24, 2018 08:54
faster, checks for magic bytes
from zlib import decompress
from io import BytesIO
import sys
data = open(sys.argv[1], "rb").read()
#use this without making giant range() array
size = len(data) - 1
#better than a string ?
output = BytesIO()
#get byte 0 for the loop
@NWPlayer123
NWPlayer123 / yaz0dec3.py
Created March 25, 2018 03:14
python 3 only version cuz I'm too lazy to make backwards compatible, use https://gist.github.com/NWPlayer123/05dd55dd1cce6eb5457741ce14f48587 for 2
from struct import unpack
import sys
with open(sys.argv[1], "rb") as f:
base = ".".join(sys.argv[1].split(".")[:-1])
with open(base + ".sarc", "wb+") as o:
assert f.read(4) == b"Yaz0"
unc_size = unpack(">I", f.read(4))[0]
o.write(b"\x00" * unc_size) #pre-allocate
o.seek(0);f.seek(16)