wszst module wasn't working properly, removed wszst prefix when calling one of its submodule

This commit is contained in:
raphael60650 2021-07-27 21:16:43 +02:00
parent 742c1c3bfa
commit 34ec530ddf
10 changed files with 41 additions and 45 deletions

View file

@ -6,7 +6,7 @@ import json
from .CT_Config import CT_Config from .CT_Config import CT_Config
from .definition import * from .definition import *
from . import wszst from .wszst import *
class RomAlreadyPatched(Exception): class RomAlreadyPatched(Exception):
@ -104,12 +104,12 @@ class Game:
""" """
if format in ["ISO", "WBFS", "CISO"]: if format in ["ISO", "WBFS", "CISO"]:
path_game_format: str = os.path.realpath(self.path + "/../MKWFaraphel." + format.lower()) path_game_format: str = os.path.realpath(self.path + "/../MKWFaraphel." + format.lower())
wszst.wit.copy(self.path, path_game_format, format) wit.copy(self.path, path_game_format, format)
shutil.rmtree(self.path) shutil.rmtree(self.path)
self.path = path_game_format self.path = path_game_format
self.gui.progress(statut=self.gui.translate("Changing game's ID"), add=1) self.gui.progress(statut=self.gui.translate("Changing game's ID"), add=1)
wszst.wit.edit(self.path, region_ID=self.region_ID, name=f"Mario Kart Wii Faraphel {self.ctconfig.version}") wit.edit(self.path, region_ID=self.region_ID, name=f"Mario Kart Wii Faraphel {self.ctconfig.version}")
def extract(self) -> None: def extract(self) -> None:
""" """
@ -126,7 +126,7 @@ class Game:
if not (os.path.exists(path_dir)): break if not (os.path.exists(path_dir)): break
directory_name, i = f"MKWiiFaraphel ({i})", i + 1 directory_name, i = f"MKWiiFaraphel ({i})", i + 1
wszst.wit.extract(self.path, path_dir) wit.extract(self.path, path_dir)
self.path = path_dir self.path = path_dir
if os.path.exists(self.path + "/DATA"): self.path += "/DATA" if os.path.exists(self.path + "/DATA"): self.path += "/DATA"
@ -195,7 +195,7 @@ class Game:
if extension == "szs": if extension == "szs":
if not (os.path.realpath(path) in extracted_file): if not (os.path.realpath(path) in extracted_file):
wszst.szs.extract(path, get_nodir(path)) szs.extract(path, get_nodir(path))
extracted_file.append(os.path.realpath(path)) extracted_file.append(os.path.realpath(path))
szs_extract_path = path + ".d" szs_extract_path = path + ".d"
@ -223,12 +223,12 @@ class Game:
for file in extracted_file: for file in extracted_file:
self.gui.progress(statut=self.gui.translate("Recompilating", "\n", get_nodir(file)), add=1) self.gui.progress(statut=self.gui.translate("Recompilating", "\n", get_nodir(file)), add=1)
wszst.szs.create(file) szs.create(file)
if os.path.exists(file + ".d"): if os.path.exists(file + ".d"):
shutil.rmtree(file + ".d") shutil.rmtree(file + ".d")
self.gui.progress(statut=self.gui.translate("Patch main.dol"), add=1) self.gui.progress(statut=self.gui.translate("Patch main.dol"), add=1)
wszst.wstrt.patch(self.path) wstrt.patch(self.path)
self.gui.progress(statut=self.gui.translate("Patch lecode.bin"), add=1) self.gui.progress(statut=self.gui.translate("Patch lecode.bin"), add=1)
@ -238,7 +238,7 @@ class Game:
shutil.copyfile("./file/lpar-default.txt", self.path + "/tmp/lpar-default.txt") shutil.copyfile("./file/lpar-default.txt", self.path + "/tmp/lpar-default.txt")
shutil.copyfile(f"./file/lecode-{self.region}.bin", self.path + f"/tmp/lecode-{self.region}.bin") shutil.copyfile(f"./file/lecode-{self.region}.bin", self.path + f"/tmp/lecode-{self.region}.bin")
wszst.lec.patch( lec.patch(
self.path, self.path,
lecode_file=f"./tmp/lecode-{self.region}.bin", lecode_file=f"./tmp/lecode-{self.region}.bin",
dest_lecode_file=f"./files/rel/lecode-{self.region}.bin", dest_lecode_file=f"./files/rel/lecode-{self.region}.bin",
@ -263,7 +263,7 @@ class Game:
:param auto_add_dir: autoadd directory :param auto_add_dir: autoadd directory
""" """
if os.path.exists(auto_add_dir): shutil.rmtree(auto_add_dir) if os.path.exists(auto_add_dir): shutil.rmtree(auto_add_dir)
wszst.szs.autoadd(self.path, auto_add_dir) szs.autoadd(self.path, auto_add_dir)
def patch_bmg(self, gamefile: str) -> None: def patch_bmg(self, gamefile: str) -> None:
""" """
@ -291,10 +291,10 @@ class Game:
bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier
self.gui.progress(statut=self.gui.translate("Patching text", " ", bmglang), add=1) self.gui.progress(statut=self.gui.translate("Patching text", " ", bmglang), add=1)
wszst.szs.extract(gamefile, get_nodir(gamefile)) szs.extract(gamefile, get_nodir(gamefile))
bmgmenu = wszst.bmg.cat(gamefile, ".d/message/Menu.bmg") # Menu.bmg bmgmenu = bmg.cat(gamefile, ".d/message/Menu.bmg") # Menu.bmg
bmgtracks = wszst.bmg.cat(gamefile, ".d/message/Common.bmg") # Common.bmg bmgtracks = bmg.cat(gamefile, ".d/message/Common.bmg") # Common.bmg
trackheader = "#--- standard track names" trackheader = "#--- standard track names"
trackend = "2328" trackend = "2328"
@ -329,9 +329,9 @@ class Game:
f.write(f" {track_id}\t= {prefix}{track_name}\n") f.write(f" {track_id}\t= {prefix}{track_name}\n")
bmgcommon = wszst.ctc.patch_bmg(ctfile="./file/CTFILE.txt", bmgcommon = ctc.patch_bmg(ctfile="./file/CTFILE.txt",
bmgs=[gamefile + ".d/message/Common.bmg", "./file/ExtraCommon.txt"]) bmgs=[gamefile + ".d/message/Common.bmg", "./file/ExtraCommon.txt"])
rbmgcommon = wszst.ctc.patch_bmg(ctfile="./file/RCTFILE.txt", rbmgcommon = ctc.patch_bmg(ctfile="./file/RCTFILE.txt",
bmgs=[gamefile + ".d/message/Common.bmg", "./file/ExtraCommon.txt"]) bmgs=[gamefile + ".d/message/Common.bmg", "./file/ExtraCommon.txt"])
shutil.rmtree(gamefile + ".d") shutil.rmtree(gamefile + ".d")
@ -342,7 +342,7 @@ class Game:
for text, colored_text in replacement_list.items(): bmgtext = bmgtext.replace(text, colored_text) for text, colored_text in replacement_list.items(): bmgtext = bmgtext.replace(text, colored_text)
with open(file, "w", encoding="utf-8") as f: with open(file, "w", encoding="utf-8") as f:
f.write(bmgtext) f.write(bmgtext)
wszst.bmg.encode(file) bmg.encode(file)
os.remove(file) os.remove(file)
finalise(f"./file/Menu_{bmglang}.txt", bmgmenu, menu_replacement) finalise(f"./file/Menu_{bmglang}.txt", bmgmenu, menu_replacement)
@ -394,7 +394,7 @@ class Game:
for i, file in enumerate(fc["img"]): for i, file in enumerate(fc["img"]):
self.gui.progress(statut=self.gui.translate("Converting images") + f"\n({i + 1}/{len(fc['img'])}) {file}", self.gui.progress(statut=self.gui.translate("Converting images") + f"\n({i + 1}/{len(fc['img'])}) {file}",
add=1) add=1)
wszst.img.encode("./file/" + file, fc["img"][file]) img.encode("./file/" + file, fc["img"][file])
def patch_img_desc(self, img_desc_path: str = "./file/img_desc", dest_dir: str = "./file") -> None: def patch_img_desc(self, img_desc_path: str = "./file/img_desc", dest_dir: str = "./file") -> None:
""" """

View file

@ -1,7 +1,7 @@
import requests import requests
from .definition import * from .definition import *
from . import wszst from .wszst import *
class Track: class Track:
@ -60,14 +60,14 @@ class Track:
check if track wu8's sha1 is correct check if track wu8's sha1 is correct
:return: 0 if yes, -1 if no :return: 0 if yes, -1 if no
""" """
if wszst.szs.sha1(self.file_wu8) == self.sha1: return 0 if szs.sha1(self.file_wu8) == self.sha1: return 0
else: return -1 else: return -1
def convert_wu8_to_szs(self) -> None: def convert_wu8_to_szs(self) -> None:
""" """
convert track to szs convert track to szs
""" """
wszst.szs.normalize(src_file=self.file_wu8) szs.normalize(src_file=self.file_wu8)
def download_wu8(self, github_content_root: str) -> int: def download_wu8(self, github_content_root: str) -> int:
""" """

View file

@ -1,5 +1 @@
from ..definition import * __all__ = ["bmg", "ctc", "img", "lec", "wstrt", "szs", "wit"]
from subprocess import CREATE_NO_WINDOW
import subprocess
__all__ = ["bmg", "ctc", "img", "lec", "wstrt", "szs", "wit", "subprocess", "CREATE_NO_WINDOW"]

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def encode(file: str) -> None: def encode(file: str) -> None:
@ -7,7 +7,7 @@ def encode(file: str) -> None:
:param file: txt file to convert :param file: txt file to convert
""" """
subprocess.run(["./tools/szs/wbmgt", "ENCODE", file, "--overwrite"], subprocess.run(["./tools/szs/wbmgt", "ENCODE", file, "--overwrite"],
creationflags=CREATE_NO_WINDOW) creationflags=subprocess.CREATE_NO_WINDOW)
def cat(path: str, subfile: str = ".d/message/Common.bmg") -> str: def cat(path: str, subfile: str = ".d/message/Common.bmg") -> str:
@ -18,5 +18,5 @@ def cat(path: str, subfile: str = ".d/message/Common.bmg") -> str:
:return: bmg definition :return: bmg definition
""" """
return subprocess.run(["./tools/szs/wbmgt", "CAT", path + subfile], return subprocess.run(["./tools/szs/wbmgt", "CAT", path + subfile],
creationflags=CREATE_NO_WINDOW, creationflags=subprocess.CREATE_NO_WINDOW,
check=True, stdout=subprocess.PIPE).stdout.decode() check=True, stdout=subprocess.PIPE).stdout.decode()

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def ctc_patch_bmg(bmgs: list, ctfile: str = "./file/CTFILE.txt"): def ctc_patch_bmg(bmgs: list, ctfile: str = "./file/CTFILE.txt"):
@ -12,4 +12,4 @@ def ctc_patch_bmg(bmgs: list, ctfile: str = "./file/CTFILE.txt"):
for bmg in bmgs: bmg_cmd.extend(["--patch-bmg", f"OVERWRITE={bmg}"]) for bmg in bmgs: bmg_cmd.extend(["--patch-bmg", f"OVERWRITE={bmg}"])
return subprocess.run( return subprocess.run(
["tools/szs/wctct", "bmg", "--le-code", "--long", ctfile, *bmg_cmd], ["tools/szs/wctct", "bmg", "--le-code", "--long", ctfile, *bmg_cmd],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode() creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode()

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def encode(src_file: str, format: str) -> None: def encode(src_file: str, format: str) -> None:
@ -8,4 +8,4 @@ def encode(src_file: str, format: str) -> None:
:param format: new image format :param format: new image format
""" """
subprocess.run(["./tools/szs/wimgt", "ENCODE", src_file, "-x", format, "--overwrite"], subprocess.run(["./tools/szs/wimgt", "ENCODE", src_file, "-x", format, "--overwrite"],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def patch(path: str, def patch(path: str,
@ -21,4 +21,4 @@ def patch(path: str,
subprocess.run( subprocess.run(
["./tools/szs/wlect", "patch", lecode_file, "-od", dest_lecode_file, "--track-dir", game_track_path, ["./tools/szs/wlect", "patch", lecode_file, "-od", dest_lecode_file, "--track-dir", game_track_path,
"--move-tracks", move_track_path, "--le-define", ctfile_path, "--lpar", lpar_path, "--overwrite"], "--move-tracks", move_track_path, "--le-define", ctfile_path, "--lpar", lpar_path, "--overwrite"],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def extract(file: str, dest_dir: str) -> None: def extract(file: str, dest_dir: str) -> None:
@ -8,7 +8,7 @@ def extract(file: str, dest_dir: str) -> None:
:param dest_dir: directory where to extract the file :param dest_dir: directory where to extract the file
""" """
subprocess.run(["./tools/szs/wszst", "EXTRACT", file, "--DEST", dest_dir + ".d"], subprocess.run(["./tools/szs/wszst", "EXTRACT", file, "--DEST", dest_dir + ".d"],
creationflags=CREATE_NO_WINDOW) creationflags=subprocess.CREATE_NO_WINDOW)
def sha1(file, autoadd_path: str = "./file/auto-add/") -> str: def sha1(file, autoadd_path: str = "./file/auto-add/") -> str:
@ -18,7 +18,7 @@ def sha1(file, autoadd_path: str = "./file/auto-add/") -> str:
:return: track's sha1 :return: track's sha1
""" """
return subprocess.run(["./tools/szs/wszst", "SHA1", file, "--autoadd-path", autoadd_path], return subprocess.run(["./tools/szs/wszst", "SHA1", file, "--autoadd-path", autoadd_path],
check=True, creationflags=CREATE_NO_WINDOW, check=True, creationflags=subprocess.CREATE_NO_WINDOW,
stdout=subprocess.PIPE).stdout.decode().split(" ")[0] stdout=subprocess.PIPE).stdout.decode().split(" ")[0]
@ -34,7 +34,7 @@ def normalize(src_file: str, dest_dir: str = "./file/Track/", dest_name: str = "
""" """
subprocess.run(["./tools/szs/wszst", "NORMALIZE", src_file, "--DEST", dest_dir + dest_name, "--" + output_format, subprocess.run(["./tools/szs/wszst", "NORMALIZE", src_file, "--DEST", dest_dir + dest_name, "--" + output_format,
"--overwrite", "--autoadd-path", autoadd_path], "--overwrite", "--autoadd-path", autoadd_path],
creationflags=CREATE_NO_WINDOW, stderr=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, stderr=subprocess.PIPE)
def create(file: str) -> None: def create(file: str) -> None:
@ -43,7 +43,7 @@ def create(file: str) -> None:
:param file: create a .szs file from the directory {file}.d :param file: create a .szs file from the directory {file}.d
""" """
subprocess.run(["./tools/szs/wszst", "CREATE", file + ".d", "-d", file, "--overwrite"], subprocess.run(["./tools/szs/wszst", "CREATE", file + ".d", "-d", file, "--overwrite"],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)
def autoadd(file: str, dest_dir: str) -> None: def autoadd(file: str, dest_dir: str) -> None:
@ -53,4 +53,4 @@ def autoadd(file: str, dest_dir: str) -> None:
:param dest_dir: directory where to store autoadd file :param dest_dir: directory where to store autoadd file
""" """
subprocess.run(["./tools/szs/wszst", "AUTOADD", file + "/files/Race/Course/", "--DEST", dest_dir], subprocess.run(["./tools/szs/wszst", "AUTOADD", file + "/files/Race/Course/", "--DEST", dest_dir],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def extract(file: str, dest_dir: str) -> None: def extract(file: str, dest_dir: str) -> None:
@ -8,7 +8,7 @@ def extract(file: str, dest_dir: str) -> None:
:param dest_dir: where to extract the game :param dest_dir: where to extract the game
""" """
subprocess.run(["./tools/wit/wit", "EXTRACT", file, "--DEST", dest_dir], subprocess.run(["./tools/wit/wit", "EXTRACT", file, "--DEST", dest_dir],
creationflags=CREATE_NO_WINDOW) creationflags=subprocess.CREATE_NO_WINDOW)
def edit(file: str, region_ID: str = "P", name: str = "Mario Kart Wii") -> None: def edit(file: str, region_ID: str = "P", name: str = "Mario Kart Wii") -> None:
@ -20,7 +20,7 @@ def edit(file: str, region_ID: str = "P", name: str = "Mario Kart Wii") -> None:
""" """
subprocess.run( subprocess.run(
["./tools/wit/wit", "EDIT", file, "--id", f"RMC{region_ID}60", "--name", name, "--modify", "ALL"], ["./tools/wit/wit", "EDIT", file, "--id", f"RMC{region_ID}60", "--name", name, "--modify", "ALL"],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)
def copy(src_path, dst_path, format: str = "ISO") -> None: def copy(src_path, dst_path, format: str = "ISO") -> None:
@ -31,4 +31,4 @@ def copy(src_path, dst_path, format: str = "ISO") -> None:
:param format: format for the new game :param format: format for the new game
""" """
subprocess.run(["./tools/wit/wit", "COPY", src_path, "--DEST", dst_path, f"--{format.lower()}", "--overwrite"], subprocess.run(["./tools/wit/wit", "COPY", src_path, "--DEST", dst_path, f"--{format.lower()}", "--overwrite"],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)

View file

@ -1,4 +1,4 @@
from . import * import subprocess
def patch(path: str) -> None: def patch(path: str) -> None:
@ -7,4 +7,4 @@ def patch(path: str) -> None:
:param path: path to the game :param path: path to the game
""" """
subprocess.run(["./tools/szs/wstrt", "patch", path + "/sys/main.dol", "--clean-dol", "--add-lecode"], subprocess.run(["./tools/szs/wstrt", "patch", path + "/sys/main.dol", "--clean-dol", "--add-lecode"],
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)