From 2148f2495c39a12a4d9cd65700c01e8081cb366a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 6 Feb 2020 17:20:14 +1000 Subject: [PATCH] Decompile currentPlayerGetWeaponInvItem --- src/game/game_066310.c | 2 +- src/game/game_111600.c | 54 ++++++++++++++-------------------- src/include/game/game_111600.h | 2 +- src/include/types.h | 4 +-- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/game/game_066310.c b/src/game/game_066310.c index bb5a05864..f0591f283 100644 --- a/src/game/game_066310.c +++ b/src/game/game_066310.c @@ -40629,7 +40629,7 @@ glabel func0f089014 /* f0893b4: 1440000f */ bnez $v0,.L0f0893f4 /* f0893b8: 8fa70080 */ lw $a3,0x80($sp) /* f0893bc: 90e4005c */ lbu $a0,0x5c($a3) -/* f0893c0: 0fc44674 */ jal func0f1119d0 +/* f0893c0: 0fc44674 */ jal currentPlayerGetWeaponInvItem /* f0893c4: afa70080 */ sw $a3,0x80($sp) /* f0893c8: 10400005 */ beqz $v0,.L0f0893e0 /* f0893cc: 8fa70080 */ lw $a3,0x80($sp) diff --git a/src/game/game_111600.c b/src/game/game_111600.c index b0781ec92..e59537d22 100644 --- a/src/game/game_111600.c +++ b/src/game/game_111600.c @@ -22,7 +22,7 @@ void currentPlayerClearInventory(void) g_Vars.currentplayer->equipment[i].type = -1; } - g_Vars.currentplayer->unk1864 = 0; + g_Vars.currentplayer->weapons = NULL; g_Vars.currentplayer->equipcuritem = 0; } @@ -268,39 +268,29 @@ bool currentPlayerHasAllGuns(void) return g_Vars.currentplayer->equipallguns; } -GLOBAL_ASM( -glabel func0f1119d0 -/* f1119d0: 3c0e800a */ lui $t6,0x800a -/* f1119d4: 8dcea244 */ lw $t6,-0x5dbc($t6) -/* f1119d8: 24050001 */ addiu $a1,$zero,0x1 -/* f1119dc: 8dc21864 */ lw $v0,0x1864($t6) -/* f1119e0: 1040000e */ beqz $v0,.L0f111a1c -/* f1119e4: 00401825 */ or $v1,$v0,$zero -/* f1119e8: 8c6f0000 */ lw $t7,0x0($v1) -.L0f1119ec: -/* f1119ec: 54af0007 */ bnel $a1,$t7,.L0f111a0c -/* f1119f0: 8c63000c */ lw $v1,0xc($v1) -/* f1119f4: 84780004 */ lh $t8,0x4($v1) -/* f1119f8: 54980004 */ bnel $a0,$t8,.L0f111a0c -/* f1119fc: 8c63000c */ lw $v1,0xc($v1) -/* f111a00: 03e00008 */ jr $ra -/* f111a04: 00601025 */ or $v0,$v1,$zero -/* f111a08: 8c63000c */ lw $v1,0xc($v1) -.L0f111a0c: -/* f111a0c: 50620004 */ beql $v1,$v0,.L0f111a20 -/* f111a10: 00001025 */ or $v0,$zero,$zero -/* f111a14: 5460fff5 */ bnezl $v1,.L0f1119ec -/* f111a18: 8c6f0000 */ lw $t7,0x0($v1) -.L0f111a1c: -/* f111a1c: 00001025 */ or $v0,$zero,$zero -.L0f111a20: -/* f111a20: 03e00008 */ jr $ra -/* f111a24: 00000000 */ sll $zero,$zero,0x0 -); +struct invitem *currentPlayerGetWeaponInvItem(s32 weaponnum) +{ + struct invitem *first = g_Vars.currentplayer->weapons; + struct invitem *item = first; + + while (item) { + if (item->type == INVITEMTYPE_1 && item->type1.weapon1 == weaponnum) { + return item; + } + + item = item->next; + + if (item == first) { + break; + } + } + + return NULL; +} bool currentPlayerHasWeapon(s32 weaponnum) { - return func0f1119d0(weaponnum) != NULL; + return currentPlayerGetWeaponInvItem(weaponnum) != NULL; } GLOBAL_ASM( @@ -745,7 +735,7 @@ glabel func0f1120f0 /* f1121a8: 1440001b */ bnez $v0,.L0f112218 /* f1121ac: 8fa7002c */ lw $a3,0x2c($sp) /* f1121b0: 02002025 */ or $a0,$s0,$zero -/* f1121b4: 0fc44674 */ jal func0f1119d0 +/* f1121b4: 0fc44674 */ jal currentPlayerGetWeaponInvItem /* f1121b8: afa7002c */ sw $a3,0x2c($sp) /* f1121bc: 10400016 */ beqz $v0,.L0f112218 /* f1121c0: 8fa7002c */ lw $a3,0x2c($sp) diff --git a/src/include/game/game_111600.h b/src/include/game/game_111600.h index da96d466d..48a1fabb6 100644 --- a/src/include/game/game_111600.h +++ b/src/include/game/game_111600.h @@ -9,7 +9,7 @@ void func0f11179c(struct invitem *item); u32 func0f1118cc(void); struct invitem *currentPlayerGetUnusedInvItem(void); void currentPlayerSetAllGuns(bool enable); -void *func0f1119d0(s32 weaponnum); +struct invitem *currentPlayerGetWeaponInvItem(s32 weaponnum); bool currentPlayerHasWeapon(s32 weaponnum); void *func0f111a4c(s32 weapon1, s32 weapon2); bool func0f111ab0(s32 weapon1, s32 weapon2); diff --git a/src/include/types.h b/src/include/types.h index 0250ffda7..78b3279aa 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -2506,7 +2506,7 @@ struct player { /*0x1858*/ u32 unk1858; /*0x185c*/ u32 flags; /*0x1860*/ u32 unk1860; - /*0x1864*/ u32 unk1864; + /*0x1864*/ struct invitem *weapons; // circular linked list /*0x1868*/ struct invitem *equipment; /*0x186c*/ s32 equipmaxitems; /*0x1870*/ u32 equipallguns; @@ -5085,7 +5085,7 @@ struct invitem { struct invitem_type3 type3; }; - /*0x0c*/ u32 unk0c; + /*0x0c*/ struct invitem *next; /*0x10*/ u32 unk10; };