From 5ddae33393c5e01d35315dd1336aa2badee2eefe Mon Sep 17 00:00:00 2001 From: Faraphel Date: Thu, 14 Jul 2022 17:06:59 +0200 Subject: [PATCH] added main.dol patch for lecode, and optionnally region, server url and section (cheat code) --- .../essentials/_PATCH/sys/main.dol | 0 .../essentials/_PATCH/sys/main.dol.json | 8 ++++ Pack/MKWFaraphel/mod_config.json | 5 --- source/mkw/ModConfig.py | 5 +-- source/mkw/Patch/PatchOperation.py | 41 ++++++++++++++++++- source/wt/str.py | 3 +- 6 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol create mode 100644 Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol.json diff --git a/Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol b/Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol new file mode 100644 index 0000000..e69de29 diff --git a/Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol.json b/Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol.json new file mode 100644 index 0000000..c169c96 --- /dev/null +++ b/Pack/MKWFaraphel/essentials/_PATCH/sys/main.dol.json @@ -0,0 +1,8 @@ +{ + "mode": "edit", + "operation": { + "str-edit": { + "region": "5500" + } + } +} \ No newline at end of file diff --git a/Pack/MKWFaraphel/mod_config.json b/Pack/MKWFaraphel/mod_config.json index 0d25096..f92ae74 100644 --- a/Pack/MKWFaraphel/mod_config.json +++ b/Pack/MKWFaraphel/mod_config.json @@ -4,11 +4,6 @@ "nickname": "MKWF", "variant": "60", - "region": { - "default": 5500, - "cheat": 20061 - }, - "tags_prefix": { "MSRDS": "green", "CTR": "YOR4", diff --git a/source/mkw/ModConfig.py b/source/mkw/ModConfig.py index 113ddfa..f4488e9 100644 --- a/source/mkw/ModConfig.py +++ b/source/mkw/ModConfig.py @@ -14,13 +14,13 @@ CT_ICON_SIZE: int = 128 # representation of the configuration of a mod class ModConfig: - __slots__ = ("name", "path", "nickname", "variant", "region", "tags_prefix", "tags_suffix", + __slots__ = ("name", "path", "nickname", "variant", "tags_prefix", "tags_suffix", "default_track", "_tracks", "version", "original_track_prefix", "swap_original_order", "keep_original_track", "enable_random_cup", "tags_cups", "track_formatting") def __init__(self, path: Path | str, name: str, nickname: str = None, version: str = None, variant: str = None, tags_prefix: dict[Tag, Color] = None, tags_suffix: dict[Tag, Color] = None, - tags_cups: list[Tag] = None, region: dict[int] | int = None, + tags_cups: list[Tag] = None, default_track: "Track | TrackGroup" = None, tracks: list["Track | TrackGroup"] = None, original_track_prefix: bool = None, swap_original_order: bool = None, keep_original_track: bool = None, enable_random_cup: bool = None, @@ -32,7 +32,6 @@ class ModConfig: self.nickname: str = nickname if nickname is not None else name self.version: str = version if version is not None else "v1.0.0" self.variant: str = variant if variant is not None else "01" - self.region: dict[int] | int = region if region is not None else 0 self.tags_prefix: dict[Tag] = tags_prefix if tags_prefix is not None else {} self.tags_suffix: dict[Tag] = tags_suffix if tags_suffix is not None else {} diff --git a/source/mkw/Patch/PatchOperation.py b/source/mkw/Patch/PatchOperation.py index e0d8cd1..2a32096 100644 --- a/source/mkw/Patch/PatchOperation.py +++ b/source/mkw/Patch/PatchOperation.py @@ -6,8 +6,11 @@ from typing import IO from PIL import Image, ImageDraw, ImageFont from source.mkw.Patch import * -from source.safe_eval import safe_eval from source.wt import img, bmg +from source.wt import str as wstrt + +Patch: any +Layer: any class PatchOperation: @@ -362,3 +365,39 @@ class PatchOperation: return decoded_content + "\n" + ("\n".join(new_bmg_lines)) + "\n" # add every new line to the end of the decoded_bmg, old bmg_id will be overwritten. + + class StrEditor(Operation): + """ + patch the main.dol file + """ + + type = "str-edit" + + def __init__(self, region: int = None, https: str = None, domain: str = None, sections: list[str] = None): + self.region = region + self.https = https + self.domain = domain + self.sections = sections + + def patch(self, patch: "Patch", file_name: str, file_content: IO) -> (str, IO): + checked_sections: list[Path] = [] + + for section in self.sections if self.sections is not None else []: + section_path = patch.path / section + if not section_path.is_relative_to(patch.path): + raise PathOutsidePatch(section_path, patch.path) + + checked_sections += section_path + # for every file in the sections, check if they are inside the patch. + + patch_content = BytesIO( + wstrt.patch_data( + file_content.read(), + self.region, + self.https, + self.domain, + checked_sections + ) + ) + + return file_name, patch_content diff --git a/source/wt/str.py b/source/wt/str.py index 4309f6f..e572921 100644 --- a/source/wt/str.py +++ b/source/wt/str.py @@ -7,7 +7,6 @@ _tools_run = get_tools_run_function(tools_path) _tools_run_popen = get_tools_run_popen_function(tools_path) -@better_wt_error(tools_path) def patch_data(dol_data: bytes, region: int = None, https: str = None, domain: str = None, sections: list[Path] = None) -> bytes: """ @@ -26,7 +25,7 @@ def patch_data(dol_data: bytes, region: int = None, https: str = None, domain: s for section in sections if sections is not None else []: args.extend(["--add-section", section]) - process = _tools_run_popen("PATCH", "-", "--DEST", "-", "--clean-dol", "add-lecode", *args) + process = _tools_run_popen("PATCH", "-", "--DEST", "-", "--clean-dol", "--add-lecode", *args) stdout, _ = process.communicate(input=dol_data) if process.returncode != 0: raise WTError(tools_path, process.returncode)