2022-03-21 21:53:02 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
# How to use:
|
|
|
|
# Place a rom in this directory then run the script.
|
|
|
|
# If you are using multiple roms, the script will let you choose one.
|
|
|
|
# To choose with a commandline argument:
|
|
|
|
# Python3 extract_assets.py <number>
|
|
|
|
# Invalid input results in the first rom being selected
|
|
|
|
|
|
|
|
import json, os, signal, time, sys, shutil, glob
|
2022-03-21 21:53:02 -04:00
|
|
|
from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError
|
2022-04-19 13:16:06 -04:00
|
|
|
from enum import Enum
|
2022-03-21 21:53:02 -04:00
|
|
|
import shutil
|
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
romVer = "..\\soh\\baserom_non_mq.z64"
|
|
|
|
roms = [];
|
|
|
|
checksums = ["", "", ""];
|
|
|
|
|
|
|
|
class Checksums(Enum):
|
|
|
|
OOT_NTSC_10 = "EC7011B7"
|
|
|
|
OOT_NTSC_11 = "D43DA81F"
|
|
|
|
OOT_NTSC_12 = "693BA2AE"
|
|
|
|
OOT_PAL_10 = "B044B569"
|
|
|
|
OOT_PAL_11 = "B2055FBD"
|
|
|
|
OOT_NTSC_JP_GC_CE = "F7F52DB8"
|
|
|
|
OOT_NTSC_JP_GC = "F611F4BA"
|
|
|
|
OOT_NTSC_US_GC = "F3DD35BA"
|
|
|
|
OOT_PAL_GC = "09465AC3"
|
|
|
|
OOT_NTSC_JP_MQ = "F43B45BA"
|
|
|
|
OOT_NTSC_US_MQ = "F034001A"
|
|
|
|
OOT_PAL_MQ = "1D4136F3"
|
|
|
|
OOT_PAL_GC_DBG1 = "871E1C92"
|
|
|
|
OOT_PAL_GC_DBG2 = "87121EFE"
|
|
|
|
OOT_PAL_GC_MQ_DBG = "917D18F6"
|
|
|
|
OOT_IQUE_TW = "3D81FB3E"
|
|
|
|
OOT_IQUE_CN = "B1E1E07B"
|
|
|
|
OOT_UNKNOWN = "FFFFFFFF"
|
|
|
|
|
|
|
|
CompatibleChecksums = [
|
|
|
|
Checksums.OOT_PAL_GC,
|
|
|
|
Checksums.OOT_PAL_GC_DBG1
|
|
|
|
]
|
|
|
|
|
|
|
|
def BuildOTR(xmlPath, rom):
|
2022-03-21 21:53:02 -04:00
|
|
|
shutil.copytree("assets", "Extract/assets")
|
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out"
|
|
|
|
execStr += " ed -i %s -b %s -fl CFG\\filelists -o placeholder -osf placeholder -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath, rom)
|
2022-03-21 21:53:02 -04:00
|
|
|
|
|
|
|
print(execStr)
|
|
|
|
exitValue = os.system(execStr)
|
|
|
|
if exitValue != 0:
|
|
|
|
print("\n")
|
|
|
|
print("Error when building the OTR file...", file=os.sys.stderr)
|
|
|
|
print("Aborting...", file=os.sys.stderr)
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
def checkChecksum(rom):
|
|
|
|
r = open(rom, "rb")
|
|
|
|
r.seek(16)
|
|
|
|
bytes = r.read(4).hex().upper()
|
|
|
|
r.close()
|
2022-04-03 15:48:44 -04:00
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
for checksum in Checksums:
|
|
|
|
if (checksum.value == bytes):
|
|
|
|
|
|
|
|
for compat in CompatibleChecksums:
|
|
|
|
if (checksum.name == compat.name):
|
|
|
|
print("Compatible rom found!")
|
|
|
|
return checksum
|
|
|
|
print("Valid oot rom found. However, not compatible with SoH.")
|
|
|
|
print("Compatible roms:")
|
|
|
|
for compat in CompatibleChecksums:
|
|
|
|
print(compat.name+" | 0x"+compat.value)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print("Wrong rom! No valid checksum found")
|
|
|
|
sys.exit(1)
|
2022-03-31 19:42:44 -04:00
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
def main():
|
|
|
|
|
|
|
|
romToUse = "";
|
|
|
|
|
|
|
|
for file in glob.glob("*.z64"):
|
|
|
|
roms.append(file)
|
|
|
|
|
|
|
|
if not (roms):
|
|
|
|
print("Error: No roms located, place one in the OTRExporter directory", file=os.sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if (len(roms) > 1):
|
|
|
|
|
|
|
|
# If commandline args exist
|
|
|
|
if (len(sys.argv) > 1):
|
|
|
|
try:
|
|
|
|
if ((int(sys.argv[1]) - 1) < 1):
|
|
|
|
romToUse = roms[0]
|
|
|
|
|
|
|
|
elif ((int(sys.argv[1]) - 1) > len(roms)):
|
|
|
|
romToUse = roms[len(roms) - 1]
|
|
|
|
|
|
|
|
else:
|
|
|
|
romToUse = roms[int(sys.argv[1]) - 1]
|
|
|
|
except:
|
|
|
|
romToUse = roms[0]
|
|
|
|
|
|
|
|
# No commandline args, select rom using user input
|
|
|
|
else:
|
|
|
|
|
|
|
|
print(str(len(roms))+" roms found, please select one by pressing 1-"+str(len(roms)))
|
|
|
|
|
|
|
|
count = 1
|
|
|
|
for list in range(len(roms)):
|
|
|
|
print(str(count)+". "+roms[list])
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
while(1):
|
|
|
|
try:
|
|
|
|
selection = int(input())
|
|
|
|
except:
|
|
|
|
print("Bad input. Try again with the number keys.")
|
|
|
|
continue
|
|
|
|
|
|
|
|
if (selection < 1 or selection > len(roms)):
|
|
|
|
print("Bad input. Try again.")
|
|
|
|
continue
|
|
|
|
|
|
|
|
else: break
|
|
|
|
|
|
|
|
romToUse = roms[selection - 1]
|
|
|
|
|
|
|
|
else:
|
|
|
|
romToUse = roms[0]
|
|
|
|
|
2022-04-24 17:10:38 -04:00
|
|
|
match checkChecksum(romToUse):
|
2022-04-19 13:16:06 -04:00
|
|
|
case Checksums.OOT_PAL_GC:
|
|
|
|
xmlVer = "GC_NMQ_PAL_F"
|
|
|
|
case Checksums.OOT_PAL_GC_DBG1:
|
|
|
|
xmlVer = "GC_NMQ_D"
|
2022-04-24 17:10:38 -04:00
|
|
|
case _: # default case
|
|
|
|
xmlVer = "GC_MQ_D"
|
2022-03-31 19:42:44 -04:00
|
|
|
|
2022-04-03 15:48:44 -04:00
|
|
|
if (os.path.exists("Extract")):
|
2022-03-21 21:53:02 -04:00
|
|
|
shutil.rmtree("Extract")
|
2022-04-03 15:48:44 -04:00
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
BuildOTR("..\\soh\\assets\\xml\\" + xmlVer + "\\", romToUse)
|
2022-03-21 21:53:02 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-04-19 13:16:06 -04:00
|
|
|
main()
|