From 82fff58062e8694d583e45816b4422d80eebcc44 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sat, 12 Jul 2025 10:05:07 -0700 Subject: [PATCH] item: introduce Item_GetAction When creating custom items, let's not immediately crash if trying to lookup an unknown item action for a new id Signed-off-by: William Casarin --- soh/include/functions.h | 1 + soh/src/overlays/actors/ovl_player_actor/z_player.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/soh/include/functions.h b/soh/include/functions.h index b322b5095..07604cef7 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -1239,6 +1239,7 @@ void Sample_Destroy(GameState* thisx); void Sample_Init(GameState* thisx); void Inventory_ChangeEquipment(s16 equipment, u16 value); void *Item_GetIcon(s16 item); +s32 Item_GetAction(s16 item); u8 Inventory_DeleteEquipment(PlayState* play, s16 equipment); void Inventory_ChangeUpgrade(s16 upgrade, s16 value); void Object_InitBank(PlayState* play, ObjectContext* objectCtx); 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 205079576..5c384b735 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -2253,7 +2253,7 @@ s8 Player_ItemToItemAction(s32 item) { } else if (item == ITEM_FISHING_POLE) { return PLAYER_IA_FISHING_POLE; } else { - return sItemActions[item]; + return Item_GetAction(item); } } @@ -10657,9 +10657,18 @@ void Player_StartMode_BlueWarp(PlayState* play, Player* this) { static u8 D_808546F0[] = { ITEM_SWORD_MASTER, ITEM_SWORD_KOKIRI }; +// Helper so that we don't buffer overrun item actions with custom items +s32 Item_GetAction(s16 item) { + if (item > ARRAY_COUNT(sItemActions)-1) { + return PLAYER_IA_POCKET_EGG; + } + + return sItemActions[item]; +} + void func_80846720(PlayState* play, Player* this, s32 arg2) { s32 item = D_808546F0[(void)0, gSaveContext.linkAge]; - s32 itemAction = sItemActions[item]; + s32 itemAction = Item_GetAction(item); Player_DestroyHookshot(this); Player_DetachHeldActor(play, this);