From 4a10cf017928944cf771d007fdfebb33cd29494c Mon Sep 17 00:00:00 2001 From: EricPlayZ Date: Wed, 24 Apr 2024 04:00:58 +0300 Subject: [PATCH] Update core.cpp --- EGameTools/source/core.cpp | 49 ++++++++++++++------------------------ 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/EGameTools/source/core.cpp b/EGameTools/source/core.cpp index 2712637..b8f04aa 100644 --- a/EGameTools/source/core.cpp +++ b/EGameTools/source/core.cpp @@ -40,6 +40,8 @@ namespace Core { static bool createdConfigThread = false; int rendererAPI = 0; + DWORD gameVer = 0; + static void LoopHookRenderer() { while (true) { if (exiting) @@ -159,29 +161,6 @@ namespace Core { } } - uint16_t gameVer = 0; - static void LoopGetGameVer() { - - auto str = GamePH::GetCurrentGameVersionStr(); - auto end = str.c_str() + std::char_traits::length(str.c_str()); - - while (true) { - if (exiting) - return; - - uint16_t value; - std::from_chars(str.c_str(), end, value); - - if(value!=0) - gameVer = value; - - if (gameVer == 0) - continue; - - break; - } - } - void OnPostUpdate() { if (!createdConfigThread) { std::thread(Config::ConfigLoop).detach(); @@ -221,6 +200,20 @@ namespace Core { return EXCEPTION_CONTINUE_EXECUTION; }*/ + static void GameVersionCheck() { + try { + gameVer = GamePH::GetCurrentGameVersion(); + } catch (const std::exception& e) { + spdlog::error("Failed to get game version, EXCEPTION: {}", e.what()); + spdlog::error("This shouldn't happen! Contact developer."); + return; + } + + spdlog::info("Got game version: v{}", GamePH::GameVerToStr(gameVer)); + if (Core::gameVer != GAME_VER_COMPAT) { + spdlog::error("Please note that your game version has not been officially tested with this mod, therefore expect bugs, glitches or the mod to completely stop working. If so, please {}", Core::gameVer > GAME_VER_COMPAT ? "wait for a new patch." : "upgrade your game version to one that the mod supports."); + } + } DWORD64 WINAPI MainThread(HMODULE hModule) { EnableConsole(); InitLogger(); @@ -239,13 +232,7 @@ namespace Core { spdlog::info("Initialized MinHook"); spdlog::warn("Getting game version"); - std::thread([]() { - LoopGetGameVer(); - spdlog::info("Got game version: v{}", GamePH::GameVerToStr(gameVer)); - if (Core::gameVer != GAME_VER_COMPAT) { - spdlog::error("Please note that your game version has not been officially tested with this mod, therefore expect bugs, glitches or the mod to completely stop working. If so, please {}", Core::gameVer > GAME_VER_COMPAT ? "wait for a new patch." : "upgrade your game version to one that the mod supports."); - } - }).detach(); + GameVersionCheck(); spdlog::warn("Hooking DX11/DX12 renderer"); std::thread([]() { @@ -280,4 +267,4 @@ namespace Core { MH_Uninitialize(); spdlog::info("Unhooked everything"); } -} \ No newline at end of file +}