From 1699eea009cbc721a83e947e7813d54bf20bb8dd Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Tue, 2 Jan 2024 06:29:47 +0100 Subject: [PATCH] Remove special IAs (#3453) * Remove special IAs * Add clarifying comment --- soh/include/z64player.h | 10 -- soh/src/code/z_player_lib.c | 9 -- .../actors/ovl_player_actor/z_player.c | 107 ++++++------------ 3 files changed, 35 insertions(+), 91 deletions(-) diff --git a/soh/include/z64player.h b/soh/include/z64player.h index 73b5166e2..e5f4b826d 100644 --- a/soh/include/z64player.h +++ b/soh/include/z64player.h @@ -132,16 +132,6 @@ typedef enum { /* 0x40 */ PLAYER_IA_MASK_GERUDO, /* 0x41 */ PLAYER_IA_MASK_TRUTH, /* 0x42 */ PLAYER_IA_LENS_OF_TRUTH, - // Upstream TODO: Document why these entries were added - /* 0x43 */ PLAYER_IA_SHIELD_DEKU, - /* 0x44 */ PLAYER_IA_SHIELD_HYLIAN, - /* 0x45 */ PLAYER_IA_SHIELD_MIRROR, - /* 0x46 */ PLAYER_IA_TUNIC_KOKIRI, - /* 0x47 */ PLAYER_IA_TUNIC_GORON, - /* 0x48 */ PLAYER_IA_TUNIC_ZORA, - /* 0x49 */ PLAYER_IA_BOOTS_KOKIRI, - /* 0x4A */ PLAYER_IA_BOOTS_IRON, - /* 0x4B */ PLAYER_IA_BOOTS_HOVER, /* 0x4C */ PLAYER_IA_MAX } PlayerItemAction; diff --git a/soh/src/code/z_player_lib.c b/soh/src/code/z_player_lib.c index b9a66c90e..e20362fd3 100644 --- a/soh/src/code/z_player_lib.c +++ b/soh/src/code/z_player_lib.c @@ -101,15 +101,6 @@ u8 sActionModelGroups[] = { PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_GERUDO PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_TRUTH PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_LENS_OF_TRUTH - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_SHIELD_DEKU - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_SHIELD_HYLIAN - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_SHIELD_MIRROR - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_TUNIC_KOKIRI - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_TUNIC_GORON - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_TUNIC_ZORA - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_BOOTS_KOKIRI - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_BOOTS_IRON - PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_BOOTS_HOVER }; TextTriggerEntry sTextTriggers[] = { diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index f192fe1ce..82a600bee 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -1074,15 +1074,6 @@ static s8 sItemActions[] = { PLAYER_IA_SWORD_KOKIRI, // ITEM_SWORD_KOKIRI PLAYER_IA_SWORD_MASTER, // ITEM_SWORD_MASTER PLAYER_IA_SWORD_BIGGORON, // ITEM_SWORD_BIGGORON - PLAYER_IA_SHIELD_DEKU, // ITEM_SHIELD_DEKU - PLAYER_IA_SHIELD_HYLIAN, // ITEM_SHIELD_HYLIAN - PLAYER_IA_SHIELD_MIRROR, // ITEM_SHIELD_MIRROR - PLAYER_IA_TUNIC_KOKIRI, // ITEM_TUNIC_KOKIRI - PLAYER_IA_TUNIC_GORON, // ITEM_TUNIC_GORON - PLAYER_IA_TUNIC_ZORA, // ITEM_TUNIC_ZORA - PLAYER_IA_BOOTS_KOKIRI, // ITEM_BOOTS_KOKIRI - PLAYER_IA_BOOTS_IRON, // ITEM_BOOTS_IRON - PLAYER_IA_BOOTS_HOVER, // ITEM_BOOTS_HOVER }; static u8 sMaskMemory; @@ -1157,15 +1148,6 @@ static s32 (*sItemActionUpdateFuncs[])(Player* this, PlayState* play) = { func_8083485C, // PLAYER_IA_MASK_GERUDO func_8083485C, // PLAYER_IA_MASK_TRUTH func_8083485C, // PLAYER_IA_LENS_OF_TRUTH - func_8083485C, // PLAYER_IA_SHIELD_DEKU - func_8083485C, // PLAYER_IA_SHIELD_HYLIAN - func_8083485C, // PLAYER_IA_SHIELD_MIRROR - func_8083485C, // PLAYER_IA_TUNIC_KOKIRI - func_8083485C, // PLAYER_IA_TUNIC_GORON - func_8083485C, // PLAYER_IA_TUNIC_ZORA - func_8083485C, // PLAYER_IA_BOOTS_KOKIRI - func_8083485C, // PLAYER_IA_BOOTS_IRON - func_8083485C, // PLAYER_IA_BOOTS_HOVER }; static void (*sItemActionInitFuncs[])(PlayState* play, Player* this) = { @@ -1236,15 +1218,6 @@ static void (*sItemActionInitFuncs[])(PlayState* play, Player* this) = { func_80833770, // PLAYER_IA_MASK_GERUDO func_80833770, // PLAYER_IA_MASK_TRUTH func_80833770, // PLAYER_IA_LENS_OF_TRUTH - func_80833770, // PLAYER_IA_SHIELD_DEKU - func_80833770, // PLAYER_IA_SHIELD_HYLIAN - func_80833770, // PLAYER_IA_SHIELD_MIRROR - func_80833770, // PLAYER_IA_TUNIC_KOKIRI - func_80833770, // PLAYER_IA_TUNIC_GORON - func_80833770, // PLAYER_IA_TUNIC_ZORA - func_80833770, // PLAYER_IA_BOOTS_KOKIRI - func_80833770, // PLAYER_IA_BOOTS_IRON - func_80833770, // PLAYER_IA_BOOTS_HOVER }; typedef enum { @@ -2037,6 +2010,10 @@ s8 Player_ItemToItemAction(s32 item) { return PLAYER_IA_LAST_USED; } else if (item == ITEM_FISHING_POLE) { return PLAYER_IA_FISHING_POLE; + // #region SOH [Enhancement] Added to prevent crashes with assignable equipment + } else if (item >= ITEM_TUNIC_KOKIRI && item <= ITEM_BOOTS_HOVER) { + return PLAYER_IA_NONE; + // #endregion } else { return sItemActions[item]; } @@ -3167,8 +3144,7 @@ void Player_UseItem(PlayState* play, Player* this, s32 item) { if ((itemAction == PLAYER_IA_NONE) || !(this->stateFlags1 & PLAYER_STATE1_IN_WATER) || ((this->actor.bgCheckFlags & 1) && - ((itemAction == PLAYER_IA_HOOKSHOT) || (itemAction == PLAYER_IA_LONGSHOT))) || - ((itemAction >= PLAYER_IA_SHIELD_DEKU) && (itemAction <= PLAYER_IA_BOOTS_HOVER))) { + ((itemAction == PLAYER_IA_HOOKSHOT) || (itemAction == PLAYER_IA_LONGSHOT)))) { if ((play->bombchuBowlingStatus == 0) && (((itemAction == PLAYER_IA_DEKU_STICK) && (AMMO(ITEM_STICK) == 0)) || @@ -3180,12 +3156,6 @@ void Player_UseItem(PlayState* play, Player* this, s32 item) { return; } - if (itemAction >= PLAYER_IA_SHIELD_DEKU) { - // Changing shields through action commands is unimplemented - // Boots and tunics handled previously - return; - } - if (itemAction == PLAYER_IA_LENS_OF_TRUTH) { if (Magic_RequestChange(play, 0, MAGIC_CONSUME_LENS)) { if (play->actorCtx.lensActive) { @@ -11000,46 +10970,39 @@ static f32 D_8085482C[] = { 0.5f, 1.0f, 3.0f }; void Player_UseTunicBoots(Player* this, PlayState* play) { // Boots and tunics equip despite state - s32 i; - s32 item; - s32 itemAction; - if (!( - this->stateFlags1 & PLAYER_STATE1_INPUT_DISABLED || - this->stateFlags1 & PLAYER_STATE1_IN_ITEM_CS || - this->stateFlags1 & PLAYER_STATE1_IN_CUTSCENE || - this->stateFlags1 & PLAYER_STATE1_TEXT_ON_SCREEN || - this->stateFlags1 & PLAYER_STATE1_DEAD || + if ( + this->stateFlags1 & (PLAYER_STATE1_INPUT_DISABLED | PLAYER_STATE1_IN_ITEM_CS | PLAYER_STATE1_IN_CUTSCENE | PLAYER_STATE1_TEXT_ON_SCREEN | PLAYER_STATE1_DEAD) || this->stateFlags2 & PLAYER_STATE2_OCARINA_PLAYING - )) { - for (i = 0; i < ARRAY_COUNT(sItemButtons); i++) { - if (CHECK_BTN_ALL(sControlInput->press.button, sItemButtons[i])) { - break; - } + ) { + return; + } + + s32 i; + for (i = 0; i < ARRAY_COUNT(sItemButtons); i++) { + if (CHECK_BTN_ALL(sControlInput->press.button, sItemButtons[i])) { + break; } - item = Player_GetItemOnButton(play, i); - if (item >= ITEM_TUNIC_KOKIRI && item <= ITEM_BOOTS_HOVER) { - this->heldItemButton = i; - itemAction = Player_ItemToItemAction(item); - if (itemAction >= PLAYER_IA_BOOTS_KOKIRI) { - u16 bootsValue = itemAction - PLAYER_IA_BOOTS_KOKIRI + 1; - if (CUR_EQUIP_VALUE(EQUIP_TYPE_BOOTS) == bootsValue) { - Inventory_ChangeEquipment(EQUIP_TYPE_BOOTS, EQUIP_VALUE_BOOTS_KOKIRI); - } else { - Inventory_ChangeEquipment(EQUIP_TYPE_BOOTS, bootsValue); - } - Player_SetEquipmentData(play, this); - func_808328EC(this, CUR_EQUIP_VALUE(EQUIP_TYPE_BOOTS) == EQUIP_VALUE_BOOTS_IRON ? NA_SE_PL_WALK_HEAVYBOOTS - : NA_SE_PL_CHANGE_ARMS); - } else if (itemAction >= PLAYER_IA_TUNIC_KOKIRI) { - u16 tunicValue = itemAction - PLAYER_IA_TUNIC_KOKIRI + 1; - if (CUR_EQUIP_VALUE(EQUIP_TYPE_TUNIC) == tunicValue) { - Inventory_ChangeEquipment(EQUIP_TYPE_TUNIC, EQUIP_VALUE_TUNIC_KOKIRI); - } else { - Inventory_ChangeEquipment(EQUIP_TYPE_TUNIC, tunicValue); - } - Player_SetEquipmentData(play, this); - func_808328EC(this, NA_SE_PL_CHANGE_ARMS); + } + s32 item = Player_GetItemOnButton(play, i); + if (item >= ITEM_TUNIC_KOKIRI && item <= ITEM_BOOTS_HOVER) { + if (item >= ITEM_BOOTS_KOKIRI) { + u16 bootsValue = item - ITEM_BOOTS_KOKIRI + 1; + if (CUR_EQUIP_VALUE(EQUIP_TYPE_BOOTS) == bootsValue) { + Inventory_ChangeEquipment(EQUIP_TYPE_BOOTS, EQUIP_VALUE_BOOTS_KOKIRI); + } else { + Inventory_ChangeEquipment(EQUIP_TYPE_BOOTS, bootsValue); } + Player_SetEquipmentData(play, this); + func_808328EC(this, CUR_EQUIP_VALUE(EQUIP_TYPE_BOOTS) == EQUIP_VALUE_BOOTS_IRON ? NA_SE_PL_WALK_HEAVYBOOTS : NA_SE_PL_CHANGE_ARMS); + } else { + u16 tunicValue = item - ITEM_TUNIC_KOKIRI + 1; + if (CUR_EQUIP_VALUE(EQUIP_TYPE_TUNIC) == tunicValue) { + Inventory_ChangeEquipment(EQUIP_TYPE_TUNIC, EQUIP_VALUE_TUNIC_KOKIRI); + } else { + Inventory_ChangeEquipment(EQUIP_TYPE_TUNIC, tunicValue); + } + Player_SetEquipmentData(play, this); + func_808328EC(this, NA_SE_PL_CHANGE_ARMS); } } }