1
0
mirror of https://github.com/blawar/ooot.git synced 2024-07-04 18:13:37 +00:00
ooot/tools/extract_baserom.py

80 lines
2.0 KiB
Python
Raw Normal View History

2020-03-17 04:31:30 +00:00
#!/usr/bin/python3
import os
import sys
import struct
from multiprocessing import Pool, cpu_count
2022-02-18 00:50:02 +00:00
from libyaz0 import decompress
from oot import *
2020-03-17 04:31:30 +00:00
2022-02-18 00:50:02 +00:00
conf = config()
2020-03-17 04:31:30 +00:00
ROM_FILE_NAME = romPath('baserom.z64')
2022-02-18 00:50:02 +00:00
FILE_TABLE_OFFSET = conf.rom.FILE_TABLE_OFFSET
2020-03-17 04:31:30 +00:00
2022-02-18 00:50:02 +00:00
FILE_NAMES = conf.rom.FILE_NAMES
2020-03-17 04:31:30 +00:00
romData = None
def initialize_worker(rom_data):
global romData
romData = rom_data
2020-03-17 04:31:30 +00:00
def read_uint32_be(offset):
return struct.unpack('>I', romData[offset:offset+4])[0]
def write_output_file(name, offset, size):
try:
with open(name, 'wb') as f:
f.write(romData[offset:offset+size])
except IOError:
print('failed to write file ' + name)
Updated Texture Asset Handling (#478) * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Fixed newline issue with ZAPD * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Fixed merge issues. * Fixed makefile merge error * Fixed additional merge error * Fixed several more merge issues * Commented out gameplay_keep and sk2 extraction, since currently unused. * Reenabled gameplay_keep extraction since it's used in the spec * Fixed build error * Removed test struct * Fixed makefile error that would happen on fresh builds * Fixed merge issue * Removed relative paths * Multithreading on extraction, spec uses numbers, few changes to XMLs * Removed redundant code from the extract_assets script * object_sk2 and object_spot09_obj OK * object_spot11_obj OK * object_spot17_obj OK * Test: One of the gameplay_keep dlists given a proper symbol * Updated asset symbol names based on new naming scheme * XMLs use "Offset" instead of "Address" now * Fixed merge issues, updated ovl_Magic_Dark xml and gfx file * Updated to use latest build of ZAPD * Updated ZAPD again * Updated ZAP to remove assimp dependency * Jenkins Test: Added .gitkeep file * Updated ZAP once more * Updated png file name to comply with new naming scheme. * Fixed bad include Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2020-12-26 11:39:52 +00:00
def ExtractFunc(i):
2022-03-24 00:13:20 +00:00
filename = str(Path(assetPath('baserom')) / FILE_NAMES[i])
2020-03-17 04:31:30 +00:00
entryOffset = FILE_TABLE_OFFSET + 16 * i
virtStart = read_uint32_be(entryOffset + 0)
virtEnd = read_uint32_be(entryOffset + 4)
physStart = read_uint32_be(entryOffset + 8)
physEnd = read_uint32_be(entryOffset + 12)
if physEnd == 0: # uncompressed
compressed = False
size = virtEnd - virtStart
else: # compressed
compressed = True
size = physEnd - physStart
print('extracting ' + filename + " (0x%08X, 0x%08X)" % (virtStart, virtEnd))
write_output_file(filename, physStart, size)
if compressed:
2022-02-18 00:50:02 +00:00
os.system(yaz0Binary() + ' -d ' + filename + ' ' + filename)
Updated Texture Asset Handling (#478) * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Fixed newline issue with ZAPD * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Fixed merge issues. * Fixed makefile merge error * Fixed additional merge error * Fixed several more merge issues * Commented out gameplay_keep and sk2 extraction, since currently unused. * Reenabled gameplay_keep extraction since it's used in the spec * Fixed build error * Removed test struct * Fixed makefile error that would happen on fresh builds * Fixed merge issue * Removed relative paths * Multithreading on extraction, spec uses numbers, few changes to XMLs * Removed redundant code from the extract_assets script * object_sk2 and object_spot09_obj OK * object_spot11_obj OK * object_spot17_obj OK * Test: One of the gameplay_keep dlists given a proper symbol * Updated asset symbol names based on new naming scheme * XMLs use "Offset" instead of "Address" now * Fixed merge issues, updated ovl_Magic_Dark xml and gfx file * Updated to use latest build of ZAPD * Updated ZAPD again * Updated ZAP to remove assimp dependency * Jenkins Test: Added .gitkeep file * Updated ZAP once more * Updated png file name to comply with new naming scheme. * Fixed bad include Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2020-12-26 11:39:52 +00:00
#####################################################################
def main():
try:
createDir(assetPath('baserom'))
except:
raise
# read baserom data
try:
with open(ROM_FILE_NAME, 'rb') as f:
rom_data = f.read()
except IOError:
print('failed to read file' + ROM_FILE_NAME)
sys.exit(1)
Updated Texture Asset Handling (#478) * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Fixed newline issue with ZAPD * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Fixed merge issues. * Fixed makefile merge error * Fixed additional merge error * Fixed several more merge issues * Commented out gameplay_keep and sk2 extraction, since currently unused. * Reenabled gameplay_keep extraction since it's used in the spec * Fixed build error * Removed test struct * Fixed makefile error that would happen on fresh builds * Fixed merge issue * Removed relative paths * Multithreading on extraction, spec uses numbers, few changes to XMLs * Removed redundant code from the extract_assets script * object_sk2 and object_spot09_obj OK * object_spot11_obj OK * object_spot17_obj OK * Test: One of the gameplay_keep dlists given a proper symbol * Updated asset symbol names based on new naming scheme * XMLs use "Offset" instead of "Address" now * Fixed merge issues, updated ovl_Magic_Dark xml and gfx file * Updated to use latest build of ZAPD * Updated ZAPD again * Updated ZAP to remove assimp dependency * Jenkins Test: Added .gitkeep file * Updated ZAP once more * Updated png file name to comply with new naming scheme. * Fixed bad include Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2020-12-26 11:39:52 +00:00
# extract files
num_cores = cpu_count()
print("Extracting baserom with " + str(num_cores) + " CPU cores.")
with Pool(num_cores, initialize_worker, (rom_data,)) as p:
p.map(ExtractFunc, range(len(FILE_NAMES)))
Updated Texture Asset Handling (#478) * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Fixed newline issue with ZAPD * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Auto stash before rebase of "upstream/master" * A large number of scenes have been decompiled. * Fixed makefile * Decompiled around 40 scenes. * Removed old file * Finished matching remaining scenes. * Removed old commented out spec lines * Decompiled a few object files. * Reorganized xmls a bit. Updated pu_box overlay to use proper symbol. * Updated texture and object file decomp * Moved scenes/ into the assets/ folder * Fixed a few compile errors * Fixed merge issues. * Fixed makefile merge error * Fixed additional merge error * Fixed several more merge issues * Commented out gameplay_keep and sk2 extraction, since currently unused. * Reenabled gameplay_keep extraction since it's used in the spec * Fixed build error * Removed test struct * Fixed makefile error that would happen on fresh builds * Fixed merge issue * Removed relative paths * Multithreading on extraction, spec uses numbers, few changes to XMLs * Removed redundant code from the extract_assets script * object_sk2 and object_spot09_obj OK * object_spot11_obj OK * object_spot17_obj OK * Test: One of the gameplay_keep dlists given a proper symbol * Updated asset symbol names based on new naming scheme * XMLs use "Offset" instead of "Address" now * Fixed merge issues, updated ovl_Magic_Dark xml and gfx file * Updated to use latest build of ZAPD * Updated ZAPD again * Updated ZAP to remove assimp dependency * Jenkins Test: Added .gitkeep file * Updated ZAP once more * Updated png file name to comply with new naming scheme. * Fixed bad include Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2020-12-26 11:39:52 +00:00
if __name__ == "__main__":
main()