diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..aad0269 --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +# __init__.py +from .ibunroku_event_strings_parser import parse_event_strings as parse_event_strings +from .ibunroku_event_strings_injecter import inject_event_strings as inject_event_strings +from .ibunroku_binner2 import from_bin as from_bin, to_bin as to_bin diff --git a/ibunroku_binner2.py b/ibunroku_binner2.py new file mode 100644 index 0000000..da8d842 --- /dev/null +++ b/ibunroku_binner2.py @@ -0,0 +1,92 @@ +import os +import struct + +def from_bin(file_path): + """ + Extracts binary files from a BIN file. + + Args: + file_path (str): Path to the BIN file. + """ + CHUNK = 2048 + pointers = [0] + folder_name = file_path.rstrip(".BIN") + "/" + + if not os.path.isdir(folder_name): + os.mkdir(folder_name) + + with open(file_path, 'rb') as f: + data = f.read() + i = 0 + while True: + pointer = struct.unpack(' 0: + pointer += 154 + pointers.append(pointer) + i += 2 + if data[i:i+2] == b'\x00\x00': + break + + for p in range(1, len(pointers) - 1): + file_start = pointers[p] + file_end = file_start + struct.unpack('H', from_hex_str(kanji_hex_code)) + i += 1 + text_pointer += len(converted_s) + new_pointers.append(text_pointer) + textblock += converted_s + + # Update file size and pointers + file_size = text_table_pointer + len(textblock) + len(data_after) + end_text_table = text_table_pointer + len(textblock) + unk_pointer1 += end_text_table + unk_pointer2 += end_text_table + unk_pointer3 += end_text_table + + # Update text pointers in the binary file + new_table = binfile_data[:text_table_pointer+8] + for i, s in enumerate(json_data["Parsed strings"]): + new_table = new_table[:int(s)+8] + struct.pack('= 0x80 and char < 0xFF: + char = int.from_bytes(raw[1][i:i+2], 'big') + char_hex = f'{char:04X}' + decoded_string += encoding_table.get(char_hex, f'|{char_hex}') + i += 2 + else: + command = raw[1][i+1] + if command == 5: + wait = int.from_bytes(raw[1][i+2:i+3], 'big') + decoded_string += f'[WAIT={wait}]' + i += 4 + elif command == 6: + color = raw[1][i+2] + decoded_string += f'[COLOR={color}]' + i += 3 + elif command == 14: + something = raw[1][i+2] + decoded_string += f'[SOMETHING={something}]' + i += 3 + else: + try: + decoded_string += commands[command] + except IndexError: + print(f'Unknown command {command} in file {file_path}') + i += 2 + strings[str(raw[0])] = decoded_string + txt.write(f'{str(raw[0])}:\t{decoded_string}\n') + + # Save other data and strings to JSON + with codecs.open('output.json', 'w', encoding='utf_8') as jsonf: + json.dump({'Header': header_json, 'Parsed strings': strings, 'Other Data': list(other_data)}, jsonf, indent=4, ensure_ascii=False) diff --git a/ibunroku_settings.py b/ibunroku_settings.py new file mode 100644 index 0000000..9834505 --- /dev/null +++ b/ibunroku_settings.py @@ -0,0 +1,38 @@ +import codecs + +def load_encoding_table(file_path): + """ + Loads the encoding table from a file and returns a dictionary mapping hex codes to characters or commands. + + Args: + file_path (str): Path to the encoding table file. + + Returns: + dict: Dictionary mapping hex codes to characters or commands. + """ + encoding_table = {} + with codecs.open(file_path, 'r', encoding='utf_8') as file: + for line in file: + line = line.strip() + if line and '=' in line: + hex_code, char = line.split('=') + encoding_table[hex_code.strip()] = char.strip() + return encoding_table + +# Mapping of commands used in the game +commands = [ + '[wait]', '[end]', '[nl]' +] + +# Mapping of Russian characters to their byte values +russian = [ + 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', '¨', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', + 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß' +] + +# Mapping of hex strings to binary strings +hex_from_str = { + '0': '0000', '1': '0001', '2': '0010', '3': '0011', '4': '0100', '5': '0101', + '6': '0110', '7': '0111', '8': '1000', '9': '1001', 'A': '1010', 'B': '1011', + 'C': '1100', 'D': '1101', 'E': '1110', 'F': '1111' +} diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..82fc7a9 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +from setuptools import setup, find_packages + +setup( + name='Persona1-text-tools', + version='0.1', + packages=find_packages(), + install_requires=[ + # Äîáàâüòå ñþäà çàâèñèìîñòè, åñëè îíè åñòü + ], + entry_points={ + 'console_scripts': [ + 'parse-event-strings=Persona1_text_tools.ibunroku_event_strings_parser:main', + 'inject-event-strings=Persona1_text_tools.ibunroku_event_strings_injecter:main', + 'bin-tool=Persona1_text_tools.ibunroku_binner2:main', + ], + }, +)