Files
Neutron/tools/binary/scooter_motion_probe.c
T

144 lines
11 KiB
C

/* Copied465220 full arithmetic and465830 keyboard input. Synthetic base actor,
body properties, wheel support, camera/audio/input; original OMT vector/trig. */
#define main unused_grappler_main
#include "grappler_scalar_probe.c"
#undef main
typedef struct{float x,y,z,w;}Vec;
static uintptr_t game_table[0x440/4],outer_table[0x180/4],wheel_table[0x220/4];
static unsigned char wheels[4][0x200];
static Vec velocity,acceleration,angular;static float scalar,friction;static int supported,missing_slot;
#define GF(g,o) (*(float*)((g)+(o)))
static void TC missing(void*self){fprintf(stderr,"MISSING caller=%x self=%x\n",(unsigned)((unsigned char*)__builtin_return_address(0)-mapped+0x400000),(unsigned)self);require(0,"unexpected virtual call");}
static int TC zero(void*self){(void)self;return 0;}
static int TC enabled(void*self){(void)self;return 1;}
static int TC support(void*self){(void)self;return supported;}
static int TC wheel_support(void*self){return ((unsigned char*)self)[4];}
static float TC speed(void*self){(void)self;return scalar;}
static float TC get_friction(void*self){(void)self;return friction;}
static void TC set_speed(void*self,float v){(void)self;scalar=v;}
static Vec*TC get_velocity(void*self,Vec*out){(void)self;*out=velocity;return out;}
static void TC set_velocity(void*self,float x,float y,float z){(void)self;velocity=(Vec){x,y,z,0};}
static void TC set_accel(void*self,float x,float y,float z){(void)self;acceleration=(Vec){x,y,z,0};}
static Vec*TC get_angular(void*self,Vec*out){(void)self;*out=angular;return out;}
static void TC set_angular(void*self,float x,float y,float z){(void)self;angular=(Vec){x,y,z,0};}
static void TC add_angular(void*self,float x,float y,float z){(void)self;angular.x+=x;angular.y+=y;angular.z+=z;}
static void TC add_velocity(void*self,float x,float y,float z){(void)self;velocity.x+=x;velocity.y+=y;velocity.z+=z;}
static void TC noop_dt(void*self,float dt){(void)self;(void)dt;}
static void TC noop(void*self){(void)self;}
static void TC mouse(void*self,short*x,short*y){(void)self;*x=*y=0;}
static void setup(void){
map_source();
const struct{uint32_t va,target;} reloc[]={/* RELOCATIONS */};
for(unsigned i=0;i<sizeof(reloc)/sizeof(reloc[0]);i++){
uint32_t value;memcpy(&value,AT(reloc[i].va),4);require(value==reloc[i].target,"absolute operand");
value=(uintptr_t)AT(value);memcpy(AT(reloc[i].va),&value,4);
}
HMODULE dll=LoadLibraryA("Z:\\work\\game\\OMT2.dll");require(dll!=NULL,"copied OMT2");
*(void**)AT(0x48d104)=GetProcAddress(dll,"?quick_magnitude@OMedia3DVector@@QBEMXZ");
*(void**)AT(0x48d10c)=GetProcAddress(dll,"?global@OMediaCosSinTable@@2V1@A");
require(*(void**)AT(0x48d104)&&*(void**)AT(0x48d10c),"OMT vector exports");
float*trig=*(void**)AT(0x48d10c);printf("TABLE quarter sin=%.9g cos=%.9g\n",trig[4096],trig[16385+4096]);
const unsigned char ready[]={0xb0,1,0xc3},base[]={0xc2,4,0};
memcpy(AT(0x475ca0),ready,3);memcpy(AT(0x462520),base,3);
for(unsigned i=0;i<sizeof(game_table)/4;i++)game_table[i]=(uintptr_t)missing;
for(unsigned i=0;i<sizeof(outer_table)/4;i++)outer_table[i]=(uintptr_t)missing;
outer_table[0x140/4]=(uintptr_t)AT(0x467000);game_table[0x278/4]=(uintptr_t)set_accel;
game_table[0x2ac/4]=(uintptr_t)get_angular;game_table[0x2b4/4]=(uintptr_t)set_angular;game_table[0x2b8/4]=(uintptr_t)add_angular;
game_table[0x220/4]=(uintptr_t)enabled;
game_table[0x210/4]=(uintptr_t)enabled;game_table[0x218/4]=(uintptr_t)support;
game_table[0x248/4]=(uintptr_t)get_friction;game_table[0x268/4]=(uintptr_t)speed;game_table[0x26c/4]=(uintptr_t)set_speed;
game_table[0x2bc/4]=(uintptr_t)get_velocity;game_table[0x2c4/4]=(uintptr_t)set_velocity;game_table[0x2cc/4]=(uintptr_t)add_velocity;
game_table[0x328/4]=(uintptr_t)AT(0x4723f0);game_table[0x334/4]=(uintptr_t)AT(0x472480);game_table[0x38c/4]=(uintptr_t)AT(0x472b10);
outer_table[0x160/4]=(uintptr_t)noop;
outer_table[0xf8/4]=(uintptr_t)mouse;outer_table[0xec/4]=(uintptr_t)noop_dt;outer_table[0x164/4]=(uintptr_t)noop;
outer_table[0x120/4]=(uintptr_t)AT(0x421c10);outer_table[0x124/4]=(uintptr_t)AT(0x421c40);
outer_table[0x128/4]=(uintptr_t)AT(0x421c70);outer_table[0x12c/4]=(uintptr_t)AT(0x421cb0);outer_table[0x130/4]=(uintptr_t)AT(0x413a60);
for(int offset=0xfc;offset<=0x11c;offset+=4)outer_table[offset/4]=(uintptr_t)zero;
for(int offset=0x134;offset<=0x150;offset+=4)outer_table[offset/4]=(uintptr_t)zero;
outer_table[0x140/4]=(uintptr_t)AT(0x467000);game_table[0x1d8/4]=(uintptr_t)zero;
wheel_table[0x218/4]=(uintptr_t)wheel_support;
}
static unsigned char*reset(float speed_in,float vx,float vy,float vz,float pitch,float yaw,float turn,int front,int rear,int ground){
memset(object,0,sizeof(object));unsigned char*g=object+0xc0;*(void**)object=outer_table;*(void**)g=game_table;
memset(AT(0x509830),0,0x1d0);acceleration=(Vec){3,4,5,0};angular=(Vec){10,20,30,0};scalar=speed_in;velocity=(Vec){vx,vy,vz,0};friction=.8f;supported=ground;
GF(g,0x224)=pitch;GF(g,0x228)=yaw;GF(g,0x22c)=0;GF(g,0x57c)=turn;GF(g,0x560)=2250;
*(int*)(g+0x590)=*(int*)(g+0x594)=1;GF(g,0x550)=700;GF(g,0x558)=1200;GF(g,0x568)=1485;*(short*)(g+0x540)=front;*(short*)(g+0x542)=rear;
for(int i=0;i<4;i++){
memset(wheels[i],0,sizeof(wheels[i]));*(void**)(wheels[i]+0xc0)=wheel_table;
wheels[i][0xc4]=i<2?i<front:i-2<rear;*(void**)(g+0x4b8+i*4)=wheels[i];
}
return g;
}
static void drive(const char*name,float s,float vx,float vy,float vz,float p,float y,float t,int front,int rear,int ground,int throttle,int brake,int reverse,float timer,float dt){
unsigned char*g=reset(s,vx,vy,vz,p,y,t,front,rear,ground);g[0x598]=throttle;g[0x599]=brake;g[0x59f]=reverse;GF(g,0x588)=timer;
((void(TC*)(void*,float))AT(0x465220))(g,dt);
printf("DRIVE %s in=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%d,%d,%d,%d,%d,%d,%.9g,%.9g out=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g\n",name,s,vx,vy,vz,p,y,t,front,rear,ground,throttle,brake,reverse,timer,dt,scalar,velocity.x,velocity.y,velocity.z,GF(g,0x228),GF(g,0x580),GF(g,0x578),GF(g,0x588));
}
static void wall_case(const char*name,float s,Vec v,Vec n,int active,int up,float dt){
unsigned char*g=reset(s,v.x,v.y,v.z,0,0,0,2,2,1);g[0x59b]=1;g[0x59c]=active;*AT(0x50985e)=up;F(0x696030)=dt;
((void(TC*)(void*,Vec,void*))AT(0x421910))(g,n,NULL);
printf("WALL %s in=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%d,%d,%.9g out=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%u\n",name,s,v.x,v.y,v.z,n.x,n.y,n.z,active,up,dt,scalar,velocity.x,velocity.y,velocity.z,acceleration.x,acceleration.y,acceleration.z,g[0x59c]);
}
static void crash_case(const char*name,float timer,float dt){
unsigned char*g=reset(0,120,100,-60,0,0,0,2,2,1);g[0x59c]=1;GF(g,0x58c)=timer;
((void(TC*)(void*,float))AT(0x4669f0))(object,dt);
printf("CRASH %s in=%.9g,%.9g out=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%u\n",name,timer,dt,velocity.x,velocity.y,velocity.z,angular.x,angular.y,angular.z,GF(g,0x58c),g[0x59c]);
}
static void face_case(const char*name,float p,float y,float r,float dp,float dy,float dr,float rate,float dt){
unsigned char*g=reset(0,0,0,0,p,y,0,2,2,1);GF(g,0x22c)=r;GF(g,0x274)=dp;GF(g,0x278)=dy;GF(g,0x27c)=dr;GF(g,0x29c)=rate;g[5]=g[10]=1;
((void(TC*)(void*,float))AT(0x473320))(g,dt);
printf("FACE %s in=%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g,%.9g out=%.9g,%.9g,%.9g\n",name,p,y,r,dp,dy,dr,rate,dt,GF(g,0x224),GF(g,0x228),GF(g,0x22c));
}
static void normal(const char*name,Vec n,float y){float initial=y,p=0,r=0;((void(*)(Vec*,float*,float*,float*))AT(0x476ff0))(&n,&p,&y,&r);printf("NORMAL %s in=%.9g,%.9g,%.9g,%.9g out=%.9g,%.9g,%.9g\n",name,n.x,n.y,n.z,initial,p,y,r);}
static void input(const char*name,float s,float t,int keyturn,int rev,int brake,int up,int down,int left,int right,int rear,float dt){
unsigned char*g=reset(s,0,0,0,0,0,t,2,rear,1);g[0x59d]=keyturn;g[0x59f]=rev;g[0x599]=brake;
*AT(0x50985e)=up;*AT(0x509860)=down;*AT(0x50985d)=left;*AT(0x50985f)=right;
((void(TC*)(void*,float))AT(0x465830))(g,dt);
printf("INPUT %s in=%.9g,%.9g,%d,%d,%d,%d,%d,%d,%d,%d,%.9g out=%.9g,%.9g,%u,%u,%u,%u\n",name,s,t,keyturn,rev,brake,up,down,left,right,rear,dt,scalar,GF(g,0x57c),g[0x59d],g[0x59f],g[0x599],g[0x598]);
}
int main(void){
setbuf(stdout,NULL);setup();
drive("rest",0,0,0,0,0,0,0,2,2,1,0,0,0,0,.1f);
drive("launch",100,0,0,0,0,0,0,2,2,1,1,0,0,0,.1f);
drive("forward",300,0,0,300,0,0,0,2,2,1,1,0,0,0,.1f);
drive("coast",300,0,0,300,0,0,0,2,2,1,0,0,0,0,.1f);
drive("turn",300,0,0,300,0,0,30,2,2,1,1,0,0,0,.1f);
drive("slowturn",80,0,0,80,0,0,-30,1,2,1,1,0,0,0,.1f);
drive("drift",400,150,10,300,0,35,25,2,2,1,1,0,0,0,.1f);
drive("falling",300,0,-100,300,0,0,0,2,2,1,1,0,0,0,.1f);
drive("rising",300,0,100,300,0,0,0,2,2,1,1,0,0,0,.1f);
drive("uphill",300,0,0,300,20,0,0,2,2,1,1,0,0,0,.1f);
drive("downhill",300,0,0,300,-20,0,0,2,2,1,1,0,0,0,.1f);
drive("reverse",-300,0,0,-300,0,0,30,2,2,1,0,1,1,0,.1f);
drive("reverse_allowed",-300,0,0,-300,0,0,30,2,2,1,0,1,1,1.1f,.1f);
drive("unsupported",300,0,0,300,0,0,30,2,2,0,1,0,0,0,.1f);
drive("frontnone",300,0,0,300,0,0,30,0,2,1,1,0,0,0,.1f);
drive("onewheel",300,0,0,300,0,0,30,1,0,1,1,0,0,0,.1f);
drive("nowheels",300,0,0,300,0,0,30,0,0,1,1,0,0,0,.1f);
drive("brakestill",0,0,0,0,0,0,0,2,2,1,0,1,1,0,.1f);
drive("braketimer",0,0,0,0,0,0,0,2,2,1,0,1,1,1,.1f);
drive("negativecoast",-30,0,0,-30,0,0,0,2,2,1,0,0,0,0,.1f);
drive("tinycoast",.1f,0,0,.1f,0,0,0,2,2,1,0,0,0,0,.1f);
drive("tick",1400,120,-13,1200,5,179,40,2,2,1,1,0,0,0,1.f/60);
normal("flat",(Vec){0,1,0,0},0);normal("slopeZ",(Vec){0,.9396926f,.3420201f,0},0);normal("slopeX",(Vec){.3420201f,.9396926f,0,0},90);normal("slopeXZ",(Vec){.2f,.95f,.2f,0},45);
for(int i=0;i<4;i++){
char name[32];sprintf(name,"input%d",i);input(name,300,10,1,0,0,i==0,i==1,i==2,i==3,2,.1f);
}
input("nosupport",300,10,1,0,0,1,0,1,0,0,.1f);
input("reverseheld",0,0,0,1,1,0,1,0,0,2,.1f);
input("brakenegative",-300,0,0,0,0,0,1,0,0,2,.1f);
input("both",300,44,0,1,1,1,1,1,1,2,.1f);
input("cap",1490,-44,0,0,0,1,0,0,1,2,.1f);
wall_case("head_on",600,(Vec){0,13,600,0},(Vec){0,0,-1,0},0,1,.1f);
wall_case("side",600,(Vec){600,13,0,0},(Vec){-1,0,0,0},0,1,.1f);
wall_case("side_no_throttle",600,(Vec){600,13,0,0},(Vec){-1,0,0,0},0,0,.1f);
wall_case("glance",600,(Vec){400,-20,300,0},(Vec){-.8f,0,-.6f,0},0,1,.1f);
wall_case("slow20",10,(Vec){0,13,20,0},(Vec){0,0,-1,0},0,1,.1f);
wall_case("reverse",-300,(Vec){0,-13,-300,0},(Vec){0,0,1,0},0,0,.1f);
wall_case("already_crash",0,(Vec){0,100,300,0},(Vec){0,0,-1,0},1,1,.1f);
crash_case("begin",0,.1f);crash_case("before_end",3.8f,.1f);crash_case("equal_end",3.9f,.1f);crash_case("after_end",4,.1f);
face_case("ordinary",10,20,30,0,30,0,5,.1f);face_case("seam",359,359,359,1,1,1,2,.1f);face_case("small",.1f,.1f,.1f,0,0,0,2,.1f);
for(int i=0;i<4;i++){char name[32];sprintf(name,"slopeYaw%d",i);normal(name,(Vec){.2f,.95f,.2f,0},i*90);}
puts("SCOOTER_MOTION_COMPLETE: copied465220/465830, synthetic dependencies");return 0;
}