From 2da7f989d717e22f1df212d94865d93f86783cca Mon Sep 17 00:00:00 2001 From: Shatyuka <958182453@qq.com> Date: Sun, 11 Sep 2022 21:00:04 +0800 Subject: [PATCH] Fix non-ansi directory --- cheat-base/src/cheat-base/render/renderer.cpp | 4 ++-- cheat-base/src/cheat-base/util.cpp | 19 +++++++++++++++++++ cheat-base/src/cheat-base/util.h | 6 +++++- cheat-library/src/user/main.cpp | 1 + 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cheat-base/src/cheat-base/render/renderer.cpp b/cheat-base/src/cheat-base/render/renderer.cpp index 4233e24..98e81e6 100644 --- a/cheat-base/src/cheat-base/render/renderer.cpp +++ b/cheat-base/src/cheat-base/render/renderer.cpp @@ -209,7 +209,7 @@ namespace renderer ImGui_ImplDX12_CreateDeviceObjects(); ImGui::GetIO().ImeWindowHandle = window; - static const std::string imguiPath = (util::GetCurrentPath() / "imgui.ini").string(); + static const std::string imguiPath = (util::GetCurrentPathUTF8() / "imgui.ini").string(); ImGui::GetIO().IniFilename = imguiPath.c_str(); io.SetPlatformImeDataFn = nullptr; // F**king bug take 4 hours of my life } @@ -222,7 +222,7 @@ namespace renderer ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; - static const std::string imguiPath = (util::GetCurrentPath() / "imgui.ini").string(); + static const std::string imguiPath = (util::GetCurrentPathUTF8() / "imgui.ini").string(); io.IniFilename = imguiPath.c_str(); LoadCustomFont(); diff --git a/cheat-base/src/cheat-base/util.cpp b/cheat-base/src/cheat-base/util.cpp index 99ec8be..6864284 100644 --- a/cheat-base/src/cheat-base/util.cpp +++ b/cheat-base/src/cheat-base/util.cpp @@ -69,6 +69,14 @@ namespace util return std::filesystem::path(pathOut).parent_path().string(); } + std::string GetModulePathUTF8(HMODULE hModule /*= nullptr*/) + { + wchar_t pathOut[MAX_PATH] = {}; + GetModuleFileNameW(hModule, pathOut, MAX_PATH); + std::wstring_convert> conv; + return conv.to_bytes(std::filesystem::path(pathOut).parent_path().wstring()); + } + static std::filesystem::path _currentPath; void SetCurrentPath(const std::filesystem::path& current_path) { @@ -80,6 +88,17 @@ namespace util return _currentPath; } + static std::filesystem::path _currentPathUTF8; + void SetCurrentPathUTF8(const std::filesystem::path& current_path) + { + _currentPathUTF8 = current_path; + } + + std::filesystem::path GetCurrentPathUTF8() + { + return _currentPathUTF8; + } + 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 16deba9..0ba8644 100644 --- a/cheat-base/src/cheat-base/util.h +++ b/cheat-base/src/cheat-base/util.h @@ -38,10 +38,14 @@ namespace util int64_t GetCurrentTimeMillisec(); std::string GetModulePath(HMODULE hModule = nullptr); + std::string GetModulePathUTF8(HMODULE hModule = nullptr); - void SetCurrentPath(const std::filesystem::path& curren_path); + void SetCurrentPath(const std::filesystem::path& current_path); std::filesystem::path GetCurrentPath(); + void SetCurrentPathUTF8(const std::filesystem::path& current_path); + std::filesystem::path GetCurrentPathUTF8(); + 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 9afda85..8f5c62b 100644 --- a/cheat-library/src/user/main.cpp +++ b/cheat-library/src/user/main.cpp @@ -15,6 +15,7 @@ void Run(HMODULE* phModule) { ResourceLoader::SetModuleHandle(*phModule); util::SetCurrentPath(util::GetModulePath(*phModule)); + util::SetCurrentPathUTF8(util::GetModulePathUTF8(*phModule)); // Init config config::Initialize((util::GetCurrentPath() / "cfg.json").string());