From 6d9f00cb46619aad3a2b52ff13263506c107af92 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Sun, 23 Jul 2023 13:18:19 -0700 Subject: [PATCH] extract_game_assets.py: fix 'make assets' (#384) --- Makefile | 2 +- tools/extract_game_assets.py | 10 +++++++--- tools/tp.py | 5 +---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7bc7b99dd91..2be60e2b283 100644 --- a/Makefile +++ b/Makefile @@ -154,7 +154,7 @@ tools: dirs $(ELF2DOL) $(YAZ0) assets: @mkdir -p game - @cd game; $(PYTHON) ../tools/extract_game_assets.py ../$(IMAGENAME) + $(PYTHON) tools/extract_game_assets.py $(IMAGENAME) game docs: $(DOXYGEN) Doxyfile diff --git a/tools/extract_game_assets.py b/tools/extract_game_assets.py index 428ae430a5e..1cfdf6ee30a 100644 --- a/tools/extract_game_assets.py +++ b/tools/extract_game_assets.py @@ -231,7 +231,7 @@ def getDolInfo(disc): return dolOffset, dolSize -def extract(path,yaz0Encoder): +def extract(isoPath: Path, gamePath: Path, yaz0Encoder): if yaz0Encoder == "oead": try: from oead import yaz0 @@ -239,7 +239,10 @@ def extract(path,yaz0Encoder): yaz0DecompressFunction = yaz0.decompress except: print("Extract: oead isn't installed, falling back to native yaz0") - with open(path, "rb") as f: + isoPath = isoPath.absolute() + cwd = os.getcwd() + os.chdir(gamePath) + with open(isoPath, "rb") as f: # Seek to fst offset information and retrieve it f.seek(fstInfoPosition) fstOffset, fstSize = getFstInfo(f, fstInfoPosition) @@ -272,10 +275,11 @@ def extract(path,yaz0Encoder): # Write assets to file writeAssets(parsedFstBin, f) + os.chdir(cwd) def main(): - extract(sys.argv[1],"native") + extract(Path(sys.argv[1]), Path(sys.argv[2]), "native") if __name__ == "__main__": diff --git a/tools/tp.py b/tools/tp.py index b504d98a0b7..f0fd6e6914d 100644 --- a/tools/tp.py +++ b/tools/tp.py @@ -337,10 +337,7 @@ def setup(debug: bool, game_path: Path, tools_path: Path, yaz0_encoder: str, for try: import extract_game_assets - previous_dir = os.getcwd() - os.chdir(str(game_path.absolute())) - extract_game_assets.extract("../" + str(iso),yaz0_encoder) - os.chdir(previous_dir) + extract_game_assets.extract(iso, game_path, yaz0_encoder) except ImportError as ex: _handle_import_error(ex) except Exception as e: