diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj
index 9bb8e5e..e0958d9 100644
--- a/DDrawCompat/DDrawCompat.vcxproj
+++ b/DDrawCompat/DDrawCompat.vcxproj
@@ -72,7 +72,7 @@
$(ProjectDir);$(IntDir)
- dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies)
+ dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;version.lib;winmm.lib;%(AdditionalDependencies)
DebugFull
true
$(IntDir)$(TargetName).lib
@@ -110,7 +110,7 @@
$(ProjectDir);$(IntDir)
- dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies)
+ dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;version.lib;winmm.lib;%(AdditionalDependencies)
DebugFull
true
$(IntDir)$(TargetName).lib
diff --git a/DDrawCompat/Win32/Version.cpp b/DDrawCompat/Win32/Version.cpp
index 8a01c39..b359489 100644
--- a/DDrawCompat/Win32/Version.cpp
+++ b/DDrawCompat/Win32/Version.cpp
@@ -2,7 +2,9 @@
#include
#include
+#include
#include
+#include
#include
@@ -10,6 +12,55 @@
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
+ 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
+ Result WINAPI getFileVersionInfoFunc(const Char* filename ,Params... params)
+ {
+ LOG_FUNC(Compat::g_origFuncName.c_str(), filename, params...);
+ fixVersionInfoFileName(filename);
+ return LOG_RESULT(CALL_ORIG_FUNC(func)(filename, params...));
+ }
+
+ template
+ Result WINAPI getFileVersionInfoFunc(DWORD flags, const Char* filename, Params... params)
+ {
+ LOG_FUNC(Compat::g_origFuncName.c_str(), filename, params...);
+ fixVersionInfoFileName(filename);
+ return LOG_RESULT(CALL_ORIG_FUNC(func)(flags, filename, params...));
+ }
+
DWORD WINAPI getVersion()
{
LOG_FUNC("GetVersion");
@@ -64,14 +115,53 @@ namespace
{
return getVersionInfo(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExW), "GetVersionExW");
}
+
+ template
+ bool hookVersionInfoFunc(const char* moduleName, const char* funcName)
+ {
+ HMODULE mod = GetModuleHandle(moduleName);
+ if (mod)
+ {
+ FARPROC func = Compat::getProcAddress(mod, funcName);
+ if (func)
+ {
+ Compat::hookFunction(moduleName, funcName, getFileVersionInfoFunc);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ template
+ void hookVersionInfoFunc(const char* funcName)
+ {
+ hookVersionInfoFunc("kernelbase", funcName) || hookVersionInfoFunc("version", funcName);
+ }
}
+namespace Compat
+{
+ template<> decltype(&GetFileVersionInfoExA) g_origFuncPtr = nullptr;
+ template<> decltype(&GetFileVersionInfoSizeExA) g_origFuncPtr = nullptr;
+}
+
+#define HOOK_VERSION_INFO_FUNCTION(func) hookVersionInfoFunc(#func)
+
namespace Win32
{
namespace Version
{
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, GetVersionExA, getVersionExA);
HOOK_FUNCTION(kernel32, GetVersionExW, getVersionExW);