From db87f6cdd70946ccd43fb0a84a6415e42b060c56 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 19 Jul 2022 13:42:49 +0200 Subject: [PATCH] added LECODE patching (the installer can now output a working game) --- source/mkw/ExtractedGame.py | 25 ++++++++++++++++++++++++- source/mkw/Game.py | 3 +-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/source/mkw/ExtractedGame.py b/source/mkw/ExtractedGame.py index 5bfa035..565f3c4 100644 --- a/source/mkw/ExtractedGame.py +++ b/source/mkw/ExtractedGame.py @@ -5,7 +5,7 @@ from typing import Generator, IO from source.mkw.ModConfig import ModConfig from source.mkw.Patch.Patch import Patch -from source.wt import szs +from source.wt import szs, lec from source.wt.wstrt import StrPath @@ -79,6 +79,29 @@ class ExtractedGame: szs.create(extracted_szs, extracted_szs.with_suffix(".szs"), overwrite=True) shutil.rmtree(str(extracted_szs.resolve())) + def patch_lecode(self, mod_config: ModConfig, cache_directory: Path | str) -> Generator[dict, None, None]: + """ + install lecode on the mod + :param cache_directory: Path to the cache + :param mod_config: mod configuration + """ + yield {"description": "Patching LECODE.bin"} + cache_directory = Path(cache_directory) + + # write ctfile data to a file in the cache + ct_file = (cache_directory / "ctfile.lpar") + ct_file.write_text(mod_config.get_ctfile()) + + # TODO: the lpar file should be customizable + for lecode_file in (self.path / "files/rel/").glob("lecode-*.bin"): + lec.patch( + lecode_file=lecode_file, + ct_file=ct_file, + lpar=mod_config.path.parent / "_LPAR/normal.lpar", + game_tracks_directory=self.path / "files/Race/Course/", + copy_tracks_directories=[cache_directory / "original-tracks/", cache_directory / "custom-tracks/"] + ) + def install_all_patch(self, mod_config: ModConfig) -> Generator[dict, None, None]: """ Install all patchs of the mod_config into the game diff --git a/source/mkw/Game.py b/source/mkw/Game.py index 3df687f..5503102 100644 --- a/source/mkw/Game.py +++ b/source/mkw/Game.py @@ -120,10 +120,9 @@ class Game: yield from extracted_game.extract_original_tracks(cache_ogtracks_directory) yield from mod_config.normalize_all_tracks(cache_autoadd_directory, cache_cttracks_directory, 8) - print(mod_config.get_ctfile()) - # patch the game yield from extracted_game.prepare_dol() yield from extracted_game.install_all_patch(mod_config) yield from extracted_game.recreate_all_szs() + yield from extracted_game.patch_lecode(mod_config, cache_directory)