Skip to content

Instantly share code, notes, and snippets.

@NWPlayer123
Created August 23, 2022 00:51
Show Gist options
  • Save NWPlayer123/bd588315656b8e3a65b059644a834222 to your computer and use it in GitHub Desktop.
Save NWPlayer123/bd588315656b8e3a65b059644a834222 to your computer and use it in GitHub Desktop.
Extract Compressed Data from Monster Hunter G (Wii) fpk files
from struct import unpack
from os import makedirs
from os.path import exists
sortme = [] #I don't trust that this is sorted
with open("0000.fpk", "rb") as f:
#read header, make sure it's valid
unknown, entry_count, header_size, total_size = unpack(">4I", f.read(0x10))
f.seek(0, 2)
assert total_size == f.tell()
f.seek(0x10)
assert header_size == 0x10
#read each entry for processing in a moment
for i in range(entry_count):
filepath, offset, cmpsize, decsize = unpack(">36s3I", f.read(0x30))
filepath = filepath.rstrip(b"\0")
if len(filepath) == 31:
print("%s possibly truncated" % filepath)
sortme.append((filepath, offset, cmpsize, decsize))
sortme.sort(key=lambda x: x[1]) #sort by offset
for entry in sortme:
(filepath, offset, cmpsize, decsize) = entry
f.seek(offset)
#put everything in output/
path = b"output/" + b"/".join(filepath.split(b"/")[:-1])
if not exists(path): #create path if it doesn't exist
makedirs(path)
with open(b"output/%s" % filepath, "wb") as o:
o.write(f.read(cmpsize))
print(b"%s done" % filepath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment