Skip to content

Commit

Permalink
Add itemtbl.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
Xzonn committed Jun 14, 2024
1 parent 71f1cca commit 438879b
Show file tree
Hide file tree
Showing 7 changed files with 4,453 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/PersonaQ2ChsLocalizationHelper
Binary file added original_files/unpacked/init/itemtbl.bin
Binary file not shown.
24 changes: 19 additions & 5 deletions scripts/export_code_bin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
from helper import CODE_BIN_PATH, DIR_EXPORT_ROOT, HARDCODED_TEXTS, get_text_bases
import os
from helper import CODE_BIN_PATH, ITEM_TBL_PATH, DIR_EXPORT_ROOT, DIR_ORIGINAL_ROOT, HARDCODED_TEXTS_CODE_BIN, HARDCODED_TEXTS_ITEM_TBL, get_text_bases


def export_code_bin(code_bin_path: str, message_root: str, hardcoded_texts: list[tuple[str, str]]):
def export_code_bin(input_path: str, sheet_name: str, message_root: str, hardcoded_texts: list[tuple[str, str]]):

def find_strings(binary: bytes, texts: list, start: str | bytes, end: str | bytes, start_index: int = 0):
if type(start) is str:
Expand All @@ -25,6 +26,8 @@ def find_strings(binary: bytes, texts: list, start: str | bytes, end: str | byte
break
sub_bytes = binary[index:zero_index]
if index != zero_index:
if index > start_index:
texts[-1]["length"] = index - texts[-1]["offset"] - 1
texts.append({
"id": f"offset_{index:08x}",
"speaker": "",
Expand All @@ -38,7 +41,7 @@ def find_strings(binary: bytes, texts: list, start: str | bytes, end: str | byte

return index

with open(code_bin_path, "rb") as reader:
with open(input_path, "rb") as reader:
binary = reader.read()

texts = []
Expand All @@ -48,12 +51,23 @@ def find_strings(binary: bytes, texts: list, start: str | bytes, end: str | byte
if index == -1:
break

with open(f"{message_root}/code.bin.json", "w", -1, "utf8") as writer:
with open(f"{message_root}/{sheet_name}.json", "w", -1, "utf8") as writer:
json.dump({
"speakers": [],
"texts": texts,
}, writer, ensure_ascii=False, indent=2)


if __name__ == "__main__":
export_code_bin(CODE_BIN_PATH, DIR_EXPORT_ROOT, HARDCODED_TEXTS)
export_code_bin(
CODE_BIN_PATH,
"code.bin",
DIR_EXPORT_ROOT,
HARDCODED_TEXTS_CODE_BIN,
)
export_code_bin(
ITEM_TBL_PATH,
os.path.relpath(ITEM_TBL_PATH, DIR_ORIGINAL_ROOT),
DIR_EXPORT_ROOT,
HARDCODED_TEXTS_ITEM_TBL,
)
6 changes: 5 additions & 1 deletion scripts/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DIR_PATCH_ROOT = "out/00040000001CBE00"

CODE_BIN_PATH = "original_files/code.bin"
ITEM_TBL_PATH = "original_files/unpacked/init/itemtbl.bin"
ZH_HANS_2_KANJI_PATH = "files/zh_Hans_2_kanji.json"
DUPLICATE_FILES_INFO_PATH = "files/duplicate_files.json"
CHAR_TABLE_PATH = "out/char_table.json"
Expand Down Expand Up @@ -76,7 +77,7 @@
r"\[道具 ([0-9A-F]{2})([0-9A-F]{2})\]": r"[F4 84 04 01 01 01 \2 \1]",
}

HARDCODED_TEXTS = [
HARDCODED_TEXTS_CODE_BIN = [
("プロローグ", "???"),
("剛毅", "女帝"),
("Aチーム", "P3女主人公"),
Expand All @@ -93,6 +94,9 @@
bytes.fromhex("F2 05 FF FF F1 41 8F E3 8F 91 82 AB 82 B7 82 E9 0A 82 E2 82 DF 82 E9 0A"),
),
]
HARDCODED_TEXTS_ITEM_TBL = [
("NULL", "鑑定・0xDFF"),
]

char_table_reversed: dict[str, str] = {}
zh_hans_no_code = set()
Expand Down
24 changes: 18 additions & 6 deletions scripts/import_code_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from logging import warning
import os
from typing import Any
from helper import CODE_BIN_PATH, CONTROL_PATTERN, DIR_IMPORT_ROOT, DIR_PATCH_ROOT
from helper import CODE_BIN_PATH, CONTROL_PATTERN, DIR_IMPORT_ROOT, DIR_ORIGINAL_ROOT, DIR_PACK_ROOT, DIR_PATCH_ROOT, ITEM_TBL_PATH


def import_code_bin(code_bin_path: str, message_root: str, output_root: str):
def import_code_bin(code_bin_path: str, sheet_name: str, message_root: str, output_path: str):
with open(code_bin_path, "rb") as reader:
binary = bytearray(reader.read())

with open(f"{message_root}/code.bin.json", "r", -1, "utf8") as reader:
with open(f"{message_root}/{sheet_name}.json", "r", -1, "utf8") as reader:
texts: list[dict[str, Any]] = json.load(reader)["texts"]

for item in texts:
Expand All @@ -34,10 +34,22 @@ def import_code_bin(code_bin_path: str, message_root: str, output_root: str):

binary[offset:offset + length] = text_bytes

os.makedirs(f"{output_root}/exefs", exist_ok=True)
with open(f"{output_root}/exefs/code.bin", "wb") as writer:
print(output_path)
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, "wb") as writer:
writer.write(binary)


if __name__ == "__main__":
import_code_bin(CODE_BIN_PATH, DIR_IMPORT_ROOT, DIR_PATCH_ROOT)
import_code_bin(
CODE_BIN_PATH,
"code.bin",
DIR_IMPORT_ROOT,
f"{DIR_PATCH_ROOT}/exefs/code.bin",
)
import_code_bin(
ITEM_TBL_PATH,
os.path.relpath(ITEM_TBL_PATH, DIR_ORIGINAL_ROOT),
DIR_IMPORT_ROOT,
f"{DIR_PACK_ROOT}/{os.path.relpath(ITEM_TBL_PATH, DIR_ORIGINAL_ROOT)}",
)
Loading

0 comments on commit 438879b

Please sign in to comment.