From 4fa36456f1c608800726badf48a9acd3891046d4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 5 May 2020 23:01:08 +1000 Subject: [PATCH] Decompile weaponGetAmmoByFunction --- src/game/chr/chraction.c | 2 +- src/game/game_0b0420.c | 42 +++++++++++----------------------- src/game/game_1999b0.c | 4 ++-- src/game/game_19c990.c | 2 +- src/include/game/game_0b0420.h | 2 +- src/include/types.h | 2 +- 6 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index c71f97db8..6b64d7a83 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -14003,7 +14003,7 @@ glabel var7f1a8ec4 .L0f03a4e8: /* f03a4e8: e7a00034 */ swc1 $f0,0x34($sp) /* f03a4ec: afa70038 */ sw $a3,0x38($sp) -/* f03a4f0: 0fc2c47b */ jal func0f0b11ec +/* f03a4f0: 0fc2c47b */ jal weaponGetAmmoByFunction /* f03a4f4: 00002825 */ or $a1,$zero,$zero /* f03a4f8: 44801000 */ mtc1 $zero,$f2 /* f03a4fc: 8fa70038 */ lw $a3,0x38($sp) diff --git a/src/game/game_0b0420.c b/src/game/game_0b0420.c index e02fced48..06b2f2989 100644 --- a/src/game/game_0b0420.c +++ b/src/game/game_0b0420.c @@ -941,36 +941,20 @@ glabel func0f0b11bc /* f0b11e8: 27bd0018 */ addiu $sp,$sp,0x18 ); +struct inventory_ammo *weaponGetAmmoByFunction(u32 weaponnum, u32 funcnum) +{ + struct weapon *weapon = weaponFindById(weaponnum); + struct weaponfunc *func = weaponGetFunctionById(weaponnum, funcnum); + + if (func && weapon && func->ammoindex >= 0) { + return weapon->ammos[func->ammoindex]; + } + + return NULL; +} + GLOBAL_ASM( -glabel func0f0b11ec -/* f0b11ec: 27bdffe0 */ addiu $sp,$sp,-32 -/* f0b11f0: afbf0014 */ sw $ra,0x14($sp) -/* f0b11f4: afa40020 */ sw $a0,0x20($sp) -/* f0b11f8: 0fc2c3f4 */ jal weaponFindById -/* f0b11fc: afa50024 */ sw $a1,0x24($sp) -/* f0b1200: 8fa40020 */ lw $a0,0x20($sp) -/* f0b1204: 8fa50024 */ lw $a1,0x24($sp) -/* f0b1208: 0fc2c401 */ jal weaponGetFunctionById -/* f0b120c: afa2001c */ sw $v0,0x1c($sp) -/* f0b1210: 1040000b */ beqz $v0,.L0f0b1240 -/* f0b1214: 8fa3001c */ lw $v1,0x1c($sp) -/* f0b1218: 5060000a */ beqzl $v1,.L0f0b1244 -/* f0b121c: 00001025 */ or $v0,$zero,$zero -/* f0b1220: 804e0007 */ lb $t6,0x7($v0) -/* f0b1224: 05c20007 */ bltzl $t6,.L0f0b1244 -/* f0b1228: 00001025 */ or $v0,$zero,$zero -/* f0b122c: 804f0007 */ lb $t7,0x7($v0) -/* f0b1230: 000fc080 */ sll $t8,$t7,0x2 -/* f0b1234: 0078c821 */ addu $t9,$v1,$t8 -/* f0b1238: 10000002 */ beqz $zero,.L0f0b1244 -/* f0b123c: 8f22001c */ lw $v0,0x1c($t9) -.L0f0b1240: -/* f0b1240: 00001025 */ or $v0,$zero,$zero -.L0f0b1244: -/* f0b1244: 8fbf0014 */ lw $ra,0x14($sp) -/* f0b1248: 27bd0020 */ addiu $sp,$sp,0x20 -/* f0b124c: 03e00008 */ jr $ra -/* f0b1250: 00000000 */ sll $zero,$zero,0x0 +glabel func0f0b1254 /* f0b1254: 27bdffe8 */ addiu $sp,$sp,-24 /* f0b1258: afbf0014 */ sw $ra,0x14($sp) /* f0b125c: afa40018 */ sw $a0,0x18($sp) diff --git a/src/game/game_1999b0.c b/src/game/game_1999b0.c index db551d686..57627f360 100644 --- a/src/game/game_1999b0.c +++ b/src/game/game_1999b0.c @@ -34,7 +34,7 @@ glabel func0f1999b0 /* f1999c0: 2881005e */ slti $at,$a0,0x5e /* f1999c4: 50200008 */ beqzl $at,.L0f1999e8 /* f1999c8: 00001025 */ or $v0,$zero,$zero -/* f1999cc: 0fc2c47b */ jal func0f0b11ec +/* f1999cc: 0fc2c47b */ jal weaponGetAmmoByFunction /* f1999d0: 00000000 */ sll $zero,$zero,0x0 /* f1999d4: 50400004 */ beqzl $v0,.L0f1999e8 /* f1999d8: 00001025 */ or $v0,$zero,$zero @@ -58,7 +58,7 @@ glabel func0f1999f8 /* f199a08: 2881005e */ slti $at,$a0,0x5e /* f199a0c: 50200008 */ beqzl $at,.L0f199a30 /* f199a10: 00001025 */ or $v0,$zero,$zero -/* f199a14: 0fc2c47b */ jal func0f0b11ec +/* f199a14: 0fc2c47b */ jal weaponGetAmmoByFunction /* f199a18: 00000000 */ sll $zero,$zero,0x0 /* f199a1c: 50400004 */ beqzl $v0,.L0f199a30 /* f199a20: 00001025 */ or $v0,$zero,$zero diff --git a/src/game/game_19c990.c b/src/game/game_19c990.c index e3b078c21..911c13fe1 100644 --- a/src/game/game_19c990.c +++ b/src/game/game_19c990.c @@ -3300,7 +3300,7 @@ glabel var7f1b94e4 /* f19fd5c: 00402025 */ or $a0,$v0,$zero /* f19fd60: 00408025 */ or $s0,$v0,$zero /* f19fd64: 02402025 */ or $a0,$s2,$zero -/* f19fd68: 0fc2c47b */ jal func0f0b11ec +/* f19fd68: 0fc2c47b */ jal weaponGetAmmoByFunction /* f19fd6c: 00002825 */ or $a1,$zero,$zero /* f19fd70: 10400003 */ beqz $v0,.L0f19fd80 /* f19fd74: 00001825 */ or $v1,$zero,$zero diff --git a/src/include/game/game_0b0420.h b/src/include/game/game_0b0420.h index f05883738..c6e155e52 100644 --- a/src/include/game/game_0b0420.h +++ b/src/include/game/game_0b0420.h @@ -24,7 +24,7 @@ struct weaponfunc *handGetWeaponFunction(struct hand *hand); struct weaponfunc *weaponGetFunction(u8 *arg0, s32 which); struct weaponfunc *currentPlayerGetWeaponFunction(u32 hand); u32 func0f0b11bc(void); -u32 func0f0b11ec(void); +struct inventory_ammo *weaponGetAmmoByFunction(u32 weaponnum, u32 funcnum); f32 func0f0b12ec(u32 arg0); u32 func0f0b131c(void); f32 func0f0b14d8(void); diff --git a/src/include/types.h b/src/include/types.h index a2132609d..fb33e4dd9 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -2599,7 +2599,7 @@ struct weaponfunc { /*0x00*/ u32 type; /*0x04*/ u16 name; /*0x06*/ u8 unk06; - /*0x07*/ s8 unk07; + /*0x07*/ s8 ammoindex; // -1 = no ammo, 0 or 1 = index into weapon->ammos[] /*0x08*/ struct inventory_menupos *menupos; /*0x0c*/ u32 *fire_animation; /*0x10*/ u32 flags;