From 4b16dd1d14e449af9cf4d198d7605b7bb7d15199 Mon Sep 17 00:00:00 2001 From: Mc-muffin <8714476+Mc-muffin@users.noreply.github.com> Date: Mon, 22 May 2023 13:02:07 -0500 Subject: [PATCH] New skits insert code --- pythonlib/games/ToolsTOR.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pythonlib/games/ToolsTOR.py b/pythonlib/games/ToolsTOR.py index 3ca1ccb..5b8cfff 100644 --- a/pythonlib/games/ToolsTOR.py +++ b/pythonlib/games/ToolsTOR.py @@ -187,7 +187,7 @@ class ToolsTOR(ToolsTales): scpk_path = Path(self.dat_archive_extract) / "SCPK" for file in tqdm(list(scpk_path.glob("*.scpk"))): - theirsce = Theirsce(Scpk(file).rsce) + theirsce = Theirsce(Scpk().from_path(file).rsce) xml_text = self.get_xml_from_theirsce(theirsce, "Story") self.id = 1 @@ -648,13 +648,26 @@ class ToolsTOR(ToolsTales): return - def pack_All_Skits(self): + def pack_all_skits(self): + print("Recreating Skit files...") - print("Recreating Skits files") - listFiles = [ele for ele in os.listdir(self.skit_XML_patch + "New/")] - for pak2_file in listFiles: - self.pack_Skit_File(pak2_file) - print("Writing file {} ...".format(pak2_file)) + # TODO: use pathlib for everything + out_path = Path(self.skit_XML_patch) / "New" + xml_path = Path(self.skit_XML_patch) / "XML" + pak2_path = Path(self.dat_archive_extract) / "SCPK" + + for file in tqdm(list(pak2_path.glob("*.pak2"))): + with open(file, "rb") as f: + pak2_data = f.read() + pak2_obj = pak2lib.get_data(pak2_data) + + old_rsce = Theirsce(pak2_obj.chunks.theirsce) + new_rsce = self.get_new_theirsce(old_rsce, xml_path / file.with_suffix(".xml").name) + new_rsce.seek(0) + pak2_obj.chunks.theirsce = new_data = new_rsce.read() + + with open(out_path / file.name, "wb") as f: + f.write(pak2lib.create_pak2(pak2_obj)) def debug_Story_Skits(self, section, file_name, text=False):