diff --git a/cheat-base/src/cheat-base/util.cpp b/cheat-base/src/cheat-base/util.cpp index 892b94b..509a965 100644 --- a/cheat-base/src/cheat-base/util.cpp +++ b/cheat-base/src/cheat-base/util.cpp @@ -62,6 +62,14 @@ namespace util return (*c); } + std::string GetModulePath(HMODULE hModule /*= nullptr*/) + { + char pathOut[MAX_PATH] = {}; + GetModuleFileNameA(hModule, pathOut, MAX_PATH); + + return std::filesystem::path(pathOut).parent_path().string(); + } + 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 dd9c0a6..7299769 100644 --- a/cheat-base/src/cheat-base/util.h +++ b/cheat-base/src/cheat-base/util.h @@ -36,6 +36,8 @@ namespace util std::string GetLastErrorAsString(DWORD errorId = 0); int64_t GetCurrentTimeMillisec(); + std::string GetModulePath(HMODULE hModule = nullptr); + 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/main.cpp b/cheat-library/src/user/main.cpp index 755daba..a6649dd 100644 --- a/cheat-library/src/user/main.cpp +++ b/cheat-library/src/user/main.cpp @@ -14,16 +14,17 @@ void Run(HMODULE* phModule) { ResourceLoader::SetModuleHandle(*phModule); + + auto cheatDir = std::filesystem::path(util::GetModulePath(*phModule)).parent_path(); // Init config - std::string configPath = (std::filesystem::current_path() / "cfg.json").string(); - config::Initialize(configPath); + config::Initialize((cheatDir / "cfg.json").string()); // Init logger auto& settings = cheat::feature::Settings::GetInstance(); if (settings.f_FileLogging) { - Logger::PrepareFileLogging((std::filesystem::current_path() / "logs").string()); + Logger::PrepareFileLogging((cheatDir / "logs").string()); Logger::SetLevel(Logger::Level::Trace, Logger::LoggerType::FileLogger); } @@ -55,5 +56,5 @@ void Run(HMODULE* phModule) cheat::Init(); - LOG_DEBUG("Config path is at %s", configPath.c_str()); + LOG_DEBUG("Config path is at %s", (cheatDir / "cfg.json").string().c_str()); } \ No newline at end of file