mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 06:13:45 -07:00
Update extract_assets.py
This commit is contained in:
parent
2f9519227e
commit
c349ac60f2
1 changed files with 99 additions and 14 deletions
|
@ -1,16 +1,44 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse, json, os, signal, time, sys, shutil
|
import argparse, json, os, signal, time, sys, shutil, glob
|
||||||
from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError
|
from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError
|
||||||
|
from enum import Enum
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
romPath = "..\\soh\\baserom_non_mq.z64"
|
romVer = "..\\soh\\baserom_non_mq.z64"
|
||||||
|
roms = [];
|
||||||
|
checksums = ["", "", ""];
|
||||||
|
|
||||||
def BuildOTR(xmlPath):
|
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):
|
||||||
shutil.copytree("assets", "Extract/assets")
|
shutil.copytree("assets", "Extract/assets")
|
||||||
|
|
||||||
execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out"
|
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, romPath)
|
execStr += " ed -i %s -b %s -fl CFG\\filelists -o placeholder -osf placeholder -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath, rom)
|
||||||
|
|
||||||
print(execStr)
|
print(execStr)
|
||||||
exitValue = os.system(execStr)
|
exitValue = os.system(execStr)
|
||||||
|
@ -20,24 +48,81 @@ def BuildOTR(xmlPath):
|
||||||
print("Aborting...", file=os.sys.stderr)
|
print("Aborting...", file=os.sys.stderr)
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
|
def checkChecksum(rom):
|
||||||
|
r = open(rom, "rb")
|
||||||
|
r.seek(16)
|
||||||
|
bytes = r.read(4).hex().upper()
|
||||||
|
r.close()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="baserom asset extractor")
|
parser = argparse.ArgumentParser(description="baserom asset extractor")
|
||||||
parser.add_argument("-v", "--version", help="Sets game version.")
|
parser.add_argument("-v", "--version", help="Sets game version.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# TODO: Read from makerom file to automatically determine game version
|
romToUse = "";
|
||||||
xmlVer = "GC_NMQ_D"
|
|
||||||
|
for file in glob.glob("*.z64"):
|
||||||
if (args.version == "gc_pal_nmpq"):
|
roms.append(file)
|
||||||
xmlVer = "GC_NMQ_PAL_F"
|
|
||||||
elif (args.version == "dbg_mq"):
|
if not (roms):
|
||||||
xmlVer = "GC_MQ_D"
|
print("Error: No roms located, place one in the OTRExporter directory", file=os.sys.stderr)
|
||||||
romPath = "..\\soh\\baserom_mq.z64"
|
sys.exit(1)
|
||||||
|
|
||||||
|
if (len(roms) > 1):
|
||||||
|
|
||||||
|
print(str(len(roms))+" roms found, please select one by pressing 1-"+str(len(roms)))
|
||||||
|
|
||||||
|
for list in range(len(roms)):
|
||||||
|
print(roms[list])
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
validRom = checkChecksum(romToUse)
|
||||||
|
|
||||||
|
match validRom.name:
|
||||||
|
case Checksums.OOT_PAL_GC:
|
||||||
|
xmlVer = "GC_NMQ_PAL_F"
|
||||||
|
case Checksums.OOT_PAL_GC_DBG1:
|
||||||
|
xmlVer = "GC_MQ_D"
|
||||||
|
case _: # default case
|
||||||
|
xmlVer = "GC_NMQ_D"
|
||||||
|
|
||||||
if (os.path.exists("Extract")):
|
if (os.path.exists("Extract")):
|
||||||
shutil.rmtree("Extract")
|
shutil.rmtree("Extract")
|
||||||
|
|
||||||
BuildOTR("..\\soh\\assets\\xml\\" + xmlVer + "\\")
|
BuildOTR("..\\soh\\assets\\xml\\" + xmlVer + "\\", romToUse)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue