From cc211637651804f6ce4aeacfb9919185dab8dcec Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 27 Dec 2025 05:09:43 -0600 Subject: [PATCH] Fix rupee overflow in StartingItemGive (#6039) --- soh/soh/Enhancements/randomizer/savefile.cpp | 48 ++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/savefile.cpp b/soh/soh/Enhancements/randomizer/savefile.cpp index 5e52d48ef..c8c3ea431 100644 --- a/soh/soh/Enhancements/randomizer/savefile.cpp +++ b/soh/soh/Enhancements/randomizer/savefile.cpp @@ -14,24 +14,6 @@ uint8_t Randomizer_GetSettingValue(RandomizerSettingKey randoSettingKey); GetItemEntry Randomizer_GetItemFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); } -void StartingItemGive(GetItemEntry getItemEntry, RandomizerCheck randomizerCheck) { - if (randomizerCheck != RC_MAX) { - OTRGlobals::Instance->gRandoContext->GetItemLocation(randomizerCheck)->SetCheckStatus(RCSHOW_SAVED); - } - if (getItemEntry.modIndex == MOD_NONE) { - if (getItemEntry.getItemId == GI_SWORD_BGS) { - gSaveContext.bgsFlag = true; - } - Item_Give(NULL, static_cast(getItemEntry.itemId)); - } else if (getItemEntry.modIndex == MOD_RANDOMIZER) { - if (getItemEntry.getItemId == RG_ICE_TRAP) { - gSaveContext.ship.pendingIceTrapCount++; - } else { - Randomizer_Item_Give(NULL, getItemEntry); - } - } -} - // RANDOTODO: Replace most of these GiveLink functions with calls to // Item_Give in z_parameter, we'll need to update Item_Give to ensure // nothing breaks when calling it without a valid play first. @@ -55,6 +37,36 @@ void GiveLinkRupees(int numOfRupees) { } } +static uint16_t rupeeCounts[] = { + 1, // ITEM_RUPEE_GREEN + 5, // ITEM_RUPEE_BLUE + 20, // ITEM_RUPEE_RED + 50, // ITEM_RUPEE_PURPLE + 200, // ITEM_RUPEE_GOLD +}; + +void StartingItemGive(GetItemEntry getItemEntry, RandomizerCheck randomizerCheck) { + if (randomizerCheck != RC_MAX) { + OTRGlobals::Instance->gRandoContext->GetItemLocation(randomizerCheck)->SetCheckStatus(RCSHOW_SAVED); + } + if (getItemEntry.modIndex == MOD_NONE) { + if (getItemEntry.itemId >= ITEM_RUPEE_GREEN && getItemEntry.itemId <= ITEM_RUPEE_GOLD) { + GiveLinkRupees(rupeeCounts[getItemEntry.itemId - ITEM_RUPEE_GREEN]); + } else { + if (getItemEntry.getItemId == GI_SWORD_BGS) { + gSaveContext.bgsFlag = true; + } + Item_Give(NULL, static_cast(getItemEntry.itemId)); + } + } else if (getItemEntry.modIndex == MOD_RANDOMIZER) { + if (getItemEntry.getItemId == RG_ICE_TRAP) { + gSaveContext.ship.pendingIceTrapCount++; + } else { + Randomizer_Item_Give(NULL, getItemEntry); + } + } +} + void GiveLinkDekuSticks(int howManySticks) { int maxStickCount = 0; if (CUR_UPG_VALUE(UPG_STICKS) == 0) {