#!/usr/bin/env python3 """Read-only authored/live body reset and cutscene-preparation provenance.""" import argparse import hashlib import json from pathlib import Path import struct from checkpoint_script_state import EXE_SHA256, find_case, read_va from pe_inspect import PE SITES = ( ('init_acceleration_get', 0x4706EA, 'ff921c010000'), ('init_acceleration_set', 0x47070F, 'ff9274020000'), ('init_impulse_get', 0x47071E, 'ff9024010000'), ('init_impulse_set', 0x470743, 'ff9288020000'), ('init_velocity_get', 0x4707BA, 'ff903c010000'), ('init_velocity_set', 0x4707DF, 'ff92c0020000'), ('authored_acceleration', 0x471294, '8b513c'), ('authored_impulse', 0x4712E4, '8b514c'), ('authored_velocity', 0x4713D4, '8b517c'), ('live_acceleration', 0x471BD8, '81c164010000'), ('live_impulse', 0x471CC8, '81c174010000'), ('live_velocity', 0x471F78, '81c1a4010000'), ('physics_impulse_get', 0x479EBB, 'ff9284020000'), ('physics_impulse_apply', 0x479EE5, 'ff97cc020000'), ('physics_impulse_clear', 0x479EF2, 'ff928c020000'), ('physics_acceleration_get', 0x479F01, 'ff9070020000'), ('physics_acceleration_apply', 0x479F4A, 'ff92cc020000'), ('physics_velocity_get', 0x479F8D, 'ff92bc020000'), ('postload_prepare', 0x42447D, 'ff9010040000'), ('jimmy_prepare_base', 0x42AFC3, 'e888f70000'), ('prepare_speed_clear', 0x43A758, 'c7860806000000000000'), ('prepare_velocity_xyz', 0x43A764, '6a006a006a008bceff90c4020000'), ('prepare_stop_sound', 0x43A77E, 'ff9248010000'), ('invalid_sound_handle_guard', 0x429A09, '83f8ff7415'), ('body_velocity_xyz_write', 0x471F48, '8981a4010000'), ('game_control_store', 0x475A44, 'a3e4995000'), ) TABLES = ( ('authored acceleration', 0x4A373C, 0x11C, 0x471290), ('live acceleration', 0x4A373C, 0x274, 0x471BD0), ('authored impulse', 0x4A373C, 0x124, 0x4712E0), ('live impulse', 0x4A373C, 0x288, 0x471CC0), ('authored velocity', 0x4A373C, 0x13C, 0x4713D0), ('live velocity', 0x4A373C, 0x2C0, 0x471F70), ('physics impulse', 0x4A373C, 0x284, 0x471C60), ('physics impulse clear', 0x4A373C, 0x28C, 0x471C90), ('physics velocity', 0x4A373C, 0x2BC, 0x471F10), ('velocity XYZ setter', 0x4A373C, 0x2C4, 0x471F40), ('velocity adder', 0x4A373C, 0x2CC, 0x471FA0), ('Jimmy preparation', 0x4A373C, 0x410, 0x42AFC0), ('Jimmy stop sound', 0x4A3BDC, 0x148, 0x429A00), ('lab control assignment', 0x4C3CD0, 0x118, 0x475A40), ('tutorial control assignment', 0x4CE910, 0x118, 0x475A40), ('outside control assignment', 0x4C5A80, 0x118, 0x475A40), ) def collect(root): pe = PE(find_case(Path(root), 'Neutron.exe')) if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256: raise ValueError('Unsupported original EXE') sites = [] for name, va, expected in SITES: actual = read_va(pe, va, len(bytes.fromhex(expected))).hex() if actual != expected: raise ValueError(f'{name} changed at {va:#x}: {actual}') sites.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=actual)) tables = [] for name, table, slot, target in TABLES: actual = struct.unpack('