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.
This commit is contained in:
Malkierian 2025-06-03 17:22:06 -07:00
commit 5baf024452
4 changed files with 32 additions and 9 deletions

View file

@ -11,6 +11,8 @@
#include "fishsanity.h"
#include "macros.h"
#include "3drando/hints.hpp"
#include "soh/SohGui/SohGui.hpp"
#include "../kaleido.h"
#include <fstream>
@ -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);

View file

@ -361,10 +361,18 @@ std::unordered_map<s16, s16> getItemIdToItemId = {
bool Randomizer::SpoilerFileExists(const char* spoilerFileName) {
if (strcmp(spoilerFileName, "") != 0) {
std::ifstream spoilerFileStream(SohUtils::Sanitize(spoilerFileName));
if (!spoilerFileStream) {
return false;
} else {
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.");
}
}
}

View file

@ -376,8 +376,12 @@ std::string SohUtils::Sanitize(std::string stringValue) {
if (pos == stringValue.end()) {
break;
}
auto checkPos = pos + 1;
auto reversePos = pos - 1;
if (*checkPos != '\\' && *reversePos != '\\') {
i = std::next(stringValue.insert(pos, '\\'), 2);
}
}
// Removes others.
stringValue.erase(std::remove_if(stringValue.begin(), stringValue.end(),

View file

@ -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) {
if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), ""))) {
CVarSetString(CVAR_GENERAL("SpoilerLog"), CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), ""));
Audio_PlayFanfare(NA_BGM_HORSE_GOAL);
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"), "");
if (!Ship_IsCStringEmpty(fileLoc)) {
Randomizer_ParseSpoiler(fileLoc);
fileSelectSpoilerFileLoaded = true;
}
if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) &&
CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {