mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-25 02:42:18 -05:00
String copy util method and fix Save Manager string copy overflows (#3274)
* add safe string copy method * use string copy for save manager * use string copy in spoiler log hint parsing * remove intermediate string vars * more string copy use in randomizer methods * use string copy in gameplay stats * add load char array method to remove string intermediate var * try string.h import instead
This commit is contained in:
parent
837072f80f
commit
fd09a12fff
@ -7,6 +7,7 @@ extern "C" {
|
|||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "../UIWidgets.hpp"
|
#include "../UIWidgets.hpp"
|
||||||
|
#include "soh/util.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -286,10 +287,8 @@ extern "C" char* GameplayStats_GetCurrentTime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoadStatsVersion1() {
|
void LoadStatsVersion1() {
|
||||||
std::string buildVersion;
|
SaveManager::Instance->LoadCharArray("buildVersion", gSaveContext.sohStats.buildVersion,
|
||||||
SaveManager::Instance->LoadData("buildVersion", buildVersion);
|
ARRAY_COUNT(gSaveContext.sohStats.buildVersion));
|
||||||
strncpy(gSaveContext.sohStats.buildVersion, buildVersion.c_str(), ARRAY_COUNT(gSaveContext.sohStats.buildVersion) - 1);
|
|
||||||
gSaveContext.sohStats.buildVersion[ARRAY_COUNT(gSaveContext.sohStats.buildVersion) - 1] = 0;
|
|
||||||
SaveManager::Instance->LoadData("buildVersionMajor", gSaveContext.sohStats.buildVersionMajor);
|
SaveManager::Instance->LoadData("buildVersionMajor", gSaveContext.sohStats.buildVersionMajor);
|
||||||
SaveManager::Instance->LoadData("buildVersionMinor", gSaveContext.sohStats.buildVersionMinor);
|
SaveManager::Instance->LoadData("buildVersionMinor", gSaveContext.sohStats.buildVersionMinor);
|
||||||
SaveManager::Instance->LoadData("buildVersionPatch", gSaveContext.sohStats.buildVersionPatch);
|
SaveManager::Instance->LoadData("buildVersionPatch", gSaveContext.sohStats.buildVersionPatch);
|
||||||
@ -683,8 +682,8 @@ void InitStats(bool isDebug) {
|
|||||||
gSaveContext.sohStats.entrancesDiscovered[entrancesIdx] = 0;
|
gSaveContext.sohStats.entrancesDiscovered[entrancesIdx] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(gSaveContext.sohStats.buildVersion, (const char*) gBuildVersion, sizeof(gSaveContext.sohStats.buildVersion) - 1);
|
SohUtils::CopyStringToCharArray(gSaveContext.sohStats.buildVersion, std::string((char*)gBuildVersion),
|
||||||
gSaveContext.sohStats.buildVersion[sizeof(gSaveContext.sohStats.buildVersion) - 1] = 0;
|
ARRAY_COUNT(gSaveContext.sohStats.buildVersion));
|
||||||
gSaveContext.sohStats.buildVersionMajor = gBuildVersionMajor;
|
gSaveContext.sohStats.buildVersionMajor = gBuildVersionMajor;
|
||||||
gSaveContext.sohStats.buildVersionMinor = gBuildVersionMinor;
|
gSaveContext.sohStats.buildVersionMinor = gBuildVersionMinor;
|
||||||
gSaveContext.sohStats.buildVersionPatch = gBuildVersionPatch;
|
gSaveContext.sohStats.buildVersionPatch = gBuildVersionPatch;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <boost_custom/container_hash/hash_32.hpp>
|
#include <boost_custom/container_hash/hash_32.hpp>
|
||||||
#include "randomizer_settings_window.h"
|
#include "randomizer_settings_window.h"
|
||||||
#include "savefile.h"
|
#include "savefile.h"
|
||||||
|
#include "soh/util.h"
|
||||||
|
|
||||||
extern "C" uint32_t ResourceMgr_IsGameMasterQuest();
|
extern "C" uint32_t ResourceMgr_IsGameMasterQuest();
|
||||||
extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum);
|
extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum);
|
||||||
@ -1298,24 +1299,20 @@ void Randomizer::ParseHintLocationsFile(const char* spoilerFileName) {
|
|||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
// Have all these use strncpy so that the null terminator is copied
|
|
||||||
// and also set the last index to null for safety
|
|
||||||
try {
|
try {
|
||||||
json spoilerFileJson;
|
json spoilerFileJson;
|
||||||
spoilerFileStream >> spoilerFileJson;
|
spoilerFileStream >> spoilerFileJson;
|
||||||
|
|
||||||
std::string childAltarJsonText = spoilerFileJson["childAltar"]["hintText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.childAltarText,
|
||||||
std::string formattedChildAltarText = FormatJsonHintText(childAltarJsonText);
|
FormatJsonHintText(spoilerFileJson["childAltar"]["hintText"]),
|
||||||
strncpy(gSaveContext.childAltarText, formattedChildAltarText.c_str(), sizeof(gSaveContext.childAltarText) - 1);
|
ARRAY_COUNT(gSaveContext.childAltarText));
|
||||||
gSaveContext.childAltarText[sizeof(gSaveContext.childAltarText) - 1] = 0;
|
|
||||||
gSaveContext.rewardCheck[0] = SpoilerfileCheckNameToEnum[spoilerFileJson["childAltar"]["rewards"]["emeraldLoc"]];
|
gSaveContext.rewardCheck[0] = SpoilerfileCheckNameToEnum[spoilerFileJson["childAltar"]["rewards"]["emeraldLoc"]];
|
||||||
gSaveContext.rewardCheck[1] = SpoilerfileCheckNameToEnum[spoilerFileJson["childAltar"]["rewards"]["rubyLoc"]];
|
gSaveContext.rewardCheck[1] = SpoilerfileCheckNameToEnum[spoilerFileJson["childAltar"]["rewards"]["rubyLoc"]];
|
||||||
gSaveContext.rewardCheck[2] = SpoilerfileCheckNameToEnum[spoilerFileJson["childAltar"]["rewards"]["sapphireLoc"]];
|
gSaveContext.rewardCheck[2] = SpoilerfileCheckNameToEnum[spoilerFileJson["childAltar"]["rewards"]["sapphireLoc"]];
|
||||||
|
|
||||||
std::string adultAltarJsonText = spoilerFileJson["adultAltar"]["hintText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.adultAltarText,
|
||||||
std::string formattedAdultAltarText = FormatJsonHintText(adultAltarJsonText);
|
FormatJsonHintText(spoilerFileJson["adultAltar"]["hintText"]),
|
||||||
strncpy(gSaveContext.adultAltarText, formattedAdultAltarText.c_str(), sizeof(gSaveContext.adultAltarText) - 1);
|
ARRAY_COUNT(gSaveContext.adultAltarText));
|
||||||
gSaveContext.adultAltarText[sizeof(gSaveContext.adultAltarText) - 1] = 0;
|
|
||||||
gSaveContext.rewardCheck[3] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["forestMedallionLoc"]];
|
gSaveContext.rewardCheck[3] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["forestMedallionLoc"]];
|
||||||
gSaveContext.rewardCheck[4] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["fireMedallionLoc"]];
|
gSaveContext.rewardCheck[4] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["fireMedallionLoc"]];
|
||||||
gSaveContext.rewardCheck[5] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["waterMedallionLoc"]];
|
gSaveContext.rewardCheck[5] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["waterMedallionLoc"]];
|
||||||
@ -1323,65 +1320,42 @@ void Randomizer::ParseHintLocationsFile(const char* spoilerFileName) {
|
|||||||
gSaveContext.rewardCheck[7] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["spiritMedallionLoc"]];
|
gSaveContext.rewardCheck[7] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["spiritMedallionLoc"]];
|
||||||
gSaveContext.rewardCheck[8] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["lightMedallionLoc"]];
|
gSaveContext.rewardCheck[8] = SpoilerfileCheckNameToEnum[spoilerFileJson["adultAltar"]["rewards"]["lightMedallionLoc"]];
|
||||||
|
|
||||||
std::string ganonHintJsonText = spoilerFileJson["ganonHintText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.ganonHintText, spoilerFileJson["ganonHintText"],
|
||||||
std::string formattedGanonHintJsonText = FormatJsonHintText(ganonHintJsonText);
|
ARRAY_COUNT(gSaveContext.ganonHintText));
|
||||||
strncpy(gSaveContext.ganonHintText, formattedGanonHintJsonText.c_str(), sizeof(gSaveContext.ganonHintText) - 1);
|
|
||||||
gSaveContext.ganonHintText[sizeof(gSaveContext.ganonHintText) - 1] = 0;
|
|
||||||
|
|
||||||
gSaveContext.masterSwordHintCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["masterSwordHintLoc"]];
|
gSaveContext.masterSwordHintCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["masterSwordHintLoc"]];
|
||||||
|
|
||||||
std::string ganonJsonText = spoilerFileJson["ganonText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.ganonText, spoilerFileJson["ganonText"],
|
||||||
std::string formattedGanonJsonText = FormatJsonHintText(ganonJsonText);
|
ARRAY_COUNT(gSaveContext.ganonText));
|
||||||
strncpy(gSaveContext.ganonText, formattedGanonJsonText.c_str(), sizeof(gSaveContext.ganonText) - 1);
|
|
||||||
gSaveContext.ganonText[sizeof(gSaveContext.ganonText) - 1] = 0;
|
|
||||||
|
|
||||||
std::string dampeJsonText = spoilerFileJson["dampeText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.dampeText, spoilerFileJson["dampeText"],
|
||||||
std::string formattedDampeJsonText = FormatJsonHintText(dampeJsonText);
|
ARRAY_COUNT(gSaveContext.dampeText));
|
||||||
strncpy(gSaveContext.dampeText, formattedDampeJsonText.c_str(), sizeof(gSaveContext.dampeText) - 1);
|
|
||||||
gSaveContext.dampeText[sizeof(gSaveContext.dampeText) - 1] = 0;
|
|
||||||
gSaveContext.dampeCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["dampeHintLoc"]];
|
gSaveContext.dampeCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["dampeHintLoc"]];
|
||||||
|
|
||||||
std::string gregJsonText = spoilerFileJson["gregText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.gregHintText, spoilerFileJson["gregText"],
|
||||||
std::string formattedGregJsonText = FormatJsonHintText(gregJsonText);
|
ARRAY_COUNT(gSaveContext.gregHintText));
|
||||||
strncpy(gSaveContext.gregHintText, formattedGregJsonText.c_str(), sizeof(gSaveContext.gregHintText) - 1);
|
|
||||||
gSaveContext.gregHintText[sizeof(gSaveContext.gregHintText) - 1] = 0;
|
|
||||||
gSaveContext.gregCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["gregLoc"]];
|
gSaveContext.gregCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["gregLoc"]];
|
||||||
|
|
||||||
std::string sheikJsonText = spoilerFileJson["sheikText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.sheikText, spoilerFileJson["sheikText"],
|
||||||
std::string formattedSheikJsonText = FormatJsonHintText(sheikJsonText);
|
ARRAY_COUNT(gSaveContext.sheikText));
|
||||||
strncpy(gSaveContext.sheikText, formattedSheikJsonText.c_str(), sizeof(gSaveContext.sheikText) - 1);
|
|
||||||
gSaveContext.sheikText[sizeof(gSaveContext.sheikText) - 1] = 0;
|
|
||||||
gSaveContext.lightArrowHintCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["lightArrowHintLoc"]];
|
gSaveContext.lightArrowHintCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["lightArrowHintLoc"]];
|
||||||
|
|
||||||
std::string sariaJsonText = spoilerFileJson["sariaText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.sariaText, spoilerFileJson["sariaText"],
|
||||||
std::string formattedSariaJsonText = FormatJsonHintText(sariaJsonText);
|
ARRAY_COUNT(gSaveContext.sariaText));
|
||||||
strncpy(gSaveContext.sariaText, formattedSariaJsonText.c_str(), sizeof(gSaveContext.sariaText) - 1);
|
|
||||||
gSaveContext.sariaText[sizeof(gSaveContext.sariaText) - 1] = 0;
|
|
||||||
gSaveContext.sariaCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["sariaHintLoc"]];
|
gSaveContext.sariaCheck = SpoilerfileCheckNameToEnum[spoilerFileJson["sariaHintLoc"]];
|
||||||
|
|
||||||
std::string warpMinuetJsonText = spoilerFileJson["warpMinuetText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.warpMinuetText, spoilerFileJson["warpMinuetText"],
|
||||||
strncpy(gSaveContext.warpMinuetText, warpMinuetJsonText.c_str(), sizeof(gSaveContext.warpMinuetText) - 1);
|
ARRAY_COUNT(gSaveContext.warpMinuetText));
|
||||||
gSaveContext.warpMinuetText[sizeof(gSaveContext.warpMinuetText) - 1] = 0;
|
SohUtils::CopyStringToCharArray(gSaveContext.warpBoleroText, spoilerFileJson["warpBoleroText"],
|
||||||
|
ARRAY_COUNT(gSaveContext.warpBoleroText));
|
||||||
std::string warpBoleroJsonText = spoilerFileJson["warpBoleroText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.warpSerenadeText, spoilerFileJson["warpSerenadeText"],
|
||||||
strncpy(gSaveContext.warpBoleroText, warpBoleroJsonText.c_str(), sizeof(gSaveContext.warpBoleroText) - 1);
|
ARRAY_COUNT(gSaveContext.warpSerenadeText));
|
||||||
gSaveContext.warpBoleroText[sizeof(gSaveContext.warpBoleroText) - 1] = 0;
|
SohUtils::CopyStringToCharArray(gSaveContext.warpRequiemText, spoilerFileJson["warpRequiemText"],
|
||||||
|
ARRAY_COUNT(gSaveContext.warpRequiemText));
|
||||||
std::string warpSerenadeJsonText = spoilerFileJson["warpSerenadeText"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.warpNocturneText, spoilerFileJson["warpNocturneText"],
|
||||||
strncpy(gSaveContext.warpSerenadeText, warpSerenadeJsonText.c_str(), sizeof(gSaveContext.warpSerenadeText) - 1);
|
ARRAY_COUNT(gSaveContext.warpNocturneText));
|
||||||
gSaveContext.warpSerenadeText[sizeof(gSaveContext.warpSerenadeText) - 1] = 0;
|
SohUtils::CopyStringToCharArray(gSaveContext.warpPreludeText, spoilerFileJson["warpPreludeText"],
|
||||||
|
ARRAY_COUNT(gSaveContext.warpPreludeText));
|
||||||
std::string warpRequiemJsonText = spoilerFileJson["warpRequiemText"].get<std::string>();
|
|
||||||
strncpy(gSaveContext.warpRequiemText, warpRequiemJsonText.c_str(), sizeof(gSaveContext.warpRequiemText) - 1);
|
|
||||||
gSaveContext.warpRequiemText[sizeof(gSaveContext.warpRequiemText) - 1] = 0;
|
|
||||||
|
|
||||||
std::string warpNocturneJsonText = spoilerFileJson["warpNocturneText"].get<std::string>();
|
|
||||||
strncpy(gSaveContext.warpNocturneText, warpNocturneJsonText.c_str(), sizeof(gSaveContext.warpNocturneText) - 1);
|
|
||||||
gSaveContext.warpNocturneText[sizeof(gSaveContext.warpNocturneText) - 1] = 0;
|
|
||||||
|
|
||||||
std::string warpPreludeJsonText = spoilerFileJson["warpPreludeText"].get<std::string>();
|
|
||||||
strncpy(gSaveContext.warpPreludeText, warpPreludeJsonText.c_str(), sizeof(gSaveContext.warpPreludeText) - 1);
|
|
||||||
gSaveContext.warpPreludeText[sizeof(gSaveContext.warpPreludeText) - 1] = 0;
|
|
||||||
|
|
||||||
json hintsJson = spoilerFileJson["hints"];
|
json hintsJson = spoilerFileJson["hints"];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -1408,10 +1382,7 @@ void Randomizer::ParseHintLocationsFile(const char* spoilerFileName) {
|
|||||||
gSaveContext.hintLocations[index].area = SpoilerfileAreaNameToEnum[hintInfo["area"]];
|
gSaveContext.hintLocations[index].area = SpoilerfileAreaNameToEnum[hintInfo["area"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string hintMessage = FormatJsonHintText(hintInfo["hint"]);
|
SohUtils::CopyStringToCharArray(gSaveContext.hintLocations[index].hintText, hintInfo["hint"], ARRAY_COUNT(gSaveContext.hintLocations[index].hintText));
|
||||||
size_t maxHintTextSize = sizeof(gSaveContext.hintLocations[index].hintText);
|
|
||||||
strncpy(gSaveContext.hintLocations[index].hintText, hintMessage.c_str(), maxHintTextSize - 1);
|
|
||||||
gSaveContext.hintLocations[index].hintText[maxHintTextSize - 1] = 0;
|
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@ -1542,9 +1513,8 @@ void Randomizer::ParseItemLocationsFile(const char* spoilerFileName, bool silent
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string inputSeed = spoilerFileJson["seed"].get<std::string>();
|
SohUtils::CopyStringToCharArray(gSaveContext.inputSeed, spoilerFileJson["seed"],
|
||||||
strncpy(gSaveContext.inputSeed, inputSeed.c_str(), sizeof(gSaveContext.inputSeed) - 1);
|
ARRAY_COUNT(gSaveContext.inputSeed));
|
||||||
gSaveContext.inputSeed[sizeof(gSaveContext.inputSeed) - 1] = 0;
|
|
||||||
|
|
||||||
gSaveContext.finalSeed = spoilerFileJson["finalSeed"].get<uint32_t>();
|
gSaveContext.finalSeed = spoilerFileJson["finalSeed"].get<uint32_t>();
|
||||||
|
|
||||||
@ -1562,8 +1532,8 @@ void Randomizer::ParseItemLocationsFile(const char* spoilerFileName, bool silent
|
|||||||
gSaveContext.itemLocations[randomizerCheck].get.fakeRgID =
|
gSaveContext.itemLocations[randomizerCheck].get.fakeRgID =
|
||||||
SpoilerfileGetNameToEnum[itemit.value()];
|
SpoilerfileGetNameToEnum[itemit.value()];
|
||||||
} else if (itemit.key() == "trickName") {
|
} else if (itemit.key() == "trickName") {
|
||||||
strncpy(gSaveContext.itemLocations[randomizerCheck].get.trickName,
|
SohUtils::CopyStringToCharArray(gSaveContext.itemLocations[randomizerCheck].get.trickName,
|
||||||
std::string(itemit.value()).c_str(), MAX_TRICK_NAME_SIZE);
|
itemit.value(), MAX_TRICK_NAME_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -3186,7 +3156,7 @@ void RandomizerSettingsWindow::DrawElement() {
|
|||||||
);
|
);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("New Seed")) {
|
if (ImGui::Button("New Seed")) {
|
||||||
strncpy(seedString, std::to_string(rand() & 0xFFFFFFFF).c_str(), MAX_SEED_STRING_SIZE);
|
SohUtils::CopyStringToCharArray(seedString, std::to_string(rand() & 0xFFFFFFFF), MAX_SEED_STRING_SIZE);
|
||||||
}
|
}
|
||||||
UIWidgets::Tooltip("Creates a new random seed value to be used when generating a randomizer");
|
UIWidgets::Tooltip("Creates a new random seed value to be used when generating a randomizer");
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "SaveManager.h"
|
#include "SaveManager.h"
|
||||||
#include "OTRGlobals.h"
|
#include "OTRGlobals.h"
|
||||||
#include "Enhancements/game-interactor/GameInteractor.h"
|
#include "Enhancements/game-interactor/GameInteractor.h"
|
||||||
|
#include "soh/util.h"
|
||||||
|
|
||||||
#include "z64.h"
|
#include "z64.h"
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
@ -95,9 +96,8 @@ void SaveManager::LoadRandomizerVersion1() {
|
|||||||
SaveManager::Instance->LoadStruct("get" + std::to_string(i), [&]() {
|
SaveManager::Instance->LoadStruct("get" + std::to_string(i), [&]() {
|
||||||
SaveManager::Instance->LoadData("rgID", gSaveContext.itemLocations[i].get.rgID);
|
SaveManager::Instance->LoadData("rgID", gSaveContext.itemLocations[i].get.rgID);
|
||||||
SaveManager::Instance->LoadData("fakeRgID", gSaveContext.itemLocations[i].get.fakeRgID);
|
SaveManager::Instance->LoadData("fakeRgID", gSaveContext.itemLocations[i].get.fakeRgID);
|
||||||
std::string trickName;
|
SaveManager::Instance->LoadCharArray("trickName", gSaveContext.itemLocations[i].get.trickName,
|
||||||
SaveManager::Instance->LoadData("trickName", trickName);
|
MAX_TRICK_NAME_SIZE);
|
||||||
strncpy(gSaveContext.itemLocations[i].get.trickName, trickName.c_str(), MAX_TRICK_NAME_SIZE);
|
|
||||||
});
|
});
|
||||||
SaveManager::Instance->LoadData("check" + std::to_string(i), gSaveContext.itemLocations[i].check);
|
SaveManager::Instance->LoadData("check" + std::to_string(i), gSaveContext.itemLocations[i].check);
|
||||||
}
|
}
|
||||||
@ -168,9 +168,8 @@ void SaveManager::LoadRandomizerVersion2() {
|
|||||||
SaveManager::Instance->LoadStruct("", [&]() {
|
SaveManager::Instance->LoadStruct("", [&]() {
|
||||||
SaveManager::Instance->LoadData("rgID", gSaveContext.itemLocations[i].get.rgID);
|
SaveManager::Instance->LoadData("rgID", gSaveContext.itemLocations[i].get.rgID);
|
||||||
SaveManager::Instance->LoadData("fakeRgID", gSaveContext.itemLocations[i].get.fakeRgID);
|
SaveManager::Instance->LoadData("fakeRgID", gSaveContext.itemLocations[i].get.fakeRgID);
|
||||||
std::string trickName;
|
SaveManager::Instance->LoadCharArray("trickName", gSaveContext.itemLocations[i].get.trickName,
|
||||||
SaveManager::Instance->LoadData("trickName", trickName);
|
MAX_TRICK_NAME_SIZE);
|
||||||
strncpy(gSaveContext.itemLocations[i].get.trickName, trickName.c_str(), MAX_TRICK_NAME_SIZE);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -189,8 +188,7 @@ void SaveManager::LoadRandomizerVersion2() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
std::string inputSeed;
|
std::string inputSeed;
|
||||||
SaveManager::Instance->LoadData("inputSeed", inputSeed);
|
SaveManager::Instance->LoadCharArray("inputSeed", gSaveContext.inputSeed, ARRAY_COUNT(gSaveContext.inputSeed));
|
||||||
memcpy(gSaveContext.inputSeed, inputSeed.c_str(), inputSeed.length() + 1);
|
|
||||||
|
|
||||||
SaveManager::Instance->LoadData("finalSeed", gSaveContext.finalSeed);
|
SaveManager::Instance->LoadData("finalSeed", gSaveContext.finalSeed);
|
||||||
|
|
||||||
@ -202,54 +200,41 @@ void SaveManager::LoadRandomizerVersion2() {
|
|||||||
SaveManager::Instance->LoadArray("hintLocations", ARRAY_COUNT(gSaveContext.hintLocations), [&](size_t i) {
|
SaveManager::Instance->LoadArray("hintLocations", ARRAY_COUNT(gSaveContext.hintLocations), [&](size_t i) {
|
||||||
SaveManager::Instance->LoadStruct("", [&]() {
|
SaveManager::Instance->LoadStruct("", [&]() {
|
||||||
SaveManager::Instance->LoadData("check", gSaveContext.hintLocations[i].check);
|
SaveManager::Instance->LoadData("check", gSaveContext.hintLocations[i].check);
|
||||||
std::string hintText;
|
SaveManager::Instance->LoadCharArray("hintText", gSaveContext.hintLocations[i].hintText,
|
||||||
SaveManager::Instance->LoadData("hintText", hintText);
|
ARRAY_COUNT(gSaveContext.hintLocations[i].hintText));
|
||||||
memcpy(gSaveContext.hintLocations[i].hintText, hintText.c_str(), hintText.length());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
std::string childAltarText;
|
SaveManager::Instance->LoadCharArray("childAltarText", gSaveContext.childAltarText,
|
||||||
SaveManager::Instance->LoadData("childAltarText", childAltarText);
|
ARRAY_COUNT(gSaveContext.childAltarText));
|
||||||
memcpy(gSaveContext.childAltarText, childAltarText.c_str(), childAltarText.length());
|
SaveManager::Instance->LoadCharArray("adultAltarText", gSaveContext.adultAltarText,
|
||||||
std::string adultAltarText;
|
ARRAY_COUNT(gSaveContext.adultAltarText));
|
||||||
SaveManager::Instance->LoadData("adultAltarText", adultAltarText);
|
|
||||||
memcpy(gSaveContext.adultAltarText, adultAltarText.c_str(), adultAltarText.length());
|
SaveManager::Instance->LoadCharArray("ganonHintText", gSaveContext.ganonHintText,
|
||||||
std::string ganonHintText;
|
ARRAY_COUNT(gSaveContext.ganonHintText));
|
||||||
SaveManager::Instance->LoadData("ganonHintText", ganonHintText);
|
SaveManager::Instance->LoadCharArray("ganonText", gSaveContext.ganonText, ARRAY_COUNT(gSaveContext.ganonText));
|
||||||
memcpy(gSaveContext.ganonHintText, ganonHintText.c_str(), ganonHintText.length());
|
|
||||||
std::string ganonText;
|
SaveManager::Instance->LoadCharArray("dampeText", gSaveContext.dampeText, ARRAY_COUNT(gSaveContext.dampeText));
|
||||||
SaveManager::Instance->LoadData("ganonText", ganonText);
|
|
||||||
memcpy(gSaveContext.ganonText, ganonText.c_str(), ganonText.length());
|
SaveManager::Instance->LoadCharArray("gregHintText", gSaveContext.gregHintText,
|
||||||
std::string dampeText;
|
ARRAY_COUNT(gSaveContext.gregHintText));
|
||||||
SaveManager::Instance->LoadData("dampeText", dampeText);
|
|
||||||
memcpy(gSaveContext.dampeText, dampeText.c_str(), dampeText.length());
|
SaveManager::Instance->LoadCharArray("sheikText", gSaveContext.sheikText, ARRAY_COUNT(gSaveContext.sheikText));
|
||||||
std::string gregHintText;
|
|
||||||
SaveManager::Instance->LoadData("gregHintText", gregHintText);
|
SaveManager::Instance->LoadCharArray("sariaText", gSaveContext.sariaText, ARRAY_COUNT(gSaveContext.sariaText));
|
||||||
memcpy(gSaveContext.gregHintText, gregHintText.c_str(), gregHintText.length());
|
|
||||||
std::string sheikText;
|
SaveManager::Instance->LoadCharArray("warpMinuetText", gSaveContext.warpMinuetText,
|
||||||
SaveManager::Instance->LoadData("sheikText", sheikText);
|
ARRAY_COUNT(gSaveContext.warpMinuetText));
|
||||||
memcpy(gSaveContext.sheikText, sheikText.c_str(), sheikText.length() + 1);
|
SaveManager::Instance->LoadCharArray("warpBoleroText", gSaveContext.warpBoleroText,
|
||||||
std::string sariaText;
|
ARRAY_COUNT(gSaveContext.warpBoleroText));
|
||||||
SaveManager::Instance->LoadData("sariaText", sariaText);
|
SaveManager::Instance->LoadCharArray("warpSerenadeText", gSaveContext.warpSerenadeText,
|
||||||
memcpy(gSaveContext.sariaText, sariaText.c_str(), sariaText.length() + 1);
|
ARRAY_COUNT(gSaveContext.warpSerenadeText));
|
||||||
std::string warpMinuetText;
|
SaveManager::Instance->LoadCharArray("warpRequiemText", gSaveContext.warpRequiemText,
|
||||||
SaveManager::Instance->LoadData("warpMinuetText", warpMinuetText);
|
ARRAY_COUNT(gSaveContext.warpRequiemText));
|
||||||
memcpy(gSaveContext.warpMinuetText, warpMinuetText.c_str(), warpMinuetText.length());
|
SaveManager::Instance->LoadCharArray("warpNocturneText", gSaveContext.warpNocturneText,
|
||||||
std::string warpBoleroText;
|
ARRAY_COUNT(gSaveContext.warpNocturneText));
|
||||||
SaveManager::Instance->LoadData("warpBoleroText", warpBoleroText);
|
SaveManager::Instance->LoadCharArray("warpPreludeText", gSaveContext.warpPreludeText,
|
||||||
memcpy(gSaveContext.warpBoleroText, warpBoleroText.c_str(), warpBoleroText.length());
|
ARRAY_COUNT(gSaveContext.warpPreludeText));
|
||||||
std::string warpSerenadeText;
|
|
||||||
SaveManager::Instance->LoadData("warpSerenadeText", warpSerenadeText);
|
|
||||||
memcpy(gSaveContext.warpSerenadeText, warpSerenadeText.c_str(), warpSerenadeText.length());
|
|
||||||
std::string warpRequiemText;
|
|
||||||
SaveManager::Instance->LoadData("warpRequiemText", warpRequiemText);
|
|
||||||
memcpy(gSaveContext.warpRequiemText, warpRequiemText.c_str(), warpRequiemText.length());
|
|
||||||
std::string warpNocturneText;
|
|
||||||
SaveManager::Instance->LoadData("warpNocturneText", warpNocturneText);
|
|
||||||
memcpy(gSaveContext.warpNocturneText, warpNocturneText.c_str(), warpNocturneText.length());
|
|
||||||
std::string warpPreludeText;
|
|
||||||
SaveManager::Instance->LoadData("warpPreludeText", warpPreludeText);
|
|
||||||
memcpy(gSaveContext.warpPreludeText, warpPreludeText.c_str(), warpPreludeText.length());
|
|
||||||
|
|
||||||
SaveManager::Instance->LoadData("adultTradeItems", gSaveContext.adultTradeItems);
|
SaveManager::Instance->LoadData("adultTradeItems", gSaveContext.adultTradeItems);
|
||||||
|
|
||||||
@ -466,8 +451,8 @@ void SaveManager::InitMeta(int fileNum) {
|
|||||||
fileMetaInfo[fileNum].buildVersionMajor = gSaveContext.sohStats.buildVersionMajor;
|
fileMetaInfo[fileNum].buildVersionMajor = gSaveContext.sohStats.buildVersionMajor;
|
||||||
fileMetaInfo[fileNum].buildVersionMinor = gSaveContext.sohStats.buildVersionMinor;
|
fileMetaInfo[fileNum].buildVersionMinor = gSaveContext.sohStats.buildVersionMinor;
|
||||||
fileMetaInfo[fileNum].buildVersionPatch = gSaveContext.sohStats.buildVersionPatch;
|
fileMetaInfo[fileNum].buildVersionPatch = gSaveContext.sohStats.buildVersionPatch;
|
||||||
strncpy(fileMetaInfo[fileNum].buildVersion, gSaveContext.sohStats.buildVersion, sizeof(fileMetaInfo[fileNum].buildVersion) - 1);
|
SohUtils::CopyStringToCharArray(fileMetaInfo[fileNum].buildVersion, gSaveContext.sohStats.buildVersion,
|
||||||
fileMetaInfo[fileNum].buildVersion[sizeof(fileMetaInfo[fileNum].buildVersion) - 1] = 0;
|
ARRAY_COUNT(fileMetaInfo[fileNum].buildVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveManager::InitFile(bool isDebug) {
|
void SaveManager::InitFile(bool isDebug) {
|
||||||
@ -1555,10 +1540,8 @@ void SaveManager::LoadBaseVersion3() {
|
|||||||
SaveManager::Instance->LoadData("gsTokens", gSaveContext.inventory.gsTokens);
|
SaveManager::Instance->LoadData("gsTokens", gSaveContext.inventory.gsTokens);
|
||||||
});
|
});
|
||||||
SaveManager::Instance->LoadStruct("sohStats", []() {
|
SaveManager::Instance->LoadStruct("sohStats", []() {
|
||||||
std::string buildVersion;
|
SaveManager::Instance->LoadCharArray("buildVersion", gSaveContext.sohStats.buildVersion,
|
||||||
SaveManager::Instance->LoadData("buildVersion", buildVersion);
|
ARRAY_COUNT(gSaveContext.sohStats.buildVersion));
|
||||||
strncpy(gSaveContext.sohStats.buildVersion, buildVersion.c_str(), ARRAY_COUNT(gSaveContext.sohStats.buildVersion) - 1);
|
|
||||||
gSaveContext.sohStats.buildVersion[ARRAY_COUNT(gSaveContext.sohStats.buildVersion) - 1] = 0;
|
|
||||||
SaveManager::Instance->LoadData("buildVersionMajor", gSaveContext.sohStats.buildVersionMajor);
|
SaveManager::Instance->LoadData("buildVersionMajor", gSaveContext.sohStats.buildVersionMajor);
|
||||||
SaveManager::Instance->LoadData("buildVersionMinor", gSaveContext.sohStats.buildVersionMinor);
|
SaveManager::Instance->LoadData("buildVersionMinor", gSaveContext.sohStats.buildVersionMinor);
|
||||||
SaveManager::Instance->LoadData("buildVersionPatch", gSaveContext.sohStats.buildVersionPatch);
|
SaveManager::Instance->LoadData("buildVersionPatch", gSaveContext.sohStats.buildVersionPatch);
|
||||||
@ -2046,6 +2029,13 @@ void SaveManager::SaveBase(SaveContext* saveContext, int sectionID, bool fullSav
|
|||||||
SaveManager::Instance->SaveData("dogParams", saveContext->dogParams);
|
SaveManager::Instance->SaveData("dogParams", saveContext->dogParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load a string into a char array based on size and ensuring it is null terminated when overflowed
|
||||||
|
void SaveManager::LoadCharArray(const std::string& name, char* destination, size_t size) {
|
||||||
|
std::string temp;
|
||||||
|
SaveManager::Instance->LoadData(name, temp);
|
||||||
|
SohUtils::CopyStringToCharArray(destination, temp, size);
|
||||||
|
}
|
||||||
|
|
||||||
void SaveManager::SaveArray(const std::string& name, const size_t size, SaveArrayFunc func) {
|
void SaveManager::SaveArray(const std::string& name, const size_t size, SaveArrayFunc func) {
|
||||||
// Create an empty array and set it as the current save context, then call the function that saves an array entry.
|
// Create an empty array and set it as the current save context, then call the function that saves an array entry.
|
||||||
nlohmann::json* saveJsonContext = currentJsonContext;
|
nlohmann::json* saveJsonContext = currentJsonContext;
|
||||||
@ -2169,8 +2159,8 @@ void SaveManager::CopyZeldaFile(int from, int to) {
|
|||||||
fileMetaInfo[to].buildVersionMajor = fileMetaInfo[from].buildVersionMajor;
|
fileMetaInfo[to].buildVersionMajor = fileMetaInfo[from].buildVersionMajor;
|
||||||
fileMetaInfo[to].buildVersionMinor = fileMetaInfo[from].buildVersionMinor;
|
fileMetaInfo[to].buildVersionMinor = fileMetaInfo[from].buildVersionMinor;
|
||||||
fileMetaInfo[to].buildVersionPatch = fileMetaInfo[from].buildVersionPatch;
|
fileMetaInfo[to].buildVersionPatch = fileMetaInfo[from].buildVersionPatch;
|
||||||
strncpy(fileMetaInfo[to].buildVersion, fileMetaInfo[from].buildVersion, sizeof(fileMetaInfo[to].buildVersion) - 1);
|
SohUtils::CopyStringToCharArray(fileMetaInfo[to].buildVersion, fileMetaInfo[from].buildVersion,
|
||||||
fileMetaInfo[to].buildVersion[sizeof(fileMetaInfo[to].buildVersion) - 1] = 0;
|
ARRAY_COUNT(fileMetaInfo[to].buildVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveManager::DeleteZeldaFile(int fileNum) {
|
void SaveManager::DeleteZeldaFile(int fileNum) {
|
||||||
|
@ -128,6 +128,8 @@ class SaveManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoadCharArray(const std::string& name, char* destination, size_t size);
|
||||||
|
|
||||||
// In the LoadArrayFunc func, the name must be "" to load from the array.
|
// In the LoadArrayFunc func, the name must be "" to load from the array.
|
||||||
using LoadArrayFunc = std::function<void(size_t)>;
|
using LoadArrayFunc = std::function<void(size_t)>;
|
||||||
void LoadArray(const std::string& name, const size_t size, LoadArrayFunc func);
|
void LoadArray(const std::string& name, const size_t size, LoadArrayFunc func);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<std::string> sceneNames = {
|
std::vector<std::string> sceneNames = {
|
||||||
@ -312,3 +313,8 @@ const std::string& SohUtils::GetItemName(int32_t item) {
|
|||||||
const std::string& SohUtils::GetQuestItemName(int32_t item) {
|
const std::string& SohUtils::GetQuestItemName(int32_t item) {
|
||||||
return questItemNames[item];
|
return questItemNames[item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SohUtils::CopyStringToCharArray(char* destination, std::string source, size_t size) {
|
||||||
|
strncpy(destination, source.c_str(), size - 1);
|
||||||
|
destination[size - 1] = '\0';
|
||||||
|
}
|
||||||
|
@ -8,4 +8,8 @@ namespace SohUtils {
|
|||||||
const std::string& GetItemName(int32_t item);
|
const std::string& GetItemName(int32_t item);
|
||||||
|
|
||||||
const std::string& GetQuestItemName(int32_t item);
|
const std::string& GetQuestItemName(int32_t item);
|
||||||
|
|
||||||
|
// Copies a string and ensures the destination is null terminated if the source string is larger than size
|
||||||
|
// Only up to size-1 characters are copied from the source string
|
||||||
|
void CopyStringToCharArray(char* destination, std::string source, size_t size);
|
||||||
} // namespace SohUtils
|
} // namespace SohUtils
|
||||||
|
Loading…
Reference in New Issue
Block a user