mirror of
https://github.com/zeldaret/oot.git
synced 2025-02-28 12:00:15 +00:00
fixbaserom cleanup
This commit is contained in:
parent
b6b50d6638
commit
f605b3a8a7
1 changed files with 24 additions and 16 deletions
|
@ -1,39 +1,48 @@
|
||||||
import os.path
|
|
||||||
from os import path
|
from os import path
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
import hashlib
|
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
|
# Determine if we have a ROM file
|
||||||
romFileName = ""
|
romFileName = ""
|
||||||
if (path.exists("baserom.z64")):
|
if path.exists("baserom_original.z64"):
|
||||||
romFileName = "baserom.z64"
|
|
||||||
if (path.exists("baserom_original.z64")):
|
|
||||||
romFileName = "baserom_original.z64"
|
romFileName = "baserom_original.z64"
|
||||||
elif (path.exists("baserom_original.n64")):
|
elif path.exists("baserom_original.n64"):
|
||||||
romFileName = "baserom_original.n64"
|
romFileName = "baserom_original.n64"
|
||||||
|
|
||||||
# Read in the original ROM
|
# Read in the original ROM
|
||||||
if (romFileName != ""):
|
if romFileName != "":
|
||||||
print("File '" + romFileName + "' found.")
|
print("File '" + romFileName + "' found.")
|
||||||
with open(romFileName, mode='rb') as file:
|
with open(romFileName, mode="rb") as file:
|
||||||
fileContent = bytearray(file.read())
|
fileContent = bytearray(file.read())
|
||||||
|
|
||||||
# Check if ROM needs to be byte swapped
|
# Check if ROM needs to be byte swapped
|
||||||
if (fileContent[0] == 0x40):
|
if fileContent[0] == 0x40:
|
||||||
# Byte Swap ROM
|
# Byte Swap ROM
|
||||||
# TODO: This is pretty slow at the moment. Look into optimizing it later...
|
# TODO: This is pretty slow at the moment. Look into optimizing it later...
|
||||||
print("ROM needs to be byte swapped...")
|
print("ROM needs to be byte swapped...")
|
||||||
i = 0
|
i = 0
|
||||||
while (i < len(fileContent)):
|
while i < len(fileContent):
|
||||||
tmp = struct.unpack_from("BBBB", fileContent, i)
|
tmp = struct.unpack_from("BBBB", fileContent, i)
|
||||||
struct.pack_into("BBBB", fileContent, i + 0, tmp[3], tmp[2], tmp[1], tmp[0])
|
struct.pack_into("BBBB", fileContent, i + 0, tmp[3], tmp[2], tmp[1], tmp[0])
|
||||||
i += 4
|
i += 4
|
||||||
|
|
||||||
perc = float(i) / float(len(fileContent))
|
perc = float(i) / float(len(fileContent))
|
||||||
|
|
||||||
if (i % (1024 * 1024 * 4) == 0):
|
if i % (1024 * 1024 * 4) == 0:
|
||||||
print(str(perc * 100) + "%")
|
print(str(perc * 100) + "%")
|
||||||
|
|
||||||
print("Byte swapping done.")
|
print("Byte swapping done.")
|
||||||
|
@ -50,10 +59,10 @@ print("Patching header...")
|
||||||
strippedContent[0x3E] = 0x50
|
strippedContent[0x3E] = 0x50
|
||||||
|
|
||||||
# Check to see if the ROM is a "vanilla" Debug ROM
|
# Check to see if the ROM is a "vanilla" Debug ROM
|
||||||
md5Hash = hashlib.md5(bytes(strippedContent)).hexdigest()
|
str_hash = get_str_hash(strippedContent)
|
||||||
|
if str_hash != "f0b7f35375f9cc8ca1b2d59d78e35405":
|
||||||
if (str(md5Hash) != "f0b7f35375f9cc8ca1b2d59d78e35405"):
|
print("Error: Expected a hash of f0b7f35375f9cc8ca1b2d59d78e35405 but got " + str_hash + ". " +
|
||||||
print("Error: Expected a hash of f0b7f35375f9cc8ca1b2d59d78e35405 but got " + str(md5Hash) + ". The baserom has probably been tampered, find a new one")
|
"The baserom has probably been tampered, find a new one")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Write out our new ROM
|
# Write out our new ROM
|
||||||
|
@ -62,4 +71,3 @@ with open("baserom.z64", mode="wb") as file:
|
||||||
file.write(bytes(strippedContent))
|
file.write(bytes(strippedContent))
|
||||||
|
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue