From 71539817b2348d9ba912173154998c8ca2e96ef1 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 5 Feb 2020 22:48:13 +1000 Subject: [PATCH] Decompile currentPlayerGetUnusedInvItem --- src/game/game_111600.c | 46 +++++++++++----------------------- src/include/game/game_111600.h | 2 +- src/include/types.h | 7 ++++-- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/game/game_111600.c b/src/game/game_111600.c index 5c136500e..a6acd45f8 100644 --- a/src/game/game_111600.c +++ b/src/game/game_111600.c @@ -257,34 +257,18 @@ glabel func0f1118cc /* f111924: 00000000 */ sll $zero,$zero,0x0 ); -GLOBAL_ASM( -glabel currentPlayerCreateInvitem -/* f111928: 3c03800a */ lui $v1,0x800a -/* f11192c: 8c63a244 */ lw $v1,-0x5dbc($v1) -/* f111930: 00001025 */ or $v0,$zero,$zero -/* f111934: 8c64186c */ lw $a0,0x186c($v1) -/* f111938: 5880000f */ blezl $a0,.L0f111978 -/* f11193c: 00001025 */ or $v0,$zero,$zero -/* f111940: 8c651868 */ lw $a1,0x1868($v1) -/* f111944: 2403ffff */ addiu $v1,$zero,-1 -/* f111948: 00003025 */ or $a2,$zero,$zero -/* f11194c: 00a03825 */ or $a3,$a1,$zero -.L0f111950: -/* f111950: 8cee0000 */ lw $t6,0x0($a3) -/* f111954: 24420001 */ addiu $v0,$v0,0x1 -/* f111958: 0044082a */ slt $at,$v0,$a0 -/* f11195c: 146e0003 */ bne $v1,$t6,.L0f11196c -/* f111960: 24e70014 */ addiu $a3,$a3,0x14 -/* f111964: 03e00008 */ jr $ra -/* f111968: 00a61021 */ addu $v0,$a1,$a2 -.L0f11196c: -/* f11196c: 1420fff8 */ bnez $at,.L0f111950 -/* f111970: 24c60014 */ addiu $a2,$a2,0x14 -/* f111974: 00001025 */ or $v0,$zero,$zero -.L0f111978: -/* f111978: 03e00008 */ jr $ra -/* f11197c: 00000000 */ sll $zero,$zero,0x0 -); +struct invitem *currentPlayerGetUnusedInvItem(void) +{ + s32 i; + + for (i = 0; i < g_Vars.currentplayer->equipmaxitems; i++) { + if (g_Vars.currentplayer->equipment[i].type == -1) { + return &g_Vars.currentplayer->equipment[i]; + } + } + + return NULL; +} void currentPlayerSetAllGuns(bool enable) { @@ -543,7 +527,7 @@ bool currentPlayerGiveWeapon(s32 weaponnum) return false; } - item = currentPlayerCreateInvitem(); + item = currentPlayerGetUnusedInvItem(); if (item) { item->type = INVITEMTYPE_1; @@ -562,7 +546,7 @@ bool currentPlayerGiveWeaponWithArgument(s32 weapon1, s32 weapon2) { if (func0f111ab0(weapon1, weapon2) == 0) { if (weaponHasFlag(weapon1, WEAPONFLAG_00001000)) { - struct invitem *item = currentPlayerCreateInvitem(); + struct invitem *item = currentPlayerGetUnusedInvItem(); if (item) { item->type = INVITEMTYPE_3; @@ -683,7 +667,7 @@ bool currentPlayerGiveProp(struct prop *prop) return true; } - item = currentPlayerCreateInvitem(); + item = currentPlayerGetUnusedInvItem(); if (item) { item->type = INVITEMTYPE_PROP; diff --git a/src/include/game/game_111600.h b/src/include/game/game_111600.h index a256839ef..7b36629fc 100644 --- a/src/include/game/game_111600.h +++ b/src/include/game/game_111600.h @@ -7,7 +7,7 @@ void func0f111600(void); u32 func0f11165c(void); void func0f11179c(struct invitem *item); u32 func0f1118cc(void); -struct invitem *currentPlayerCreateInvitem(void); +struct invitem *currentPlayerGetUnusedInvItem(void); void currentPlayerSetAllGuns(bool enable); u32 func0f1119d0(void); bool func0f111a28(s32 weaponnum); diff --git a/src/include/types.h b/src/include/types.h index 2d1ed6dcb..fa4ff99f1 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -2512,8 +2512,8 @@ struct player { /*0x185c*/ u32 flags; /*0x1860*/ u32 unk1860; /*0x1864*/ u32 unk1864; - /*0x1868*/ u32 unk1868; - /*0x186c*/ u32 equipmaxitems; + /*0x1868*/ struct invitem *equipment; + /*0x186c*/ s32 equipmaxitems; /*0x1870*/ u32 equipallguns; /*0x1874*/ u32 equipcuritem; /*0x1878*/ struct gunheld gunheldarr[10]; @@ -5089,6 +5089,9 @@ struct invitem { struct invitem_typeprop type_prop; struct invitem_type3 type3; }; + + /*0x0c*/ u32 unk0c; + /*0x10*/ u32 unk10; }; #endif