From 105a552d367ded63e9149c0c5a8f0793074ba9d5 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 19 Jan 2020 20:38:45 +1000 Subject: [PATCH] Decompile mpGetBodyIndexByBodyId --- src/game/game_187770.c | 45 +++++++++++++--------------------- src/game/game_1a3340.c | 2 +- src/include/constants.h | 2 +- src/include/game/game_187770.h | 2 +- src/include/types.h | 2 +- src/setup/setup_020df0.c | 2 +- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/game/game_187770.c b/src/game/game_187770.c index 2c3292db6..8268fca93 100644 --- a/src/game/game_187770.c +++ b/src/game/game_187770.c @@ -5165,34 +5165,23 @@ glabel func0f18bb90 /* f18bbd4: 00000000 */ sll $zero,$zero,0x0 ); -GLOBAL_ASM( -glabel func0f18bbd8 -/* f18bbd8: 3082ffff */ andi $v0,$a0,0xffff -/* f18bbdc: 2401006b */ addiu $at,$zero,0x6b -/* f18bbe0: 14410003 */ bne $v0,$at,.L0f18bbf0 -/* f18bbe4: afa40000 */ sw $a0,0x0($sp) -/* f18bbe8: 03e00008 */ jr $ra -/* f18bbec: 2402003e */ addiu $v0,$zero,0x3e -.L0f18bbf0: -/* f18bbf0: 3c048008 */ lui $a0,%hi(g_MpBodies) -/* f18bbf4: 248477bc */ addiu $a0,$a0,%lo(g_MpBodies) -/* f18bbf8: 00001825 */ or $v1,$zero,$zero -/* f18bbfc: 2405003d */ addiu $a1,$zero,0x3d -.L0f18bc00: -/* f18bc00: 848f0000 */ lh $t7,0x0($a0) -/* f18bc04: 544f0004 */ bnel $v0,$t7,.L0f18bc18 -/* f18bc08: 24630001 */ addiu $v1,$v1,0x1 -/* f18bc0c: 03e00008 */ jr $ra -/* f18bc10: 00601025 */ or $v0,$v1,$zero -/* f18bc14: 24630001 */ addiu $v1,$v1,0x1 -.L0f18bc18: -/* f18bc18: 1465fff9 */ bne $v1,$a1,.L0f18bc00 -/* f18bc1c: 24840008 */ addiu $a0,$a0,0x8 -/* f18bc20: 3c028008 */ lui $v0,0x8008 -/* f18bc24: 844277bc */ lh $v0,0x77bc($v0) -/* f18bc28: 03e00008 */ jr $ra -/* f18bc2c: 00000000 */ sll $zero,$zero,0x0 -); +s32 mpGetBodyIndexByBodyId(u16 bodyid) +{ + s32 i; + + if (bodyid == BODY_DRCAROLL) { + return 62; // NUM_MPBODIES + 1 + } + + for (i = 0; i != NUM_MPBODIES; i++) { + if (g_MpBodies[i].bodyid == bodyid) { + return i; + } + } + + // @bug: Should return 0 as a fallback, not the first body's bodyid + return g_MpBodies[0].bodyid; +} char *mpGetBodyName(u8 bodynum) { diff --git a/src/game/game_1a3340.c b/src/game/game_1a3340.c index 6e54473f7..1ee5f399b 100644 --- a/src/game/game_1a3340.c +++ b/src/game/game_1a3340.c @@ -3146,7 +3146,7 @@ glabel menudialog001a5f48 /* f1a5f60: 0fc68484 */ jal func0f1a1210 /* f1a5f64: 908488a0 */ lbu $a0,-0x7760($a0) /* f1a5f68: 3044ffff */ andi $a0,$v0,0xffff -/* f1a5f6c: 0fc62ef6 */ jal func0f18bbd8 +/* f1a5f6c: 0fc62ef6 */ jal mpGetBodyIndexByBodyId /* f1a5f70: afa20044 */ sw $v0,0x44($sp) /* f1a5f74: afa20040 */ sw $v0,0x40($sp) /* f1a5f78: 0fc62f27 */ jal func0f18bc9c diff --git a/src/include/constants.h b/src/include/constants.h index c4d50f442..d81669bb0 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -1192,7 +1192,7 @@ #define BODY_FEM_GUARD 0x68 #define BODY_DD_LABTECH 0x69 #define BODY_DD_SECGUARD 0x6a -#define BODY_DRCARROLL 0x6b +#define BODY_DRCAROLL 0x6b #define BODY_EYESPY 0x6c #define BODY_DARK_RIPPED 0x6d #define BODY_DD_GUARD 0x6e diff --git a/src/include/game/game_187770.h b/src/include/game/game_187770.h index 5c0736ae4..cadcd303d 100644 --- a/src/include/game/game_187770.h +++ b/src/include/game/game_187770.h @@ -52,7 +52,7 @@ u32 func0f18bb48(void); u32 func0f18bb64(void); u32 mpGetNumBodies(void); u32 func0f18bb90(void); -u32 func0f18bbd8(void); +s32 mpGetBodyIndexByBodyId(u16 bodyid); char *mpGetBodyName(u8 bodynum); u8 mpGetBodyUnk06(u8 bodynum); s32 func0f18bc9c(s32 arg0); diff --git a/src/include/types.h b/src/include/types.h index f0a1f5426..a9f976a1c 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -2874,7 +2874,7 @@ struct mpsimulant { }; struct mpbody { - u16 slot; + s16 bodyid; s16 name; u16 unk04; u8 unk06; diff --git a/src/setup/setup_020df0.c b/src/setup/setup_020df0.c index db4c49057..b48f76d6d 100644 --- a/src/setup/setup_020df0.c +++ b/src/setup/setup_020df0.c @@ -12052,7 +12052,7 @@ struct mpsimulant mpspecialsimulants[] = { // 2d7dc struct mpbody g_MpBodies[NUM_MPBODIES] = { - // slot, name, unk04, unk06 + // global body ID, name, unk04, unk06 /*0x00*/ { 0x0056, 0x5610, 0x0004, 0x00 }, /*0x01*/ { 0x0062, 0x5611, 0x0004, 0x46 }, /*0x02*/ { 0x0061, 0x5612, 0x000c, 0x41 },