#!/usr/bin/env python3 """Read-only Rocketship contracts and isolated input/vertical probe generators. The input probe executes copied41A6C0 only through41AC0E, with synthetic mouse/support/transform/audio dependencies. The vertical probe executes only 41A470..41A6A8 with synthetic body accessors. Neither runs the original game. """ from __future__ import annotations import argparse import hashlib import json import math from pathlib import Path import re import struct from checkpoint_script_state import EXE_SHA256, find_case, read_va from pe_inspect import PE BODIES = ( ('ctor', 0x43d840, 0x43da40, '33d27053c2070f0c278bf3e14808d16c4479893d1ccb16c1ac8e199dfd9e53ba'), ('init', 0x43dd10, 0x43dd92, 'cd6e843749b7c87db7df223fd98f5f16c5b01b7097c0b0d4a661dd28eb1bd494'), ('flying_ctor', 0x419b70, 0x419db0, '85c0e74764282ed55e2c7268a0dec5944097b16f1a9df71054e5458b446ee2c0'), ('flight_apply', 0x41a140, 0x41a6b1, '20fc706986e58791dc19334a01a772dd517cbd260079382dac2f009fc8707bb7'), ('flight_input', 0x41a6c0, 0x41ade1, '4c68ae3cf48aecf266ef0a9e8ec81646bd4b774251aac4e38563765a51db2625'), ('rocket_input', 0x43e7e0, 0x43e854, 'db973aebd9dad23de493d79606b3016e3e04c7ba029452ee07a6fd6e9abfd5b9'), ('mount', 0x42944d, 0x429686, '2e8e15c52bf02a06afe2a56ccf8b31551368aefcde046c444ddb01a3ef978c70'), ('cleanup', 0x428512, 0x42871d, 'e35f82a6b4e791e77278cdf84bc3878237d57c54355254cfbeff3923d2c70ee6'), ('vr02_ctor', 0x456270, 0x456360, '058e77e27d8dbb2de5306c0582ccc1c7caf81cf29ae64caa43d3d1cd174b63c8'), ('fire_ctor', 0x4192e0, 0x41944c, 'e66ca12f68c3fc87bd855d0865871d387627684e31429460b84139f28e77afdb'), ) VTABLES = ((0x4b25ac, 0x110, 0x471240), (0x4b25ac, 0x264, 0x471b40), (0x4b25ac, 0x3c4, 0x43df70), (0x4b25ac, 0x3cc, 0x43e7e0), (0x4b2a4c, 0x128, 0x43ea80), (0x4cdd30, 0x134, 0x475cd0)) CONSTANTS = ((0x49d5b0, -60.), (0x49d5b4, 60.), (0x49d5b8, 0.0181818176060915), (0x49d5d4, 0.10000000149011612), (0x49d5dc, 0.9090909361839294), (0x49d5e4, 160.), (0x49b1fc, 130.), (0x48e5bc, 500.)) PROBE_GLOBALS = (0x509a50, 0x50985d, 0x50985f, 0x509aa0, 0x509aa4, 0x48d914, 0x48d948, 0x48d94c, 0x49b1fc, 0x49d5e4, 0x509882, 0x509881, 0x509885, 0x509891, 0x509848, 0x50985e, 0x509834, 0x49d5e0, 0x49d5dc, 0x48e5bc, 0x509860, 0x50993a, 0x49d5d8, 0x49d5d4, 0x48e5ec, 0x495324, 0x49d5d0, 0x49d5cc, 0x49d5c8) VERTICAL_GLOBALS = (0x48d96c, 0x48d914, 0x49d5b4, 0x49d5b0, 0x5cfc04) def collect(original: Path | str): pe = PE(find_case(Path(original), 'Neutron.exe')) if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256: raise ValueError('Unexpected original EXE identity') bodies = [] for name, start, end, expected in BODIES: digest = hashlib.sha256(read_va(pe, start, end-start)).hexdigest() if digest != expected: raise ValueError(f'Changed source span {name}') bodies.append(dict(name=name, va=hex(start), file_offset=hex(pe.offset(start-pe.base)), length=end-start, sha256=digest)) for table, slot, target in VTABLES: if struct.unpack(' #include #include #include #include #define TC __attribute__((thiscall)) static unsigned char *mapped,object[0x1000],camera[0x100]; static uintptr_t table[0x400/4],outer[0x200/4]; static int grounded; static short mouse_x,mouse_y; static float euler[4],destination[3]; #define AT(va) (mapped+(va)-0x400000) #define F(g,off) (*(float*)((g)+(off))) static void require(int condition,const char*message){if(!condition){fprintf(stderr,"FAIL %s\n",message);exit(2);}} static void __cdecl mouse(short*x,short*y){*x=mouse_x;*y=mouse_y;} static int TC supported(void*self){(void)self;return grounded;} static float* TC rotation(void*self,float*out){(void)self;memcpy(out,euler,sizeof(euler));return out;} static void TC desired(void*self,float x,float y,float z){(void)self;destination[0]=x;destination[1]=y;destination[2]=z;} static void TC sound(void*self,int mode){(void)self;(void)mode;} static void TC missing(void*self){(void)self;require(0,"unexpected virtual");} static const struct{uint32_t va,target;} relocations[]={ /* RELOCATIONS */ }; static void map_copy(void){ mapped=VirtualAlloc(NULL,0x299000,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE); require(mapped!=NULL,"map copied source"); FILE*f=fopen("Neutron.exe","rb");require(f!=NULL,"copied EXE"); fseek(f,0,SEEK_END);long size=ftell(f);rewind(f);require(size==1019904,"bounded EXE size"); unsigned char*data=malloc(size);require(data!=NULL,"file buffer"); require(fread(data,1,size,f)==(size_t)size,"read source");fclose(f); require(*(uint16_t*)data==IMAGE_DOS_SIGNATURE,"DOS header"); uint32_t offset=*(uint32_t*)(data+0x3c);require(offset<(uint32_t)size-sizeof(IMAGE_NT_HEADERS32),"NT bounds"); IMAGE_NT_HEADERS32*nt=(void*)(data+offset); require(nt->Signature==IMAGE_NT_SIGNATURE&&nt->FileHeader.Machine==IMAGE_FILE_MACHINE_I386&&nt->OptionalHeader.ImageBase==0x400000&&nt->OptionalHeader.SizeOfImage==0x299000,"PE identity"); IMAGE_SECTION_HEADER*sections=IMAGE_FIRST_SECTION(nt); require((unsigned char*)(sections+nt->FileHeader.NumberOfSections)<=data+size,"section table"); for(unsigned i=0;iFileHeader.NumberOfSections;i++){ IMAGE_SECTION_HEADER*s=§ions[i]; require((uint64_t)s->PointerToRawData+s->SizeOfRawData<=(uint64_t)size&&(uint64_t)s->VirtualAddress+s->SizeOfRawData<=0x299000,"section bounds"); memcpy(mapped+s->VirtualAddress,data+s->PointerToRawData,s->SizeOfRawData); } free(data); for(unsigned i=0;i