diff --git a/cnc-ddraw.vcxproj b/cnc-ddraw.vcxproj index a4d025d..3f5d12d 100644 --- a/cnc-ddraw.vcxproj +++ b/cnc-ddraw.vcxproj @@ -27,6 +27,7 @@ + @@ -80,6 +81,7 @@ + diff --git a/cnc-ddraw.vcxproj.filters b/cnc-ddraw.vcxproj.filters index 0f07cb0..b15230e 100644 --- a/cnc-ddraw.vcxproj.filters +++ b/cnc-ddraw.vcxproj.filters @@ -168,6 +168,9 @@ Source Files + + Source Files + @@ -299,6 +302,9 @@ Header Files + + Header Files + diff --git a/inc/delay_imports.h b/inc/delay_imports.h new file mode 100644 index 0000000..19bbc23 --- /dev/null +++ b/inc/delay_imports.h @@ -0,0 +1,21 @@ +#ifndef DELAY_IMPORTS_H +#define DELAY_IMPORTS_H + +#define ThreadQuerySetWin32StartAddress 9 + +typedef NTSTATUS(WINAPI* RTLVERIFYVERSIONINFOPROC)(PRTL_OSVERSIONINFOEXW, ULONG, ULONGLONG); +typedef ULONGLONG(WINAPI* VERSETCONDITIONMASKPROC)(ULONGLONG, DWORD, BYTE); +typedef const char* (CDECL* WINE_GET_VERSIONPROC)(); +typedef void (CDECL* WINE_GET_HOST_VERSIONPROC)(const char** sysname, const char** release); +typedef NTSTATUS(WINAPI* NTQUERYINFORMATIONTHREADPROC)(HANDLE, LONG, PVOID, ULONG, PULONG); + +extern NTQUERYINFORMATIONTHREADPROC NtQueryInformationThread; +extern RTLVERIFYVERSIONINFOPROC RtlVerifyVersionInfo; +extern WINE_GET_VERSIONPROC wine_get_version; +extern WINE_GET_HOST_VERSIONPROC wine_get_host_version; + +extern VERSETCONDITIONMASKPROC VerSetConditionMaskProc; + +void imports_init(); + +#endif diff --git a/inc/versionhelpers.h b/inc/versionhelpers.h index fa542ac..6c4076d 100644 --- a/inc/versionhelpers.h +++ b/inc/versionhelpers.h @@ -33,7 +33,6 @@ #define VerSetConditionMask verhelp_set_mask #endif -void verhelp_init(); BOOL verhelp_verify_version(PRTL_OSVERSIONINFOEXW versionInfo, ULONG typeMask, ULONGLONG conditionMask); ULONGLONG verhelp_set_mask(ULONGLONG ConditionMask, DWORD TypeMask, BYTE Condition); const char* verhelp_wine_get_version(); diff --git a/src/delay_imports.c b/src/delay_imports.c new file mode 100644 index 0000000..3d02969 --- /dev/null +++ b/src/delay_imports.c @@ -0,0 +1,33 @@ +#include +#include "versionhelpers.h" + +typedef NTSTATUS(WINAPI* RTLVERIFYVERSIONINFOPROC)(PRTL_OSVERSIONINFOEXW, ULONG, ULONGLONG); +typedef ULONGLONG(WINAPI* VERSETCONDITIONMASKPROC)(ULONGLONG, DWORD, BYTE); +typedef const char* (CDECL* WINE_GET_VERSIONPROC)(); +typedef void (CDECL* WINE_GET_HOST_VERSIONPROC)(const char** sysname, const char** release); +typedef NTSTATUS(WINAPI* NTQUERYINFORMATIONTHREADPROC)(HANDLE, LONG, PVOID, ULONG, PULONG); + +NTQUERYINFORMATIONTHREADPROC NtQueryInformationThread; +RTLVERIFYVERSIONINFOPROC RtlVerifyVersionInfo; +WINE_GET_VERSIONPROC wine_get_version; +WINE_GET_HOST_VERSIONPROC wine_get_host_version; + +VERSETCONDITIONMASKPROC VerSetConditionMaskProc; + +void imports_init() +{ + HMODULE mod = GetModuleHandleA("ntdll.dll"); + if (mod) + { + NtQueryInformationThread = (NTQUERYINFORMATIONTHREADPROC)GetProcAddress(mod, "NtQueryInformationThread"); + RtlVerifyVersionInfo = (RTLVERIFYVERSIONINFOPROC)GetProcAddress(mod, "RtlVerifyVersionInfo"); + wine_get_version = (WINE_GET_VERSIONPROC)GetProcAddress(mod, "wine_get_version"); + wine_get_host_version = (WINE_GET_HOST_VERSIONPROC)GetProcAddress(mod, "wine_get_host_version"); + } + + mod = GetModuleHandleA("Kernel32.dll"); + if (mod) + { + VerSetConditionMaskProc = (VERSETCONDITIONMASKPROC)GetProcAddress(mod, "VerSetConditionMask"); + } +} diff --git a/src/dllmain.c b/src/dllmain.c index f3f98b1..03a6b5f 100644 --- a/src/dllmain.c +++ b/src/dllmain.c @@ -12,6 +12,7 @@ #include "indeo.h" #include "utils.h" #include "versionhelpers.h" +#include "delay_imports.h" #include "keyboard.h" @@ -33,7 +34,7 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) { g_ddraw_module = hDll; - verhelp_init(); + imports_init(); if (GetEnvironmentVariable("cnc_ddraw_config_init", NULL, 0)) { diff --git a/src/versionhelpers.c b/src/versionhelpers.c index 7c19528..9888184 100644 --- a/src/versionhelpers.c +++ b/src/versionhelpers.c @@ -1,33 +1,7 @@ #include #include "versionhelpers.h" +#include "delay_imports.h" -typedef NTSTATUS(WINAPI* RTLVERIFYVERSIONINFOPROC)(PRTL_OSVERSIONINFOEXW, ULONG, ULONGLONG); -typedef ULONGLONG(WINAPI* VERSETCONDITIONMASKPROC)(ULONGLONG, DWORD, BYTE); -typedef const char* (CDECL* WINE_GET_VERSIONPROC)(); -typedef void (CDECL* WINE_GET_HOST_VERSIONPROC)(const char** sysname, const char** release); - -static RTLVERIFYVERSIONINFOPROC RtlVerifyVersionInfo; -static VERSETCONDITIONMASKPROC VerSetConditionMaskProc; -static WINE_GET_VERSIONPROC wine_get_version; -static WINE_GET_HOST_VERSIONPROC wine_get_host_version; - -/* GetProcAddress is rather slow so we use a function to initialize it once on startup */ -void verhelp_init() -{ - HMODULE mod = GetModuleHandleA("ntdll.dll"); - if (mod) - { - RtlVerifyVersionInfo = (RTLVERIFYVERSIONINFOPROC)GetProcAddress(mod, "RtlVerifyVersionInfo"); - wine_get_version = (WINE_GET_VERSIONPROC)GetProcAddress(mod, "wine_get_version"); - wine_get_host_version = (WINE_GET_HOST_VERSIONPROC)GetProcAddress(mod, "wine_get_host_version"); - } - - mod = GetModuleHandleA("Kernel32.dll"); - if (mod) - { - VerSetConditionMaskProc = (VERSETCONDITIONMASKPROC)GetProcAddress(mod, "VerSetConditionMask"); - } -} BOOL verhelp_verify_version(PRTL_OSVERSIONINFOEXW versionInfo, ULONG typeMask, ULONGLONG conditionMask) {