From 5fa623cea3f58aa678554e4525965ed314168a8d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 5 Feb 2020 17:34:12 +1000 Subject: [PATCH] Decompile currentPlayerGiveProp --- src/files/setup/setupear.c | 11 +++++ src/game/game_066310.c | 2 +- src/game/game_111600.c | 75 ++++++++++++++-------------------- src/include/constants.h | 4 ++ src/include/game/game_111600.h | 4 +- src/include/types.h | 5 +++ 6 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/files/setup/setupear.c b/src/files/setup/setupear.c index 7f8ad1ba8..c1018e2ef 100644 --- a/src/files/setup/setupear.c +++ b/src/files/setup/setupear.c @@ -554,9 +554,20 @@ u8 props[] = { stdobject(0x00e6, MODEL_A51_CRATE2, 0x0267, 0x000201e1, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000003e8, 0x00000000, 0x00000000, 0x0fff0000) stdobject(0x0100, MODEL_A51_CRATE2, 0x0268, 0x000201e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000003e8, 0x00000000, 0x00000000, 0x0fff0000) stdobject(0x0033, MODEL_QUADPOD, 0x013d, 0x000005e1, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000003e8, 0x00000000, 0x00000000, 0x0fff0000) + + /** + * @bug: This should be using MODEL_CHRNIGHTSIGHT. + * + * When picking up night vision the game checks if the perfect darkness + * cheat is enabled and skips adding the night vision to your inventory as + * it would already be there. But because this uses IR specs instead, the + * check doesn't match and a duplicate night vision is added to the + * inventory. + */ tag(0x05, 1) stdobject(0x0100, MODEL_MISC_IRSPECS, 0x013d, 0x014605e1, 0x00004001, 0x00400000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000003e8, 0x00000000, 0x00000000, 0x0fff0000) rename_object(-1, 0x2d, 0x1e2d, 0x1e2e, 0x1e2f, 0x1e30, 0x1e31, 0x0000, 0x0000) // "Obtain Night Vision." + tag(0x06, 1) stdobject(0x0100, MODEL_CHRSHIELD, 0x0243, 0x01460501, 0x00004001, 0x00400000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000003e8, 0x00000000, 0x00000000, 0x0fff0000) rename_object(-1, 0x4f, 0x1e32, 0x1e33, 0x1e34, 0x1e35, 0x1e36, 0x0000, 0x0000) // "Obtain shield tech item." diff --git a/src/game/game_066310.c b/src/game/game_066310.c index 76d128672..7114441d4 100644 --- a/src/game/game_066310.c +++ b/src/game/game_066310.c @@ -40352,7 +40352,7 @@ glabel func0f088840 /* f088fe4: 8fb80094 */ lw $t8,0x94($sp) /* f088fe8: 17000003 */ bnez $t8,.L0f088ff8 /* f088fec: 00000000 */ sll $zero,$zero,0x0 -/* f088ff0: 0fc447f3 */ jal func0f111fcc +/* f088ff0: 0fc447f3 */ jal currentPlayerGiveProp /* f088ff4: 8fa400a0 */ lw $a0,0xa0($sp) .L0f088ff8: /* f088ff8: 10000002 */ beqz $zero,.L0f089004 diff --git a/src/game/game_111600.c b/src/game/game_111600.c index e777ff4ca..bac25da10 100644 --- a/src/game/game_111600.c +++ b/src/game/game_111600.c @@ -257,7 +257,7 @@ glabel func0f1118cc ); GLOBAL_ASM( -glabel func0f111928 +glabel currentPlayerCreateInvitem /* f111928: 3c03800a */ lui $v1,0x800a /* f11192c: 8c63a244 */ lw $v1,-0x5dbc($v1) /* f111930: 00001025 */ or $v0,$zero,$zero @@ -555,10 +555,10 @@ bool currentPlayerGiveWeapon(s32 weaponnum) return false; } - item = func0f111928(); + item = currentPlayerCreateInvitem(); if (item) { - item->type = 1; + item->type = INVITEMTYPE_1; item->type1.weapon1 = weaponnum; item->type1.weapon2 = -1; func0f11179c(item); @@ -574,10 +574,10 @@ bool currentPlayerGiveWeaponWithArgument(s32 weapon1, s32 weapon2) { if (func0f111ab0(weapon1, weapon2) == 0) { if (weaponHasFlag(weapon1, WEAPONFLAG_00001000)) { - struct invitem *item = func0f111928(); + struct invitem *item = currentPlayerCreateInvitem(); if (item) { - item->type = 3; + item->type = INVITEMTYPE_3; item->type3.weapon1 = weapon1; item->type3.weapon2 = weapon2; func0f11179c(item); @@ -680,46 +680,31 @@ glabel func0f111ea4 /* f111fc8: 27bd0030 */ addiu $sp,$sp,0x30 ); -GLOBAL_ASM( -glabel func0f111fcc -/* f111fcc: 27bdffe8 */ addiu $sp,$sp,-24 -/* f111fd0: afbf0014 */ sw $ra,0x14($sp) -/* f111fd4: afa40018 */ sw $a0,0x18($sp) -/* f111fd8: 0fc41b99 */ jal cheatIsActive -/* f111fdc: 24040015 */ addiu $a0,$zero,0x15 -/* f111fe0: 1040000e */ beqz $v0,.L0f11201c -/* f111fe4: 8fa30018 */ lw $v1,0x18($sp) -/* f111fe8: 906e0000 */ lbu $t6,0x0($v1) -/* f111fec: 24010001 */ addiu $at,$zero,0x1 -/* f111ff0: 15c1000a */ bne $t6,$at,.L0f11201c -/* f111ff4: 00000000 */ sll $zero,$zero,0x0 -/* f111ff8: 8c620004 */ lw $v0,0x4($v1) -/* f111ffc: 10400007 */ beqz $v0,.L0f11201c -/* f112000: 00000000 */ sll $zero,$zero,0x0 -/* f112004: 844f0004 */ lh $t7,0x4($v0) -/* f112008: 240100f3 */ addiu $at,$zero,0xf3 -/* f11200c: 15e10003 */ bne $t7,$at,.L0f11201c -/* f112010: 00000000 */ sll $zero,$zero,0x0 -/* f112014: 1000000b */ beqz $zero,.L0f112044 -/* f112018: 24020001 */ addiu $v0,$zero,0x1 -.L0f11201c: -/* f11201c: 0fc4464a */ jal func0f111928 -/* f112020: 00000000 */ sll $zero,$zero,0x0 -/* f112024: 8fa30018 */ lw $v1,0x18($sp) -/* f112028: 10400005 */ beqz $v0,.L0f112040 -/* f11202c: 00402025 */ or $a0,$v0,$zero -/* f112030: 24180002 */ addiu $t8,$zero,0x2 -/* f112034: ac580000 */ sw $t8,0x0($v0) -/* f112038: 0fc445e7 */ jal func0f11179c -/* f11203c: ac430004 */ sw $v1,0x4($v0) -.L0f112040: -/* f112040: 24020001 */ addiu $v0,$zero,0x1 -.L0f112044: -/* f112044: 8fbf0014 */ lw $ra,0x14($sp) -/* f112048: 27bd0018 */ addiu $sp,$sp,0x18 -/* f11204c: 03e00008 */ jr $ra -/* f112050: 00000000 */ sll $zero,$zero,0x0 -); +bool currentPlayerGiveProp(struct prop *prop) +{ + struct invitem *item; + + // Don't add duplicate night vision to inventory + // (night vision is already there when using perfect darkness) + // Note that this check doesn't work on Investigation because it uses the + // IR specs model. See bug note in Investigation's setup file (setupear.c). + if (cheatIsActive(CHEAT_PERFECTDARKNESS) + && prop->type == PROPTYPE_OBJ + && prop->obj + && prop->obj->obj == MODEL_CHRNIGHTSIGHT) { + return true; + } + + item = currentPlayerCreateInvitem(); + + if (item) { + item->type = INVITEMTYPE_PROP; + item->type_prop.prop = prop; + func0f11179c(item); + } + + return true; +} GLOBAL_ASM( glabel func0f112054 diff --git a/src/include/constants.h b/src/include/constants.h index 1cc931352..d503619f9 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -517,6 +517,10 @@ #define INVENTORYFUNCTYPE_SPECIAL 0x0004 #define INVENTORYFUNCTYPE_VISUAL 0x0005 +#define INVITEMTYPE_1 1 +#define INVITEMTYPE_PROP 2 +#define INVITEMTYPE_3 3 + // These actions are assigned to chr->myaction #define MA_NONE 0 #define MA_NORMAL 1 diff --git a/src/include/game/game_111600.h b/src/include/game/game_111600.h index de9e7ebc1..c20ac4319 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 *func0f111928(void); +struct invitem *currentPlayerCreateInvitem(void); void currentPlayerSetAllGuns(bool enable); u32 func0f1119d0(void); bool func0f111a28(s32 weaponnum); @@ -22,7 +22,7 @@ bool func0f111cf8(s32 weapon1, s32 weapon2); bool currentPlayerGiveWeapon(s32 weaponnum); bool currentPlayerGiveWeaponWithArgument(s32 weapon1, s32 weapon2); void func0f111ea4(u32 arg0); -u32 func0f111fcc(void); +bool currentPlayerGiveProp(struct prop *prop); u32 func0f112054(void); u32 func0f1120f0(void); u32 func0f1122ec(void); diff --git a/src/include/types.h b/src/include/types.h index 33288bf7c..2d1ed6dcb 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5072,6 +5072,10 @@ struct invitem_type1 { s16 weapon2; }; +struct invitem_typeprop { + struct prop *prop; +}; + struct invitem_type3 { s32 weapon1; s32 weapon2; @@ -5082,6 +5086,7 @@ struct invitem { union { struct invitem_type1 type1; + struct invitem_typeprop type_prop; struct invitem_type3 type3; }; };