1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 12:54:51 +00:00
oot/fixbaserom.py
Nicholas Estelami b95643b397
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 06:39:52 -05:00

73 lines
2.3 KiB
Python

from os import path
import sys
import struct
import hashlib
def get_str_hash(byte_array):
return str(hashlib.md5(byte_array).hexdigest())
# If the baserom exists and is correct, we don't need to change anything
if path.exists("baserom.z64"):
with open("baserom.z64", mode="rb") as file:
fileContent = bytearray(file.read())
if get_str_hash(fileContent) == "f0b7f35375f9cc8ca1b2d59d78e35405":
print("Found valid baserom - exiting early")
sys.exit(0)
# Determine if we have a ROM file
romFileName = ""
if path.exists("baserom_original.z64"):
romFileName = "baserom_original.z64"
elif path.exists("baserom_original.n64"):
romFileName = "baserom_original.n64"
# Read in the original ROM
if romFileName != "":
print("File '" + romFileName + "' found.")
with open(romFileName, mode="rb") as file:
fileContent = bytearray(file.read())
# Check if ROM needs to be byte swapped
if fileContent[0] == 0x40:
# Byte Swap ROM
# TODO: This is pretty slow at the moment. Look into optimizing it later...
print("ROM needs to be byte swapped...")
i = 0
while i < len(fileContent):
tmp = struct.unpack_from("BBBB", fileContent, i)
struct.pack_into("BBBB", fileContent, i + 0, tmp[3], tmp[2], tmp[1], tmp[0])
i += 4
perc = float(i) / float(len(fileContent))
if i % (1024 * 1024 * 4) == 0:
print(str(perc * 100) + "%")
print("Byte swapping done.")
else:
print("Error: Could not find baserom_original.z64/baserom_original.n64.")
sys.exit(1)
# Strip the overdump
print("Stripping overdump...")
strippedContent = list(fileContent[0:0x3600000])
# Patch the header
print("Patching header...")
strippedContent[0x3E] = 0x50
# Check to see if the ROM is a "vanilla" Debug ROM
str_hash = get_str_hash(bytearray(strippedContent))
if str_hash != "f0b7f35375f9cc8ca1b2d59d78e35405":
print("Error: Expected a hash of f0b7f35375f9cc8ca1b2d59d78e35405 but got " + str_hash + ". " +
"The baserom has probably been tampered, find a new one")
sys.exit(1)
# Write out our new ROM
print("Writing new ROM 'baserom.z64'.")
with open("baserom.z64", mode="wb") as file:
file.write(bytes(strippedContent))
print("Done!")