From 89e17d434625604731193febaa0e457d3ec55efb Mon Sep 17 00:00:00 2001 From: Stewie Date: Sat, 16 Jul 2022 15:11:44 -0400 Subject: [PATCH] Move function to the child class instead --- ToolsTales.py | 116 +++----------------------------------------------- 1 file changed, 6 insertions(+), 110 deletions(-) diff --git a/ToolsTales.py b/ToolsTales.py index 4ad8fc1..bb556e4 100644 --- a/ToolsTales.py +++ b/ToolsTales.py @@ -30,23 +30,14 @@ class ToolsTales: self.gameName = gameName self.repo_name = repo_name self.basePath = os.getcwd() + self.tblFile = tblFile - with open("../{}/Data/{}/Misc/{}".format(repo_name, gameName, tblFile), encoding="utf-8") as f: - jsonRaw = json.load(f) - if self.repo_name == "Tales-of-Destiny-DC": - self.jsonTblTags ={ k1:{ int(k2) if (k1 != "TBL") else k2:v2 for k2,v2 in jsonRaw[k1].items()} for k1,v1 in jsonRaw.items()} - else: - self.jsonTblTags ={ k1:{ int(k2,16) if (k1 != "TBL") else k2:v2 for k2,v2 in jsonRaw[k1].items()} for k1,v1 in jsonRaw.items()} - - - self.itable = dict([[i, struct.pack(">H", int(j))] for j, i in self.jsonTblTags['TBL'].items()]) - self.itags = dict([[i, j] for j, i in self.jsonTblTags['TAGS'].items()]) - self.inames = dict([[i, j] for j, i in self.jsonTblTags['NAME'].items()]) - self.icolors = dict([[i, j] for j, i in self.jsonTblTags['COLOR'].items()]) - self.id = 1 - with open("../{}/Data/{}/Menu/MenuFiles.json".format(repo_name, gameName)) as f: - self.menu_files_json = json.load(f) + + menu_path = "../{}/Data/{}/Menu/MenuFiles.json".format(repo_name, gameName) + if os.path.exists(menu_path): + with open(menu_path) as f: + self.menu_files_json = json.load(f) def generate_xdelta_patch(self, xdelta_name): @@ -447,102 +438,7 @@ class ToolsTales: x = '%x' % (n,) return ('0' * (len(x) % 2)) + x - #Convert a bytes object to text using TAGS and TBL in the json file - def bytes_to_text(self, fileRead, offset=-1, end_strings = b"\x00"): - finalText = '' - TAGS = self.jsonTblTags['TAGS'] - - if (offset > 0): - fileRead.seek(offset, 0) - - pos = fileRead.tell() - b = fileRead.read(1) - while b != end_strings: - #print(hex(fileRead.tell())) - b = ord(b) - - if (b >= 0x99 and b <= 0x9F) or (b >= 0xE0 and b <= 0xEB): - c = (b << 8) + ord(fileRead.read(1)) - - # if str(c) not in json_data.keys(): - # json_data[str(c)] = char_index[decode(c)] - try: - finalText += (self.jsonTblTags['TBL'][str(c)]) - except KeyError: - b_u = (c >> 8) & 0xff - b_l = c & 0xff - finalText += ("{%02X}" % b_u) - finalText += ("{%02X}" % b_l) - elif b == 0x1: - finalText += ("\n") - elif b in (0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xB, 0xC, 0xD, 0xE, 0xF): - b2 = struct.unpack("" % (tag_name, b2)) - else: - finalText += "<%02X:%08X>" % (b, b2) - elif chr(b) in self.PRINTABLE_CHARS: - finalText += chr(b) - elif b >= 0xA1 and b < 0xE0: - finalText += struct.pack("B", b).decode("cp932") - elif b in (0x13, 0x17, 0x1A): - tag_name = f"Unk{b:02X}" - hex_value = "" - - while fileRead.read(1) != b"\x80": - fileRead.seek(fileRead.tell()-1) - mark = fileRead.read(1) - hex_value += mark.hex() - if mark == "\x38": - hex_value += f"{struct.unpack('