Fix Crash if something costs 0 in shop (#6106)

This commit is contained in:
DizzyEggg 2025-01-25 17:38:19 +01:00 committed by GitHub
parent 856553daf4
commit df50320ca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1066,7 +1066,11 @@ static void Task_BuyHowManyDialogueInit(u8 taskId)
BuyMenuPrintItemQuantityAndPrice(taskId);
ScheduleBgCopyTilemapToVram(0);
maxQuantity = GetMoney(&gSaveBlock1Ptr->money) / sShopData->totalCost;
// Avoid division by zero in-case something costs 0 pokedollars.
if (sShopData->totalCost == 0)
maxQuantity = MAX_BAG_ITEM_CAPACITY;
else
maxQuantity = GetMoney(&gSaveBlock1Ptr->money) / sShopData->totalCost;
if (maxQuantity > MAX_BAG_ITEM_CAPACITY)
sShopData->maxQuantity = MAX_BAG_ITEM_CAPACITY;