From 554379fd7068d93c77a7e0b2cd805468b94d3b1c Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sat, 29 Mar 2025 00:02:38 -0400 Subject: [PATCH] Fix some options not updating correctly when dropping jsons and applying Presets (#5240) * Re-Run ship init funcs on json drop and preset apply * Prevent registering rando locations from running more than once * Moves registered=true right after early return * Move ShipInit call into applyPreset --- soh/soh/Enhancements/Presets/Presets.cpp | 1 + soh/soh/Enhancements/randomizer/ShuffleCows.cpp | 3 +++ soh/soh/Enhancements/randomizer/ShuffleCrates.cpp | 3 +++ soh/soh/Enhancements/randomizer/ShuffleFairies.cpp | 3 +++ soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp | 3 +++ soh/soh/Enhancements/randomizer/ShuffleGrass.cpp | 3 +++ soh/soh/Enhancements/randomizer/ShufflePots.cpp | 3 +++ soh/soh/Enhancements/randomizer/fishsanity.cpp | 3 +++ soh/soh/OTRGlobals.cpp | 1 + 9 files changed, 23 insertions(+) diff --git a/soh/soh/Enhancements/Presets/Presets.cpp b/soh/soh/Enhancements/Presets/Presets.cpp index 8d08869f5..79552ef5d 100644 --- a/soh/soh/Enhancements/Presets/Presets.cpp +++ b/soh/soh/Enhancements/Presets/Presets.cpp @@ -34,6 +34,7 @@ void applyPreset(std::vector entries) { } Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame(); } + ShipInit::Init("*"); } void DrawPresetSelector(PresetType presetTypeId) { diff --git a/soh/soh/Enhancements/randomizer/ShuffleCows.cpp b/soh/soh/Enhancements/randomizer/ShuffleCows.cpp index ff4680a17..0f03bd196 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleCows.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleCows.cpp @@ -59,6 +59,9 @@ void RegisterShuffleCows() { static RegisterShipInitFunc initFunc(RegisterShuffleCows, { "IS_RANDO" }); void Rando::StaticData::RegisterCowLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format-off locationTable[RC_KF_LINKS_HOUSE_COW] = Location::Base(RC_KF_LINKS_HOUSE_COW, RCQUEST_BOTH, RCTYPE_COW, ACTOR_EN_COW, SCENE_LINKS_HOUSE, 0x00, "Links House Cow", RHT_KF_LINKS_HOUSE_COW, RG_MILK, SpoilerCollectionCheck::RandomizerInf(RAND_INF_COWS_MILKED_KF_LINKS_HOUSE_COW)); locationTable[RC_HF_COW_GROTTO_COW] = Location::Base(RC_HF_COW_GROTTO_COW, RCQUEST_BOTH, RCTYPE_COW, RCAREA_HYRULE_FIELD, ACTOR_EN_COW, SCENE_GROTTOS, TWO_ACTOR_PARAMS(3485, -291), "Cow Grotto Cow", RHT_HF_COW_GROTTO_COW, RG_MILK, SpoilerCollectionCheck::RandomizerInf(RAND_INF_COWS_MILKED_HF_COW_GROTTO_COW)); diff --git a/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp b/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp index 2106b4873..3c75c7c6c 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp @@ -278,6 +278,9 @@ void RegisterShuffleCrates() { } void Rando::StaticData::RegisterCrateLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format off // Overworld Crates // Randomizer Check Randomizer Check Quest Area Scene ID Params Short Name Hint Text Key Vanilla Spoiler Collection Check diff --git a/soh/soh/Enhancements/randomizer/ShuffleFairies.cpp b/soh/soh/Enhancements/randomizer/ShuffleFairies.cpp index c9e53e315..a2b8015d4 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleFairies.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleFairies.cpp @@ -185,6 +185,9 @@ void ShuffleFairies_UnregisterHooks() { } void Rando::StaticData::RegisterFairyLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format off locationTable[RC_SFM_FAIRY_GROTTO_FAIRY_1] = Location::Fairy(RC_SFM_FAIRY_GROTTO_FAIRY_1, RCQUEST_BOTH, RCAREA_SACRED_FOREST_MEADOW, SCENE_FAIRYS_FOUNTAIN, 0x1800, "Grotto Fairy 1", RHT_SFM_FAIRY_GROTTO_FAIRY, SpoilerCollectionCheck::RandomizerInf(RAND_INF_SFM_FAIRY_GROTTO_FAIRY_1)); locationTable[RC_SFM_FAIRY_GROTTO_FAIRY_2] = Location::Fairy(RC_SFM_FAIRY_GROTTO_FAIRY_2, RCQUEST_BOTH, RCAREA_SACRED_FOREST_MEADOW, SCENE_FAIRYS_FOUNTAIN, 0x1801, "Grotto Fairy 2", RHT_SFM_FAIRY_GROTTO_FAIRY, SpoilerCollectionCheck::RandomizerInf(RAND_INF_SFM_FAIRY_GROTTO_FAIRY_2)); diff --git a/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp b/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp index 858e9f3e2..15a7df4db 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp @@ -45,6 +45,9 @@ void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* sh } void Rando::StaticData::RegisterFreestandingLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format off locationTable[RC_KF_BOULDER_RUPEE_2] = Location::Collectable(RC_KF_BOULDER_RUPEE_2, RCQUEST_BOTH, RCTYPE_FREESTANDING, ACTOR_EN_ITEM00, SCENE_KOKIRI_FOREST, TWO_ACTOR_PARAMS(-712, 1857), "Boulder Maze Second Rupee", RHT_KOKIRI_FOREST_RUPEE, RG_BLUE_RUPEE, SpoilerCollectionCheck::RandomizerInf(RAND_INF_KF_BOULDER_RUPEE_2)); locationTable[RC_KF_BOULDER_RUPEE_1] = Location::Collectable(RC_KF_BOULDER_RUPEE_1, RCQUEST_BOTH, RCTYPE_FREESTANDING, ACTOR_EN_ITEM00, SCENE_KOKIRI_FOREST, TWO_ACTOR_PARAMS(-1009, 1556), "Boulder Maze First Rupee", RHT_KOKIRI_FOREST_RUPEE, RG_BLUE_RUPEE, SpoilerCollectionCheck::RandomizerInf(RAND_INF_KF_BOULDER_RUPEE_1)); diff --git a/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp b/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp index 37d407fb3..ff81778a5 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp @@ -157,6 +157,9 @@ void RegisterShuffleGrass() { void Rando::StaticData::RegisterGrassLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format off // Overworld Grass // Randomizer Check Randomizer Check Quest Area Scene ID Params Short Name Spoiler Name Hint Text Key Vanilla Spoiler Collection Check diff --git a/soh/soh/Enhancements/randomizer/ShufflePots.cpp b/soh/soh/Enhancements/randomizer/ShufflePots.cpp index 41b586455..0d45df189 100644 --- a/soh/soh/Enhancements/randomizer/ShufflePots.cpp +++ b/soh/soh/Enhancements/randomizer/ShufflePots.cpp @@ -95,6 +95,9 @@ void ShufflePots_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va } void Rando::StaticData::RegisterPotLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format off // Overworld Pots // Randomizer Check Randomizer Check Quest Area Scene ID Params Short Name Hint Text Key Vanilla Spoiler Collection Check diff --git a/soh/soh/Enhancements/randomizer/fishsanity.cpp b/soh/soh/Enhancements/randomizer/fishsanity.cpp index 85f847df4..d6a76acc0 100644 --- a/soh/soh/Enhancements/randomizer/fishsanity.cpp +++ b/soh/soh/Enhancements/randomizer/fishsanity.cpp @@ -580,6 +580,9 @@ extern "C" { } void Rando::StaticData::RegisterFishLocations() { + static bool registered = false; + if (registered) return; + registered = true; // clang-format off // Fishing Pond locationTable[RC_LH_CHILD_FISH_1] = Location::Fish(RC_LH_CHILD_FISH_1, RCQUEST_BOTH, ACTOR_FISHING, SCENE_FISHING_POND, 100, RAND_INF_CHILD_FISH_1, "Child Pond Fish 1", RHT_LH_POND_FISH, RG_NONE); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 4e5f3be8a..b4db2ae7f 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -2538,6 +2538,7 @@ void SoH_ProcessDroppedFiles(std::string filePath) { std::dynamic_pointer_cast(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console"))->ClearBindings(); gui->SaveConsoleVariablesNextFrame(); + ShipInit::Init("*"); uint32_t finalHash = boost::hash_32{}(configJson.dump()); gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Configuration Loaded. Hash: %d", finalHash);