#!/usr/bin/env python3 """Read-only479D20 composition guards, grounded in retained REA body evidence.""" from __future__ import annotations 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 BODY_START = 0x479D20 BODY_END = 0x47A32A BODY_SHA256 = '5f4b05518bef5e5f0ecc3909ff0de0b43d2c7350c6beae0c4f797d3238a77fa1' REA_BODY = 'ev_5439072b32ae9f9208795ad2b07bc524e2407b46da487072fb3dfd8c10e7c4b0' SITES = ( ('read_previous_support', 0x479D2E, 'ff9018020000'), ('cache_previous_support', 0x479D34, 'a2495d6900'), ('read_support_enabled_before_integration_gate', 0x479D3D, 'ff92c8010000'), ('clear_current_support', 0x479D4E, 'ff901c020000'), ('integration_gate', 0x479D58, 'ff9210020000'), ('disabled_integration_return', 0x479D60, '0f84bd050000'), ('geometry_global_gate', 0x479DDA, '381de5694f00'), ('geometry_enabled_anchor', 0x479DE4, '8b1653680050c3c6538bceff92f4020000'), ('geometry_disabled_support_true', 0x479DF9, '6a018bceff901c020000'), ('geometry_disabled_anchor_current_y', 0x479E03, '8b4424408b165350538bceff92f4020000'), ('geometry_disabled_inverse_gravity_y', 0x479E14, 'd90504fc5c00'), ('geometry_disabled_acceleration_xyz', 0x479E26, 'ff9278020000'), ('geometry_disabled_velocity_y_zero', 0x479E54, 'ff97c4020000'), ('read_angular_velocity', 0x479E63, 'ff92ac020000'), ('rotate_before_impulse', 0x479EAC, 'ff9034030000'), ('read_pending_impulse', 0x479EBB, 'ff9284020000'), ('add_pending_impulse', 0x479EE5, 'ff97cc020000'), ('consume_pending_impulse', 0x479EF2, 'ff928c020000'), ('read_acceleration', 0x479F01, 'ff9070020000'), ('add_acceleration', 0x479F4A, 'ff92cc020000'), ('add_gravity', 0x479F7E, 'ff90cc020000'), ('read_final_velocity', 0x479F8D, 'ff92bc020000'), ('collision220_gate', 0x479FD6, 'ff9020020000'), ('world1d0_gate', 0x479FE8, 'ff92d0010000'), ('reset_last_polygon', 0x47A038, '891d4c5d6900'), ('reset_nearest_face130000', 0x47A03E, 'c7055c5d690000e8fd47'), ('reset_nearest_edge_radius', 0x47A062, 'd91de0fb5c00'), ('capture_previous_root', 0x47A084, 'ff90fc020000'), ('delta_y_compare_zero', 0x47A08A, 'd90514d94800d9442430d8d9'), ('reset_auxiliary_collision_state', 0x47A096, '891d845d6900'), ('delta_y_nonpositive_branch', 0x47A09E, 'f6c441753d'), ('positive_full_dispatch', 0x47A0D6, 'e8d5130000'), ('nonpositive_horizontal_dispatch', 0x47A10F, 'e89c130000'), ('add_vertical_after_horizontal', 0x47A114, 'd944243cd844244c83c41cd95c2420'), ('read_previous_root_after_callback', 0x47A12C, 'ff92f8020000'), ('read_live_root_after_callback', 0x47A13D, 'ff9210030000'), ('root_compare_x', 0x47A143, 'd9078bc8d819'), ('root_compare_y', 0x47A154, 'd94704d85904'), ('root_compare_z', 0x47A165, 'd94708d85908'), ('root_compare_w', 0x47A176, 'd9470cd8590c'), ('clamp_candidate_y', 0x47A187, 'd9442420d81d086a4d00'), ('clamp_candidate_y_store', 0x47A198, 'c74424200050c3c6'), ('publish_candidate314', 0x47A1C4, 'ff9014030000'), ('world_disabled_capture_previous', 0x47A1FA, 'ff92fc020000'), ('world_disabled_translate', 0x47A220, 'ff921c030000'), ('post_motion_support_gate', 0x47A22A, 'ff90c8010000'), ('post_motion_support', 0x47A235, 'e856160000'), ('read_published_speed_for_friction', 0x47A241, 'ff9268020000'), ('friction', 0x47A25A, 'e8d1000000'), ('collision_disabled228_gate', 0x47A264, 'ff9228020000'), ('collision_disabled_translate', 0x47A28E, 'ff921c030000'), ('suppression_scale', 0x47A298, 'ff9030020000'), ('angular_suppression_inclusive', 0x47A2C5, 'f6c441740d'), ('angular_suppression_zero', 0x47A2D1, 'ff92b4020000'), ('linear_suppression_inclusive', 0x47A2FA, 'f6c4417424'), ('linear_suppression_published_speed', 0x47A303, 'ff9268020000'), ('linear_suppression_zero', 0x47A31D, 'ff90c4020000'), ('ctor_suppression_scale_half', 0x46FE01, '680000003f8bcde813130000'), ('player_friction_point8', 0x4373B0, '68cdcc4c3f'), ('player_friction_setter', 0x4373BD, 'e8ee9d0300'), ('friction_authored_to_live24c', 0x4711B0, '8b4424048b1150894128ff924c020000c20400'), ('jimmy_postload_radius60', 0x4236A3, '6800007042'), ('jimmy_postload_factor1265', 0x4236B3, '6885eba13f'), ('air_helper_complete_to_interface', 0x437FA3, '8dbec0000000'), ('burst_radius100', 0x4384E4, '680000c842'), ('burst_live_radius264', 0x4384F3, 'ff9264020000'), ('held_landing_radius60', 0x4386C1, '6800007042'), ('held_landing_live_radius264', 0x4386C8, 'ff9264020000'), ('authored_radius_to_live264', 0x471240, '8b4424048b1150894134ff9264020000c20400'), ('live_radius260', 0x471B30, 'd9815c010000c3'), ('live_radius264', 0x471B40, '8b44240489815c010000c20400'), ('live_support_factor250', 0x471AF0, 'd98154010000c3'), ('live_support_factor254', 0x471B00, '8b442404898154010000c20400'), ('ctor_zero_register', 0x46FC08, '33db'), ('ctor_authored_speed_zero', 0x46FE51, '538bcde817140000'), ('authored_speed_getter114', 0x471260, 'd94138c3'), ('authored_speed_setter118_to_live26c', 0x471270, '8b4424048b1150894138ff926c020000c20400'), ('init_authored_speed114', 0x4706CF, 'ff9714010000'), ('init_publish_speed26c', 0x4706DB, 'ff976c020000'), ('published_speed_getter268', 0x471B50, 'd98160010000c3'), ('published_speed_setter26c', 0x471B60, '8b442404898160010000c20400'), ) TABLES = ((0x100, 0x4711E0), (0x110, 0x471240), (0x248, 0x471AD0), (0x24C, 0x471AE0), (0x250, 0x471AF0), (0x254, 0x471B00), (0x260, 0x471B30), (0x264, 0x471B40), (0x114, 0x471260), (0x118, 0x471270), (0x268, 0x471B50), (0x26C, 0x471B60)) def phase_order(*, support_enabled=True, integration_enabled=True, geometry_enabled=True, collision_enabled=True, world_enabled=True, translation_locked=False, upward=False): """Control-flow projection only; no numeric/body or native execution claim.""" phases = ['read_previous_support'] if support_enabled: phases.append('clear_current_support') phases.append('integration_gate') if not integration_enabled: return phases phases.append('anchor_far_below' if geometry_enabled else 'geometry_off_support_anchor_acceleration_velocity') phases.extend(('rotate', 'impulse_add', 'impulse_clear', 'acceleration_add', 'gravity_add', 'velocity_to_delta')) if collision_enabled: if world_enabled: phases.extend(('reset_static_context', 'capture_previous_root', 'full_dispatch' if upward else 'horizontal_dispatch')) if not upward: phases.append('add_fall_y') phases.extend(('compare_previous_live_root_vec4', 'conditional_clamp_y_publish314')) else: phases.extend(('capture_previous_root', 'translate31c')) if support_enabled: phases.append('support47b890') phases.append('published_speed_zero_friction') elif not translation_locked: phases.append('translate31c') phases.extend(('angular_suppression', 'published_speed_zero_linear_suppression')) return phases def can_publish(previous_root, live_root): """Finite Vec4 equality predicate47A143..47A181, after contact callback.""" if len(previous_root) != 4 or len(live_root) != 4: raise ValueError('Source publication comparison is Vec4') return all(a == b for a, b in zip(previous_root, live_root, strict=True)) def collect(original): pe = PE(find_case(Path(original), 'Neutron.exe')) digest = hashlib.sha256(pe.data).hexdigest() if digest != EXE_SHA256: raise ValueError('Unexpected original executable identity') body = read_va(pe, BODY_START, BODY_END-BODY_START) if hashlib.sha256(body).hexdigest() != BODY_SHA256: raise ValueError('Changed body integration instructions') sites = [] for name, va, expected in SITES: actual = read_va(pe, va, len(bytes.fromhex(expected))) if actual.hex() != expected: raise ValueError(f'Changed source site {name} at {va:x}') sites.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=expected)) factor = struct.unpack('