You've already forked Microtransactions64
mirror of
https://github.com/Print-and-Panic/Microtransactions64.git
synced 2026-01-21 10:17:19 -08:00
Global folder integration for all features that need a baserom (#677)
* Look for shared baserom directory using XDG_DATA_DIR instead of polluting the home directory * move global baserom folder detection to a new file that the makefile can use * ignore __pycache__ in tools * edit make patch to use global baserom detector * Extract jp/sh/eu from global folder too * genericize asset extraction for all versions * force at least US to extract --------- Co-authored-by: Matt Pharoah <mtpharoah@gmail.com> Co-authored-by: someone2639 <someone2639@gmail.com>
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -38,6 +38,9 @@
|
||||
# datadump
|
||||
/tools/ddump/*
|
||||
|
||||
# python cache in tools/
|
||||
/tools/__pycache__/*
|
||||
|
||||
# Text editor remnants
|
||||
*.swp
|
||||
.vscode/*
|
||||
|
||||
10
Makefile
10
Makefile
@@ -305,23 +305,23 @@ ifeq ($(filter clean distclean print-%,$(MAKECMDGOALS)),)
|
||||
# Make sure assets exist
|
||||
NOEXTRACT ?= 0
|
||||
ifeq ($(NOEXTRACT),0)
|
||||
DUMMY != $(PYTHON) extract_assets.py $(VERSION) >&2 || echo FAIL
|
||||
DUMMY != $(PYTHON) extract_assets.py us >&2 || echo FAIL
|
||||
ifeq ($(DUMMY),FAIL)
|
||||
$(error Failed to extract assets from US ROM)
|
||||
endif
|
||||
ifneq (,$(wildcard baserom.jp.z64))
|
||||
ifneq (,$(shell python3 tools/detect_baseroms.py jp))
|
||||
DUMMY != $(PYTHON) extract_assets.py jp >&2 || echo FAIL
|
||||
ifeq ($(DUMMY),FAIL)
|
||||
$(error Failed to extract assets from JP ROM)
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(wildcard baserom.eu.z64))
|
||||
ifneq (,$(shell python3 tools/detect_baseroms.py eu))
|
||||
DUMMY != $(PYTHON) extract_assets.py eu >&2 || echo FAIL
|
||||
ifeq ($(DUMMY),FAIL)
|
||||
$(error Failed to extract assets from EU ROM)
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(wildcard baserom.sh.z64))
|
||||
ifneq (,$(shell python3 tools/detect_baseroms.py sh))
|
||||
DUMMY != $(PYTHON) extract_assets.py sh >&2 || echo FAIL
|
||||
ifeq ($(DUMMY),FAIL)
|
||||
$(error Failed to extract assets from SH ROM)
|
||||
@@ -588,7 +588,7 @@ unf: $(ROM) $(LOADER)
|
||||
libultra: $(BUILD_DIR)/libultra.a
|
||||
|
||||
patch: $(ROM)
|
||||
$(FLIPS) --create --bps ./baserom.$(VERSION).z64 $(ROM) $(BUILD_DIR)/$(TARGET_STRING).bps
|
||||
$(FLIPS) --create --bps $(shell python3 tools/detect_baseroms.py $(VERSION)) $(ROM) $(BUILD_DIR)/$(TARGET_STRING).bps
|
||||
|
||||
# Extra object file dependencies
|
||||
$(BUILD_DIR)/asm/ipl3.o: $(IPL3_RAW_FILES)
|
||||
|
||||
@@ -4,56 +4,7 @@ import os
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
XDG_DATA_DIR=os.environ.get("XDG_DATA_HOME") or "~/.local/share"
|
||||
ROMS_DIR=os.path.expanduser(os.path.join(XDG_DATA_DIR, "HackerSM64"))
|
||||
|
||||
sha1_LUT = {
|
||||
"eu": "4ac5721683d0e0b6bbb561b58a71740845dceea9",
|
||||
"jp": "8a20a5c83d6ceb0f0506cfc9fa20d8f438cafe51",
|
||||
"sh": "3f319ae697533a255a1003d09202379d78d5a2e0",
|
||||
"us": "9bef1128717f958171a4afac3ed78ee2bb4e86ce",
|
||||
}
|
||||
|
||||
sha1_swapLUT = {
|
||||
"eu": "d80ee9eeb6454d53a96ceb6ed0aca3ffde045091",
|
||||
"jp": "1d2579dd5fb1d8263a4bcc063a651a64acc88921",
|
||||
"sh": "2a2b85e94581545ca3c05b8f864b488b141a8a1f",
|
||||
"us": "1002dd7b56aa0a59a9103f1fb3d57d6b161f8da7",
|
||||
}
|
||||
|
||||
def get_rom_candidates():
|
||||
fileArray = [f for f in os.listdir(os.getcwd()) if os.path.isfile(f)]
|
||||
if os.path.exists(ROMS_DIR):
|
||||
fileArray += [os.path.join(ROMS_DIR, f) for f in os.listdir(ROMS_DIR) if os.path.isfile(os.path.join(ROMS_DIR, f))]
|
||||
|
||||
foundVersions = {}
|
||||
|
||||
for f in fileArray:
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
["sha1sum", f],
|
||||
stdout=subprocess.PIPE
|
||||
)
|
||||
sha1sum = p.communicate()[0].decode('ascii').split()[0]
|
||||
for k, v in sha1_LUT.items():
|
||||
if v == sha1sum:
|
||||
foundVersions[k] = f
|
||||
|
||||
for k, v in sha1_swapLUT.items():
|
||||
if v == sha1sum: # the ROM is swapped!
|
||||
subprocess.run(
|
||||
[
|
||||
"dd","conv=swab",
|
||||
"if=%s" % f,
|
||||
"of=/tmp/baserom.%s.swapped.z64" % k
|
||||
],
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
foundVersions[k] = "/tmp/baserom.%s.swapped.z64" % k
|
||||
except Exception as e:
|
||||
continue
|
||||
return foundVersions
|
||||
|
||||
from tools.detect_baseroms import get_rom_candidates
|
||||
|
||||
def read_asset_map():
|
||||
with open("assets.json") as f:
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
flips5.cpp:2771: warning: "error" redefined
|
||||
2771 | #define error(which) do { err = which; goto error; } while(0)
|
||||
|
|
||||
flips5.cpp:2021: note: this is the location of the previous definition
|
||||
2021 | #define error(why) do { ret.error=why; return ret; } while(0)
|
||||
|
|
||||
flips5.cpp:3454: warning: "error" redefined
|
||||
3454 | #define error(which) do { error=which; goto exit; } while(0)
|
||||
|
|
||||
flips5.cpp:2771: note: this is the location of the previous definition
|
||||
2771 | #define error(which) do { err = which; goto error; } while(0)
|
||||
|
|
||||
flips5.cpp:3455: warning: "assert_sum" redefined
|
||||
3455 | #define assert_sum(a,b) do { if (SIZE_MAX-(a)<(b)) error(ups_too_big); } while(0)
|
||||
|
|
||||
flips5.cpp:1675: note: this is the location of the previous definition
|
||||
1675 | #define assert_sum(a,b) do { if (SIZE_MAX-(a)<(b)) error(bps_too_big); } while(0)
|
||||
|
|
||||
flips5.cpp:3456: warning: "assert_shift" redefined
|
||||
3456 | #define assert_shift(a,b) do { if (SIZE_MAX>>(b)<(a)) error(ups_too_big); } while(0)
|
||||
|
|
||||
flips5.cpp:1676: note: this is the location of the previous definition
|
||||
1676 | #define assert_shift(a,b) do { if (SIZE_MAX>>(b)<(a)) error(bps_too_big); } while(0)
|
||||
|
|
||||
66
tools/detect_baseroms.py
Normal file
66
tools/detect_baseroms.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
|
||||
XDG_DATA_DIR=os.environ.get("XDG_DATA_HOME") or "~/.local/share"
|
||||
ROMS_DIR=os.path.expanduser(os.path.join(XDG_DATA_DIR, "HackerSM64"))
|
||||
|
||||
sha1_LUT = {
|
||||
"eu": "4ac5721683d0e0b6bbb561b58a71740845dceea9",
|
||||
"jp": "8a20a5c83d6ceb0f0506cfc9fa20d8f438cafe51",
|
||||
"sh": "3f319ae697533a255a1003d09202379d78d5a2e0",
|
||||
"us": "9bef1128717f958171a4afac3ed78ee2bb4e86ce",
|
||||
}
|
||||
|
||||
sha1_swapLUT = {
|
||||
"eu": "d80ee9eeb6454d53a96ceb6ed0aca3ffde045091",
|
||||
"jp": "1d2579dd5fb1d8263a4bcc063a651a64acc88921",
|
||||
"sh": "2a2b85e94581545ca3c05b8f864b488b141a8a1f",
|
||||
"us": "1002dd7b56aa0a59a9103f1fb3d57d6b161f8da7",
|
||||
}
|
||||
|
||||
def get_rom_candidates():
|
||||
fileArray = [f for f in os.listdir(os.getcwd()) if os.path.isfile(f)]
|
||||
if os.path.exists(ROMS_DIR):
|
||||
fileArray += [os.path.join(ROMS_DIR, f) for f in os.listdir(ROMS_DIR) if os.path.isfile(os.path.join(ROMS_DIR, f))]
|
||||
|
||||
foundVersions = {}
|
||||
|
||||
for f in fileArray:
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
["sha1sum", f],
|
||||
stdout=subprocess.PIPE
|
||||
)
|
||||
sha1sum = p.communicate()[0].decode('ascii').split()[0]
|
||||
for k, v in sha1_LUT.items():
|
||||
if v == sha1sum:
|
||||
foundVersions[k] = f
|
||||
|
||||
for k, v in sha1_swapLUT.items():
|
||||
if v == sha1sum: # the ROM is swapped!
|
||||
subprocess.run(
|
||||
[
|
||||
"dd","conv=swab",
|
||||
"if=%s" % f,
|
||||
"of=/tmp/baserom.%s.swapped.z64" % k
|
||||
],
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
foundVersions[k] = "/tmp/baserom.%s.swapped.z64" % k
|
||||
except Exception as e:
|
||||
continue
|
||||
return foundVersions
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: {sys.argv[0]} version (us jp eu sh)")
|
||||
sys.exit(1)
|
||||
gamelist = get_rom_candidates();
|
||||
version = sys.argv[1]
|
||||
|
||||
if version in gamelist:
|
||||
print(gamelist[version])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user