Identify unnamed body functions

This commit is contained in:
Ryan Dwyer 2024-08-18 12:34:05 +10:00
parent 1b0a1cf307
commit 55ce7f314f
14 changed files with 56 additions and 74 deletions

View File

@ -86,7 +86,7 @@ The decomp project wraps all decompiled piracy checks in `#if PIRACYCHECKS` stat
**Payload:** Writes a filesystem terminator file to the start of EEPROM. This disables the cartridge's save data, removing the ability to read existing files and create new ones.
### body_allocate_eyespy
### body_instantiate_eyespy
**When Called:** When loading any stage that uses the eyespy.

View File

@ -29,7 +29,7 @@ u32 var8009cd24;
s32 g_ActiveMaleHeads[8];
s32 g_ActiveFemaleHeads[8];
s32 g_NumBondBodies = 0;
s32 g_NumTuxedos = 0;
s32 g_NumMaleGuardHeads = 0;
s32 g_NumFemaleGuardHeads = 0;
s32 g_NumMaleGuardTeamHeads = 0;
@ -37,7 +37,7 @@ s32 g_NumFemaleGuardTeamHeads = 0;
s32 var80062b14 = 0;
s32 var80062b18 = 0;
s32 g_BondBodies[] = {
s32 g_TuxedoBodynums[] = {
BODY_DJBOND,
BODY_CONNERY,
BODY_DALTON,
@ -127,7 +127,7 @@ s32 g_FemaleGuardTeamHeads[] = {
-1,
};
s32 var80062c80 = 0;
s32 g_TuxedoIndex = 0;
s32 g_ActiveMaleHeadsIndex = 0;
s32 g_ActiveFemaleHeadsIndex = 0;
@ -155,7 +155,7 @@ u32 body_get_race(s32 bodynum)
return RACE_HUMAN;
}
bool body_load(s32 bodynum)
bool body_load_modeldef(s32 bodynum)
{
if (!g_HeadsAndBodies[bodynum].modeldef) {
g_HeadsAndBodies[bodynum].modeldef = modeldef_load_to_new(g_HeadsAndBodies[bodynum].filenum);
@ -165,7 +165,7 @@ bool body_load(s32 bodynum)
return false;
}
struct model *body0f02ce8c(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, struct model *model, bool isplayer, u8 varyheight)
struct model *body_instantiate_model_to_addr(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, struct model *model, bool isplayer, u8 varyheight)
{
f32 scale = g_HeadsAndBodies[bodynum].scale * 0.10000001f;
f32 animscale = g_HeadsAndBodies[bodynum].animscale;
@ -196,7 +196,7 @@ struct model *body0f02ce8c(s32 bodynum, s32 headnum, struct modeldef *bodymodeld
bodymodeldef->rwdatalen += headmodeldef->rwdatalen;
} else if (headnum > 0) {
if (headmodeldef == NULL) {
if (g_Vars.normmplayerisrunning && !IS4MB()) {
if (g_Vars.normmplayerisrunning && IS8MB()) {
headmodeldef = modeldef_load_to_new(g_HeadsAndBodies[headnum].filenum);
g_HeadsAndBodies[headnum].modeldef = headmodeldef;
g_FileInfo[g_HeadsAndBodies[headnum].filenum].loadedsize = 0;
@ -286,12 +286,12 @@ struct model *body0f02ce8c(s32 bodynum, s32 headnum, struct modeldef *bodymodeld
return model;
}
struct model *body0f02d338(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, u8 varyheight)
struct model *body_instantiate_model_to_new(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, u8 varyheight)
{
return body0f02ce8c(bodynum, headnum, bodymodeldef, headmodeldef, sunglasses, NULL, false, varyheight);
return body_instantiate_model_to_addr(bodynum, headnum, bodymodeldef, headmodeldef, sunglasses, NULL, false, varyheight);
}
struct model *body_allocate_model(s32 bodynum, s32 headnum, u32 spawnflags)
struct model *body_instantiate_model_with_spawnflags(s32 bodynum, s32 headnum, u32 spawnflags)
{
bool sunglasses = false;
u8 varyheight = true;
@ -306,12 +306,12 @@ struct model *body_allocate_model(s32 bodynum, s32 headnum, u32 spawnflags)
varyheight = false;
}
return body0f02d338(bodynum, headnum, NULL, NULL, sunglasses, varyheight);
return body_instantiate_model_to_new(bodynum, headnum, NULL, NULL, sunglasses, varyheight);
}
s32 body0f02d3f8(void)
s32 body_get_tuxedo_bodynum(void)
{
return g_BondBodies[var80062c80];
return g_TuxedoBodynums[g_TuxedoIndex];
}
s32 body_choose_head(s32 bodynum)
@ -343,7 +343,7 @@ s32 body_choose_head(s32 bodynum)
* Chr definitions are stored in a packed format in each stage's setup file.
* The packed format is used for space saving reasons.
*/
void body_allocate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex)
void body_instantiate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex)
{
struct pad pad;
RoomNum rooms[2];
@ -385,7 +385,7 @@ void body_allocate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex)
headmodeldef = NULL;
if (packed->bodynum == 255) {
bodynum = body0f02d3f8();
bodynum = body_get_tuxedo_bodynum();
} else {
bodynum = packed->bodynum;
}
@ -405,9 +405,9 @@ void body_allocate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex)
headmodeldef = func0f18e57c(index, &headnum);
}
model = body0f02ce8c(bodynum, headnum, NULL, headmodeldef, false, NULL, false, false);
model = body_instantiate_model_to_addr(bodynum, headnum, NULL, headmodeldef, false, NULL, false, false);
} else {
model = body_allocate_model(bodynum, headnum, packed->spawnflags);
model = body_instantiate_model_with_spawnflags(bodynum, headnum, packed->spawnflags);
}
if (model != NULL) {
@ -531,7 +531,7 @@ void body_allocate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex)
}
}
struct prop *body_allocate_eyespy(struct pad *pad, RoomNum room)
struct prop *body_instantiate_eyespy(struct pad *pad, RoomNum room)
{
RoomNum rooms[2];
struct prop *prop;
@ -569,7 +569,7 @@ struct prop *body_allocate_eyespy(struct pad *pad, RoomNum room)
}
#endif
model = body_allocate_model(BODY_EYESPY, 0, 0);
model = body_instantiate_model_with_spawnflags(BODY_EYESPY, 0, 0);
if (model) {
prop = chr_allocate(model, &pad->pos, rooms, 0, ailist_find_by_id(GAILIST_IDLE));
@ -682,52 +682,35 @@ void body_calculate_head_offset(struct modeldef *headmodeldef, s32 headnum, s32
}
#endif
// In the switch statement below, most versions set the offset directly.
// JPN increments it instead.
#if VERSION >= VERSION_JPN_FINAL
switch (g_HeadsAndBodies[headnum].type) {
default:
case HEADBODYTYPE_FEMALE:
offset += 0;
break;
case HEADBODYTYPE_MAIAN:
offset += 0;
break;
case HEADBODYTYPE_DEFAULT:
offset -= 35;
break;
case HEADBODYTYPE_MRBLONDE:
offset += 0;
break;
case HEADBODYTYPE_CASS:
offset -= 20;
break;
case HEADBODYTYPE_FEMALEGUARD:
offset -= 40;
break;
}
#define ADJUST(var, amount) (var + amount)
#else
// Same as JPN, but sets the value rather than adjusts
#define ADJUST(var, amount) (amount)
#endif
switch (g_HeadsAndBodies[headnum].type) {
default:
case HEADBODYTYPE_FEMALE:
offset = 0;
offset = ADJUST(offset, 0);
break;
case HEADBODYTYPE_MAIAN:
offset = 0;
offset = ADJUST(offset, 0);
break;
case HEADBODYTYPE_DEFAULT:
offset = -35;
offset = ADJUST(offset, -35);
break;
case HEADBODYTYPE_MRBLONDE:
offset = 0;
offset = ADJUST(offset, 0);
break;
case HEADBODYTYPE_CASS:
offset = -20;
offset = ADJUST(offset, -20);
break;
case HEADBODYTYPE_FEMALEGUARD:
offset = -40;
offset = ADJUST(offset, -40);
break;
}
#endif
switch (g_HeadsAndBodies[bodynum].type) {
case HEADBODYTYPE_FEMALE:

View File

@ -9,10 +9,10 @@
void bodies_init(void)
{
g_NumBondBodies = 0;
g_NumTuxedos = 0;
while (g_BondBodies[g_NumBondBodies] >= 0) {
g_NumBondBodies++;
while (g_TuxedoBodynums[g_NumTuxedos] >= 0) {
g_NumTuxedos++;
}
g_NumMaleGuardTeamHeads = 0;

View File

@ -26,7 +26,7 @@ void bodies_reset(s32 stagenum)
g_HeadsAndBodies[i].modeldef = NULL;
}
var80062c80 = random() % g_NumBondBodies;
g_TuxedoIndex = random() % g_NumTuxedos;
var80062b14 = 0;
var80062b18 = 0;

View File

@ -47,7 +47,7 @@ void botmgr_allocate_bot(s32 chrnum, s32 aibotnum)
bodynum = BODY_DDSHOCK;
}
model = body_allocate_model(bodynum, headnum, 0);
model = body_instantiate_model_with_spawnflags(bodynum, headnum, 0);
if (model != NULL) {
struct coord pos = {0.0f, 0.0f, 0.0f};

View File

@ -15099,7 +15099,7 @@ struct prop *chr_spawn_at_coord(s32 bodynum, s32 headnum, struct coord *pos, Roo
if (chr_adjust_pos_for_spawn(20, &pos2, rooms2, angle, (spawnflags & SPAWNFLAG_ALLOWONSCREEN) != 0, false))
#endif
{
struct model *model = body_allocate_model(bodynum, headnum, spawnflags);
struct model *model = body_instantiate_model_with_spawnflags(bodynum, headnum, spawnflags);
struct chrdata *chr;
if (model) {

View File

@ -149,12 +149,12 @@ void stage_load_all_ailist_models(void)
if (setup_load_modeldef(id));
break;
case AICMD_SPAWNCHRATPAD:
body_load(cmd[2]);
if ((s8)cmd[3] >= 0 && body_load((s8)cmd[3]));
body_load_modeldef(cmd[2]);
if ((s8)cmd[3] >= 0 && body_load_modeldef((s8)cmd[3]));
break;
case AICMD_SPAWNCHRATCHR:
body_load(cmd[2]);
if ((s8)cmd[3] >= 0 && body_load((s8)cmd[3]));
body_load_modeldef(cmd[2]);
if ((s8)cmd[3] >= 0 && body_load_modeldef((s8)cmd[3]));
break;
case AICMD_EQUIPWEAPON:
setup_load_modeldef(cmd[3] | (cmd[2] << 8));

View File

@ -1822,7 +1822,7 @@ Gfx *menu_render_model(Gfx *gdl, struct menumodel *menumodel, s32 modeltype)
menumodel->bodymodel.rwdatalen = 256;
menumodel->bodymodel.anim = &menumodel->bodyanim;
body0f02ce8c(bodynum, headnum, menumodel->bodymodeldef, menumodel->headmodeldef, totalfilelen * 0, &menumodel->bodymodel, false, 1);
body_instantiate_model_to_addr(bodynum, headnum, menumodel->bodymodeldef, menumodel->headmodeldef, totalfilelen * 0, &menumodel->bodymodel, false, 1);
} else {
totalfilelen = ALIGN64(file_get_inflated_size(menumodel->newparams)) + 0x4000;
if (1);

View File

@ -1450,7 +1450,7 @@ void player_tick_chr_body(void)
}
}
g_Vars.currentplayer->model00d4 = body0f02ce8c(bodynum, headnum, bodymodeldef, headmodeldef, false, model, true, true);
g_Vars.currentplayer->model00d4 = body_instantiate_model_to_addr(bodynum, headnum, bodymodeldef, headmodeldef, false, model, true, true);
chr0f020b14(g_Vars.currentplayer->prop, g_Vars.currentplayer->model00d4, &g_Vars.currentplayer->prop->pos,
g_Vars.currentplayer->prop->rooms, turnangle, 0);

View File

@ -34,7 +34,7 @@ void player_init_eyespy(void)
if (g_Vars.currentplayer->eyespy == NULL) {
/**
* To create the eyespy's prop, a pad must be passed to body_allocate_eyespy.
* To create the eyespy's prop, a pad must be passed to body_instantiate_eyespy.
* However the eyespy doesn't have a pad because it's held by the
* player, so it needs to choose one from the stage. The method used
* will increment the chosen pad number each time the stage is loaded
@ -45,7 +45,7 @@ void player_init_eyespy(void)
* causing the mid cutscene to play instead of the intro.
*/
pad_unpack(nextpad++, PADFIELD_ROOM | PADFIELD_POS, &pad);
prop = body_allocate_eyespy(&pad, pad.room);
prop = body_instantiate_eyespy(&pad, pad.room);
if (prop) {
g_Vars.currentplayer->eyespy = memp_alloc(sizeof(struct eyespy), MEMPOOL_STAGE);

View File

@ -1545,7 +1545,7 @@ void setup_create_props(s32 stagenum)
break;
case OBJTYPE_CHR:
if (withchrs) {
body_allocate_chr(stagenum, (struct packedchr *) obj, index);
body_instantiate_chr(stagenum, (struct packedchr *) obj, index);
}
break;
case OBJTYPE_DOOR:

View File

@ -140,19 +140,19 @@ extern struct chrdata *g_ChrSlots;
extern s32 g_NumChrSlots;
extern struct shieldhit *g_ShieldHits;
extern bool g_ShieldHitActive;
extern s32 g_NumBondBodies;
extern s32 g_NumTuxedos;
extern s32 g_NumMaleGuardHeads;
extern s32 g_NumFemaleGuardHeads;
extern s32 g_NumMaleGuardTeamHeads;
extern s32 g_NumFemaleGuardTeamHeads;
extern s32 var80062b14;
extern s32 var80062b18;
extern s32 g_BondBodies[];
extern s32 g_TuxedoBodynums[];
extern s32 g_MaleGuardHeads[];
extern s32 g_MaleGuardTeamHeads[];
extern s32 g_FemaleGuardHeads[];
extern s32 g_FemaleGuardTeamHeads[];
extern s32 var80062c80;
extern s32 g_TuxedoIndex;
extern s32 g_ActiveMaleHeadsIndex;
extern s32 g_ActiveFemaleHeadsIndex;
extern f32 g_EnemyAccuracyScale;

View File

@ -9,14 +9,13 @@ void bodies_init(void);
void bodies_reset(s32 stagenum);
u32 body_get_race(s32 bodynum);
bool body_load(s32 bodynum);
struct model *body0f02ce8c(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, struct model *model, bool isplayer, u8 varyheight);
struct model *body0f02d338(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, u8 varyheight);
struct model *body_allocate_model(s32 bodynum, s32 headnum, u32 spawnflags);
s32 body0f02d3f8(void);
bool body_load_modeldef(s32 bodynum);
struct model *body_instantiate_model_to_addr(s32 bodynum, s32 headnum, struct modeldef *bodymodeldef, struct modeldef *headmodeldef, bool sunglasses, struct model *model, bool isplayer, u8 varyheight);
struct model *body_instantiate_model_with_spawnflags(s32 bodynum, s32 headnum, u32 spawnflags);
s32 body_get_tuxedo_bodynum(void);
s32 body_choose_head(s32 bodynum);
void body_allocate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex);
struct prop *body_allocate_eyespy(struct pad *pad, RoomNum room);
void body_instantiate_chr(s32 stagenum, struct packedchr *packed, s32 cmdindex);
struct prop *body_instantiate_eyespy(struct pad *pad, RoomNum room);
void body_calculate_head_offset(struct modeldef *headmodeldef, s32 headnum, s32 bodynum);
#endif

View File

@ -169,7 +169,7 @@ void piracy_patch_checksums(void)
patch(algo04, "chr_uncloak", "bot_pickup_prop");
patch(algo05, "chrs_check_for_noise", "__scHandleRetrace");
patch(algo06, "lv_reset", "lv_get_slow_motion_type");
patch(algo07, "body_allocate_eyespy", "lv_reset");
patch(algo07, "body_instantiate_eyespy", "lv_reset");
patch(algo08, "chr_consider_grenade_throw", "bg_reset");
patch(algo09, "bgun_tick_gun_load", "tags_reset");
patch(algo10, "explosion_alert_chrs", "glass_destroy");