diff --git a/TOR_Test.py b/TOR_Test.py index 154374a..e625a1e 100644 --- a/TOR_Test.py +++ b/TOR_Test.py @@ -12,8 +12,6 @@ import lxml.etree as etree tool = ToolsTOR.ToolsTOR("TBL_All.json") -tool.pakComposer_Comptoe("11181.pak3", "-d", "-3", True, r"G:\TalesHacking\PythonLib_Playground\Data\TOR\Menu\New") - tool.extract_All_Menu() diff --git a/ToolsTales.py b/ToolsTales.py index 8afe391..0f50d75 100644 --- a/ToolsTales.py +++ b/ToolsTales.py @@ -60,30 +60,42 @@ class ToolsTales: # action is -d or -c # fileType : -0, -1 or -3 # basePath is the location of the PAK file you want to compress/decompress - def pakComposer_Comptoe(self, fileName, action, fileType, do_comptoe, working): + def pakComposer_Comptoe(self, file_name, action, file_type, do_comptoe, working): - #Delete the file if already there + #Delete the file if already there + file_number = file_name.split(".")[0] if (action == '-c'): - if os.path.exists(fileName): - os.remove( fileName.replace(".pak{}", fileType[1])) + if os.path.exists(file_name): + os.remove( file_name.replace(".pak{}", file_type[1])) else: - shutil.rmtree(fileName.split(".")[0]) + + if os.path.exists(working+"/"+file_number): + shutil.rmtree(working+"/"+file_number) #Run Pakcomposer with parameters - args = [ "pakcomposer", action, fileName, fileType] - - if do_comptoe: - args.append("-u") - args.append("-x") - + args = [ "pakcomposer", action, file_name, file_type, "-x"] listFile = subprocess.run( args, cwd=working ) - print(listFile) - + if do_comptoe: + + files = [ele for ele in os.listdir(working+"/"+file_number) if ".compress" in ele] + for ele in files: + + ctype=0 + with open(working+"/{}/".format(file_number)+ele, "rb") as f: + ctype = ord(f.read(1)) + + args = ["comptoe", "-d{}".format(ctype), ele, ele.split(".")[0]+"d.unknown"] + listFile = subprocess.run( + args, + cwd=working+"/"+file_number + ) + + def fps4_action(self, action, b_file, dat_file, destination): fps4.dump_fps4(b_file, dat_file, destination) @@ -844,16 +856,13 @@ class ToolsTales: return [pointers_offset, pointers_value] - def prepare_Menu_File(self, file_definition): + def prepare_Menu_File(self, file_original): - file_original = file_definition['File_Original'] file_name = os.path.basename(file_original) - file_number = file_name.split(".")[0] - extension = file_name.split(".")[-1] #Copy the files under Menu Folder menu_path = "../Data/{}/Menu/New/".format(self.gameName) - shutil.copy( file_definition['File_Original'], menu_path+file_name) + shutil.copy( file_original, menu_path+file_name) #Extract if needed (PakComposer or other) if "pak" in file_name: @@ -911,13 +920,15 @@ class ToolsTales: self.mkdir("../Data/{}/Menu/New".format(self.gameName)) + + #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])) + res = [ self.prepare_Menu_File(ele) for ele in files_to_prepare] + for file_definition in self.menu_files_json: print("...{}".format(file_definition['File_Extract'])) - - self.prepare_Menu_File(file_definition) - self.extract_Menu_File(file_definition) diff --git a/__pycache__/ToolsTales.cpython-38.pyc b/__pycache__/ToolsTales.cpython-38.pyc index 1401b51..f8dd4e7 100644 Binary files a/__pycache__/ToolsTales.cpython-38.pyc and b/__pycache__/ToolsTales.cpython-38.pyc differ