Recover actor normal callbacks and late collision reads

This commit is contained in:
UnixNight committed 2026-11-07 19:36:26 -05:00
1 parent bf876e9c3c
commit bdca29d3aa
19 files changed
+963 -1

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
#!/usr/bin/env python3
"""Guard and execute original normal callbacks on bounded synthetic actors."""
import argparse
import hashlib
import json
from pathlib import Path
import struct
from dynamic_context import collect as dynamic_collect
from collision_response import header
from checkpoint_script_state import find_case,read_va
from pe_inspect import PE
from physical_registration import CLASSES
from dynamic_reclip import differences
CALLBACKS=(('jimmy_wall',0x42a660,0x42a714),('player_wall',0x43aa40,0x43afe3),
('base_ceiling',0x472690,0x47274a),('base_wall',0x458890,0x4588cd),
('reflection',0x472750,0x472970),('soldier_wall',0x409590,0x4095ee))
# Complete operands reviewed within individual instructions in retained REA
# ev_0d64cc58fa8f5573fc8e61e0f2c20e36288099212bd2257d3a3121361fd6c904.
# A numeric scan across instruction boundaries incorrectly selected4095BE.
CALLBACK_OPERANDS=(
(0x42a663,0x4f0588),(0x42a678,0x4f8210),(0x42a69d,0x4f82bc),
(0x42a6a3,0x4f82c0),(0x42a6b1,0x4f82bc),(0x42a6bb,0x4f82c0),
(0x42a6cd,0x49d5b4),(0x43aa52,0x48e5a0),(0x43ab58,0x48d400),
(0x43abd2,0x4f0668),(0x43ac25,0x48d108),(0x43ac3c,0x48e5b4),
(0x43acb9,0x4f0668),(0x43ad05,0x4afd40),(0x43ad9d,0x48e5ec),
(0x43adbd,0x48d400),(0x43ae4c,0x48e5ec),(0x43ae6c,0x48d400),
(0x43af16,0x48d108),(0x43af30,0x48e5b4),(0x43afd1,0x4f0670),
(0x4726ac,0x48d914),(0x472703,0x48d914),(0x47278f,0x48d104),
(0x47279d,0x48d104),(0x4727a3,0x48d924),(0x472882,0x48d108),
(0x4728b1,0x48e5b4),(0x4728bb,0x48d104),(0x4728c1,0x48d924),
(0x472900,0x48e5b4),(0x47290a,0x48d914),(0x472917,0x48e5b0),
(0x472924,0x48e5c4),(0x47292c,0x48e5c0),(0x472939,0x48e5c4),
(0x47294a,0x4d5fd8))
GETTERS=((0x1d0,0x4718f0,'8a813c010000c3',0x13c),
(0x1d8,0x471910,'8a813d010000c3',0x13d),
(0x1e0,0x471930,'8a8137010000c3',0x137),
(0x248,0x471ad0,'d98150010000c3',0x150),
(0x260,0x471b30,'d9815c010000c3',0x15c))
SLOTS=(0x370,0x374,0x378,0x1d0,0x1d8,0x1e0,0x248,0x260,0x270,0x274,0x2b8,0x2bc,0x2c0,0x2c4)
CASES=('jimmy_null','jimmy_jetpack','jimmy_ordinary_polygon','jimmy_elapsed_gate',
'jimmy_mode1','jimmy_mode2','jimmy_uncontrolled','jimmy_gadget7_inactive',
'jimmy_gadget7_equal','jimmy_gadget7_large','ceiling_positive','ceiling_negative',
'ceiling_velocity_only','ceiling_acceleration_only','generic_disabled','generic_axis',
'generic_no_damping','generic_excess_damping','generic_oblique','generic_fresh_y',
'soldier_mode0','soldier_mode10','soldier_mode10_disabled','dynamic_jimmy',
'dynamic_generic','dynamic_soldier','late_inhibition','late_radius','late_geometry','late_force')
def collect(original):
report=dynamic_collect(original);pe=PE(find_case(Path(original),'Neutron.exe'))
for name,start,end in CALLBACKS:
code=read_va(pe,start,end-start)
report['bodies'].append(dict(name=name,va=hex(start),file_offset=hex(pe.offset(start-pe.base)),
length=end-start,sha256=hashlib.sha256(code).hexdigest()))
for va,target in CALLBACK_OPERANDS:
if read_va(pe,va,4)!=struct.pack('<I',target):raise ValueError('Changed reviewed operand')
report['probe_operands'].append(dict(va=va,target=target))
report['probe_operands'].sort(key=lambda p:p['va'])
bindings=[]
for kind,name,ctor,table,displacement,*_ in CLASSES:
bindings.append(dict(kind=kind,name=name,table=hex(table),displacement=hex(displacement),
table_file_offset=hex(pe.offset(table-pe.base)),
methods={hex(slot):hex(struct.unpack('<I',read_va(pe,table+slot,4))[0]) for slot in SLOTS}))
report['normal_bindings']=bindings
getters=[]
for slot,va,code,field in GETTERS:
if read_va(pe,va,len(bytes.fromhex(code))).hex()!=code:raise ValueError('Changed scalar getter')
if any(c['methods'][hex(slot)]!=hex(va) for c in bindings):raise ValueError('Getter override requires separate recovery')
getters.append(dict(slot=hex(slot),va=hex(va),file_offset=hex(pe.offset(va-pe.base)),field=hex(field),bytes=code))
report['scalar_getters']=getters
report['scope']='Complete normal callbacks and dynamic/static kernels, synthetic actor/getters/grid; Soldier complete174 and Jimmy204 are record-only stubs, not executed policies.'
return report
def generate(original,output):
original,output=Path(original).resolve(),Path(output).resolve()
if output.is_relative_to(original) or original.is_relative_to(output):raise ValueError('Separate output required')
if output.exists() and any(p.is_symlink() for p in output.rglob('*')):raise ValueError('Generated output contains symlinks')
report=collect(original);output.mkdir(parents=True,exist_ok=True)
for name in ('actor_contact_probe.c','collision_dispatch_probe.c','collision_response_probe.c'):
text=Path(__file__).with_name(name).read_text()
if name=='collision_dispatch_probe.c':text=text.split('int main(void)')[0]
(output/name).write_text(text)
(output/'collision_response_relocations.h').write_text(header(report))
(output/'source.json').write_text(json.dumps(report,indent=2)+'\n')
return dict(bodies=len(report['bodies']),relocations=len(report['probe_operands']),classes=len(report['normal_bindings']))
def capture(output,directory):
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
source=json.loads((output/'source.json').read_text());metadata=json.loads((directory/'capture.json').read_text())
log=(directory/'wine.log').read_text()
if metadata['captures'][-1]['wineExit']!=0 or 'ACTOR_CONTACT_COMPLETE' not in log:raise ValueError('Incomplete execution')
for name,key in [('Neutron.exe','sha256'),('OMT2.dll','omt_sha256')]:
if sha(find_case(directory/'game',name))!=source[key]:raise ValueError('Copied source identity mismatch')
if json.loads((directory/'probe-identity.json').read_text())['sha256']!=sha(output/'probe.exe'):raise ValueError('Probe identity mismatch')
cases=[json.loads(line[6:]) for line in log.splitlines() if line.startswith('ACTOR ')]
if tuple(c['name'] for c in cases)!=CASES:raise ValueError('Incomplete case sequence')
files=[directory/'wine.log',directory/'capture.json',directory/'probe-identity.json',
*(output/name for name in ('source.json','actor_contact_probe.c','collision_dispatch_probe.c',
'collision_response_probe.c','collision_response_relocations.h','probe.exe'))]
(output/'observations.json').write_text(json.dumps(dict(cases=cases,scope=source['scope'],
provenance={str(p):sha(p) for p in files}),indent=2)+'\n')
return dict(cases=len(cases),scope=source['scope'])
def compare(output,managed):
native=json.loads((output/'observations.json').read_text());actual=json.loads(managed.read_text())
if any(tuple(c['name'] for c in data['cases'])!=CASES for data in (native,actual)):
raise ValueError('Case sequence differs')
cases=[dict(name=a['name'],differences=differences(a,b)) for a,b in zip(native['cases'],actual['cases'])]
result=dict(exact_cases=sum(not c['differences'] for c in cases),total_cases=len(cases),cases=cases,
scope='Exact float32 numeric values and full emitted state/trace; derived endpoints remain synthetic.')
(output/'comparison.json').write_text(json.dumps(result,indent=2)+'\n')
return result
if __name__=='__main__':
cli=argparse.ArgumentParser(description=__doc__);cli.add_argument('original',type=Path)
cli.add_argument('--output',type=Path,required=True);mode=cli.add_mutually_exclusive_group()
mode.add_argument('--capture',type=Path);mode.add_argument('--managed',type=Path);args=cli.parse_args()
print(json.dumps(compare(args.output,args.managed) if args.managed else
capture(args.output,args.capture) if args.capture else generate(args.original,args.output),indent=2))
+125
View File
@@ -0,0 +1,125 @@
/* Complete original callbacks; actor accessors and derived policy endpoints are
* fixtures. No original constructor, entrypoint or full soldier knockback runs. */
#include "collision_dispatch_probe.c"
static unsigned char complete_body[0x2400],box_body[0x500],test_material[32],test_chunk[32];
#define BODY (complete_body+0xc0)
static uintptr_t body_methods[0x440/4],outer_methods[0x210/4],box_methods[0x440/4];
static Vec body_root,body_previous,body_velocity,body_acceleration,body_angular,knock_normal;
static float body_radius,damping,knock_force;
static int reflect,mutation,fresh_y,inhibited,knocks,cleanups,velocity_gets;
static unsigned radius_count;static float radius_values[16];
static char event_log[1024];static unsigned event_length;
typedef void(TC *Angles)(void*,short*,short*);
static Angles original_angles;
static Vec angle_vectors[8];static short angle_pitch[8],angle_yaw[8];static unsigned angle_count;
static void event(const char*s){int n=snprintf(event_log+event_length,sizeof(event_log)-event_length,"%s%s",event_length?",":"",s);require(n>0&&event_length+(unsigned)n<sizeof(event_log),"event bound");event_length+=(unsigned)n;}
static void vector_json(Vec v){printf("[%.9g,%.9g,%.9g,%.9g]",v.x,v.y,v.z,v.w);}
static Vec*TC t_velocity(void*self,Vec*out){require(self==BODY,"velocity owner");event("Gv");velocity_gets++;if(fresh_y&&velocity_gets==2)body_velocity.y=99;*out=body_velocity;return out;}
static void TC t_velocity4(void*self,Vec v){require(self==BODY,"velocity4 owner");event("Sv4");body_velocity=v;}
static void TC t_velocity3(void*self,float x,float y,float z){require(self==BODY,"velocity3 owner");event("Sv3");body_velocity.x=x;body_velocity.y=y;body_velocity.z=z;}
static Vec*TC t_acceleration(void*self,Vec*out){require(self==BODY,"acceleration owner");event("Ga");*out=body_acceleration;return out;}
static void TC t_acceleration4(void*self,Vec v){require(self==BODY,"acceleration4 owner");event("Sa4");body_acceleration=v;}
static void TC t_angular(void*self,float x,float y,float z){require(self==BODY,"angular owner");event("Aw");body_angular.x+=x;body_angular.y+=y;body_angular.z+=z;}
static int TC t_reflect(void*self){require(self==BODY,"reflect owner");event("Gate");return reflect;}
static float TC t_damping(void*self){require(self==BODY,"damping owner");event("F");return damping;}
static void TC t_angles(void*self,short*p,short*y){require(angle_count<8,"angle bound");unsigned i=angle_count++;angle_vectors[i]=*(Vec*)self;original_angles(self,p,y);angle_pitch[i]=*p;angle_yaw[i]=*y;event("Angles");}
static void TC t_knock(void*self,float force,Vec n){require(self==complete_body&&force==500,"knock owner/force");event("K174");knocks++;knock_force=force;knock_normal=n;
if(mutation==1)inhibited=1;
if(mutation==2)body_radius=20;
if(mutation==3)*(unsigned char*)AT(0x4f69e5)=0;
if(mutation==4)BODY[0x42c]=1;
}
static void TC t_cleanup(void*self){require(self==complete_body,"cleanup owner");event("C204");cleanups++;}
static void TC unexpected(void*self){(void)self;require(0,"unsupported callback policy");}
static float TC t_radius(void*self){if(self==box_body)return 40;require(self==BODY&&radius_count<16,"radius owner/bound");radius_values[radius_count++]=body_radius;event("Radius");return body_radius;}
static Vec*TC t_root(void*self,Vec*out){*out=self==box_body?(Vec){0,0,0,1}:body_root;return out;}
static Vec*TC t_previous(void*self,Vec*out){require(self==BODY,"previous owner");*out=body_previous;return out;}
static void TC t_publish(void*self,Vec value){require(self==BODY,"root owner");event("Root");body_root=value;}
static int TC t_geometry(void*self){(void)self;return 1;}
static int TC t_mode(void*self){(void)self;return 0;}
static int TC t_inhibit(void*self){require(self==box_body,"box inhibit owner");event("Inhibit");return inhibited;}
static Vec*TC t_low(void*self,Vec*out){(void)self;*out=(Vec){-50,-50,-10,1};return out;}
static Vec*TC t_high(void*self,Vec*out){(void)self;*out=(Vec){50,50,10,1};return out;}
static Vec*TC t_point(void*self,Vec*out,float x,float y,float z){(void)self;*out=(Vec){x,y,z,1};return out;}
static void reset(int kind){
memset(complete_body,0,sizeof(complete_body));memset(box_body,0,sizeof(box_body));
memset(body_methods,0,sizeof(body_methods));memset(outer_methods,0,sizeof(outer_methods));memset(box_methods,0,sizeof(box_methods));
*(void**)complete_body=outer_methods;*(void**)BODY=body_methods;*(void**)box_body=box_methods;
outer_methods[0x160/4]=outer_methods[0x164/4]=(uintptr_t)unexpected;
outer_methods[0x174/4]=(uintptr_t)t_knock;outer_methods[0x204/4]=(uintptr_t)t_cleanup;
body_methods[0x2bc/4]=(uintptr_t)t_velocity;body_methods[0x2c0/4]=(uintptr_t)t_velocity4;body_methods[0x2c4/4]=(uintptr_t)t_velocity3;
body_methods[0x270/4]=(uintptr_t)t_acceleration;body_methods[0x274/4]=(uintptr_t)t_acceleration4;
body_methods[0x2b8/4]=(uintptr_t)t_angular;body_methods[0x1d8/4]=(uintptr_t)t_reflect;body_methods[0x248/4]=(uintptr_t)t_damping;
body_methods[0x378/4]=(uintptr_t)AT(0x472750);body_methods[0x370/4]=(uintptr_t)AT(0x472690);
body_methods[0x374/4]=(uintptr_t)AT(kind==0?0x42a660:kind==1?0x458890:0x409590);
body_methods[0x260/4]=box_methods[0x260/4]=(uintptr_t)t_radius;
body_methods[0x310/4]=box_methods[0x310/4]=(uintptr_t)t_root;
body_methods[0x2f8/4]=(uintptr_t)t_previous;body_methods[0x314/4]=(uintptr_t)t_publish;
body_methods[0x1d0/4]=(uintptr_t)t_geometry;body_methods[0x178/4]=(uintptr_t)t_mode;
box_methods[0x1e0/4]=(uintptr_t)t_inhibit;box_methods[0x2e4/4]=(uintptr_t)t_low;
box_methods[0x2dc/4]=(uintptr_t)t_high;box_methods[0x384/4]=(uintptr_t)t_point;
body_root=(Vec){0,0,15,1};body_previous=(Vec){0,0,50,1};
body_velocity=(Vec){0,7,-40,0};body_acceleration=(Vec){11,13,17,0};body_angular=(Vec){1,2,3,0};
body_radius=10;damping=.25f;reflect=1;mutation=fresh_y=inhibited=knocks=cleanups=velocity_gets=0;
event_length=angle_count=radius_count=0;event_log[0]=0;knock_force=0;knock_normal=(Vec){0};
*(float*)(BODY+0x774)=4;*(short*)AT(0x4f0588)=-1;*AT(0x4f8210)=0;
*(float*)AT(0x4f82bc)=36;*(float*)AT(0x4f82c0)=48;*(void**)AT(0x5099e4)=BODY;
empty_grid();*(void**)AT(0x695d4c)=NULL;*(float*)AT(0x695d5c)=77;*(float*)AT(0x5cfbe0)=88;
*(Vec*)AT(0x5cfbe8)=(Vec){111,222,333,1};*(unsigned*)AT(0x695d74)=0;
*(unsigned*)AT(0x695d70)=*(unsigned*)AT(0x695d78)=0;
*(unsigned char*)AT(0x4f69e5)=1;*AT(0x695d46)=*AT(0x695d45)=0;
memset(test_material,0,sizeof(test_material));memset(test_chunk,0,sizeof(test_chunk));
*(void**)(polygon[0]+4)=test_material;*(void**)(test_material+0xc)=test_chunk;*(int*)(test_chunk+8)=23;
}
static void emit(const char*name,int contact){
printf("ACTOR {\"name\":\"%s\",\"contact\":%d,\"root\":",name,contact);vector_json(body_root);
printf(",\"velocity\":");vector_json(body_velocity);printf(",\"acceleration\":");vector_json(body_acceleration);
printf(",\"angular\":");vector_json(body_angular);
printf(",\"movementMode\":%d,\"actorMode\":%d,\"marker\":%u,\"tether\":[%.9g,%.9g],\"knocks\":%d,\"force\":%.9g,\"knockNormal\":",
*(short*)(BODY+0x704),*(int*)(BODY+0x608),BODY[0x1d65],*(float*)AT(0x4f82bc),*(float*)AT(0x4f82c0),knocks,knock_force);vector_json(knock_normal);
printf(",\"cleanups\":%d,\"radius\":%.9g,\"forceStatic\":%u,\"geometry\":%u,\"inhibited\":%d,\"radii\":[",cleanups,body_radius,BODY[0x42c],*AT(0x4f69e5),inhibited);
for(unsigned i=0;i<radius_count;i++)printf("%s%.9g",i?",":"",radius_values[i]);
printf("],\"angles\":[");for(unsigned i=0;i<angle_count;i++){printf("%s{\"vector\":",i?",":"");vector_json(angle_vectors[i]);printf(",\"pitch\":%d,\"yaw\":%d}",angle_pitch[i],angle_yaw[i]);}
printf("],\"passes\":%u,\"visits\":%u,\"face\":%.9g,\"edge\":%.9g,\"events\":\"%s\"}\n",*(unsigned*)AT(0x695d78),*(unsigned*)AT(0x695d70),*(float*)AT(0x695d5c),*(float*)AT(0x5cfbe0),event_log);
}
static void direct(const char*name,int ceiling,void*p){
((void(TC*)(void*,Vec,void*))body_methods[(ceiling?0x370:0x374)/4])(BODY,(Vec){0,0,1,0},p);emit(name,-1);
}
static void dynamic(const char*name){int contact=((int(__cdecl*)(void*,void*))AT(0x47a5e0))(box_body,BODY)&255;emit(name,contact);}
static void wall35(void){add_triangle(0,(Vec){-100,-100,35,1},(Vec){-100,100,35,1},(Vec){100,100,35,1},(Vec){0,0,1,0});}
int main(void){
setbuf(stdout,NULL);map_copy();HMODULE dll=GetModuleHandleA("OMT2.dll");require(dll!=NULL,"mapped OMT");
FARPROC address=GetProcAddress(dll,"?angles@OMedia3DVector@@QAEXAAF0@Z");
memcpy(&original_angles,&address,sizeof(original_angles));require(original_angles!=NULL,"original angles");
*(void**)AT(0x48d108)=t_angles;
reset(0);direct("jimmy_null",0,NULL);
reset(0);*(short*)AT(0x4f0588)=3;direct("jimmy_jetpack",0,NULL);
reset(0);direct("jimmy_ordinary_polygon",0,polygon[0]);
reset(0);*(float*)(BODY+0x774)=3;*(int*)(test_chunk+8)=120;direct("jimmy_elapsed_gate",0,polygon[0]);
reset(0);*(short*)(BODY+0x704)=1;direct("jimmy_mode1",0,NULL);
reset(0);*(short*)(BODY+0x704)=2;direct("jimmy_mode2",0,NULL);
reset(0);*(void**)AT(0x5099e4)=NULL;direct("jimmy_uncontrolled",0,NULL);
reset(0);*(short*)AT(0x4f0588)=7;direct("jimmy_gadget7_inactive",0,NULL);
reset(0);*(short*)AT(0x4f0588)=7;*AT(0x4f8210)=1;direct("jimmy_gadget7_equal",0,NULL);
reset(0);*(short*)AT(0x4f0588)=7;*AT(0x4f8210)=1;*(float*)AT(0x4f82c0)=49;direct("jimmy_gadget7_large",0,NULL);
reset(0);direct("ceiling_positive",1,NULL);
reset(0);body_velocity.y=-7;body_acceleration.y=-13;direct("ceiling_negative",1,NULL);
reset(0);body_acceleration.y=-13;direct("ceiling_velocity_only",1,NULL);
reset(0);body_velocity.y=-7;direct("ceiling_acceleration_only",1,NULL);
reset(1);reflect=0;direct("generic_disabled",0,NULL);
reset(1);direct("generic_axis",0,NULL);
reset(1);damping=0;direct("generic_no_damping",0,NULL);
reset(1);damping=1.25f;direct("generic_excess_damping",0,NULL);
reset(1);body_velocity.x=30;direct("generic_oblique",0,NULL);
reset(1);fresh_y=1;direct("generic_fresh_y",0,NULL);
reset(2);direct("soldier_mode0",0,NULL);
reset(2);*(int*)(BODY+0x608)=10;direct("soldier_mode10",0,NULL);
reset(2);reflect=0;*(int*)(BODY+0x608)=10;direct("soldier_mode10_disabled",0,NULL);
reset(0);dynamic("dynamic_jimmy");reset(1);dynamic("dynamic_generic");
reset(2);*(int*)(BODY+0x608)=10;dynamic("dynamic_soldier");
reset(2);*(int*)(BODY+0x608)=10;mutation=1;dynamic("late_inhibition");
reset(2);*(int*)(BODY+0x608)=10;mutation=2;wall35();dynamic("late_radius");
reset(2);*(int*)(BODY+0x608)=10;mutation=3;wall35();*(void**)AT(0x695d4c)=polygon[0];dynamic("late_geometry");
reset(2);*(int*)(BODY+0x608)=10;mutation=4;wall35();dynamic("late_force");
puts("ACTOR_CONTACT_COMPLETE");return 0;
}