From cf7d6ad511c00354c6ba3386561dcea5c6f9aed7 Mon Sep 17 00:00:00 2001 From: Callow Date: Wed, 13 Jul 2022 15:06:50 +0300 Subject: [PATCH] fix: `teleports` and `imgui.ini` located in game folder --- cheat-base/src/cheat-base/render/renderer.cpp | 5 +++++ cheat-base/src/cheat-base/util.cpp | 11 +++++++++++ cheat-base/src/cheat-base/util.h | 4 ++++ .../src/user/cheat/teleport/CustomTeleports.cpp | 4 +++- .../src/user/cheat/teleport/CustomTeleports.h | 2 +- cheat-library/src/user/main.cpp | 9 ++++----- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/cheat-base/src/cheat-base/render/renderer.cpp b/cheat-base/src/cheat-base/render/renderer.cpp index 4639f8d..f9ba79b 100644 --- a/cheat-base/src/cheat-base/render/renderer.cpp +++ b/cheat-base/src/cheat-base/render/renderer.cpp @@ -202,6 +202,9 @@ namespace renderer ImGui_ImplDX12_CreateDeviceObjects(); ImGui::GetIO().ImeWindowHandle = window; + + static const std::string imguiPath = (util::GetCurrentPath() / "imgui.ini").string(); + ImGui::GetIO().IniFilename = imguiPath.c_str(); io.SetPlatformImeDataFn = nullptr; // F**king bug take 4 hours of my life } @@ -213,6 +216,8 @@ namespace renderer ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + static const std::string imguiPath = (util::GetCurrentPath() / "imgui.ini").string(); + io.IniFilename = imguiPath.c_str(); LoadCustomFont(); SetupImGuiStyle(); diff --git a/cheat-base/src/cheat-base/util.cpp b/cheat-base/src/cheat-base/util.cpp index 509a965..e5a2807 100644 --- a/cheat-base/src/cheat-base/util.cpp +++ b/cheat-base/src/cheat-base/util.cpp @@ -70,6 +70,17 @@ namespace util return std::filesystem::path(pathOut).parent_path().string(); } + static std::filesystem::path _currentPath; + void SetCurrentPath(const std::filesystem::path& current_path) + { + _currentPath = current_path; + } + + std::filesystem::path GetCurrentPath() + { + return _currentPath; + } + std::optional SelectDirectory(const char* title) { auto currPath = std::filesystem::current_path(); diff --git a/cheat-base/src/cheat-base/util.h b/cheat-base/src/cheat-base/util.h index 7299769..16deba9 100644 --- a/cheat-base/src/cheat-base/util.h +++ b/cheat-base/src/cheat-base/util.h @@ -6,6 +6,7 @@ #include #include +#include #include @@ -38,6 +39,9 @@ namespace util std::string GetModulePath(HMODULE hModule = nullptr); + void SetCurrentPath(const std::filesystem::path& curren_path); + std::filesystem::path GetCurrentPath(); + std::vector StringSplit(const std::string& delimiter, const std::string& content); std::string SplitWords(const std::string& value); std::string MakeCapital(std::string value); diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index e1bf6c2..8e6738f 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -20,11 +20,13 @@ namespace cheat::feature NF(f_DebugMode, "Debug Mode", "CustomTeleports", false), // Soon to be added NF(f_Enabled, "Custom Teleport", "CustomTeleports", false), NF(f_Next, "Teleport Next", "CustomTeleports", Hotkey(VK_OEM_6)), - NF(f_Previous, "Teleport Previous", "CustomTeleports", Hotkey(VK_OEM_4)) + NF(f_Previous, "Teleport Previous", "CustomTeleports", Hotkey(VK_OEM_4)), + dir(util::GetCurrentPath() / "teleports") { f_Next.value().PressedEvent += MY_METHOD_HANDLER(CustomTeleports::OnNext); f_Previous.value().PressedEvent += MY_METHOD_HANDLER(CustomTeleports::OnPrevious); } + const FeatureGUIInfo& CustomTeleports::GetGUIInfo() const { static const FeatureGUIInfo info{ "Custom Teleports", "Teleport", true }; diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.h b/cheat-library/src/user/cheat/teleport/CustomTeleports.h index eb03b34..e1fd414 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.h +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.h @@ -45,7 +45,7 @@ namespace cheat::feature void DrawStatus() override; std::vector Teleports; - std::filesystem::path dir = std::filesystem::current_path() / "teleports"; + std::filesystem::path dir; private: std::set checkedIndices; diff --git a/cheat-library/src/user/main.cpp b/cheat-library/src/user/main.cpp index cfff302..9afda85 100644 --- a/cheat-library/src/user/main.cpp +++ b/cheat-library/src/user/main.cpp @@ -14,17 +14,16 @@ void Run(HMODULE* phModule) { ResourceLoader::SetModuleHandle(*phModule); - - auto cheatDir = std::filesystem::path(util::GetModulePath(*phModule)); + util::SetCurrentPath(util::GetModulePath(*phModule)); // Init config - config::Initialize((cheatDir / "cfg.json").string()); + config::Initialize((util::GetCurrentPath() / "cfg.json").string()); // Init logger auto& settings = cheat::feature::Settings::GetInstance(); if (settings.f_FileLogging) { - Logger::PrepareFileLogging((cheatDir / "logs").string()); + Logger::PrepareFileLogging((util::GetCurrentPath() / "logs").string()); Logger::SetLevel(Logger::Level::Trace, Logger::LoggerType::FileLogger); } @@ -56,5 +55,5 @@ void Run(HMODULE* phModule) cheat::Init(); - LOG_DEBUG("Config path is at %s", (cheatDir / "cfg.json").string().c_str()); + LOG_DEBUG("Config path is at %s", (util::GetCurrentPath() / "cfg.json").string().c_str()); } \ No newline at end of file