Prevent Key Items that open other menus from causing a crash if registered and used from the field (#5810)

This commit is contained in:
iriv24 2024-12-15 10:04:06 -05:00 committed by GitHub
parent beeca545aa
commit c7a2ef3371
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1399,11 +1399,19 @@ void ItemUseOutOfBattle_ZygardeCube(u8 taskId)
} }
void ItemUseOutOfBattle_Fusion(u8 taskId) void ItemUseOutOfBattle_Fusion(u8 taskId)
{
if (!gTasks[taskId].tUsingRegisteredKeyItem)
{ {
gItemUseCB = ItemUseCB_Fusion; gItemUseCB = ItemUseCB_Fusion;
gTasks[taskId].data[0] = FALSE; gTasks[taskId].data[0] = FALSE;
SetUpItemUseCallback(taskId); SetUpItemUseCallback(taskId);
} }
else
{
// TODO: handle key items with callbacks to menus allow to be used by registering them.
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
}
}
void Task_UseHoneyOnField(u8 taskId) void Task_UseHoneyOnField(u8 taskId)
{ {
@ -1551,11 +1559,19 @@ static void ItemUseOnFieldCB_TownMap(u8 taskId)
} }
void ItemUseOutOfBattle_TownMap(u8 taskId) void ItemUseOutOfBattle_TownMap(u8 taskId)
{
if (!gTasks[taskId].tUsingRegisteredKeyItem)
{ {
sItemUseOnFieldCB = ItemUseOnFieldCB_TownMap; sItemUseOnFieldCB = ItemUseOnFieldCB_TownMap;
gFieldCallback = FieldCB_UseItemOnField; gFieldCallback = FieldCB_UseItemOnField;
gBagMenu->newScreenCallback = CB2_ReturnToField; gBagMenu->newScreenCallback = CB2_ReturnToField;
Task_FadeAndCloseBagMenu(taskId); Task_FadeAndCloseBagMenu(taskId);
} }
else
{
// TODO: handle key items with callbacks to menus allow to be used by registering them.
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
}
}
#undef tUsingRegisteredKeyItem #undef tUsingRegisteredKeyItem