mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 06:13:45 -07:00
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:
parent
260fb84150
commit
5baf024452
4 changed files with 32 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue