From 48c5afc66fe215bcf29de5491cc523337024791a Mon Sep 17 00:00:00 2001 From: EricPlayZ Date: Wed, 24 Apr 2024 04:03:23 +0300 Subject: [PATCH] Update Other.cpp --- EGameTools/source/game/GamePH/Other.cpp | 73 ++++++++++--------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/EGameTools/source/game/GamePH/Other.cpp b/EGameTools/source/game/GamePH/Other.cpp index d137d1e..49f57cd 100644 --- a/EGameTools/source/game/GamePH/Other.cpp +++ b/EGameTools/source/game/GamePH/Other.cpp @@ -4,59 +4,46 @@ #include "gen_TPPModel.h" namespace GamePH { - const std::tuple GetCurrentGameVersion() { - WCHAR inBuf[MAX_PATH] = { 0 }; - GetModuleFileNameW(GetModuleHandleW(nullptr), inBuf, static_cast(std::size(inBuf))); - std::wstring fileStr = inBuf; + const DWORD GetCurrentGameVersion() { + char exePath[MAX_PATH]{}; + GetModuleFileNameA(GetModuleHandleA(nullptr), exePath, sizeof(exePath)); - DWORD verHandle; - DWORD verSz = GetFileVersionInfoSizeW(fileStr.data(), &verHandle); + DWORD dummy{}; + DWORD size = GetFileVersionInfoSizeA(exePath, &dummy); + if (!size) + return 0; - if (verSz != 0 && verHandle == 0) { + std::vector data(size); + if (!GetFileVersionInfoA(exePath, 0, size, data.data())) + return 0; - std::vector verData(verSz); + VS_FIXEDFILEINFO* fileInfo = nullptr; + UINT fileInfoSize = 0; + if (!VerQueryValueA(data.data(), "\\", reinterpret_cast(&fileInfo), &fileInfoSize)) + return 0; + if (fileInfo == nullptr) + return 0; - if (GetFileVersionInfoW(fileStr.data(), verHandle, verSz, verData.data())) { + const DWORD major = HIWORD(fileInfo->dwFileVersionMS); + const DWORD minor = LOWORD(fileInfo->dwFileVersionMS); + const DWORD patch = HIWORD(fileInfo->dwFileVersionLS); - LPVOID buffer; - UINT bufferLength; - - if (VerQueryValueW(verData.data(), L"\\", &buffer, &bufferLength) && bufferLength != 0) { - - VS_FIXEDFILEINFO* verInfo = reinterpret_cast(buffer); - - if (verInfo->dwSignature == 0xFEEF04BD) { - const auto major = (verInfo->dwFileVersionMS >> 16) & 0xFFFF; - const auto minor = verInfo->dwFileVersionMS & 0xFFFF; - const auto build = (verInfo->dwFileVersionLS >> 16) & 0xFFFF; - const auto revision = verInfo->dwFileVersionLS & 0xFFFF; - return { major, minor, build, revision }; - } - } - } - } - - return { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF }; + return major * 10000 + minor * 100 + patch; } + const std::string GameVerToStr(DWORD version) { + DWORD major = version / 10000; + DWORD minor = (version / 100) % 100; + DWORD patch = version % 100; + return std::string(std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch)); + } const std::string GetCurrentGameVersionStr() { - auto [major, minor, build, revision] = GetCurrentGameVersion(); - - if (major == 0xFFFF || minor == 0xFFFF || build == 0xFFFF || revision == 0xFFFF) + if (!GetCurrentGameVersion()) return "UNKNOWN"; - return std::string(std::to_string(major) + std::to_string(minor) + std::to_string(build) + std::to_string(revision)); + return GameVerToStr(GetCurrentGameVersion()); } - - const std::string GameVerToStr(uint16_t version) { - uint16_t major = version / 10000; - uint16_t minor = (version / 100) % 100; - uint16_t build = (version / 10) % 10; - uint16_t revision = version % 10; - - return std::string(std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(build) + "." + std::to_string(revision)); - } - + static DWORD64 ShowTPPModelFunc2(GameDI_PH* pGameDI_PH) { DWORD64(*pShowTPPModelFunc2)(LPVOID pGameDI_PH) = (decltype(pShowTPPModelFunc2))Offsets::Get_ShowTPPModelFunc2(); if (!pShowTPPModelFunc2) @@ -87,4 +74,4 @@ namespace GamePH { return pReloadJumps(); } -} \ No newline at end of file +}