#!/usr/bin/env python3 """Guard the Grappler/body handoff and generate its isolated copied-code probe. Original files are read only. The generated probe uses synthetic actors and a two-triangle grid; it does not start the original game or run its entry point. """ import argparse import hashlib import json from pathlib import Path import struct from body_step_evidence import collect as body_collect from checkpoint_script_state import find_case, read_va from collision_response import header from pe_inspect import PE RANGES = ( ('physics_scheduler', 0x479BC0, 0x479D1B, '857abe5d3602741415f84c7a735cd867a86126eb0ed8049ecebf962025d45e64'), ('attached', 0x429D00, 0x42A660, '9f4f17bafbca614ee64094df4d951c53cb122f8e15adb9fd7f8a58be589cc2f3'), ('jimmy_wall', 0x42A660, 0x42A714, 'd52831057c35afbdb73babff81857a6a3cfb2466f639b8be0a80e6300d386b0c'), ('player_wall_full', 0x43AA40, 0x43AFE3, '2acd114eb62fe67490d9301bc8e68f196830be74eb9076f52f79111467344a78'), ('ceiling_stop', 0x472690, 0x47274A, 'febfe9381b19074c41b229b314307c85f95710a35c7907935f76519052d4b50c'), ) SPHERE = (0x695D4C, 0x695D5C, 0x5CFBE0, 0x5CFBE8) def collect(original): report = body_collect(original) pe = PE(find_case(Path(original), 'Neutron.exe')) report['handoff_ranges'] = [] for name, start, end, digest in RANGES: data = read_va(pe, start, end-start) if hashlib.sha256(data).hexdigest() != digest: raise ValueError(f'Changed {name}') report['handoff_ranges'].append(dict(name=name, va=hex(start), file_offset=hex(pe.offset(start-pe.base)), length=end-start, sha256=digest)) if name in ('jimmy_wall', 'player_wall_full', 'ceiling_stop'): for target in (0x4F0588, 0x4F8210, 0x4F82BC, 0x4F82C0, 0x49D5B4, 0x48E5A0, 0x48D914): value = struct.pack('value=r; n->next=s;n->previous=s->previous;s->previous->next=n;s->previous=n; } } static void snapshot(const char*name,Body*b,unsigned a,unsigned c,int unchanged) { Context s=context(); printf("CASE %s root=%.9g,%.9g,%.9g lastWall=%d face=%.9g edge=%.9g " "hit=%.9g,%.9g,%.9g callback370=%u callback374=%u unchanged=%d support=%d\n", name,b->position.x,b->position.y,b->position.z,s.last==wallPolygon,s.face,s.edge, s.hit.x,s.hit.y,s.hit.z,contact370-a,contact374-c,unchanged,b->supported); } static void full_callbacks(void) { // Direct offsets belong to the original player interface, not our Body stub. unsigned char jimmy[0x2100],before[0x2100],material[0x20],definition[0x20]; uintptr_t completeTable[0x500/4]; for(unsigned i=0;i