From ca33366ef70b54d26e975cc3a65b9b28e30bbec7 Mon Sep 17 00:00:00 2001 From: Mc-muffin <8714476+Mc-muffin@users.noreply.github.com> Date: Fri, 19 May 2023 07:30:53 -0500 Subject: [PATCH] Formatting changes --- Tales_Exe.py | 43 ++++++++++++++++++---------------- ToolsNDX.py | 4 ++-- ToolsTODDC.py | 17 +------------- ToolsTOR.py | 65 ++++++++++++++++++++++----------------------------- ToolsTales.py | 38 ++++++++++++++---------------- theirsce.py | 10 ++++---- 6 files changed, 75 insertions(+), 102 deletions(-) diff --git a/Tales_Exe.py b/Tales_Exe.py index ebe5ad5..e0b2d45 100644 --- a/Tales_Exe.py +++ b/Tales_Exe.py @@ -1,15 +1,12 @@ -import ToolsTOR -import ToolsNDX -import json import argparse -import textwrap -import os import io -import re -import requests +import os import subprocess -import RepoFunctions + import GoogleAPI +import RepoFunctions +import ToolsNDX +import ToolsTOR repos_infos ={ "TOR": @@ -25,24 +22,24 @@ repos_infos ={ } - SCRIPT_VERSION = "0.0.3" + + def generate_xdelta_patch(repo_name, xdelta_name="Tales-Of-Rebirth_Patch_New.xdelta"): - + print("Create xdelta patch") original_path = "../Data/{}/Disc/Original/{}.iso".format(repo_name, repo_name) new_path = "../Data/{}/Disc/New/{}.iso".format(repo_name, repo_name) subprocess.run(["xdelta", "-f", "-s", original_path, new_path, xdelta_name]) - - + def get_directory_path(path): return os.path.dirname(os.path.abspath(path)) def check_arguments(parser, args): if hasattr(args, "elf_path") and not args.elf_path: args.elf_path = get_directory_path(args.input) + "/SLPS_254.50" - + if hasattr(args, "elf_out") and not args.elf_out: args.elf_out = get_directory_path(args.input) + "/NEW_SLPS_254.50" @@ -53,6 +50,7 @@ def check_arguments(parser, args): else: args.output = args.input + def get_arguments(argv=None): # Init argument parser parser = argparse.ArgumentParser() @@ -181,6 +179,7 @@ def get_arguments(argv=None): return args + def send_xdelta(): file_link = GoogleAPI.upload_xdelta(xdelta_name, "Stewie") #Need to add user for the folder @@ -205,22 +204,26 @@ def hex2bytes(tales_instance, hex_value): with open("text_dump.txt", "w",encoding="utf-8") as f: f.write(txt) + def getTalesInstance(game_name): - + if game_name == "TOR": talesInstance = ToolsTOR.ToolsTOR("TBL_All.json") elif game_name == "NDX": talesInstance = ToolsNDX.ToolsNDX("TBL_All.json") + else: + raise ValueError("Unkown game name") return talesInstance - + + if __name__ == "__main__": args = get_arguments() game_name = args.game tales_instance = getTalesInstance(game_name) - org = repos_infos[game_name]['Org'] - repo_name = repos_infos[game_name]['Repo'] + org = repos_infos[game_name]["Org"] + repo_name = repos_infos[game_name]["Repo"] if args.action == "insert": @@ -243,7 +246,7 @@ if __name__ == "__main__": #generate_xdelta_patch(repo_name, xdelta_name) if args.action == "extract": - + if args.file_type == "Iso": tales_instance.extract_Iso(args.iso) tales_instance.extract_Main_Archive() @@ -253,7 +256,7 @@ if __name__ == "__main__": if args.file_type == "Menu": tales_instance.extract_All_Menu() - + if args.file_type == "Story": tales_instance.extract_All_Story(args.replace) @@ -263,4 +266,4 @@ if __name__ == "__main__": if args.action == "debug": if args.file_type in ["Story", "Skits"]: - tales_instance.debug_Story_Skits(args.file_type, args.file_name, args.text) \ No newline at end of file + tales_instance.debug_Story_Skits(args.file_type, args.file_name, args.text) diff --git a/ToolsNDX.py b/ToolsNDX.py index f0989f7..d3d064e 100644 --- a/ToolsNDX.py +++ b/ToolsNDX.py @@ -1,6 +1,6 @@ -from ToolsTales import ToolsTales +from .ToolsTales import ToolsTales import subprocess -from dicttoxml import dicttoxml +# from dicttoxml import dicttoxml import json import struct import shutil diff --git a/ToolsTODDC.py b/ToolsTODDC.py index f43525a..1f159a2 100644 --- a/ToolsTODDC.py +++ b/ToolsTODDC.py @@ -1,19 +1,4 @@ -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 +from .ToolsTales import ToolsTales class ToolsTODDC(ToolsTales): diff --git a/ToolsTOR.py b/ToolsTOR.py index aefa0dc..1229d42 100644 --- a/ToolsTOR.py +++ b/ToolsTOR.py @@ -1,25 +1,25 @@ -from dataclasses import dataclass -from itertools import tee -from ToolsTales import ToolsTales -import subprocess -from dicttoxml import dicttoxml +import io 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 +import shutil +import struct +from dataclasses import dataclass +from itertools import tee from pathlib import Path -import string -import io + +import lxml.etree as etree +import pandas as pd +from tqdm import tqdm +from scpk import Scpk + +import comptolib as comptolib import pak2 as pak2lib from theirsce import Theirsce -from theirsce_instructions import AluOperation, InstructionType, ReferenceScope, TheirsceBaseInstruction, TheirsceReferenceInstruction, TheirsceStringInstruction -from tqdm import tqdm +from theirsce_instructions import (AluOperation, InstructionType, + TheirsceBaseInstruction) +from .ToolsTales import ToolsTales + @dataclass class LineEntry: @@ -44,15 +44,15 @@ class ToolsTOR(ToolsTales): #Path to used - dat_bin_original = '../Data/Tales-Of-Rebirth/Disc/Original/DAT.BIN' - dat_bin_new = '../Data/Tales-Of-Rebirth/Disc/New/DAT.BIN' - elf_original = '../Data/Tales-Of-Rebirth/Disc/Original/SLPS_254.50' - elf_new = '../Data/Tales-Of-Rebirth/Disc/New/SLPS_254.50' - story_XML_new = '../Tales-Of-Rebirth/Data/TOR/Story/' #Story XML files will be extracted here - story_XML_patch = '../Data/Tales-Of-Rebirth/Story/' #Story XML files will be extracted here - skit_XML_patch = '../Data/Tales-Of-Rebirth/Skits/' #Skits XML files will be extracted here - skit_XML_new = '../Tales-Of-Rebirth/Data/TOR/Skits/' - dat_archive_extract = '../Data/Tales-Of-Rebirth/DAT/' + dat_bin_original = '../Data/Tales-Of-Rebirth/Disc/Original/DAT.BIN' + dat_bin_new = '../Data/Tales-Of-Rebirth/Disc/New/DAT.BIN' + elf_original = '../Data/Tales-Of-Rebirth/Disc/Original/SLPS_254.50' + elf_new = '../Data/Tales-Of-Rebirth/Disc/New/SLPS_254.50' + story_XML_new = '../Tales-Of-Rebirth/Data/TOR/Story/' #Story XML files will be extracted here + story_XML_patch = '../Data/Tales-Of-Rebirth/Story/' #Story XML files will be extracted here + skit_XML_patch = '../Data/Tales-Of-Rebirth/Skits/' #Skits XML files will be extracted here + skit_XML_new = '../Tales-Of-Rebirth/Data/TOR/Skits/' + dat_archive_extract = '../Data/Tales-Of-Rebirth/DAT/' def __init__(self, tbl): @@ -67,8 +67,7 @@ class ToolsTOR(ToolsTales): for k, v in self.jsonTblTags.items(): self.ijsonTblTags[k] = {v2: k2 for k2, v2 in v.items()} self.id = 1 - - #byteCode + # byteCode self.story_byte_code = b"\xF8" self.string_opcode = InstructionType.STRING self.list_status_insertion = ['Done', 'Proofreading', 'Editing'] @@ -81,8 +80,8 @@ class ToolsTOR(ToolsTales): return new.join(li) def add_line_break(self, text): - temp = ""; - currentLineSize = 0; + temp = "" + currentLineSize = 0 text_size = len(text) max_size = 32 @@ -619,8 +618,6 @@ class ToolsTOR(ToolsTales): #Open the original SCPK with open( self.dat_archive_extract + "SCPK/" + scpk_file_name, 'r+b') as scpk: - - #Get nb_files and files_size scpk.read(4) scpk.read(4) @@ -641,10 +638,6 @@ class ToolsTOR(ToolsTales): for pointer_offset, fsize in file_size_dict.items(): data_compressed = scpk.read(fsize) - - - - if self.is_compressed(data_compressed): c_type = struct.unpack("