Document architecture checkpoint and restore original task callback order
This commit is contained in:
1 parent
69d0187a21
commit
531883aaac
45 files changed
+2935
-43
No files matched your search
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only camera/audio/UI checkpoint anchors, with PE-mapped offsets.
|
||||
|
||||
Run from GamePort: python3 tools/binary/checkpoint_camera_audio_ui.py ../Original
|
||||
This checks immutable source instructions; it neither executes nor writes originals.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
from pe_inspect import PE
|
||||
|
||||
EXE_SHA256 = 'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8'
|
||||
DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'
|
||||
|
||||
# Deliberately selected instruction sequences, rather than matching whole functions.
|
||||
ANCHORS = (
|
||||
('follow_default_eye_y200', 0x437742, 'c781cc07000000004843'),
|
||||
('follow_virtual_ray_callback', 0x439714, 'ff966c010000'),
|
||||
('follow_x_gain', 0x4397B1, 'd88d54080000d84c2414d88c2480000000'),
|
||||
('follow_y_extra_gain', 0x4397C2, 'd98558080000dc05d02a4a00'),
|
||||
('follow_viewport_position', 0x4397F8, 'a1509a5000'),
|
||||
('follow_ray_call', 0x43B874, 'e897090400'),
|
||||
('follow_hit_adjustment', 0x43B8AD, 'd826d80dacd54900'),
|
||||
('follow_hit_gain', 0x43B8F7, 'd90538314a00'),
|
||||
('jimmy_complete_vtable_ray_slot', 0x4A3D48, '20b84300'),
|
||||
('cam_interface_update_slot', 0x497FC0, '905f4100'),
|
||||
('cam_complete_activate_slot', 0x498138, 'a0654100'),
|
||||
('mca_interface_update_slot', 0x4A9328, 'a00d4300'),
|
||||
('mca_complete_activate_slot', 0x4A94A0, '80124300'),
|
||||
('default_local_eye', 0x447E2F, '680000fac3680000fa43'),
|
||||
('default_snap_threshold', 0x447E9D, 'd81dace54800dfe0f6c441'),
|
||||
('default_snap_store', 0x447EAA, 'd95944'),
|
||||
('cam_voice_poll', 0x415FC2, '8b8eb408000051e8c2780600'),
|
||||
('cam_music_bank', 0x416776, 'a104606900'),
|
||||
('cam_effect_bank_release_gate', 0x416813, '891d08606900881d34844f00'),
|
||||
('mca_effect_bank_release_gate', 0x4315C2, '891d08606900881d34844f00'),
|
||||
('default_effect_bank_restore_gate', 0x447F64, 'a30860690085c07406881d34844f00'),
|
||||
('voice_duration_and_repeat_flag', 0x47D8CB, 'ff50148b44240c85c075078a463084c07405'),
|
||||
('ui_dispatch_base_first', 0x404080, '83ec1453558b6c242056578bf155e8adf10600'),
|
||||
('ui_controlled_clock_then_draw', 0x4043D9,
|
||||
'391de49950000f8495000000d90588814f00d84424288bced91d88814f008b16ff92d0040000'),
|
||||
('modal_pause_game', 0x407022, '8b0d48995000538b01ff9068010000'),
|
||||
)
|
||||
|
||||
CONSTANTS = (
|
||||
('default_snap_distance', 0x48E5AC, 'f', 1000.0),
|
||||
('ray_hit_weight', 0x49D5AC, 'f', .75),
|
||||
('ray_hit_follow_gain', 0x4A3138, 'f', 1.5),
|
||||
('follow_y_gain_extra', 0x4A2AD0, 'd', .2),
|
||||
('special_eye_state_threshold', 0x495338, 'd', 1.7),
|
||||
('special_eye_back_multiplier', 0x4AFCF0, 'd', 3.7),
|
||||
('look_target_height_multiplier', 0x4AFCE8, 'd', 1.9),
|
||||
)
|
||||
|
||||
GLOBALS = (('viewport', 0x509A50), ('controlled', 0x5099E4),
|
||||
('music_database', 0x696004), ('current_wave_database', 0x696008),
|
||||
('sound_engine', 0x69600C), ('default_positional_sfx_gate', 0x4F8434),
|
||||
('objective_timer', 0x4F8188), ('objective_selector', 0x4F8194),
|
||||
('modal_active', 0x4F8198), ('modal_type', 0x4F8048))
|
||||
|
||||
|
||||
def recover(original):
|
||||
original = Path(original)
|
||||
pe = PE(original / 'Neutron.exe')
|
||||
exe_hash = hashlib.sha256(pe.data).hexdigest()
|
||||
dll_hash = hashlib.sha256((original / 'OMT2.dll').read_bytes()).hexdigest()
|
||||
if exe_hash != EXE_SHA256 or dll_hash != DLL_SHA256:
|
||||
raise ValueError('Unrecognized original module hash; do not apply preferred-VA evidence')
|
||||
result = {'module_hashes': {'Neutron.exe': exe_hash, 'OMT2.dll': dll_hash},
|
||||
'anchors': [], 'constants': [], 'globals': []}
|
||||
for name, va, expected in ANCHORS:
|
||||
off = pe.offset(va - pe.base)
|
||||
actual = pe.data[off:off + len(bytes.fromhex(expected))].hex()
|
||||
if actual != expected:
|
||||
raise ValueError(f'{name}: expected instruction bytes differ at {va:#x}')
|
||||
result['anchors'].append({'name': name, 'va': hex(va),
|
||||
'file_offset': hex(off), 'bytes': actual})
|
||||
for name, va, fmt, expected in CONSTANTS:
|
||||
off = pe.offset(va - pe.base)
|
||||
actual = struct.unpack_from('<' + fmt, pe.data, off)[0]
|
||||
if actual != expected:
|
||||
raise ValueError(f'{name}: constant differs')
|
||||
result['constants'].append({'name': name, 'va': hex(va),
|
||||
'file_offset': hex(off), 'value': actual, 'format': fmt})
|
||||
for name, va in GLOBALS:
|
||||
try:
|
||||
off = hex(pe.offset(va - pe.base))
|
||||
except ValueError:
|
||||
off = None # PE zero-fill; a VA is not automatically a physical file offset.
|
||||
result['globals'].append({'name': name, 'va': hex(va), 'file_offset': off})
|
||||
return result
|
||||
|
||||
|
||||
def obstructed_eye(look, hit):
|
||||
"""43B8AD..43B8F4 algebra, independent of unrecovered ray layer/filter rules."""
|
||||
return tuple(a - (a - b) * .75 for a, b in zip(look, hit, strict=True))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('original', type=Path)
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(recover(args.original), indent=2))
|
||||
Reference in new issue
Block a user