From 91d1e5970d787eab37884ce578b73f45992ef5de Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sat, 10 Aug 2024 17:07:03 -0400 Subject: [PATCH] Fix an issue with a stray Rando::Context shared_ptr hanging around. (#4259) * Fix an issue with a stray Rando::Context shared_ptr hanging around. * Fixes accidental leftover from when I found this bug on another branch * Properly reset randoContext on every save load, not just after save creation --- soh/soh/Enhancements/randomizer/3drando/location_access.cpp | 4 ++-- soh/soh/Enhancements/randomizer/3drando/location_access.hpp | 2 +- soh/soh/Enhancements/randomizer/entrance.cpp | 5 +++++ soh/soh/Enhancements/randomizer/entrance.h | 1 + soh/soh/SaveManager.cpp | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/3drando/location_access.cpp b/soh/soh/Enhancements/randomizer/3drando/location_access.cpp index b181a3cdb..a64ef5f55 100644 --- a/soh/soh/Enhancements/randomizer/3drando/location_access.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/location_access.cpp @@ -240,12 +240,12 @@ bool HasAccessTo(const RandomizerRegion area) { return areaTable[area].HasAccess(); } -std::shared_ptr randoCtx; +Rando::Context* randoCtx; std::shared_ptr logic; void AreaTable_Init() { using namespace Rando; - randoCtx = Context::GetInstance(); + randoCtx = Context::GetInstance().get(); logic = randoCtx->GetLogic(); grottoEvents = { EventAccess(&logic->GossipStoneFairy, { [] { return logic->GossipStoneFairy || logic->CanSummonGossipFairy; } }), diff --git a/soh/soh/Enhancements/randomizer/3drando/location_access.hpp b/soh/soh/Enhancements/randomizer/3drando/location_access.hpp index 1492e82ec..286551cab 100644 --- a/soh/soh/Enhancements/randomizer/3drando/location_access.hpp +++ b/soh/soh/Enhancements/randomizer/3drando/location_access.hpp @@ -12,7 +12,7 @@ typedef bool (*ConditionFn)(); // I hate this but every alternative I can think of right now is worse -extern std::shared_ptr randoCtx; +extern Rando::Context* randoCtx; extern std::shared_ptr logic; class EventAccess { diff --git a/soh/soh/Enhancements/randomizer/entrance.cpp b/soh/soh/Enhancements/randomizer/entrance.cpp index 16fbdfd3b..39eab1398 100644 --- a/soh/soh/Enhancements/randomizer/entrance.cpp +++ b/soh/soh/Enhancements/randomizer/entrance.cpp @@ -235,6 +235,11 @@ Entrance* Entrance::AssumeReachable() { return assumed; } +EntranceShuffler::EntranceShuffler() { + playthroughEntrances = {}; + entranceOverrides = {}; +} + bool EntranceShuffler::HasNoRandomEntrances() { return mNoRandomEntrances; } diff --git a/soh/soh/Enhancements/randomizer/entrance.h b/soh/soh/Enhancements/randomizer/entrance.h index e17687842..08861ff0d 100644 --- a/soh/soh/Enhancements/randomizer/entrance.h +++ b/soh/soh/Enhancements/randomizer/entrance.h @@ -115,6 +115,7 @@ using EntrancePools = std::map>; class EntranceShuffler { public: + EntranceShuffler(); std::array entranceOverrides; std::vector> playthroughEntrances; bool HasNoRandomEntrances(); diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 00cd3115e..448a8d2e0 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -2841,7 +2841,7 @@ extern "C" void Save_SaveGlobal(void) { } extern "C" void Save_LoadFile(void) { - if (gSaveContext.questId == QUEST_RANDOMIZER) { + if (SaveManager::Instance->fileMetaInfo[gSaveContext.fileNum].randoSave) { // Reset rando context for rando saves. OTRGlobals::Instance->gRandoContext.reset(); OTRGlobals::Instance->gRandoContext = Rando::Context::CreateInstance();