91 lines
5.7 KiB
C
91 lines
5.7 KiB
C
/* Copied registration and per-object Init/PostLoad loop. No original entrypoint.
|
|
Synthetic transforms/Init/PostLoad, logging, allocation and timer dependencies. */
|
|
#define main unused_scalar_main
|
|
#include "grappler_scalar_probe.c"
|
|
#undef main
|
|
typedef struct Node {struct Node*next,*previous;void*value;} Node;
|
|
typedef struct Actor {
|
|
unsigned char raw[0x900];uintptr_t table[0x440/4];
|
|
int id,family,inits,nested;float position[3],rotation[3];
|
|
} Actor;
|
|
static Actor actors[3];static Node bodies,registry,registry_nodes[3];
|
|
static uintptr_t app_table[0x130/4];static unsigned char app[0x900];
|
|
static char events[1024];static unsigned used;static int append_stage;
|
|
static void*game(Actor*a){return a->raw+0x100;}
|
|
static Actor*owner(void*g){for(int i=0;i<3;i++)if(game(&actors[i])==g)return &actors[i];require(0,"actor owner");return NULL;}
|
|
static void event(char code,Actor*a){used+=(unsigned)snprintf(events+used,sizeof(events)-used,"%c%d;",code,a->id);require(used<sizeof(events)-10,"events");}
|
|
static void TC position(void*g,float x,float y,float z){Actor*a=owner(g);a->position[0]=x;a->position[1]=y;a->position[2]=z;event('P',a);}
|
|
static void TC rotation(void*g,float x,float y,float z){Actor*a=owner(g);a->rotation[0]=x;a->rotation[1]=y;a->rotation[2]=z;event('R',a);}
|
|
static void TC zero(void*g,float x,float y,float z){require(x==0&&y==0&&z==0,"registration150 zero");event('Z',owner(g));}
|
|
static void list_init(Node*n){n->next=n->previous=n;n->value=NULL;}
|
|
static void add_registry(int id){
|
|
Node*n=®istry_nodes[id];n->value=game(&actors[id]);n->next=®istry;n->previous=registry.previous;
|
|
registry.previous->next=n;registry.previous=n;
|
|
}
|
|
static void register_body(Actor*a,int guarded){
|
|
unsigned entry=guarded?0x42ab50:a->family?0x464210:0x4623d0;
|
|
((void(TC*)(void*))AT(entry))(game(a));
|
|
}
|
|
static void TC init(void*g){
|
|
Actor*a=owner(g);event('I',a);a->inits++;
|
|
if(a->nested){a->nested=0;register_body(&actors[1],0);}
|
|
if(a->id==0&&append_stage==1){append_stage=0;add_registry(2);}
|
|
}
|
|
static void TC post(void*g){Actor*a=owner(g);event('L',a);if(a->id==0&&append_stage==2){append_stage=0;add_registry(2);}}
|
|
static void logging(void*g,const char*label){(void)g;(void)label;}
|
|
static void TC cleanup(void*self){require(self==app,"app owner");events[used++]='C';events[used++]=';';events[used]=0;}
|
|
static void timer(void){events[used++]='T';events[used++]=';';events[used]=0;}
|
|
static void*allocate(size_t size){require(size==12,"body node bytes");return malloc(size);}
|
|
static void reset(void){
|
|
if(bodies.next)while(bodies.next!=&bodies){Node*n=bodies.next;bodies.next=n->next;free(n);}
|
|
list_init(&bodies);list_init(®istry);memset(actors,0,sizeof(actors));
|
|
memset(app,0,sizeof(app));*(void**)app=app_table;app_table[0x10c/4]=(uintptr_t)cleanup;
|
|
used=0;events[0]=0;append_stage=0;*(void**)AT(0x695d3c)=&bodies;*(unsigned*)AT(0x695d40)=0;
|
|
*(void**)AT(0x50999c)=®istry;
|
|
for(int i=0;i<3;i++){
|
|
Actor*a=&actors[i];a->id=i;a->family=i==1;*(void**)game(a)=a->table;
|
|
#define SLOT(s,f) a->table[(s)/4]=(uintptr_t)(f)
|
|
SLOT(0x16c,position);SLOT(0x174,rotation);SLOT(0x150,zero);SLOT(0x28,init);SLOT(0x40c,post);SLOT(0x3f8,logging);
|
|
#undef SLOT
|
|
unsigned char*complete=(unsigned char*)game(a)-(a->family?0xc8:0xc0);
|
|
float xyz[]={1.25f+i,-2.5f-i,3.75f+i};short angles[]={1024,-2048,4096};
|
|
memcpy(complete+0x44,xyz,sizeof(xyz));memcpy(complete+0x50,angles,sizeof(angles));
|
|
}
|
|
}
|
|
static void snapshot(const char*name){
|
|
printf("REG {\"name\":\"%s\",\"events\":\"%s\",\"order\":[",name,events);int first=1;
|
|
for(Node*n=bodies.next;n!=&bodies;n=n->next){printf("%s%d",first?"":",",owner(n->value)->id);first=0;}
|
|
printf("],\"count\":%u,\"flags\":[",*(unsigned*)AT(0x695d40));
|
|
for(int i=0;i<3;i++)printf("%s%u",i?",":"",*((unsigned char*)game(&actors[i])+0x49e));
|
|
printf("],\"inits\":[%d,%d,%d],\"positions\":[",actors[0].inits,actors[1].inits,actors[2].inits);
|
|
for(int i=0;i<3;i++)printf("%s[%.9g,%.9g,%.9g]",i?",":"",actors[i].position[0],actors[i].position[1],actors[i].position[2]);
|
|
printf("],\"rotations\":[");
|
|
for(int i=0;i<3;i++)printf("%s[%.9g,%.9g,%.9g]",i?",":"",actors[i].rotation[0],actors[i].rotation[1],actors[i].rotation[2]);
|
|
puts("]}");
|
|
}
|
|
static void next(void){used=0;events[0]=0;}
|
|
int main(void){
|
|
setbuf(stdout,NULL);map_source();
|
|
static const struct{unsigned va,target;} relocations[]={/* RELOCATIONS */};
|
|
for(unsigned i=0;i<sizeof(relocations)/sizeof(*relocations);i++){
|
|
uint32_t value=(uintptr_t)AT(relocations[i].target);
|
|
require(*(uint32_t*)AT(relocations[i].va)==relocations[i].target,"original relocation operand");
|
|
memcpy(AT(relocations[i].va),&value,4);
|
|
}
|
|
jump(AT(0x478990),allocate);jump(AT(0x47e470),timer);
|
|
reset();register_body(&actors[0],0);snapshot("polygon_first");
|
|
next();register_body(&actors[0],0);snapshot("polygon_repeat");
|
|
next();register_body(&actors[0],1);snapshot("guard_already_registered");
|
|
next();*((unsigned char*)game(&actors[0])+0x49e)=0;register_body(&actors[0],1);snapshot("clear_then_guard");
|
|
reset();register_body(&actors[1],0);snapshot("sprite_first");
|
|
next();register_body(&actors[1],0);snapshot("sprite_repeat");
|
|
reset();actors[0].nested=1;register_body(&actors[0],0);snapshot("nested_init_registration");
|
|
reset();*((unsigned char*)game(&actors[0])+0x13e)=0;*((unsigned char*)game(&actors[0])+0x140)=0;
|
|
register_body(&actors[0],0);snapshot("register_disabled_body");
|
|
reset();add_registry(0);add_registry(1);add_registry(2);((void(TC*)(void*))AT(0x46e570))(app);snapshot("loader_three");
|
|
reset();add_registry(0);add_registry(1);append_stage=1;((void(TC*)(void*))AT(0x46e570))(app);snapshot("loader_append_on_init");
|
|
reset();add_registry(0);add_registry(1);append_stage=2;((void(TC*)(void*))AT(0x46e570))(app);snapshot("loader_append_on_post");
|
|
reset();((void(TC*)(void*))AT(0x46e570))(app);snapshot("loader_empty");
|
|
puts("PHYSICAL_REGISTRATION_COMPLETE");return 0;
|
|
}
|