Trace Carl lifecycle and add read-only original state observer

This commit is contained in:
UnixNight committed 2026-11-06 10:27:10 -05:00
1 parent c642b69849
commit 4cd62d3627
28 files changed
+2387 -5

No files matched your search

@@ -0,0 +1,80 @@
/* Composed copied original input/controller/facing/skip-prefix routines.
Synthetic supported Jimmy/menu/vtables, zero devices, no body/render/scheduler.
Base40E050 is replaced by actual facing43A420 only; motion/action methods are
recorded shims. This is not full original skip or gameplay execution. */
#define main unused_scalar_main
#include "grappler_scalar_probe.c"
#undef main
typedef struct {float x,y,z,w;} Vec;
static uintptr_t game[0x450/4],outer[0x190/4],menu[0x500/4];
static unsigned char menu_object[16];
static int actions,moves,stops;
static LONG CALLBACK exception(EXCEPTION_POINTERS*e){fprintf(stderr,"PROBE_EXCEPTION pc=%lx relative=%lx code=%lx\n",e->ContextRecord->Eip,e->ContextRecord->Eip-(uintptr_t)mapped+0x400000,e->ExceptionRecord->ExceptionCode);fprintf(stderr,"fault=%lx eax=%lx ecx=%lx edx=%lx esi=%lx esp=%lx\n",e->ExceptionRecord->ExceptionInformation[1],e->ContextRecord->Eax,e->ContextRecord->Ecx,e->ContextRecord->Edx,e->ContextRecord->Esi,e->ContextRecord->Esp);ExitProcess(2);return EXCEPTION_CONTINUE_SEARCH;}
#define OF(o) (*(float*)(object+(o)))
#define GF(o) OF(0xc0+(o))
#define MODE (*(short*)(object+0x7c4))
static void fix(uint32_t a,uint32_t b){
const uint32_t targets[]={/* RELOCATIONS */};
for(;a+4<=b;a++){uint32_t v;memcpy(&v,AT(a),4);for(unsigned i=0;i<sizeof(targets)/4;i++)if(v==targets[i]){v=(uintptr_t)AT(v);memcpy(AT(a),&v,4);a+=3;break;}}
}
static int TC yes(void*self){(void)self;return 1;}
static int TC no(void*self){(void)self;return 0;}
static void TC noop(void*self){(void)self;}
static const char*TC current_action(void*self){(void)self;return "STOP";}
static int compare_action(const char*a,const char*b){(void)a;(void)b;return 1;}
static void TC action(void*self,const char*name){(void)self;(void)name;actions++;}
static void TC motion(void*self,float dt){(void)self;(void)dt;moves++;}
static void TC base(void*self,float dt){((void(TC*)(void*,float))AT(0x43a420))(self,dt);}
static void mouse(short*x,short*y){*x=*y=0;}
static void*lookup(const char*tag){(void)tag;puts("CALL lookup");return object+0xc0;}
static void stop(int handle,int release){puts("CALL stop");(void)handle;(void)release;stops++;}
static void*entry(uint32_t start,uint32_t end,int ground){
unsigned char*c=VirtualAlloc(NULL,256,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE),*p=c;require(c!=NULL,"wrapper");
emit_byte(&p,0x53);emit_byte(&p,0x55);emit_byte(&p,0x56);emit_byte(&p,0x57);emit_byte(&p,0x81);emit_byte(&p,0xec);word(&p,0x90);
emit_byte(&p,0x31);emit_byte(&p,0xdb);emit_byte(&p,0xbe);word(&p,(uintptr_t)object);
if(ground){emit_byte(&p,0xbd);word(&p,(uintptr_t)object);emit_byte(&p,0x31);emit_byte(&p,0xff);emit_byte(&p,0xba);word(&p,1);emit_byte(&p,0x31);emit_byte(&p,0xf6);emit_byte(&p,0xbb);word(&p,(uintptr_t)(object+0x9bc));
const int slots[]={0x14,0x18,0x1c};for(int i=0;i<3;i++){emit_byte(&p,0xc7);emit_byte(&p,0x44);emit_byte(&p,0x24);emit_byte(&p,slots[i]);word(&p,0);}}
jump(p,AT(start));p+=5;unsigned char*exit=p;emit_byte(&p,0x81);emit_byte(&p,0xc4);word(&p,0x90);emit_byte(&p,0x5f);emit_byte(&p,0x5e);emit_byte(&p,0x5d);emit_byte(&p,0x5b);emit_byte(&p,0xc3);jump(AT(end),exit);return c;
}
static void(*ground_input)(void);
static void TC ground(void*self,float dt){(void)self;(void)dt;ground_input();}
static void snap(const char*phase){
printf("STATE %s mode=%d turn=%.9g current=%.9g,%.9g,%.9g target=%.9g,%.9g,%.9g dirty=%u latch=%u skip=%u actions=%d moves=%d stops=%d\n",phase,MODE,OF(0x6d4),GF(0x224),GF(0x228),GF(0x22c),GF(0x274),GF(0x278),GF(0x27c),object[0xca],object[0x1e00],*AT(0x4f83e4),actions,moves,stops);
}
static void one(int after,int skip,int sign,void(*skip_prefix)(void),void(*flatten)(void)){
memset(object,0,sizeof(object));*(void**)object=outer;*(void**)(object+0xc0)=game;
memset(AT(0x509830),0,0x1d0);*(short*)AT(0x4f0588)=-1;*AT(0x4f8181)=*AT(0x4f83e0)=*AT(0x4f83e4)=0;
*(void**)AT(0x5099e4)=object+0xc0;object[0xc5]=1;object[0xca]=1;
OF(0x6bc)=30;OF(0x6c0)=35;OF(0x6c4)=600;OF(0x6d4)=sign*11.666668f;object[0x6e6]=1;MODE=1;
GF(0x224)=343;GF(0x228)=155;GF(0x22c)=sign>0?357:3;GF(0x274)=-40;GF(0x278)=153;GF(0x27c)=-sign*11.666668f;
*(void**)(object+0xa18)=menu_object;*(int*)(object+0xa3c)=-1;
actions=moves=stops=0;
printf("CASE order=%s skip=%d sign=%d\n",after?"retained":"fresh",skip,sign);snap("before_entry");
flatten();snap("after_entry");
((void(TC*)(void*,void*))AT(0x475a40))(NULL,NULL);
for(int i=0;i<180;i++)((void(TC*)(void*,float))AT(0x437940))(object+0xc0,1.f/60);
snap("locked");
if(skip)skip_prefix();
snap("after_skip_prefix");
((void(TC*)(void*,void*))AT(0x475a40))(NULL,object+0xc0);*AT(0x4f83e4)=0;snap("control_granted");
if(after){((void(TC*)(void*,float))AT(0x437940))(object+0xc0,1.f/60);snap("first_player");((void(TC*)(void*,float))AT(0x438a60))(object+0xc0,1.f/60);snap("first_input");}
else {((void(TC*)(void*,float))AT(0x438a60))(object+0xc0,1.f/60);snap("first_input");((void(TC*)(void*,float))AT(0x437940))(object+0xc0,1.f/60);snap("first_player");}
for(int i=0;i<300;i++){
if(after)((void(TC*)(void*,float))AT(0x437940))(object+0xc0,1.f/60);
((void(TC*)(void*,float))AT(0x438a60))(object+0xc0,1.f/60);
if(!after)((void(TC*)(void*,float))AT(0x437940))(object+0xc0,1.f/60);
}snap("after_idle");
}
int main(void){
setbuf(stdout,NULL);map_source();AddVectoredExceptionHandler(1,exception);
const uint32_t ranges[][2]={{0x437940,0x437c3a},{0x438a60,0x438ba2},{0x439900,0x439e33},{0x43915d,0x4395cf},{0x43a420,0x43a5cd},{0x472480,0x472570},{0x475a40,0x475a4c},{0x431518,0x431590},{0x430f1d,0x430f5c},{0x429910,0x429963}};
for(unsigned i=0;i<sizeof(ranges)/sizeof(ranges[0]);i++)fix(ranges[i][0],ranges[i][1]);
for(unsigned i=0;i<4;i++){uint32_t*v=(void*)AT(0x438ba4+i*4);*v=(uintptr_t)AT(*v);}
const unsigned char ready[]={0xb0,1,0xc3};memcpy(AT(0x475ca0),ready,3);jump(AT(0x40e050),base);jump(AT(0x46a460),mouse);jump(AT(0x474070),lookup);jump(AT(0x47d7a0),stop);jump(AT(0x487c20),compare_action);
const unsigned char air_return[]={0x5f,0x5e,0x5d,0x5b,0x83,0xc4,0x7c,0xc2,4,0};memcpy(AT(0x439e33),air_return,sizeof(air_return));
game[0x218/4]=(uintptr_t)yes;game[0x328/4]=(uintptr_t)AT(0x4723f0);game[0x32c/4]=(uintptr_t)AT(0x472450);game[0x334/4]=(uintptr_t)AT(0x458f90);game[0x36c/4]=(uintptr_t)AT(0x472660);game[0x26c/4]=(uintptr_t)AT(0x471b60);
outer[0x100/4]=(uintptr_t)current_action;outer[0x124/4]=(uintptr_t)ground;outer[0x128/4]=(uintptr_t)AT(0x439900);outer[0x130/4]=(uintptr_t)motion;outer[0x134/4]=(uintptr_t)motion;outer[0x140/4]=(uintptr_t)AT(0x429910);outer[0x150/4]=(uintptr_t)action;outer[0x158/4]=(uintptr_t)no;outer[0x15c/4]=(uintptr_t)no;menu[0x488/4]=(uintptr_t)noop;*(void**)menu_object=menu;
ground_input=entry(0x43915d,0x4395cf,1);void(*skip_prefix)(void)=entry(0x430f1d,0x430f5c,0);void(*flatten)(void)=entry(0x431518,0x431590,0);
for(int after=0;after<2;after++)for(int skip=0;skip<2;skip++)for(int sign=-1;sign<=1;sign+=2)one(after,skip,sign,skip_prefix,flatten);
puts("JIMMY_SKIP_COMPOSITION_COMPLETE");return 0;
}