added main.dol patch for lecode, and optionnally region, server url and section (cheat code)

This commit is contained in:
Faraphel 2022-07-14 17:06:59 +02:00
parent ce30419f8c
commit 5ddae33393
6 changed files with 51 additions and 11 deletions

View file

@ -0,0 +1,8 @@
{
"mode": "edit",
"operation": {
"str-edit": {
"region": "5500"
}
}
}

View file

@ -4,11 +4,6 @@
"nickname": "MKWF",
"variant": "60",
"region": {
"default": 5500,
"cheat": 20061
},
"tags_prefix": {
"MSRDS": "green",
"CTR": "YOR4",

View file

@ -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 {}

View file

@ -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

View file

@ -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)