diff options
| author | Adam Bird <Archez@users.noreply.github.com> | 2023-11-04 10:34:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-04 10:34:12 -0400 |
| commit | cde9a3b655570370e4ed4928e8c9f3a0f631c52e (patch) | |
| tree | d18b5797fac91659776279050adbd4bf08ca2503 | |
| parent | f1bc0a726813d7e70ad471fdebd080e6fd77996a (diff) | |
Store port version in OTR files (#10)
* store port version in otr files
* semver numbers shouldn't be negative
| -rw-r--r-- | OTRExporter/Main.cpp | 54 | ||||
| -rwxr-xr-x | extract_assets.py | 15 |
2 files changed, 58 insertions, 11 deletions
diff --git a/OTRExporter/Main.cpp b/OTRExporter/Main.cpp index f5eff8e..b6a09cb 100644 --- a/OTRExporter/Main.cpp +++ b/OTRExporter/Main.cpp @@ -29,6 +29,7 @@ std::string otrFileName = "oot.otr"; std::string customOtrFileName = ""; std::string customAssetsPath = ""; +std::string portVersionString = "0.0.0"; std::shared_ptr<LUS::Archive> otrArchive; BinaryWriter* fileWriter; @@ -70,6 +71,37 @@ static void ExporterProgramEnd() { uint32_t crc = 0xFFFFFFFF; const uint8_t endianness = (uint8_t)Endianness::Big; + + std::vector<uint16_t> portVersion = {}; + std::vector<std::string> versionParts = StringHelper::Split(portVersionString, "."); + + // If a major.minor.patch string was not passed in, fallback to 0 0 0 + if (versionParts.size() != 3) { + portVersion = { 0, 0, 0 }; + } else { + // Parse version values to number + for (const auto& val : versionParts) { + uint16_t num = 0; + try { + num = (uint16_t)std::stoi(val, nullptr); + } catch (std::invalid_argument &e) { + num = 0; + } catch (std::out_of_range &e) { + num = 0; + } + + portVersion.push_back(num); + } + } + + MemoryStream *portVersionStream = new MemoryStream(); + BinaryWriter portVerWriter(portVersionStream); + portVerWriter.SetEndianness(Endianness::Big); + portVerWriter.Write(endianness); + portVerWriter.Write(portVersion[0]); // Major + portVerWriter.Write(portVersion[1]); // Minor + portVerWriter.Write(portVersion[2]); // Patch + portVerWriter.Close(); if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory) { @@ -95,8 +127,12 @@ static void ExporterProgramEnd() printf("Generating OTR Archive...\n"); otrArchive = LUS::Archive::CreateArchive(otrFileName, 40000); + printf("Adding game version file.\n"); otrArchive->AddFile("version", (uintptr_t)versionStream->ToVector().data(), versionStream->GetLength()); + printf("Adding portVersion file.\n"); + otrArchive->AddFile("portVersion", (uintptr_t)portVersionStream->ToVector().data(), portVersionStream->GetLength()); + for (const auto& item : files) { std::string fName = item.first; @@ -113,6 +149,7 @@ static void ExporterProgramEnd() fileData.size()); } } + otrArchive = nullptr; delete fileWriter; files.clear(); @@ -128,8 +165,12 @@ static void ExporterProgramEnd() } const auto& lst = Directory::ListFiles(customAssetsPath); + + printf("Generating Custom OTR Archive...\n"); std::shared_ptr<LUS::Archive> customOtr = LUS::Archive::CreateArchive(customOtrFileName, 4096); - //sohOtr->AddFile("version", (uintptr_t)versionStream->ToVector().data(), versionStream->GetLength()); + + printf("Adding portVersion file.\n"); + customOtr->AddFile("portVersion", (uintptr_t)portVersionStream->ToVector().data(), portVersionStream->GetLength()); for (const auto& item : lst) { @@ -193,16 +234,15 @@ static void ExporterParseArgs(int argc, char* argv[], int& i) if (arg == "--otrfile") { otrFileName = argv[i + 1]; i++; - } - - if (arg == "--customOtrFile") { + } else if (arg == "--customOtrFile") { customOtrFileName = argv[i + 1]; i++; - } - - if (arg == "--customAssetsPath") { + } else if (arg == "--customAssetsPath") { customAssetsPath = argv[i + 1]; i++; + } else if (arg == "--portVer") { + portVersionString = argv[i + 1]; + i++; } } diff --git a/extract_assets.py b/extract_assets.py index 6700410..63b64a2 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -8,7 +8,7 @@ import struct import subprocess import argparse -def BuildOTR(xmlPath, rom, zapd_exe=None, genHeaders=None, customAssetsPath=None, customOtrFile=None): +def BuildOTR(xmlPath, rom, zapd_exe=None, genHeaders=None, customAssetsPath=None, customOtrFile=None, portVer=None): if not zapd_exe: zapd_exe = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out" @@ -24,6 +24,9 @@ def BuildOTR(xmlPath, rom, zapd_exe=None, genHeaders=None, customAssetsPath=None "--customOtrFile", customOtrFile, "--otrfile", "oot-mq.otr" if Z64Rom.isMqRom(rom) else "oot.otr"]) + if portVer: + exec_cmd.extend(["--portVer", portVer]) + print(exec_cmd) exitValue = subprocess.call(exec_cmd) if exitValue != 0: @@ -32,7 +35,7 @@ def BuildOTR(xmlPath, rom, zapd_exe=None, genHeaders=None, customAssetsPath=None print("Aborting...", file=os.sys.stderr) print("\n") -def BuildCustomOtr(zapd_exe=None, assets_path=None, otrfile=None): +def BuildCustomOtr(zapd_exe=None, assets_path=None, otrfile=None, portVer=None): if not zapd_exe: zapd_exe = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out" @@ -44,6 +47,9 @@ def BuildCustomOtr(zapd_exe=None, assets_path=None, otrfile=None): exec_cmd = [zapd_exe, "botr", "-se", "OTR", "--norom", "--customAssetsPath", assets_path, "--customOtrFile", otrfile] + if portVer: + exec_cmd.extend(["--portVer", portVer]) + print(exec_cmd) exitValue = subprocess.call(exec_cmd) if exitValue != 0: @@ -63,17 +69,18 @@ def main(): parser.add_argument("--xml-root", help="Root path for the rom xmls", dest="xml_root", type=str) parser.add_argument("--custom-assets-path", help="Path to custom assets for the custom otr file", dest="custom_assets_path", type=str) parser.add_argument("--custom-otr-file", help="Name for custom otr file", dest="custom_otr_file", type=str) + parser.add_argument("--port-ver", help="Store the port version in the otr", dest="port_ver", type=str) args = parser.parse_args() if args.norom: - BuildCustomOtr(args.zapd_exe, args.custom_assets_path, args.custom_otr_file) + BuildCustomOtr(args.zapd_exe, args.custom_assets_path, args.custom_otr_file, portVer=args.port_ver) return roms = [ Z64Rom(args.rom) ] if args.rom else rom_chooser.chooseROM(args.verbose, args.non_interactive) for rom in roms: BuildOTR(os.path.join(args.xml_root, rom.version.xml_ver), rom.file_path, zapd_exe=args.zapd_exe, genHeaders=args.gen_headers, - customAssetsPath=args.custom_assets_path, customOtrFile=args.custom_otr_file) + customAssetsPath=args.custom_assets_path, customOtrFile=args.custom_otr_file, portVer=args.port_ver) if __name__ == "__main__": main() |
