From 7cf62e4caaedd9526d2a7c18d4b92a6b4f3d094a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 29 Mar 2020 12:08:28 +1000 Subject: [PATCH] Decompile currentPlayerGetAmmoQuantityForWeapon --- src/game/game_097ba0.c | 42 ++++++++++++---------------------- src/game/propobj.c | 11 +++++---- src/include/constants.h | 4 ++++ src/include/game/game_097ba0.h | 2 +- src/include/types.h | 2 +- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/game/game_097ba0.c b/src/game/game_097ba0.c index 209765f7e..07a4222e6 100644 --- a/src/game/game_097ba0.c +++ b/src/game/game_097ba0.c @@ -12169,7 +12169,7 @@ glabel func0f0a1a10 /* f0a1a30: 00002825 */ or $a1,$zero,$zero /* f0a1a34: 10400005 */ beqz $v0,.L0f0a1a4c /* f0a1a38: 8fa40018 */ lw $a0,0x18($sp) -/* f0a1a3c: 0fc2a69d */ jal func0f0a9a74 +/* f0a1a3c: 0fc2a69d */ jal currentPlayerGetAmmoQuantityForWeapon /* f0a1a40: 00002825 */ or $a1,$zero,$zero /* f0a1a44: 58400004 */ blezl $v0,.L0f0a1a58 /* f0a1a48: 00001025 */ or $v0,$zero,$zero @@ -21774,32 +21774,20 @@ glabel weaponGetAmmoType /* f0a9a70: 00000000 */ sll $zero,$zero,0x0 ); -GLOBAL_ASM( -glabel func0f0a9a74 -/* f0a9a74: 27bdffe8 */ addiu $sp,$sp,-24 -/* f0a9a78: afbf0014 */ sw $ra,0x14($sp) -/* f0a9a7c: 0fc2c3f4 */ jal weaponFindById -/* f0a9a80: afa5001c */ sw $a1,0x1c($sp) -/* f0a9a84: 1040000a */ beqz $v0,.L0f0a9ab0 -/* f0a9a88: 8fae001c */ lw $t6,0x1c($sp) -/* f0a9a8c: 000e7880 */ sll $t7,$t6,0x2 -/* f0a9a90: 004fc021 */ addu $t8,$v0,$t7 -/* f0a9a94: 8f03001c */ lw $v1,0x1c($t8) -/* f0a9a98: 50600006 */ beqzl $v1,.L0f0a9ab4 -/* f0a9a9c: 00001025 */ or $v0,$zero,$zero -/* f0a9aa0: 0fc2a5dc */ jal ammoGetQuantity -/* f0a9aa4: 8c640000 */ lw $a0,0x0($v1) -/* f0a9aa8: 10000003 */ beqz $zero,.L0f0a9ab8 -/* f0a9aac: 8fbf0014 */ lw $ra,0x14($sp) -.L0f0a9ab0: -/* f0a9ab0: 00001025 */ or $v0,$zero,$zero -.L0f0a9ab4: -/* f0a9ab4: 8fbf0014 */ lw $ra,0x14($sp) -.L0f0a9ab8: -/* f0a9ab8: 27bd0018 */ addiu $sp,$sp,0x18 -/* f0a9abc: 03e00008 */ jr $ra -/* f0a9ac0: 00000000 */ sll $zero,$zero,0x0 -); +u32 currentPlayerGetAmmoQuantityForWeapon(u32 weaponnum, u32 func) +{ + struct weapon *weapon = weaponFindById(weaponnum); + + if (weapon) { + struct inventory_ammo *ammo = weapon->ammos[func]; + + if (ammo) { + return ammoGetQuantity(ammo->type); + } + } + + return 0; +} void currentPlayerGiveAmmoForWeapon(u32 weaponnum, u32 func, u32 quantity) { diff --git a/src/game/propobj.c b/src/game/propobj.c index 70b3832cb..5ccba50b9 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -38014,8 +38014,9 @@ bool propobjInteract(struct prop *prop) func0f0887c8(WEAPON_LAPTOPGUN, 0); func0f087d10(WEAPON_LAPTOPGUN); - if (laptop->unka9 > 0 && laptop->unka9 != 255) { - currentPlayerGiveAmmoForWeapon(WEAPON_LAPTOPGUN, 0, func0f0a9a74(WEAPON_LAPTOPGUN, 0) + laptop->unka9); + if (laptop->ammoquantity > 0 && laptop->ammoquantity != 255) { + s32 newqty = currentPlayerGetAmmoQuantityForWeapon(WEAPON_LAPTOPGUN, FUNC_PRIMARY) + laptop->ammoquantity; + currentPlayerGiveAmmoForWeapon(WEAPON_LAPTOPGUN, FUNC_PRIMARY, newqty); } } } else { @@ -40205,7 +40206,7 @@ glabel var7f1aae84 .L0f089290: /* f089290: 90e4005c */ lbu $a0,0x5c($a3) /* f089294: afa70080 */ sw $a3,0x80($sp) -/* f089298: 0fc2a69d */ jal func0f0a9a74 +/* f089298: 0fc2a69d */ jal currentPlayerGetAmmoQuantityForWeapon /* f08929c: 00002825 */ or $a1,$zero,$zero /* f0892a0: 8fa70080 */ lw $a3,0x80($sp) /* f0892a4: 00002825 */ or $a1,$zero,$zero @@ -40222,7 +40223,7 @@ glabel var7f1aae84 /* f0892cc: 24050001 */ addiu $a1,$zero,0x1 /* f0892d0: 1481000e */ bne $a0,$at,.L0f08930c /* f0892d4: 00000000 */ sll $zero,$zero,0x0 -/* f0892d8: 0fc2a69d */ jal func0f0a9a74 +/* f0892d8: 0fc2a69d */ jal currentPlayerGetAmmoQuantityForWeapon /* f0892dc: afa70080 */ sw $a3,0x80($sp) /* f0892e0: 8fa70080 */ lw $a3,0x80($sp) /* f0892e4: 24050001 */ addiu $a1,$zero,0x1 @@ -42732,7 +42733,7 @@ glabel var7f1aae98 /* f08b500: 0fc4a24b */ jal setCurrentPlayerNum /* f08b504: 00402025 */ or $a0,$v0,$zero /* f08b508: 2404000e */ addiu $a0,$zero,0xe -/* f08b50c: 0fc2a69d */ jal func0f0a9a74 +/* f08b50c: 0fc2a69d */ jal currentPlayerGetAmmoQuantityForWeapon /* f08b510: 00002825 */ or $a1,$zero,$zero /* f08b514: 284100c8 */ slti $at,$v0,0xc8 /* f08b518: 14200004 */ bnez $at,.L0f08b52c diff --git a/src/include/constants.h b/src/include/constants.h index 475e20c40..9fd875352 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -519,6 +519,10 @@ #define FLOORFLAG_0100 0x0100 #define FLOORFLAG_4000 0x4000 +// Weapon functions +#define FUNC_PRIMARY 0 +#define FUNC_SECONDARY 1 + #define GAILIST_IDLE 0x0000 #define GAILIST_UNALERTED_0001 0x0001 #define GAILIST_UNALERTED_0002 0x0002 diff --git a/src/include/game/game_097ba0.h b/src/include/game/game_097ba0.h index bf9fb0cac..a520c9915 100644 --- a/src/include/game/game_097ba0.h +++ b/src/include/game/game_097ba0.h @@ -158,7 +158,7 @@ s32 ammotypeGetMaxCapacity(u32 ammotype); bool ammotypeAllowsUnlimitedAmmo(u32 ammotype); u32 func0f0a9980(void); s32 weaponGetAmmoType(s32 weaponnum, u32 func); -s32 func0f0a9a74(s32 weaponnum, s32 arg1); +u32 currentPlayerGetAmmoQuantityForWeapon(u32 weaponnum, u32 func); void currentPlayerGiveAmmoForWeapon(u32 weaponnum, u32 func, u32 quantity); u32 func0f0a9b10(void); u32 func0f0a9b68(void); diff --git a/src/include/types.h b/src/include/types.h index 9c701de72..130ddc5d3 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -958,7 +958,7 @@ struct autogunobj { // objtype 0d /*0xa0*/ u32 unka0; /*0xa4*/ u32 unka4; /*0xa8*/ u8 autogun_type; - /*0xa9*/ u8 unka9; + /*0xa9*/ u8 ammoquantity; }; struct multiammocrateobj { // objtype 14