From 41c63ab6c08f891ef1a03fb8b353e0ee1d98c70d Mon Sep 17 00:00:00 2001 From: Mc-muffin <8714476+Mc-muffin@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:48:13 -0500 Subject: [PATCH] Truncate Theirsce files before insertion Avoids dangling bytes that make DAT.BIN bigger --- pythonlib/formats/FileIO.py | 6 ++++++ pythonlib/games/ToolsTOR.py | 1 + 2 files changed, 7 insertions(+) diff --git a/pythonlib/formats/FileIO.py b/pythonlib/formats/FileIO.py index c0cf891..380c0ac 100644 --- a/pythonlib/formats/FileIO.py +++ b/pythonlib/formats/FileIO.py @@ -35,6 +35,12 @@ class FileIO(object): def tell(self): return self.f.tell() + + def truncate(self, size=None): + if size is None: + self.f.truncate(self.f.tell()) + else: + self.f.truncate(size) def seek(self, pos, whence=0): self.f.seek(pos, whence) diff --git a/pythonlib/games/ToolsTOR.py b/pythonlib/games/ToolsTOR.py index f17536e..4bbab50 100644 --- a/pythonlib/games/ToolsTOR.py +++ b/pythonlib/games/ToolsTOR.py @@ -428,6 +428,7 @@ class ToolsTOR(ToolsTales): #Go at the start of the dialog #Loop on every Entry and reinsert theirsce.seek(theirsce.strings_offset + 1) + theirsce.truncate() nodes = [ele for ele in root.iter('Entry') if ele.find('Id').text != "-1"] nodes = [ele for ele in nodes if ele.find('PointerOffset').text != "-1"]