Recover Grappler aim gating and implement verified ray constraint components
This commit is contained in:
1 parent
0c913d15aa
commit
ffea678e90
21 files changed
+1604
-16
No files matched your search
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Guarded VR08 ray/caller context and imported original-code probe results."""
|
||||
import argparse
|
||||
from collections import Counter
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import struct
|
||||
from grappler import collect as source_contract
|
||||
from checkpoint_script_state import find_case,read_va
|
||||
from pe_inspect import PE
|
||||
from shrink_heading import DLL_SHA256
|
||||
|
||||
RANGES=(('aim',0x42a406,0x42a652),('constraint',0x429ea0,0x429fa4),
|
||||
('impact_post_base',0x42a69b,0x42a6f1),('input_gate',0x426030,0x4260a6),
|
||||
('input_return',0x4269c3,0x4269cd),('primary_poll',0x42a7a0,0x42a7d6),
|
||||
('consuming_enter',0x46a3e0,0x46a3fb),('aim_return',0x42a652,0x42a660))
|
||||
|
||||
|
||||
def collect(original):
|
||||
contract=source_contract(original);original=Path(original)
|
||||
pe=PE(find_case(original,'Neutron.exe'))
|
||||
if struct.unpack('<I',read_va(pe,0x4d0204,4))[0]!=0x475cd0:
|
||||
raise ValueError('Changed VR08 polygon filter virtual')
|
||||
if read_va(pe,0x475cd0,5)!=bytes.fromhex('32c0c21800'):
|
||||
raise ValueError('Changed false polygon filter leaf')
|
||||
if read_va(pe,0x426098,14)!=bytes.fromhex('ff908801000084c00f851d090000'):
|
||||
raise ValueError('Changed aim-to-active-input return gate')
|
||||
dll_hash=hashlib.sha256(find_case(original,'OMT2.dll').read_bytes()).hexdigest()
|
||||
if dll_hash!=DLL_SHA256:raise ValueError('Unexpected original DLL')
|
||||
return dict(source_sha256=contract['sha256'],dll_sha256=dll_hash,
|
||||
vr08_filter=dict(table='0x4d00d0',slot='0x134',target='0x475cd0'),
|
||||
ranges=[dict(kind=k,va=hex(a),end_va=hex(b),file_offset=hex(pe.offset(a-pe.base)),
|
||||
sha256=hashlib.sha256(read_va(pe,a,b-a)).hexdigest()) for k,a,b in RANGES],
|
||||
scope='Synthetic ray/material/cursor accessors; original DLL magnitude; constraint before body and contact after stubbed base; no game entrypoint')
|
||||
|
||||
|
||||
def reference(original,log,executable):
|
||||
report=collect(original);log=Path(log);text=log.read_text()
|
||||
if 'GRAPPLER_QUERY_CONSTRAINT_COMPLETE' not in text:raise ValueError('Probe incomplete')
|
||||
cases=[]
|
||||
for line in text.splitlines():
|
||||
match=re.fullmatch(r'CASE (aim|constraint|impact) ([\w-]+) in=([^ ]+) out=([^ ]+)',line)
|
||||
if match:
|
||||
kind,name,p,o=match.groups();cases.append(dict(kind=kind,name=name,
|
||||
input=[float(x) for x in p.split(',')],observed=[float(x) for x in o.split(',')]))
|
||||
if Counter(c['kind'] for c in cases)!=dict(aim=23,constraint=10,impact=9):raise ValueError('Expected42 complete cases')
|
||||
root=Path(__file__).parent
|
||||
report.update(cases=cases,generators={name:hashlib.sha256((root/name).read_bytes()).hexdigest()
|
||||
for name in ('grappler_query_probe.c','grappler_scalar_probe.c')},
|
||||
executable_sha256=hashlib.sha256(Path(executable).read_bytes()).hexdigest(),
|
||||
log_sha256=hashlib.sha256(log.read_bytes()).hexdigest())
|
||||
return report
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
cli=argparse.ArgumentParser(description=__doc__);cli.add_argument('original',type=Path)
|
||||
cli.add_argument('--log',type=Path);cli.add_argument('--executable',type=Path);cli.add_argument('--output',type=Path)
|
||||
args=cli.parse_args()
|
||||
if bool(args.log)!=bool(args.executable):cli.error('--log and --executable are required together')
|
||||
if args.output and (args.output.resolve().is_relative_to(args.original.resolve())
|
||||
or args.original.resolve().is_relative_to(args.output.resolve())):cli.error('Output must be separate from originals')
|
||||
result=reference(args.original,args.log,args.executable) if args.log else collect(args.original)
|
||||
text=json.dumps(result,indent=2)+'\n'
|
||||
if args.output:args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_text(text)
|
||||
else:print(text,end='')
|
||||
@@ -0,0 +1,117 @@
|
||||
/* Copied aim suffix, constraint math and post-base impact suffix.
|
||||
Synthetic ray result/material/cursor/body accessors; no game entrypoint. */
|
||||
#define main scalar_probe_unused_main
|
||||
#include "grappler_scalar_probe.c"
|
||||
#undef main
|
||||
static unsigned char cursor[0x700],polygon[32],material[32],definition[32];
|
||||
static uintptr_t cursor_table[0x60/4],cursor_game_table[0x320/4],jimmy_table[0x210/4];
|
||||
static unsigned char query_success;static int primary,enter_key,hidden,visibility_calls,detach_calls;
|
||||
static float cursor_position[3],constraint_result[6];
|
||||
static void TC cursor_hide(void*self,int hide){require(self==cursor,"cursor owner");hidden=hide;visibility_calls++;}
|
||||
static void TC cursor_xyz(void*self,float x,float y,float z){require(self==cursor+0xc8,"cursor interface");cursor_position[0]=x;cursor_position[1]=y;cursor_position[2]=z;}
|
||||
static void TC detach(void*self){require(self==object,"Jimmy detach owner");detach_calls++;}
|
||||
static int primary_fire(void){return primary;}
|
||||
static int enter(int key){require(key==13,"auxiliary primary key");return enter_key;}
|
||||
static void relocate_query(uint32_t start,uint32_t end){
|
||||
const uint32_t values[]={0x5cfc60,0x5cfc64,0x5cfc68,0x5cfc6c,0x4a3e68,0x695d54,
|
||||
0x4f82b8,0x4a3e58,0x48d104,0x48d924,0x48d96c,0x4f8214,0x4f8218,0x4f821c,
|
||||
0x4f82cc,0x4f82bc,0x4f82c0,0x48d404,0x4a3e8c,0x49d5b4};
|
||||
for(uint32_t a=start;a+4<=end;a++){
|
||||
uint32_t value;memcpy(&value,AT(a),4);
|
||||
for(unsigned i=0;i<sizeof(values)/sizeof(values[0]);i++)if(value==values[i]){
|
||||
uint32_t relocated=(uintptr_t)AT(value);memcpy(AT(a),&relocated,4);a+=3;break;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void call_patch(uint32_t address,void*target){jump(AT(address),target);*AT(address)=0xe8;}
|
||||
static void epilogue(unsigned char**p){
|
||||
emit_byte(p,0x81);emit_byte(p,0xc4);word(p,0xa0);emit_byte(p,0x5f);emit_byte(p,0x5e);emit_byte(p,0x5d);emit_byte(p,0x5b);emit_byte(p,0xc3);
|
||||
}
|
||||
static void*frame_start(unsigned char**out){
|
||||
unsigned char*c=VirtualAlloc(NULL,512,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);require(c!=NULL,"frame shim");*out=c;
|
||||
emit_byte(out,0x53);emit_byte(out,0x55);emit_byte(out,0x56);emit_byte(out,0x57);
|
||||
emit_byte(out,0x81);emit_byte(out,0xec);word(out,0xa0);
|
||||
emit_byte(out,0x8b);emit_byte(out,0x84);emit_byte(out,0x24);word(out,0xb4);
|
||||
return c;
|
||||
}
|
||||
static void*aim_frame(void){
|
||||
unsigned char*p,*c=frame_start(&p);
|
||||
stack_copy(&p,0,0x2c);stack_copy(&p,4,0x30);stack_copy(&p,8,0x34);
|
||||
stack_copy(&p,12,0x3c);stack_copy(&p,16,0x40);stack_copy(&p,20,0x44);stack_copy(&p,24,0x98);
|
||||
emit_byte(&p,0xbe);word(&p,(uintptr_t)(object+0xc0));emit_byte(&p,0xbf);word(&p,(uintptr_t)object);
|
||||
emit_byte(&p,0xa0);word(&p,(uintptr_t)&query_success);jump(p,AT(0x42a406));p+=5;
|
||||
unsigned char*end=p;epilogue(&p);
|
||||
jump(AT(0x42a48b),end);jump(AT(0x42a53d),end);jump(AT(0x42a635),end);
|
||||
/* Skip source-frame pops, execute the original XOR AL,AL at42A654,
|
||||
then return through our frame shim without manufacturing its result. */
|
||||
*AT(0x42a652)=0xeb;*AT(0x42a653)=0; jump(AT(0x42a656),end);
|
||||
return c;
|
||||
}
|
||||
static void save_stack(unsigned char**p,int offset,void*destination){
|
||||
emit_byte(p,0x8b);emit_byte(p,0x84);emit_byte(p,0x24);word(p,offset);
|
||||
emit_byte(p,0xa3);word(p,(uintptr_t)destination);
|
||||
}
|
||||
static void*constraint_frame(void){
|
||||
unsigned char*p,*c=frame_start(&p);
|
||||
stack_copy(&p,0,0x2c);stack_copy(&p,4,0x30);stack_copy(&p,8,0x34);stack_copy(&p,12,0x98);
|
||||
emit_byte(&p,0xbe);word(&p,(uintptr_t)(object+0xc0));
|
||||
emit_byte(&p,0xb8);word(&p,(uintptr_t)AT(0x4f8214));jump(p,AT(0x429ea0));p+=5;
|
||||
unsigned char*end=p;emit_byte(&p,0x83);emit_byte(&p,0xc4);emit_byte(&p,4); /* pending root accessor argument */
|
||||
for(int i=0;i<6;i++)save_stack(&p,i<3?0x0c+4*i:0x1c+4*(i-3),&constraint_result[i]);
|
||||
epilogue(&p);jump(AT(0x429fa4),end);return c;
|
||||
}
|
||||
static void*impact_frame(void){
|
||||
unsigned char*p,*c=frame_start(&p);emit_byte(&p,0xbe);word(&p,(uintptr_t)(object+0xc0));
|
||||
jump(p,AT(0x42a69b));p+=5;unsigned char*end=p;epilogue(&p);
|
||||
jump(AT(0x42a6f1),end);jump(AT(0x42a710),end);return c;
|
||||
}
|
||||
static void aim_case(const char*name,int hit,float distance,int kind,int id,int fire,int key,float length,float dt,void*fn){
|
||||
float args[]={0,0,0,0,2400,2400,dt};query_success=hit;primary=fire;enter_key=key;
|
||||
F(0x5cfc60)=0;F(0x5cfc64)=distance;F(0x5cfc68)=0;F(0x5cfc6c)=1;F(0x4f82b8)=length;
|
||||
*(void**)AT(0x695d54)=kind==1?NULL:polygon;*(void**)(polygon+4)=kind==2?NULL:material;
|
||||
*(void**)(material+0xc)=kind==3?NULL:definition;*(int*)(definition+8)=id;
|
||||
hidden=-1;visibility_calls=0;for(int i=0;i<3;i++)cursor_position[i]=12345;
|
||||
unsigned char consumed=((unsigned char(*)(float*))fn)(args);
|
||||
printf("CASE aim %s in=%d,%.9g,%d,%d,%d,%d,%.9g,%.9g out=%u,%d,%d,%.9g,%.9g,%.9g,%.9g\n",name,hit,distance,kind,id,fire,key,length,dt,consumed,hidden,visibility_calls,cursor_position[0],cursor_position[1],cursor_position[2],F(0x4f82b8));
|
||||
}
|
||||
static void constraint_case(const char*name,float x,float y,float z,float ax,float ay,float az,float sx,float sz,float length,float dt,void*fn){
|
||||
float pivot=y+116,args[]={x,pivot,z,dt};F(0x4f8214)=ax;F(0x4f8218)=ay;F(0x4f821c)=az;
|
||||
F(0x4f82bc)=sx;F(0x4f82c0)=sz;F(0x4f82b8)=length;((run_fn)fn)(args);
|
||||
printf("CASE constraint %s in=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g out=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g\n",name,x,y,z,ax,ay,az,sx,sz,length,dt,constraint_result[0],constraint_result[1],constraint_result[2],constraint_result[3],constraint_result[4],constraint_result[5]);
|
||||
}
|
||||
static void impact_case(const char*name,float x,float z,void*fn){
|
||||
float args[]={0};F(0x4f82bc)=x;F(0x4f82c0)=z;object[0x1e25]=0;detach_calls=0;((run_fn)fn)(args);
|
||||
printf("CASE impact %s in=%.9g,%.9g out=%.9g,%.9g,%d,%u\n",name,x,z,F(0x4f82bc),F(0x4f82c0),detach_calls,object[0x1e25]);
|
||||
}
|
||||
int main(void){
|
||||
map_source();HMODULE omt=LoadLibraryA("OMT2.dll");require(omt!=NULL,"copied original DLL");
|
||||
FARPROC magnitude=GetProcAddress(omt,"?quick_magnitude@OMedia3DVector@@QBEMXZ");require(magnitude!=NULL,"native magnitude");*(FARPROC*)AT(0x48d104)=magnitude;
|
||||
cursor_table[0x58/4]=(uintptr_t)cursor_hide;cursor_game_table[0x318/4]=(uintptr_t)cursor_xyz;
|
||||
jimmy_table[0x204/4]=(uintptr_t)detach;*(void**)object=jimmy_table;
|
||||
*(void**)cursor=cursor_table;*(void**)(cursor+0xc8)=cursor_game_table;*(int*)(cursor+0x70)=1;*(void**)(object+0xb14)=cursor;
|
||||
relocate_query(0x42a406,0x42a652);relocate_query(0x429ea0,0x429fa4);relocate_query(0x42a69b,0x42a6f1);
|
||||
call_patch(0x42a4f8,primary_fire);call_patch(0x42a503,enter);
|
||||
void*aim=aim_frame(),*constraint=constraint_frame(),*impact=impact_frame();
|
||||
aim_case("miss",0,700,0,0,1,0,300,.1f,aim);aim_case("near",1,449,0,0,1,0,300,.1f,aim);
|
||||
aim_case("equal",1,450,0,0,0,0,300,.1f,aim);aim_case("far",1,700,0,0,0,0,300,.1f,aim);
|
||||
int ids[]={60,69,70,80,89,90,210,219,220,-1,170};
|
||||
for(unsigned i=0;i<sizeof(ids)/sizeof(ids[0]);i++){char name[32];sprintf(name,"material_%d",ids[i]);aim_case(name,1,700,0,ids[i],0,0,300,.1f,aim);}
|
||||
aim_case("no_polygon",1,700,1,60,0,0,300,.1f,aim);aim_case("no_material",1,700,2,0,0,0,300,.1f,aim);
|
||||
aim_case("no_definition",1,700,3,60,0,0,300,.1f,aim);aim_case("blocked_fire",1,700,0,60,1,0,300,.1f,aim);
|
||||
aim_case("blocked_enter",1,700,0,60,0,1,300,.1f,aim);aim_case("blocked_idle",1,700,0,60,0,0,300,.1f,aim);
|
||||
aim_case("blocked_equal",1,700,0,60,1,0,250,.1f,aim);aim_case("near_fire",1,449,0,60,1,0,300,.1f,aim);
|
||||
constraint_case("vertical",0,0,0,0,1000,0,0,0,600,1.f/60,constraint);
|
||||
constraint_case("diagonal",0,0,0,300,800,400,0,0,600,1.f/60,constraint);
|
||||
constraint_case("perturbed",125,320,-210,-150,1200,450,12,-23,700,1.f/60,constraint);
|
||||
constraint_case("long_tick",0,0,0,300,800,400,50,-50,350,.6f,constraint);
|
||||
constraint_case("short",-40,300,15,280,500,-120,-20,35,125,.1f,constraint);
|
||||
constraint_case("negative",0,0,0,300,800,400,10,20,-50,.1f,constraint);
|
||||
constraint_case("fraction",12.125f,-37.25f,89.625f,317.875f,982.125f,-211.375f,3.25f,-1.75f,463.125f,.017f,constraint);
|
||||
constraint_case("horizontal",0,0,0,600,116,0,0,0,400,.1f,constraint);
|
||||
constraint_case("zero_length",0,0,0,300,800,400,1,2,0,.1f,constraint);
|
||||
constraint_case("large",-13000,900,-12000,14000,19000,18000,-40,20,23000,1.f/60,constraint);
|
||||
impact_case("zero",0,0,impact);impact_case("below",59.9f,0,impact);impact_case("equal_x",60,0,impact);
|
||||
impact_case("equal_z",0,60,impact);impact_case("pythagoras",36,48,impact);impact_case("above",36,48.0001f,impact);
|
||||
impact_case("diagonal",45,45,impact);impact_case("negative",-60,0,impact);impact_case("negative_above",0,-60.1f,impact);
|
||||
puts("GRAPPLER_QUERY_CONSTRAINT_COMPLETE");return 0;
|
||||
}
|
||||
Reference in new issue
Block a user