mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
parent
f78a96a334
commit
4598013310
@ -72,7 +72,7 @@
|
|||||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;version.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
|
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
|
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
|
||||||
@ -110,7 +110,7 @@
|
|||||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;version.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
|
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
|
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include <Common/Hook.h>
|
#include <Common/Hook.h>
|
||||||
#include <Common/Log.h>
|
#include <Common/Log.h>
|
||||||
|
#include <Common/Path.h>
|
||||||
#include <Config/Settings/WinVersionLie.h>
|
#include <Config/Settings/WinVersionLie.h>
|
||||||
|
#include <Dll/Dll.h>
|
||||||
|
|
||||||
#include <Win32/Version.h>
|
#include <Win32/Version.h>
|
||||||
|
|
||||||
@ -10,6 +12,55 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
DWORD getModuleFileName(HMODULE mod, char* filename, DWORD size)
|
||||||
|
{
|
||||||
|
return GetModuleFileNameA(mod, filename, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD getModuleFileName(HMODULE mod, wchar_t* filename, DWORD size)
|
||||||
|
{
|
||||||
|
return GetModuleFileNameW(mod, filename, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
HMODULE getModuleHandle(const char* moduleName)
|
||||||
|
{
|
||||||
|
return GetModuleHandleA(moduleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
HMODULE getModuleHandle(const wchar_t* moduleName)
|
||||||
|
{
|
||||||
|
return GetModuleHandleW(moduleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Char>
|
||||||
|
void fixVersionInfoFileName(const Char*& filename)
|
||||||
|
{
|
||||||
|
if (getModuleHandle(filename) == Dll::g_currentModule)
|
||||||
|
{
|
||||||
|
static Char path[MAX_PATH];
|
||||||
|
if (0 != getModuleFileName(Dll::g_origDDrawModule, path, MAX_PATH))
|
||||||
|
{
|
||||||
|
filename = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <auto func, typename Result, typename Char, typename... Params>
|
||||||
|
Result WINAPI getFileVersionInfoFunc(const Char* filename ,Params... params)
|
||||||
|
{
|
||||||
|
LOG_FUNC(Compat::g_origFuncName<func>.c_str(), filename, params...);
|
||||||
|
fixVersionInfoFileName(filename);
|
||||||
|
return LOG_RESULT(CALL_ORIG_FUNC(func)(filename, params...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <auto func, typename Result, typename Char, typename... Params>
|
||||||
|
Result WINAPI getFileVersionInfoFunc(DWORD flags, const Char* filename, Params... params)
|
||||||
|
{
|
||||||
|
LOG_FUNC(Compat::g_origFuncName<func>.c_str(), filename, params...);
|
||||||
|
fixVersionInfoFileName(filename);
|
||||||
|
return LOG_RESULT(CALL_ORIG_FUNC(func)(flags, filename, params...));
|
||||||
|
}
|
||||||
|
|
||||||
DWORD WINAPI getVersion()
|
DWORD WINAPI getVersion()
|
||||||
{
|
{
|
||||||
LOG_FUNC("GetVersion");
|
LOG_FUNC("GetVersion");
|
||||||
@ -64,14 +115,53 @@ namespace
|
|||||||
{
|
{
|
||||||
return getVersionInfo<OSVERSIONINFOEXW>(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExW), "GetVersionExW");
|
return getVersionInfo<OSVERSIONINFOEXW>(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExW), "GetVersionExW");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <auto origFunc>
|
||||||
|
bool hookVersionInfoFunc(const char* moduleName, const char* funcName)
|
||||||
|
{
|
||||||
|
HMODULE mod = GetModuleHandle(moduleName);
|
||||||
|
if (mod)
|
||||||
|
{
|
||||||
|
FARPROC func = Compat::getProcAddress(mod, funcName);
|
||||||
|
if (func)
|
||||||
|
{
|
||||||
|
Compat::hookFunction<origFunc>(moduleName, funcName, getFileVersionInfoFunc<origFunc>);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <auto origFunc>
|
||||||
|
void hookVersionInfoFunc(const char* funcName)
|
||||||
|
{
|
||||||
|
hookVersionInfoFunc<origFunc>("kernelbase", funcName) || hookVersionInfoFunc<origFunc>("version", funcName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Compat
|
||||||
|
{
|
||||||
|
template<> decltype(&GetFileVersionInfoExA) g_origFuncPtr<GetFileVersionInfoExA> = nullptr;
|
||||||
|
template<> decltype(&GetFileVersionInfoSizeExA) g_origFuncPtr<GetFileVersionInfoSizeExA> = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HOOK_VERSION_INFO_FUNCTION(func) hookVersionInfoFunc<func>(#func)
|
||||||
|
|
||||||
namespace Win32
|
namespace Win32
|
||||||
{
|
{
|
||||||
namespace Version
|
namespace Version
|
||||||
{
|
{
|
||||||
void installHooks()
|
void installHooks()
|
||||||
{
|
{
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoA);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoW);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoExA);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoExW);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeA);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeW);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeExA);
|
||||||
|
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeExW);
|
||||||
|
|
||||||
HOOK_FUNCTION(kernel32, GetVersion, getVersion);
|
HOOK_FUNCTION(kernel32, GetVersion, getVersion);
|
||||||
HOOK_FUNCTION(kernel32, GetVersionExA, getVersionExA);
|
HOOK_FUNCTION(kernel32, GetVersionExA, getVersionExA);
|
||||||
HOOK_FUNCTION(kernel32, GetVersionExW, getVersionExW);
|
HOOK_FUNCTION(kernel32, GetVersionExW, getVersionExW);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user