Merge pull request #13 from lifebottle/dev

Apache3 automate small script
This commit is contained in:
fortiersteven
2022-04-10 15:58:51 -04:00
committed by GitHub
6 changed files with 209 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.

103
apache_automate.py Normal file
View File

@@ -0,0 +1,103 @@
from pywinauto import application
from pywinauto.keyboard import send_keys
from pywinauto import mouse
from pywinauto.findwindows import find_windows
import os
import shutil
def open_apache3_iso(repo_name):
app = application.Application(backend="uia").start('apache3.exe')
app = application.Application(backend="uia").connect(title='Apache3 Build 3.10.6 (BETA)')
#Get the window about FREE license
app.Information.set_focus()
send_keys('{ENTER}')
#Get the window about Drive missing
drive_missing = app.Apache3Build.child_window(title="apache3", control_type="Window")
drive_missing.set_focus()
send_keys('{ENTER}')
iso_path = os.path.join( os.path.normpath(os.getcwd() + os.sep + os.pardir), "Data",repo_name,"Disc","New","{}.iso".format(repo_name))
#Click on the Open Iso button
app.Apache3Build.child_window(auto_id="1011").click()
#File Name textbox
text_box_filename = app.Dialog.child_window(auto_id="1152").wrapper_object()
text_box_filename.type_keys(r"{}".format(iso_path))
#Open the iso
app.Dialog.child_window(title="Open", auto_id="1", control_type="Button").wrapper_object().click()
return app
def locate_right_click(file_name, app):
item = app.Apache3Build.child_window(title=file_name, control_type="ListItem").wrapper_object()
pos_x = item.rectangle().mid_point().x
pos_y = item.rectangle().mid_point().y
app.Apache3Build.set_focus()
mouse.click(button='right', coords=(pos_x, pos_y))
def browse_replace_file(file_replace_ele, new_file_path, repo_name):
#Browse the file and put the new file path
new_file_path = os.path.join( os.path.normpath(os.getcwd() + os.sep + os.pardir), "Data",repo_name, "Menu", "New", "SLPS_254.50")
file_replace_ele.child_window(auto_id="1095").wrapper_object().click()
file_replace_ele.Dialog.child_window(title="File name:", auto_id="1152", control_type="Edit").wrapper_object().type_keys(new_file_path)
file_replace_ele.Dialog.child_window(title="Open", auto_id="1", control_type="Button").wrapper_object().click()
#Click on the Replace File button
file_replace_ele.child_window(title="Replace File", auto_id="1094", control_type="Button").wrapper_object().click()
def replace_files(files_list, app):
new_file_path_format = os.path.join( os.path.normpath(os.getcwd() + os.sep + os.pardir), "Data",repo_name, "Disc", "New")
for file_name in files_list:
#Locate file and right-click it
locate_right_click(file_name, app)
#Click on the option "Replace Selected File"
replace_file_pos = app.Context.child_window(title="Replace Selected File", auto_id="32782", control_type="MenuItem").wrapper_object().rectangle().mid_point()
mouse.click(button='left', coords=(replace_file_pos.x, replace_file_pos.y))
file_replace_ele = app.Apache3Build.Apache3FileReplacer
#Uncheck TOC and Check Ignore File size
file_replace_ele.child_window(title="Update TOC", auto_id="1092", control_type="CheckBox").wrapper_object().click()
file_replace_ele.child_window(title="Ignore File Size Differences", auto_id="1093", control_type="CheckBox").click()
browse_replace_file(file_replace_ele, os.path.join(new_file_path_format, file_name), repo_name)
#Files to reinsert
#files_list = ['SLPS_254.50', 'DAT.bin']
files_list = ['SLPS_254.50']
repo_name = "Tales-Of-Rebirth"
#copy original Iso
original_path = os.path.join(os.getcwd(), "..", "Data", repo_name, "Disc", "Original", "{}.iso".format(repo_name))
new_path = os.path.join(os.getcwd(), "..", "Data", repo_name, "Disc", "New", "{}.iso".format(repo_name))
print("Copy Original Iso into New folder")
shutil.copy( original_path, new_path)
try:
app = application.Application(backend="uia").connect(title='Apache3 Build 3.10.6 (BETA)')
app.Apache3Build.close()
except:
print("Open Apache3 and load the iso")
app = open_apache3_iso(repo_name)
print("Replace the different files")
replace_files(files_list,app)
print("Close Apache3")
app.Apache3Build.close()