From 3e74c336279d2218c297accfe715878b794619c6 Mon Sep 17 00:00:00 2001 From: Jack Walker <7463599+Jack-Walker@users.noreply.github.com> Date: Fri, 27 Mar 2020 22:30:19 -0400 Subject: [PATCH 1/5] Added 'extract' target to makefile Created a THANKS.md file for credits. Updated checksum.md5 for a "vanilla" debug ROM Added fixbaserom.py which automatically removes the overdump, byte swaps, and patches the ROM header. --- .gitignore | 2 ++ THANKS.md | 1 + checksum.md5 | 2 +- checksum_old.md5 | 1 + fixbaserom.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 5 +++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 THANKS.md create mode 100644 checksum_old.md5 create mode 100644 fixbaserom.py diff --git a/.gitignore b/.gitignore index a01307c6b1..5f1493e3eb 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ baserom/ *.elf *.sra *.z64 +*.n64 +*.v64 *.map *.dump out.txt diff --git a/THANKS.md b/THANKS.md new file mode 100644 index 0000000000..13b9dbc43e --- /dev/null +++ b/THANKS.md @@ -0,0 +1 @@ +Thanks to z64me and CrookedPoe for their actor documentation. https://github.com/CrookedPoe/z64-rw \ No newline at end of file diff --git a/checksum.md5 b/checksum.md5 index 98da4b6798..4483a7ce34 100644 --- a/checksum.md5 +++ b/checksum.md5 @@ -1 +1 @@ -717179476af84133b14ff73af87db57a zelda_ocarina_mq_dbg.z64 +f0b7f35375f9cc8ca1b2d59d78e35405 zelda_ocarina_mq_dbg.z64 \ No newline at end of file diff --git a/checksum_old.md5 b/checksum_old.md5 new file mode 100644 index 0000000000..98da4b6798 --- /dev/null +++ b/checksum_old.md5 @@ -0,0 +1 @@ +717179476af84133b14ff73af87db57a zelda_ocarina_mq_dbg.z64 diff --git a/fixbaserom.py b/fixbaserom.py new file mode 100644 index 0000000000..cc06d78d3a --- /dev/null +++ b/fixbaserom.py @@ -0,0 +1,50 @@ +import os.path +from os import path +import sys +import struct + +# Read in the original ROM +if (path.exists("baserom_original.z64")): + print("File 'baserom_original.z64' found.") + with open("baserom_original.z64", mode='rb') as file: + fileContent = file.read() +elif (path.exists("baserom_original.n64")): + print("File 'baserom_original.n64' found.") + print("Byte swapping...") + with open("baserom_original.n64", mode='rb') as file: + fileContent = bytearray(file.read()) + + # Byte Swap ROM + # TODO: This is pretty slow at the moment. Look into optimizing it later... + i = 0 + while (i < len(fileContent)): + tmp = struct.unpack_from("BBBB", fileContent, i) + struct.pack_into("BBBB", fileContent, i + 0, tmp[3], tmp[2], tmp[1], tmp[0]) + i += 4 + + perc = float(i) / float(len(fileContent)) + + if (i % (1024 * 1024 * 4) == 0): + print(str(perc * 100) + "%") + + print("Byte swapping done.") +else: + print("Error: Could not find a baserom_original.z64 or baserom_original.n64.") + sys.exit(1) + +# Strip the overdump +print("Stripping overdump...") +strippedContent = list(fileContent[0:0x3600000]) + +# Patch the header +print("Patching header...") +strippedContent[0x3E] = 0x50 + + +# Write out our new ROM +print("Writing new ROM 'baserom.z64'.") +with open("baserom.z64", mode="wb") as file: + file.write(bytes(strippedContent)) + +print("Done!") + diff --git a/makefile b/makefile index 55ba473563..0702023fac 100644 --- a/makefile +++ b/makefile @@ -129,6 +129,11 @@ build/undefined_syms.txt: undefined_syms.txt clean: $(RM) $(ROM) $(ELF) -r build +extract: + make -C tools + python3 fixbaserom.py + python3 extract_baserom.py + python3 extract_assets.py #### Various Recipes #### From ba929118337024bf3b1c3f7c83f4073562087ecf Mon Sep 17 00:00:00 2001 From: Jack Walker <7463599+Jack-Walker@users.noreply.github.com> Date: Sat, 28 Mar 2020 00:03:01 -0400 Subject: [PATCH 2/5] Forgot to save updated readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 47df5289e6..2b6ebcdbb1 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,4 @@ This is a disassembly and decompilation of Legend of Zelda: Ocarina of Time Mast It builds the following ROM: * zelda_ocarina_mq_dbg.z64 `md5: 717179476af84133b14ff73af87db57a` -Please refer to the Getting Started guide in the Wiki for setup instructions. - -Thanks to z64me and CrookedPoe for their actor documentation. https://github.com/CrookedPoe/z64-rw +Please refer to the Getting Started guide in the Wiki for setup instructions. \ No newline at end of file From ec37636a7a764dcb0cca3bfe6a463855b91127ab Mon Sep 17 00:00:00 2001 From: Jack Walker <7463599+Jack-Walker@users.noreply.github.com> Date: Sat, 28 Mar 2020 17:34:57 -0400 Subject: [PATCH 3/5] Updated jenkins file, readme, and replaced 'extract' target with 'setup' --- Jenkinsfile | 6 ++---- README.md | 2 +- checksum_old.md5 | 1 - makefile | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) delete mode 100644 checksum_old.md5 diff --git a/Jenkinsfile b/Jenkinsfile index 2247df2d6a..b7845d0b77 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,13 +5,11 @@ pipeline { stage('Setup') { steps { echo 'Setting up...' - sh 'cp /usr/local/etc/roms/baserom_oot.z64 baserom.z64' + sh 'cp /usr/local/etc/roms/baserom_oot.z64 baserom_original.z64' sh 'git submodule update --init --recursive' - sh 'make -C tools' sh 'cp -r /usr/local/etc/ido/ido7.1_compiler tools/ido7.1_compiler' sh 'chmod +x -R tools/ido*' - sh 'python3 extract_baserom.py' - sh 'python3 extract_assets.py' + sh 'make setup' } } stage('Build') { diff --git a/README.md b/README.md index 2b6ebcdbb1..46f963b68a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,6 @@ This repo does not include all assets necessary for compiling the ROM. A prior c This is a disassembly and decompilation of Legend of Zelda: Ocarina of Time Master Quest (debug) It builds the following ROM: -* zelda_ocarina_mq_dbg.z64 `md5: 717179476af84133b14ff73af87db57a` +* zelda_ocarina_mq_dbg.z64 `md5: f0b7f35375f9cc8ca1b2d59d78e35405` Please refer to the Getting Started guide in the Wiki for setup instructions. \ No newline at end of file diff --git a/checksum_old.md5 b/checksum_old.md5 deleted file mode 100644 index 98da4b6798..0000000000 --- a/checksum_old.md5 +++ /dev/null @@ -1 +0,0 @@ -717179476af84133b14ff73af87db57a zelda_ocarina_mq_dbg.z64 diff --git a/makefile b/makefile index 0702023fac..2272230b53 100644 --- a/makefile +++ b/makefile @@ -129,7 +129,7 @@ build/undefined_syms.txt: undefined_syms.txt clean: $(RM) $(ROM) $(ELF) -r build -extract: +setup: make -C tools python3 fixbaserom.py python3 extract_baserom.py From d780e6b13e380839b8bfc0d6395a1fb61d76abf2 Mon Sep 17 00:00:00 2001 From: Jack Walker <7463599+Jack-Walker@users.noreply.github.com> Date: Mon, 30 Mar 2020 19:38:51 -0400 Subject: [PATCH 4/5] Updated fixbaserom script - Script now checks ROM header to determine if ROM is byte swapped. - Checks the hash of the ROM to determine if it's "vanilla". --- fixbaserom.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/fixbaserom.py b/fixbaserom.py index cc06d78d3a..88c6840249 100644 --- a/fixbaserom.py +++ b/fixbaserom.py @@ -2,34 +2,33 @@ import os.path from os import path import sys import struct +import hashlib # Read in the original ROM if (path.exists("baserom_original.z64")): print("File 'baserom_original.z64' found.") with open("baserom_original.z64", mode='rb') as file: - fileContent = file.read() -elif (path.exists("baserom_original.n64")): - print("File 'baserom_original.n64' found.") - print("Byte swapping...") - with open("baserom_original.n64", mode='rb') as file: fileContent = bytearray(file.read()) - - # Byte Swap ROM - # TODO: This is pretty slow at the moment. Look into optimizing it later... - i = 0 - while (i < len(fileContent)): - tmp = struct.unpack_from("BBBB", fileContent, i) - struct.pack_into("BBBB", fileContent, i + 0, tmp[3], tmp[2], tmp[1], tmp[0]) - i += 4 - perc = float(i) / float(len(fileContent)) + # Check if ROM needs to be byte swapped + if (fileContent[0] == 0x40): + # Byte Swap ROM + # TODO: This is pretty slow at the moment. Look into optimizing it later... + print("ROM needs to be byte swapped...") + i = 0 + while (i < len(fileContent)): + tmp = struct.unpack_from("BBBB", fileContent, i) + struct.pack_into("BBBB", fileContent, i + 0, tmp[3], tmp[2], tmp[1], tmp[0]) + i += 4 - if (i % (1024 * 1024 * 4) == 0): - print(str(perc * 100) + "%") + perc = float(i) / float(len(fileContent)) + + if (i % (1024 * 1024 * 4) == 0): + print(str(perc * 100) + "%") - print("Byte swapping done.") + print("Byte swapping done.") else: - print("Error: Could not find a baserom_original.z64 or baserom_original.n64.") + print("Error: Could not find baserom_original.z64.") sys.exit(1) # Strip the overdump @@ -40,6 +39,12 @@ strippedContent = list(fileContent[0:0x3600000]) print("Patching header...") strippedContent[0x3E] = 0x50 +# Check to see if the ROM is a "vanilla" Debug ROM +md5Hash = hashlib.md5(bytearray(strippedContent)).hexdigest() + +if (str(md5Hash) != "f0b7f35375f9cc8ca1b2d59d78e35405"): + print("Error: Expected a hash of f0b7f35375f9cc8ca1b2d59d78e35405 but got " + str(md5Hash) + ". The baserom is probably not \"vanilla\"") + sys.exit(1) # Write out our new ROM print("Writing new ROM 'baserom.z64'.") From 675215417f1858dca6b1b4c1de58372804f27461 Mon Sep 17 00:00:00 2001 From: Jack Walker <7463599+Jack-Walker@users.noreply.github.com> Date: Tue, 31 Mar 2020 16:41:02 -0400 Subject: [PATCH 5/5] Updated script to check for multiple ROM extensions. --- fixbaserom.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fixbaserom.py b/fixbaserom.py index 88c6840249..3cc67be0a8 100644 --- a/fixbaserom.py +++ b/fixbaserom.py @@ -4,10 +4,18 @@ import sys import struct import hashlib -# Read in the original ROM + +# Determine if we have a ROM file +romFileName = "" if (path.exists("baserom_original.z64")): - print("File 'baserom_original.z64' found.") - with open("baserom_original.z64", mode='rb') as file: + romFileName = "baserom_original.z64" +elif (path.exists("baserom_original.n64")): + romFileName = "baserom_original.n64" + +# Read in the original ROM +if (romFileName != ""): + print("File '" + romFileName + "' found.") + with open(romFileName, mode='rb') as file: fileContent = bytearray(file.read()) # Check if ROM needs to be byte swapped @@ -28,9 +36,9 @@ if (path.exists("baserom_original.z64")): print("Byte swapping done.") else: - print("Error: Could not find baserom_original.z64.") + print("Error: Could not find baserom_original.z64/baserom_original.n64.") sys.exit(1) - + # Strip the overdump print("Stripping overdump...") strippedContent = list(fileContent[0:0x3600000])