From de0e60f80c4d5824bf06a1c0761b01b46af3ebe1 Mon Sep 17 00:00:00 2001 From: Aaron Gamache Date: Wed, 13 Jul 2022 22:08:56 -0400 Subject: [PATCH 1/5] Fixes macOS randomizer functionality with App Directory --- soh/soh/Enhancements/randomizer/3drando/rando_main.cpp | 3 ++- soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp b/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp index a936b65671f..7c4ef251af2 100644 --- a/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp @@ -7,6 +7,7 @@ // #include #include #include +#include #define TICKS_PER_SEC 268123480.0 @@ -18,7 +19,7 @@ void RandoMain::GenerateRando(std::unordered_map cvarS // std::string settingsFileName = "./randomizer/latest_settings.json"; // CVar_SetString("gLoadedPreset", settingsFileName.c_str()); - std::string fileName = GenerateRandomizer(cvarSettings); + std::string fileName = Ship::GlobalCtx2::GetPathRelativeToAppDirectory(GenerateRandomizer(cvarSettings).c_str()); CVar_SetString("gSpoilerLog", fileName.c_str()); Game::SaveSettings(); diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index 3ed486a44d5..4f16349f0bb 100644 --- a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp @@ -26,6 +26,8 @@ #include #include +#include + using json = nlohmann::json; json jsonData; @@ -721,12 +723,12 @@ const char* SpoilerLog_Write(int language) { //WriteShuffledEntrances(spoilerLog); WriteAllLocations(language); - if (!std::filesystem::exists("./Randomizer")) { - std::filesystem::create_directory("./Randomizer"); + if (!std::filesystem::exists(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer"))) { + std::filesystem::create_directory(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer")); } std::string jsonString = jsonData.dump(4); - std::ofstream jsonFile("./Randomizer/" + Settings::seed + ".json"); + std::ofstream jsonFile(Ship::GlobalCtx2::GetPathRelativeToAppDirectory((std::string("Randomizer/") + std::string(Settings::seed) + std::string(".json")).c_str())); jsonFile << std::setw(4) << jsonString << std::endl; jsonFile.close(); From b625e43c4818e478eb1caa8efb188f2d2dea4d01 Mon Sep 17 00:00:00 2001 From: Aaron Gamache Date: Wed, 13 Jul 2022 23:51:35 -0400 Subject: [PATCH 2/5] Fix windows build --- soh/soh.vcxproj | 2 ++ soh/soh.vcxproj.filters | 3 +++ soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp | 9 +++++---- soh/soh/GetAppDirectory.cpp | 5 +++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 soh/soh/GetAppDirectory.cpp diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 5f7ea818f1e..52d65b90ee4 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -254,6 +254,7 @@ + @@ -941,6 +942,7 @@ + diff --git a/soh/soh.vcxproj.filters b/soh/soh.vcxproj.filters index bbe6578f26a..69b6b274efe 100644 --- a/soh/soh.vcxproj.filters +++ b/soh/soh.vcxproj.filters @@ -2379,6 +2379,9 @@ Source Files\src + + Source Files + diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index 4f16349f0bb..eeeb689bf4d 100644 --- a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp @@ -26,7 +26,7 @@ #include #include -#include +extern std::string GlobalCtx2_GetPathRelativeToAppDirectory(const char* path); using json = nlohmann::json; @@ -723,12 +723,13 @@ const char* SpoilerLog_Write(int language) { //WriteShuffledEntrances(spoilerLog); WriteAllLocations(language); - if (!std::filesystem::exists(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer"))) { - std::filesystem::create_directory(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer")); + if (!std::filesystem::exists(GlobalCtx2_GetPathRelativeToAppDirectory("Randomizer"))) { + std::filesystem::create_directory(GlobalCtx2_GetPathRelativeToAppDirectory("Randomizer")); } std::string jsonString = jsonData.dump(4); - std::ofstream jsonFile(Ship::GlobalCtx2::GetPathRelativeToAppDirectory((std::string("Randomizer/") + std::string(Settings::seed) + std::string(".json")).c_str())); + std::ofstream jsonFile(GlobalCtx2_GetPathRelativeToAppDirectory( + (std::string("Randomizer/") + std::string(Settings::seed) + std::string(".json")).c_str())); jsonFile << std::setw(4) << jsonString << std::endl; jsonFile.close(); diff --git a/soh/soh/GetAppDirectory.cpp b/soh/soh/GetAppDirectory.cpp new file mode 100644 index 00000000000..c304744fc12 --- /dev/null +++ b/soh/soh/GetAppDirectory.cpp @@ -0,0 +1,5 @@ +#include + +std::string GlobalCtx2_GetPathRelativeToAppDirectory(const char* path) { + return Ship::GlobalCtx2::GetPathRelativeToAppDirectory(path); +} \ No newline at end of file From 5be6893a96be114e396f4f4bd804b7681dd5bbec Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Wed, 13 Jul 2022 23:53:45 -0400 Subject: [PATCH 3/5] Update soh/soh/Enhancements/randomizer/3drando/rando_main.cpp --- soh/soh/Enhancements/randomizer/3drando/rando_main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp b/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp index 7c4ef251af2..e14cf502dd1 100644 --- a/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/rando_main.cpp @@ -7,6 +7,8 @@ // #include #include #include +#define NOGDI +#define WIN32_LEAN_AND_MEAN #include #define TICKS_PER_SEC 268123480.0 From b2e5b8bc3a8c77b0d1941cce51040644b64802f1 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Wed, 13 Jul 2022 23:55:57 -0400 Subject: [PATCH 4/5] Update soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp --- soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index eeeb689bf4d..21bba313b2c 100644 --- a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp @@ -26,7 +26,9 @@ #include #include -extern std::string GlobalCtx2_GetPathRelativeToAppDirectory(const char* path); +#define NOGDI +#define WIN32_LEAN_AND_MEAN +#include "GlobalCtx2.h" using json = nlohmann::json; From bed61f7843039b60a5b56e7c068b36ece8e7a0b3 Mon Sep 17 00:00:00 2001 From: Aaron Gamache Date: Thu, 14 Jul 2022 00:05:47 -0400 Subject: [PATCH 5/5] Revert band-aid fix --- soh/soh.vcxproj | 1 - soh/soh.vcxproj.filters | 3 --- soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp | 6 +++--- soh/soh/GetAppDirectory.cpp | 5 ----- 4 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 soh/soh/GetAppDirectory.cpp diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 52d65b90ee4..7f5672cb44b 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -254,7 +254,6 @@ - diff --git a/soh/soh.vcxproj.filters b/soh/soh.vcxproj.filters index 69b6b274efe..bbe6578f26a 100644 --- a/soh/soh.vcxproj.filters +++ b/soh/soh.vcxproj.filters @@ -2379,9 +2379,6 @@ Source Files\src - - Source Files - diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index 21bba313b2c..68f037aa33c 100644 --- a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp @@ -725,12 +725,12 @@ const char* SpoilerLog_Write(int language) { //WriteShuffledEntrances(spoilerLog); WriteAllLocations(language); - if (!std::filesystem::exists(GlobalCtx2_GetPathRelativeToAppDirectory("Randomizer"))) { - std::filesystem::create_directory(GlobalCtx2_GetPathRelativeToAppDirectory("Randomizer")); + if (!std::filesystem::exists(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer"))) { + std::filesystem::create_directory(Ship::GlobalCtx2::GetPathRelativeToAppDirectory("Randomizer")); } std::string jsonString = jsonData.dump(4); - std::ofstream jsonFile(GlobalCtx2_GetPathRelativeToAppDirectory( + std::ofstream jsonFile(Ship::GlobalCtx2::GetPathRelativeToAppDirectory( (std::string("Randomizer/") + std::string(Settings::seed) + std::string(".json")).c_str())); jsonFile << std::setw(4) << jsonString << std::endl; jsonFile.close(); diff --git a/soh/soh/GetAppDirectory.cpp b/soh/soh/GetAppDirectory.cpp deleted file mode 100644 index c304744fc12..00000000000 --- a/soh/soh/GetAppDirectory.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -std::string GlobalCtx2_GetPathRelativeToAppDirectory(const char* path) { - return Ship::GlobalCtx2::GetPathRelativeToAppDirectory(path); -} \ No newline at end of file