Merge pull request #3 from 0x-FADED/version_stuff

- Fetch game version using Windows' API instead of using the game's function
This commit is contained in:
EricPlayZ
2024-04-24 04:11:11 +03:00
committed by GitHub
6 changed files with 56 additions and 42 deletions

View File

@ -262,7 +262,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>DbgHelp.lib;spdlog-mtd.lib;freetype-mtd.lib;libMinHook-x64-v141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>DbgHelp.lib;Version.lib;spdlog-mtd.lib;freetype-mtd.lib;libMinHook-x64-v141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OptimizeReferences>
</OptimizeReferences>
<EnableCOMDATFolding>
@ -298,7 +298,7 @@
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>source\spdlog\lib;source\ImGui\freetype\lib;source\MinHook\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>DbgHelp.lib;spdlog-mt.lib;freetype-mt.lib;libMinHook-x64-v141-mtd.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>DbgHelp.lib;Version.lib;spdlog-mt.lib;freetype-mt.lib;libMinHook-x64-v141-mtd.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary />
<AdditionalOptions>/NOIMPLIB /NOEXP %(AdditionalOptions)</AdditionalOptions>
</Link>

View File

@ -40,6 +40,8 @@ namespace Core {
static bool createdConfigThread = false;
int rendererAPI = 0;
DWORD gameVer = 0;
static void LoopHookRenderer() {
while (true) {
if (exiting)
@ -159,20 +161,6 @@ namespace Core {
}
}
DWORD64 gameVer = 0;
static void LoopGetGameVer() {
while (true) {
if (exiting)
return;
gameVer = GamePH::GetCurrentGameVersion();
if (!gameVer)
continue;
break;
}
}
void OnPostUpdate() {
if (!createdConfigThread) {
std::thread(Config::ConfigLoop).detach();
@ -212,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();
@ -230,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([]() {
@ -271,4 +267,4 @@ namespace Core {
MH_Uninitialize();
spdlog::info("Unhooked everything");
}
}
}

View File

@ -16,9 +16,9 @@
#define VK_MWHEELUP 0x101
#endif
constexpr auto MOD_VERSION_STR = "v1.1.2";
constexpr auto MOD_VERSION = 10102;
constexpr auto GAME_VER_COMPAT = 11502;
constexpr const char* MOD_VERSION_STR = "v1.1.3";
constexpr DWORD MOD_VERSION = 10103;
constexpr DWORD GAME_VER_COMPAT = 11600;
struct Key {
constexpr Key(std::string_view name, int code, ImGuiKey imGuiCode) : name(name), code(code), imGuiCode(imGuiCode) {}
@ -227,6 +227,6 @@ namespace Core {
extern bool exiting;
extern int rendererAPI;
extern DWORD64 gameVer;
extern DWORD gameVer;
extern void OnPostUpdate();
}
}

View File

@ -4,17 +4,36 @@
#include "gen_TPPModel.h"
namespace GamePH {
const DWORD64 GetCurrentGameVersion() {
DWORD64(*pGetCurrentGameVersion)() = (decltype(pGetCurrentGameVersion))Offsets::Get_GetCurrentGameVersion();
if (!pGetCurrentGameVersion)
const DWORD GetCurrentGameVersion() {
char exePath[MAX_PATH]{};
GetModuleFileNameA(GetModuleHandleA(nullptr), exePath, sizeof(exePath));
DWORD dummy{};
DWORD size = GetFileVersionInfoSizeA(exePath, &dummy);
if (!size)
return 0;
return pGetCurrentGameVersion();
std::vector<BYTE> data(size);
if (!GetFileVersionInfoA(exePath, 0, size, data.data()))
return 0;
VS_FIXEDFILEINFO* fileInfo = nullptr;
UINT fileInfoSize = 0;
if (!VerQueryValueA(data.data(), "\\", reinterpret_cast<void**>(&fileInfo), &fileInfoSize))
return 0;
if (fileInfo == nullptr)
return 0;
const DWORD major = HIWORD(fileInfo->dwFileVersionMS);
const DWORD minor = LOWORD(fileInfo->dwFileVersionMS);
const DWORD patch = HIWORD(fileInfo->dwFileVersionLS);
return major * 10000 + minor * 100 + patch;
}
const std::string GameVerToStr(DWORD64 version) {
DWORD64 major = version / 10000;
DWORD64 minor = (version / 100) % 100;
DWORD64 patch = version % 100;
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));
}
@ -55,4 +74,4 @@ namespace GamePH {
return pReloadJumps();
}
}
}

View File

@ -3,9 +3,9 @@
#include <basetsd.h>
namespace GamePH {
extern const DWORD64 GetCurrentGameVersion();
extern const std::string GameVerToStr(DWORD64 version);
extern const DWORD GetCurrentGameVersion();
extern const std::string GameVerToStr(DWORD version);
extern const std::string GetCurrentGameVersionStr();
extern void ShowTPPModel(bool showTPPModel);
extern bool ReloadJumps();
}
}

View File

@ -50,7 +50,6 @@ struct Offsets {
// Functions
AddOffset(ReadVideoSettings, "engine_x64_rwdi.dll", "48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC ?? 48 8B FA 48 8B D9 45 84 C0", Utils::SigScan::PatternType::Address, LPVOID)
AddOffset(MoveCameraFromForwardUpPos, "engine_x64_rwdi.dll", "48 89 5C 24 ?? 57 48 83 EC ?? 49 8B C1 48 8B F9", Utils::SigScan::PatternType::Address, LPVOID)
AddOffset(GetCurrentGameVersion, "gamedll_ph_x64_rwdi.dll", "B8 ?? ?? ?? ?? C3 CC CC CC CC CC CC CC CC CC CC 48 83 79", Utils::SigScan::PatternType::Address, LPVOID)
AddOffset(CalculateFreeCamCollision, "gamedll_ph_x64_rwdi.dll", "48 8B C4 55 53 56 57 48 8D A8 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 83 B9", Utils::SigScan::PatternType::Address, LPVOID)
//AddOffset(GetViewCamera, "engine_x64_rwdi.dll", "E8 [?? ?? ?? ?? 48 85 C0 74 28 48 8B C8", PatternType::RelativePointer, LPVOID)
AddOffset(CreatePlayerHealthModule, "gamedll_ph_x64_rwdi.dll", "48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 4C 8B F1 E8 ?? ?? ?? ?? 48 8D 05", Utils::SigScan::PatternType::Address, LPVOID)