mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 14:23:44 -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 "fishsanity.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "3drando/hints.hpp"
|
#include "3drando/hints.hpp"
|
||||||
|
#include "soh/SohGui/SohGui.hpp"
|
||||||
|
|
||||||
#include "../kaleido.h"
|
#include "../kaleido.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -397,6 +399,7 @@ void Context::ParseSpoiler(const char* spoilerFileName) {
|
||||||
try {
|
try {
|
||||||
nlohmann::json spoilerFileJson;
|
nlohmann::json spoilerFileJson;
|
||||||
spoilerFileStream >> spoilerFileJson;
|
spoilerFileStream >> spoilerFileJson;
|
||||||
|
spoilerFileStream.close();
|
||||||
ParseHashIconIndexesJson(spoilerFileJson);
|
ParseHashIconIndexesJson(spoilerFileJson);
|
||||||
Rando::Settings::GetInstance()->ParseJson(spoilerFileJson);
|
Rando::Settings::GetInstance()->ParseJson(spoilerFileJson);
|
||||||
ParseItemLocationsJson(spoilerFileJson);
|
ParseItemLocationsJson(spoilerFileJson);
|
||||||
|
|
|
@ -361,10 +361,18 @@ std::unordered_map<s16, s16> getItemIdToItemId = {
|
||||||
bool Randomizer::SpoilerFileExists(const char* spoilerFileName) {
|
bool Randomizer::SpoilerFileExists(const char* spoilerFileName) {
|
||||||
if (strcmp(spoilerFileName, "") != 0) {
|
if (strcmp(spoilerFileName, "") != 0) {
|
||||||
std::ifstream spoilerFileStream(SohUtils::Sanitize(spoilerFileName));
|
std::ifstream spoilerFileStream(SohUtils::Sanitize(spoilerFileName));
|
||||||
if (!spoilerFileStream) {
|
if (spoilerFileStream) {
|
||||||
return false;
|
nlohmann::json contents;
|
||||||
} else {
|
spoilerFileStream >> contents;
|
||||||
return true;
|
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()) {
|
if (pos == stringValue.end()) {
|
||||||
break;
|
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.
|
// Removes others.
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "soh/SaveManager.h"
|
#include "soh/SaveManager.h"
|
||||||
#include "soh/OTRGlobals.h"
|
#include "soh/OTRGlobals.h"
|
||||||
#include "soh/ResourceManagerHelpers.h"
|
#include "soh/ResourceManagerHelpers.h"
|
||||||
|
#include "soh/ShipUtils.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
s16 left;
|
s16 left;
|
||||||
|
@ -1053,20 +1054,27 @@ void FileChoose_UpdateRandomizer() {
|
||||||
if (!SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) &&
|
if (!SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) &&
|
||||||
!CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {
|
!CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {
|
||||||
CVarSetString(CVAR_GENERAL("SpoilerLog"), "");
|
CVarSetString(CVAR_GENERAL("SpoilerLog"), "");
|
||||||
|
Randomizer_SetSpoilerLoaded(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CVarGetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0) != 0 ||
|
if (CVarGetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0) != 0 ||
|
||||||
!(Randomizer_IsSeedGenerated() || Randomizer_IsSpoilerLoaded()) &&
|
!(Randomizer_IsSeedGenerated() || Randomizer_IsSpoilerLoaded()) &&
|
||||||
SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) && !fileSelectSpoilerFileLoaded) {
|
SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) && !fileSelectSpoilerFileLoaded) {
|
||||||
if (CVarGetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0) != 0) {
|
if (CVarGetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0) != 0) {
|
||||||
CVarSetString(CVAR_GENERAL("SpoilerLog"), CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), ""));
|
if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("RandomizerDroppedFile"), ""))) {
|
||||||
Audio_PlayFanfare(NA_BGM_HORSE_GOAL);
|
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"), "");
|
const char* fileLoc = CVarGetString(CVAR_GENERAL("SpoilerLog"), "");
|
||||||
CVarSetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0);
|
CVarSetInteger(CVAR_GENERAL("RandomizerNewFileDropped"), 0);
|
||||||
CVarSetString(CVAR_GENERAL("RandomizerDroppedFile"), "");
|
CVarSetString(CVAR_GENERAL("RandomizerDroppedFile"), "");
|
||||||
Randomizer_ParseSpoiler(fileLoc);
|
if (!Ship_IsCStringEmpty(fileLoc)) {
|
||||||
fileSelectSpoilerFileLoaded = true;
|
Randomizer_ParseSpoiler(fileLoc);
|
||||||
|
fileSelectSpoilerFileLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) &&
|
if (SpoilerFileExists(CVarGetString(CVAR_GENERAL("SpoilerLog"), "")) &&
|
||||||
CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {
|
CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue