diff --git a/pythonlib/formats/pak.py b/pythonlib/formats/pak.py index 5a9d654..44ae608 100644 --- a/pythonlib/formats/pak.py +++ b/pythonlib/formats/pak.py @@ -16,7 +16,7 @@ class Pak: def __init__(self) -> None: self.type = -1 self.align = False - self.files = [] + self.files: list[pak_file] = [] @staticmethod def from_path(path, type) -> "Pak": diff --git a/pythonlib/formats/scpk.py b/pythonlib/formats/scpk.py index c7e56ac..154c74f 100644 --- a/pythonlib/formats/scpk.py +++ b/pythonlib/formats/scpk.py @@ -26,6 +26,7 @@ class Scpk: self.map: bytes = b"" self._map_comp_type = 0 self.chars: dict[int, Pak] = dict() + self.char_ids: list[int] = list() self.rsce: bytes = b"" self._rsce_comp_type = 0 self.unk_file: bytes = b"" @@ -63,12 +64,11 @@ class Scpk: if flags & CHR_FLAG: f.seek(cursor) total_chars = f.read_uint16() - char_ids = [] for _ in range(total_chars): - char_ids.append(f.read_uint16()) + self.char_ids.append(f.read_uint16()) cursor += sizes.pop(0) - for id in char_ids: + for id in self.char_ids: size = sizes.pop(0) self.chars[id] = Pak.from_path(f.read_at(cursor, size), 1) cursor += size diff --git a/pythonlib/games/ToolsTOR.py b/pythonlib/games/ToolsTOR.py index 4d06b45..e0f8225 100644 --- a/pythonlib/games/ToolsTOR.py +++ b/pythonlib/games/ToolsTOR.py @@ -1063,6 +1063,15 @@ class ToolsTOR(ToolsTales): xml_path = self.paths["story_xml"] scpk_path = self.paths["extracted_files"] / "DAT" / "SCPK" + # Collect available anp3's + anp3_path = self.paths["translated_files"] / "graphic" + + anp3s: dict[str, tuple[int, bytes]] = dict() + + for anp3 in anp3_path.glob("*.anp3"): + with anp3.open("rb") as f: + anp3s[anp3.stem[:5]] = (int(anp3.stem[6:8]), f.read()) + in_list = [] if self.changed_only: for item in porcelain.status(self.get_repo_fixed()).unstaged: # type: ignore @@ -1082,6 +1091,12 @@ class ToolsTOR(ToolsTales): new_rsce = self.get_new_theirsce(old_rsce, xml_path / file.with_suffix(".xml").name) new_rsce.seek(0) curr_scpk.rsce = new_rsce.read() + + # insert anp3 (if applicable) + scpk_name = file.stem[:5] + if scpk_name in anp3s: + char_id = curr_scpk.char_ids[anp3s[scpk_name][0]] + curr_scpk.chars[char_id].files[0].data = anp3s[scpk_name][1] with open(out_path / file.name, "wb") as f: f.write(curr_scpk.to_bytes())