#!/usr/bin/env python3 """Read-only retained-character initialization and PostLoad evidence.""" from __future__ import annotations import argparse import hashlib import json from pathlib import Path import struct import sys sys.path.insert(0, str(Path(__file__).resolve().parent)) from checkpoint_script_state import EXE_SHA256, find_case, read_va, rel_call_target from pe_inspect import PE sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'levels')) import gam SITES = ( ('player_init_base', 0x437896, 'e8550f0200'), ('player_init_speed_zero', 0x4378A1, '898608060000'), ('player_init_turn_zero', 0x4378A7, '898614060000'), ('player_init_618_zero', 0x4378AD, '898618060000'), ('player_init_euler_getter', 0x4378B8, 'ff9028030000'), ('player_init_yaw_capture', 0x4378BE, '8b500489961c060000'), ('euler_getter_y', 0x4723FC, '8b9128020000'), ('postload_jump_zero', 0x42378B, '6689bd28070000'), ('postload_normal_radius60', 0x4236A3, '6800007042'), ('postload_normal_support_factor', 0x4236B3, '6885eba13f'), ('postload_animation_pause_disable', 0x42370A, 'ff901c010000'), ('stage_sound_stop', 0x43B7FB, 'ff9248010000'), ('sound_stop_only_handle', 0x429A19, 'c786440a0000ffffffff'), ('fire_constructor_preservation', 0x421E51, 'e8eaf00400'), ('fire_constructor_owner_zero', 0x421E62, '899ebc060000'), ('fire_constructor_timer_zero', 0x421E68, '899ec0060000'), ('fire_owner_assignment', 0x437525, '8981bc060000'), ('fire_grounded_owner_clear', 0x421FE9, 'c7860006000000000000'), ('fire_timer_tick', 0x421FF3, 'd98600060000d8642418'), ('player_constructor_mode_zero', 0x43748A, '66899dc4070000'), ('goddard_init_base_jump', 0x41E6A0, 'e90b98feff'), ('goddard_init_authored_state', 0x407EBC, '8b867c080000898608060000'), ('goddard_init_waypoint_clear', 0x407EC8, 'c7860008000000000000'), ('goddard_postload_base', 0x41E593, 'e8e8aefeff'), ('goddard_reuse_callback', 0x423CE2, 'ff9074010000'), ('inventory_disable_compare_one', 0x40389E, '66833801751166c7000400'), ('inventory_enable_compare_four', 0x4038AA, '66833804750566c7000100'), ('tutorial_level_lower_bound', 0x423E52, '3d31305256'), ('tutorial_level_upper_bound', 0x423E5D, '3d38305256'), ('tutorial_mode_flag', 0x423E6A, 'c6853809000001'), ('tutorial_objective_hidden', 0x423EC6, 'c70588814f000000a041'), ) VTABLES = ( ('Jimmy Init', 0x4A373C, 0x28, 0x437890), ('Jimmy PostLoad', 0x4A373C, 0x40C, 0x423610), ('Jimmy Euler getter', 0x4A373C, 0x328, 0x4723F0), ('Jimmy transition stop sound', 0x4A3BDC, 0x148, 0x429A00), ('Jimmy animation pause', 0x4A3BDC, 0x11C, 0x40D350), ('Fire Init', 0x4A3160, 0x28, 0x4587F0), ('Fire PostLoad', 0x4A3160, 0x40C, 0x40E7B0), ('Goddard Init', 0x49F480, 0x28, 0x41E6A0), ('Goddard PostLoad', 0x49F480, 0x40C, 0x41E590), ('Shadow Init', 0x4B37B8, 0x28, 0x4587F0), ('Shadow PostLoad', 0x4B37B8, 0x40C, 0x43F810), ) GADGET_INDICES = (7, 3, 0, 5, 1, 6, 2, 4) ENABLE_CALLS = (0x423DEF, 0x423DFA, 0x423E05, 0x423E10, 0x423E1B, 0x423E26, 0x423E34, 0x423E3F) DISABLE_CALLS = (0x423E71, 0x423E7C, 0x423E87, 0x423E92, 0x423E9D, 0x423EA8, 0x423EB6, 0x423EC1) def gadget_postload(states, tutorial): """Common PostLoad prefix only:403870 preserves values other than1/4. Later level tails override this result; see retained_return_cleanup.py. This function does not model final scene availability. """ values = list(states) if len(values) < 8: raise ValueError('Need all eight group0 gadget entries') for index in GADGET_INDICES: if values[index] == 4: values[index] = 1 if tutorial: for index in GADGET_INDICES: if values[index] == 1: values[index] = 4 return values def collect(root: Path): pe = PE(find_case(root, 'Neutron.exe')) digest = hashlib.sha256(pe.data).hexdigest() sites = [] for name, va, expected in SITES: actual = read_va(pe, va, len(bytes.fromhex(expected))).hex() item = dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), expected=expected, actual=actual, matches=actual == expected) if actual.startswith('e8'): item['direct_call_target'] = hex(rel_call_target(pe, va)) sites.append(item) tables = [] for name, table, slot, expected in VTABLES: actual = struct.unpack('