From 5baf024452c637e44f4794d6884ccb3874306c07 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Tue, 3 Jun 2025 17:22:06 -0700 Subject: [PATCH] Change spoiler drop success sound to puzzle success chime. Add spoiler drop fail sound (sys_error). Improve path sanitizer operation. Add check for a spoiler having a version and it equaling running version. Deletes spoiler CVar if spoiler becomes unusuable while running, and prevents loading dropped spoilers that don't match. --- soh/soh/Enhancements/randomizer/context.cpp | 3 +++ soh/soh/Enhancements/randomizer/randomizer.cpp | 16 ++++++++++++---- soh/soh/util.cpp | 6 +++++- .../gamestates/ovl_file_choose/z_file_choose.c | 16 ++++++++++++---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/context.cpp b/soh/soh/Enhancements/randomizer/context.cpp index 550cd0e93..89fb1dc85 100644 --- a/soh/soh/Enhancements/randomizer/context.cpp +++ b/soh/soh/Enhancements/randomizer/context.cpp @@ -11,6 +11,8 @@ #include "fishsanity.h" #include "macros.h" #include "3drando/hints.hpp" +#include "soh/SohGui/SohGui.hpp" + #include "../kaleido.h" #include @@ -397,6 +399,7 @@ void Context::ParseSpoiler(const char* spoilerFileName) { try { nlohmann::json spoilerFileJson; spoilerFileStream >> spoilerFileJson; + spoilerFileStream.close(); ParseHashIconIndexesJson(spoilerFileJson); Rando::Settings::GetInstance()->ParseJson(spoilerFileJson); ParseItemLocationsJson(spoilerFileJson); diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 18a23df53..aa257b709 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -361,10 +361,18 @@ std::unordered_map getItemIdToItemId = { bool Randomizer::SpoilerFileExists(const char* spoilerFileName) { if (strcmp(spoilerFileName, "") != 0) { std::ifstream spoilerFileStream(SohUtils::Sanitize(spoilerFileName)); - if (!spoilerFileStream) { - return false; - } else { - return true; + if (spoilerFileStream) { + nlohmann::json contents; + spoilerFileStream >> contents; + spoilerFileStream.close(); + if (contents.contains("version") && strcmp(std::string(contents["version"]).c_str(), (char*)gBuildVersion) == 0) { + return true; + } else { + SohGui::RegisterPopup("Old Spoiler Version", "The spoiler file located at\n" + + std::string(spoilerFileName) + + "\nwas made by an version that doesn't match the currently running version.\n" + + "Loading for this file has been cancelled."); + } } } diff --git a/soh/soh/util.cpp b/soh/soh/util.cpp index 1e5bb2ae8..19ee68201 100644 --- a/soh/soh/util.cpp +++ b/soh/soh/util.cpp @@ -376,7 +376,11 @@ std::string SohUtils::Sanitize(std::string stringValue) { if (pos == stringValue.end()) { break; } - i = std::next(stringValue.insert(pos, '\\'), 2); + auto checkPos = pos + 1; + auto reversePos = pos - 1; + if (*checkPos != '\\' && *reversePos != '\\') { + i = std::next(stringValue.insert(pos, '\\'), 2); + } } // Removes others. diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 6dae312ac..d170beb95 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -26,6 +26,7 @@ #include "soh/SaveManager.h" #include "soh/OTRGlobals.h" #include "soh/ResourceManagerHelpers.h" +#include "soh/ShipUtils.h" typedef struct { s16 left; @@ -1053,20 +1054,27 @@ void FileChoose_UpdateRandomizer() { if (!SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) && !CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) { CVarSetString(CVAR_GENERAL("SpoilerLog"), ""); + Randomizer_SetSpoilerLoaded(false); } if (CVarGetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0) != 0 || !(Randomizer_IsSeedGenerated() || Randomizer_IsSpoilerLoaded()) && SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) && !fileSelectSpoilerFileLoaded) { if (CVarGetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0) != 0) { - CVarSetString(CVAR_GENERAL("SpoilerLog"), CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), "")); - Audio_PlayFanfare(NA_BGM_HORSE_GOAL); + if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), ""))) { + CVarSetString(CVAR_GENERAL("SpoilerLog"), CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), "")); + Sfx_PlaySfxCentered(NA_SE_SY_CORRECT_CHIME); + } else { + Sfx_PlaySfxCentered(NA_SE_SY_ERROR); + } } const char* fileLoc = CVarGetString(CVAR_GENERAL("SpoilerLog"), ""); CVarSetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0); CVarSetString(CVAR_GENERAL("RandomizerDroppedFile"), ""); - Randomizer_ParseSpoiler(fileLoc); - fileSelectSpoilerFileLoaded = true; + if (!Ship_IsCStringEmpty(fileLoc)) { + Randomizer_ParseSpoiler(fileLoc); + fileSelectSpoilerFileLoaded = true; + } if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) && CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {