2022-03-21 21:53:02 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-05-11 13:18:24 -04:00
|
|
|
import os, sys, shutil
|
2022-03-21 21:53:02 -04:00
|
|
|
import shutil
|
2022-05-11 13:18:24 -04:00
|
|
|
from rom_info import Z64Rom
|
|
|
|
import rom_chooser
|
2022-07-18 19:33:36 -04:00
|
|
|
import struct
|
2022-07-21 19:12:43 -04:00
|
|
|
import subprocess
|
2022-08-16 03:34:30 -04:00
|
|
|
import argparse
|
2022-04-19 13:16:06 -04:00
|
|
|
|
2023-04-14 09:54:56 -04:00
|
|
|
def BuildOTR(xmlPath, rom, zapd_exe=None, genHeaders=None):
|
2022-03-21 21:53:02 -04:00
|
|
|
shutil.copytree("assets", "Extract/assets")
|
|
|
|
|
2022-08-16 03:34:30 -04:00
|
|
|
if not zapd_exe:
|
|
|
|
zapd_exe = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out"
|
|
|
|
|
2022-07-21 19:12:43 -04:00
|
|
|
exec_cmd = [zapd_exe, "ed", "-i", xmlPath, "-b", rom, "-fl", "CFG/filelists",
|
2023-04-14 09:54:56 -04:00
|
|
|
"-o", "placeholder", "-osf", "placeholder", "-rconf", "CFG/Config.xml"]
|
|
|
|
|
|
|
|
# generate headers, but not otrs by excluding the otr exporter
|
|
|
|
if genHeaders:
|
|
|
|
exec_cmd.extend(["-gsf", "1"])
|
|
|
|
else:
|
|
|
|
# generate otrs, but not headers
|
|
|
|
exec_cmd.extend(["-gsf", "0", "-se", "OTR", "--otrfile",
|
|
|
|
"oot-mq.otr" if Z64Rom.isMqRom(rom) else "oot.otr"])
|
2022-03-21 21:53:02 -04:00
|
|
|
|
2022-07-21 19:12:43 -04:00
|
|
|
print(exec_cmd)
|
|
|
|
exitValue = subprocess.call(exec_cmd)
|
2022-03-21 21:53:02 -04:00
|
|
|
if exitValue != 0:
|
|
|
|
print("\n")
|
|
|
|
print("Error when building the OTR file...", file=os.sys.stderr)
|
|
|
|
print("Aborting...", file=os.sys.stderr)
|
|
|
|
print("\n")
|
|
|
|
|
2023-08-15 20:26:23 -04:00
|
|
|
def BuildSohOtr(zapd_exe=None):
|
|
|
|
shutil.copytree("assets", "Extract/assets")
|
|
|
|
|
|
|
|
if not zapd_exe:
|
|
|
|
zapd_exe = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out"
|
|
|
|
|
|
|
|
exec_cmd = [zapd_exe, "botr", "-se", "OTR", "--norom"]
|
|
|
|
|
|
|
|
print(exec_cmd)
|
|
|
|
exitValue = subprocess.call(exec_cmd)
|
|
|
|
if exitValue != 0:
|
|
|
|
print("\n")
|
|
|
|
print("Error when building soh.otr file...", file=os.sys.stderr)
|
|
|
|
print("Aborting...", file=os.sys.stderr)
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-19 13:16:06 -04:00
|
|
|
def main():
|
2022-08-16 03:34:30 -04:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-z", "--zapd", help="Path to ZAPD executable", dest="zapd_exe", type=str)
|
|
|
|
parser.add_argument("rom", help="Path to the rom", type=str, nargs="?")
|
2022-10-16 23:07:35 -04:00
|
|
|
parser.add_argument("--non-interactive", help="Runs the script non-interactively for use in build scripts.", dest="non_interactive", action="store_true")
|
2023-01-17 17:05:24 -05:00
|
|
|
parser.add_argument("-v", "--verbose", help="Display rom's header checksums and their corresponding xml folder", dest="verbose", action="store_true")
|
2023-04-14 09:54:56 -04:00
|
|
|
parser.add_argument("--gen-headers", help="Generate source headers to be checked in", dest="gen_headers", action="store_true")
|
2023-08-15 20:26:23 -04:00
|
|
|
parser.add_argument("--norom", help="Generate only soh.otr to be bundled to the game", dest="norom", action="store_true")
|
2022-08-16 03:34:30 -04:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-08-15 20:26:23 -04:00
|
|
|
if args.norom:
|
|
|
|
if (os.path.exists("Extract")):
|
|
|
|
shutil.rmtree("Extract")
|
|
|
|
|
|
|
|
BuildSohOtr(args.zapd_exe)
|
|
|
|
return
|
|
|
|
|
2023-01-17 17:05:24 -05:00
|
|
|
roms = [ Z64Rom(args.rom) ] if args.rom else rom_chooser.chooseROM(args.verbose, args.non_interactive)
|
|
|
|
for rom in roms:
|
2022-10-16 23:07:35 -04:00
|
|
|
if (os.path.exists("Extract")):
|
|
|
|
shutil.rmtree("Extract")
|
2022-05-11 13:18:24 -04:00
|
|
|
|
2023-04-14 09:54:56 -04:00
|
|
|
BuildOTR("../soh/assets/xml/" + rom.version.xml_ver + "/", rom.file_path, zapd_exe=args.zapd_exe, genHeaders=args.gen_headers)
|
2022-03-21 21:53:02 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-04-19 13:16:06 -04:00
|
|
|
main()
|