implemented patch function in lec

This commit is contained in:
Faraphel 2022-07-18 23:58:39 +02:00
parent 92ea7be730
commit ea35b09f44
2 changed files with 22 additions and 17 deletions

View file

@ -111,14 +111,18 @@ class Game:
# extract the game # extract the game
yield from self.extract(extracted_game.path) yield from self.extract(extracted_game.path)
# install mystuff
yield from extracted_game.install_mystuff()
# prepare the cache # prepare the cache
# TODO: normalize all tracks should get the threads amount changeable # TODO: normalize all tracks should get the threads amount changeable
yield from extracted_game.extract_autoadd(cache_autoadd_directory) yield from extracted_game.extract_autoadd(cache_autoadd_directory)
yield from extracted_game.extract_original_tracks(cache_ogtracks_directory) yield from extracted_game.extract_original_tracks(cache_ogtracks_directory)
yield from mod_config.normalize_all_tracks(cache_autoadd_directory, cache_cttracks_directory) yield from mod_config.normalize_all_tracks(cache_autoadd_directory, cache_cttracks_directory, 8)
print(mod_config.get_ctfile())
# patch the game # patch the game
yield from extracted_game.install_mystuff()
yield from extracted_game.prepare_dol() yield from extracted_game.prepare_dol()
yield from extracted_game.install_all_patch(mod_config) yield from extracted_game.install_all_patch(mod_config)
yield from extracted_game.recreate_all_szs() yield from extracted_game.recreate_all_szs()

View file

@ -4,28 +4,29 @@ tools_path = tools_szs_dir / "wlect"
_tools_run = get_tools_run_function(tools_path) _tools_run = get_tools_run_function(tools_path)
_tools_run_popen = get_tools_run_popen_function(tools_path)
def patch_data(lecode_data: bytes, game_tracks_directory: Path | str, def patch(lecode_file: "Path | str", ct_file: Path | str, lpar: Path | str,
copy_tracks_directory: Path | str, move_tracks_directory: Path | str, game_tracks_directory: Path | str = None,
ct_file: Path | str, lpar: Path | str) -> bytes: copy_tracks_directories: list[Path | str] = None,
move_tracks_directories: list[Path | str] = None,
) -> Path:
""" """
Patch a LECODE.bin file content Patch a LECODE.bin file content
:param lpar: parameter that can be applied to the lecode configuration :param lpar: parameter that can be applied to the lecode configuration
:param ct_file: file defining track and arena slots :param ct_file: file defining track and arena slots
:param move_tracks_directory: tracks to move inside the game :param move_tracks_directories: tracks to move inside the game
:param copy_tracks_directory: tracks to copy inside the game :param copy_tracks_directories: tracks to copy inside the game
:param game_tracks_directory: directory to all the game tracks :param game_tracks_directory: directory to all the game tracks
:param lecode_data: LECODE.bin file content :param lecode_file: LECODE.bin file
:return: patched LECODE.bin file content :return: path to the patched LECODE file
""" """
args = [] args = []
# TODO: implement args if game_tracks_directory is not None: args.extend(["--track-dir", game_tracks_directory])
for copy_tracks_directory in copy_tracks_directories if copy_tracks_directories is not None else []:
args.extend(["--copy-tracks", copy_tracks_directory])
for move_tracks_directory in move_tracks_directories if move_tracks_directories is not None else []:
args.extend(["--move-tracks", move_tracks_directory])
process = _tools_run_popen("PATCH", "-", "--DEST", "-", *args) _tools_run("PATCH", lecode_file, "--le-define", ct_file, "--lpar", lpar, "--overwrite", *args)
stdout, _ = process.communicate(input=lecode_data) return Path(lecode_file)
if process.returncode != 0:
raise WTError(tools_path, process.returncode)
return stdout