import os import struct import codecs import json from ibunroku_settings import load_encoding_table, commands def parse_event_strings(file_path, tbl_path): """ Parses event strings from a binary file and saves the output to text and JSON files. Args: file_path (str): Path to the binary file. tbl_path (str): Path to the encoding table file. """ encoding_table = load_encoding_table(tbl_path) with open(file_path, 'rb') as f: data = f.read() # Unpack header information header_size = struct.unpack('= 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)