Merge pull request #12 from lifebottle/create-files-TODDC

Create files toddc
This commit is contained in:
fortiersteven
2022-03-27 20:35:59 -04:00
committed by GitHub
5 changed files with 106 additions and 9 deletions

66
TODDC_Test.py Normal file
View File

@@ -0,0 +1,66 @@
import ToolsTODDC
import json
import struct
import comptolib
import io
import re
import string
import pandas as pd
import json
import os
import lxml.etree as etree
tool = ToolsTODDC.ToolsTODDC("TBL_All.json")
ele = tool.menu_files_json[0]
tool.extract_Menu_File(ele)
repo_name = "Tales-Of-Destiny-DC"
tblFile = "TBL_ALL.json"
with open("../{}/Data/Misc/{}".format(repo_name, tblFile), encoding="utf-8") as f:
jsonRaw = json.load(f)
jsonTblTags ={ k1:{ int(k2) if (k2 != "TBL") else int(k2):v2 for k2,v2 in jsonRaw[k1].items()} for k1,v1 in jsonRaw.items()}
#jsonTblTags = {k2:v2 for k2,v2 in jsonRaw[k1].items()} for k1,v1 in jsonRaw.items()}
TAGS = jsonTblTags['TAGS']
with open("../Data/Tales-Of-Destiny-DC/Menu/New/00016/00016_0000d.unknown", "rb") as fileRead:
fileRead.seek(0x3C87D)
b = fileRead.read(1)
b = ord(b)
finalText=""
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 += (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("<L", fileRead.read(4))[0]
if b in TAGS:
tag_name = TAGS.get(b)
tag_param = None
tag_search = tag_name.upper()
if (tag_search in jsonTblTags.keys()):
tags2 = jsonTblTags[tag_search]
tag_param = tags2.get(b2, None)
if tag_param != None:
finalText += tag_param
else:
finalText += ("<%s:%08X>" % (tag_name, b2))
else:
finalText += "<%02X:%08X>" % (b, b2)

25
ToolsTODDC.py Normal file
View File

@@ -0,0 +1,25 @@
from ToolsTales import ToolsTales
import subprocess
from dicttoxml import dicttoxml
import json
import struct
import shutil
import os
import re
import pandas as pd
import xml.etree.ElementTree as ET
import lxml.etree as etree
import comptolib
from xml.dom import minidom
from pathlib import Path
import string
import io
class ToolsTODDC(ToolsTales):
def __init__(self, tbl):
super().__init__("TODDC", tbl, "Tales-of-Destiny-DC")

View File

@@ -31,17 +31,21 @@ class ToolsTales:
self.repo_name = repo_name
self.basePath = os.getcwd()
with open("../{}/Data/{}/Misc/{}".format(repo_name, gameName, tblFile)) as f:
with open("../{}/Data/Misc/{}".format(repo_name, tblFile), encoding="utf-8") as f:
jsonRaw = json.load(f)
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()}
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['NAMES'].items()])
self.icolors = dict([[i, j] for j, i in self.jsonTblTags['COLORS'].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()])
with open("../{}/Data/{}/Menu/MenuFiles.json".format(repo_name, gameName)) as f:
with open("../{}/Data/Menu/MenuFiles.json".format(repo_name)) as f:
self.menu_files_json = json.load(f)
@@ -469,7 +473,7 @@ class ToolsTales:
tag_name = TAGS.get(b)
tag_param = None
tag_search = tag_name.upper()+'S'
tag_search = tag_name.upper()
if (tag_search in self.jsonTblTags.keys()):
tags2 = self.jsonTblTags[tag_search]
tag_param = tags2.get(b2, None)
@@ -891,12 +895,14 @@ class ToolsTales:
text_end = section['Text_End']
#Extract Pointers of the file
print("Extract Pointers")
pointers_offset, pointers_value = self.get_special_pointers( text_start, text_end, base_offset, section['Pointer_Offset_Start'], section['Nb_Per_Block'], section['Step'], section['Section'], file_path)
#Extract Text from the pointers
print("Extract Text")
texts = [ self.bytes_to_text(f, ele + base_offset)[0] for ele in pointers_value]
print(texts)
#Make a list
section_list.extend( [section['Section']] * len(texts))
@@ -911,7 +917,7 @@ class ToolsTales:
#Write to XML file
txt=etree.tostring(root, encoding="UTF-8", pretty_print=True)
with open(file_definition['File_XML'].replace("/{}".format(self.repo_name),""), "wb") as xmlFile:
with open(file_definition['File_XML'].replace("/{}".format(self.repo_name),"").replace("/Data","/Data/{}".format(self.repo_name)), "wb") as xmlFile:
xmlFile.write(txt)
@@ -920,7 +926,7 @@ class ToolsTales:
print("Extracting Menu Files")
self.mkdir("../Data/{}/Menu/New".format(self.gameName))
self.mkdir("../Data/{}/Menu/New".format(self.repo_name))
#Prepare the menu files (Unpack PAK files and use comptoe)
files_to_prepare = list(dict.fromkeys([ele['File_Original'] for ele in self.menu_files_json]))

Binary file not shown.