import os import pathlib import re import struct BACKUP_DIR = "original_patches" LAYERED_FS_DIR = "romfs" MOD_DIR = "mods" INFO_ENTRY_STRUCT = struct.Struct(' latest_patch_num: latest_patch_num = cur_patch_num latest_patch_name = dir_entry if not latest_patch_num: print(f"Failed to find latest patch. Did you include it in {BACKUP_DIR}?") exit(1) print("Using found latest:", latest_patch_name) # Collect original entries index_entry_map = {} path_index_map = {} original_info0_path = os.path.join(BACKUP_DIR, latest_patch_name, "INFO0.bin") with open(original_info0_path, 'rb') as info0_file: while True: cur_entry_data = info0_file.read(INFO_ENTRY_STRUCT.size) if len(cur_entry_data) == 0: break cur_entry = InfoEntry(data=cur_entry_data) index_entry_map[cur_entry.index] = cur_entry path_index_map[cur_entry.path] = cur_entry.index original_info2_path = os.path.join(BACKUP_DIR, latest_patch_name, "INFO2.bin") with open(original_info2_path, 'rb') as info2_file: _, info1_entry_count = struct.unpack('