From dd5e72a02300539676b80f9fa07114c97734aacb Mon Sep 17 00:00:00 2001 From: Adam Bird Date: Wed, 29 Nov 2023 00:29:25 -0500 Subject: [PATCH] limit entrance discovered saving to end of operation (#3459) --- .../randomizer/randomizer_entrance.c | 28 +++++++++++-------- .../randomizer/randomizer_entrance.h | 2 +- .../randomizer/randomizer_grotto.c | 4 +-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_entrance.c b/soh/soh/Enhancements/randomizer/randomizer_entrance.c index f2f1a8a3f..e6ec3fef3 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_entrance.c +++ b/soh/soh/Enhancements/randomizer/randomizer_entrance.c @@ -76,7 +76,7 @@ static s16 newIceCavernEntrance = ICE_CAVERN_ENTRANCE; static s8 hasCopiedEntranceTable = 0; static s8 hasModifiedEntranceTable = 0; -void Entrance_SetEntranceDiscovered(u16 entranceIndex); +void Entrance_SetEntranceDiscovered(u16 entranceIndex, u8 isReversedEntrance); u8 Entrance_EntranceIsNull(EntranceOverride* entranceOverride) { return entranceOverride->index == 0 && entranceOverride->destination == 0 && entranceOverride->blueWarp == 0 @@ -276,13 +276,13 @@ s16 Entrance_OverrideNextIndex(s16 nextEntranceIndex) { return nextEntranceIndex; } - Entrance_SetEntranceDiscovered(nextEntranceIndex); + Entrance_SetEntranceDiscovered(nextEntranceIndex, false); EntranceTracker_SetLastEntranceOverride(nextEntranceIndex); return Grotto_OverrideSpecialEntrance(Entrance_GetOverride(nextEntranceIndex)); } s16 Entrance_OverrideDynamicExit(s16 dynamicExitIndex) { - Entrance_SetEntranceDiscovered(dynamicExitList[dynamicExitIndex]); + Entrance_SetEntranceDiscovered(dynamicExitList[dynamicExitIndex], false); EntranceTracker_SetLastEntranceOverride(dynamicExitList[dynamicExitIndex]); return Grotto_OverrideSpecialEntrance(Entrance_GetOverride(dynamicExitList[dynamicExitIndex])); } @@ -784,7 +784,7 @@ u8 Entrance_GetIsEntranceDiscovered(u16 entranceIndex) { return 0; } -void Entrance_SetEntranceDiscovered(u16 entranceIndex) { +void Entrance_SetEntranceDiscovered(u16 entranceIndex, u8 isReversedEntrance) { // Skip if already set to save time from setting the connected entrance or // if this entrance is outside of the randomized entrance range (i.e. is a dynamic entrance) if (entranceIndex > MAX_ENTRANCE_RANDO_USED_INDEX || Entrance_GetIsEntranceDiscovered(entranceIndex)) { @@ -796,14 +796,20 @@ void Entrance_SetEntranceDiscovered(u16 entranceIndex) { if (idx < SAVEFILE_ENTRANCES_DISCOVERED_IDX_COUNT) { u32 entranceBit = 1 << (entranceIndex - (idx * bitsPerIndex)); gSaveContext.sohStats.entrancesDiscovered[idx] |= entranceBit; - // Set connected - for (size_t i = 0; i < ENTRANCE_OVERRIDES_MAX_COUNT; i++) { - if (entranceIndex == gSaveContext.entranceOverrides[i].index) { - Entrance_SetEntranceDiscovered(gSaveContext.entranceOverrides[i].overrideDestination); - break; + + // Set reverse entrance when not decoupled + if (!Randomizer_GetSettingValue(RSK_DECOUPLED_ENTRANCES) && !isReversedEntrance) { + for (size_t i = 0; i < ENTRANCE_OVERRIDES_MAX_COUNT; i++) { + if (entranceIndex == gSaveContext.entranceOverrides[i].index) { + Entrance_SetEntranceDiscovered(gSaveContext.entranceOverrides[i].overrideDestination, true); + break; + } } } } - // Save entrancesDiscovered - Save_SaveSection(SECTION_ID_ENTRANCES); + + // Save entrancesDiscovered when it is not the reversed entrance + if (!isReversedEntrance) { + Save_SaveSection(SECTION_ID_ENTRANCES); + } } diff --git a/soh/soh/Enhancements/randomizer/randomizer_entrance.h b/soh/soh/Enhancements/randomizer/randomizer_entrance.h index c00f29701..c71b2493a 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_entrance.h +++ b/soh/soh/Enhancements/randomizer/randomizer_entrance.h @@ -63,7 +63,7 @@ void Entrance_OverrideSpawnScene(int32_t sceneNum, int32_t spawn); int32_t Entrance_OverrideSpawnSceneRoom(int32_t sceneNum, int32_t spawn, int32_t room); void Entrance_EnableFW(void); uint8_t Entrance_GetIsEntranceDiscovered(uint16_t entranceIndex); -void Entrance_SetEntranceDiscovered(uint16_t entranceIndex); +void Entrance_SetEntranceDiscovered(uint16_t entranceIndex, uint8_t isReversedEntrance); #ifdef __cplusplus } #endif diff --git a/soh/soh/Enhancements/randomizer/randomizer_grotto.c b/soh/soh/Enhancements/randomizer/randomizer_grotto.c index 408dc0160..78e429fb2 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_grotto.c +++ b/soh/soh/Enhancements/randomizer/randomizer_grotto.c @@ -140,7 +140,7 @@ s16 Grotto_OverrideSpecialEntrance(s16 nextEntranceIndex) { // If Link hits a grotto exit, load the entrance index from the grotto exit list // based on the current grotto ID if (nextEntranceIndex == 0x7FFF) { - Entrance_SetEntranceDiscovered(ENTRANCE_RANDO_GROTTO_EXIT_START + grottoId); + Entrance_SetEntranceDiscovered(ENTRANCE_RANDO_GROTTO_EXIT_START + grottoId, false); EntranceTracker_SetLastEntranceOverride(ENTRANCE_RANDO_GROTTO_EXIT_START + grottoId); nextEntranceIndex = grottoExitList[grottoId]; } @@ -211,7 +211,7 @@ void Grotto_OverrideActorEntrance(Actor* thisx) { if (grottoContent == grottoLoadTable[index].content && gPlayState->sceneNum == grottoLoadTable[index].scene) { // Find the override for the matching index from the grotto Load List - Entrance_SetEntranceDiscovered(ENTRANCE_RANDO_GROTTO_LOAD_START + index); + Entrance_SetEntranceDiscovered(ENTRANCE_RANDO_GROTTO_LOAD_START + index, false); EntranceTracker_SetLastEntranceOverride(ENTRANCE_RANDO_GROTTO_LOAD_START + index); index = grottoLoadList[index];