Index: Installer/dxgl.nsi |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "DXGL ${PRODUCT_VERSION} Installer"
|
86 | 86 | VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${PRODUCT_VERSION}"
|
87 | 87 | VIAddVersionKey /LANG=${LANG_ENGLISH} "InternalName" "DXGL"
|
88 | Â | -VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © 2011-2014 William Feely"
|
 | 88 | +VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © 2011-2015 William Feely"
|
89 | 89 | VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "DXGL-${PRODUCT_VERSION}-win32.exe"
|
90 | 90 | VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "DXGL"
|
91 | 91 | VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "${PRODUCT_VERSION}"
|
Index: ddraw/ddraw.cpp |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2011-2014 William Feely
|
 | 3 | +// Copyright (C) 2011-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -25,8 +25,8 @@ |
26 | 26 | #include "glDirectDrawClipper.h"
|
27 | 27 | #include "timer.h"
|
28 | 28 | #include "glRenderer.h"
|
 | 29 | +#include "hooks.h"
|
29 | 30 | #include <intrin.h>
|
30 | Â | -#include <tlhelp32.h>
|
31 | 31 |
|
32 | 32 | DXGLCFG dxglcfg;
|
33 | 33 | DWORD gllock = 0;
|
— | — | @@ -109,39 +109,6 @@ |
110 | 110 | }
|
111 | 111 |
|
112 | 112 | /**
|
113 | Â | - * This function is used by DirectDrawCreate to test if opengl32.dll is calling
|
114 | Â | - * these functions. If so, DirectDrawCreate will load the system ddraw.dll and
|
115 | Â | - * call its DirectDrawCreate function.
|
116 | Â | - * @param returnaddress
|
117 | Â | - * The address to evaluate whether it is from opengl32.dll or not.
|
118 | Â | - * The return address of the calling function may be obtained with the
|
119 | Â | - * _ReturnAddress() function.
|
120 | Â | - * @return
|
121 | Â | - * Returns nonzero if the address points to opengl32.dll, otherwise returns zero.
|
122 | Â | - */
|
123 | Â | -BOOL IsCallerOpenGL(void *returnaddress)
|
124 | Â | -{
|
125 | Â | - TRACE_ENTER(1,14,returnaddress);
|
126 | Â | - int isgl = 0;
|
127 | Â | - MODULEENTRY32 modentry = {0};
|
128 | Â | - HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0);
|
129 | Â | - modentry.dwSize = sizeof(MODULEENTRY32);
|
130 | Â | - Module32First(hSnapshot,&modentry);
|
131 | Â | - do
|
132 | Â | - {
|
133 | Â | - if((modentry.modBaseAddr <= returnaddress) &&
|
134 | Â | - (modentry.modBaseAddr+modentry.modBaseSize > returnaddress))
|
135 | Â | - {
|
136 | Â | - if(!_tcsicmp(modentry.szModule,_T("opengl32.dll"))) isgl=1;
|
137 | Â | - break;
|
138 | Â | - }
|
139 | Â | - } while(Module32Next(hSnapshot,&modentry));
|
140 | Â | - CloseHandle(hSnapshot);
|
141 | Â | - TRACE_EXIT(22,isgl);
|
142 | Â | - return isgl;
|
143 | Â | -}
|
144 | Â | -
|
145 | Â | -/**
|
146 | 113 | * Creates an IDirectDraw compatible interface to the DXGL graphics library.
|
147 | 114 | * @param lpGUID
|
148 | 115 | * Address to the GUID of the device to be created, or NULL for the current
|
Index: ddraw/ddraw.rc |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2011-2014 William Feely
|
 | 3 | +// Copyright (C) 2011-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | VALUE "FileDescription", "DXGL DDraw Library"
|
66 | 66 | VALUE "FileVersion", DXGLVERSTRING
|
67 | 67 | VALUE "InternalName", "DXGL"
|
68 | Â | - VALUE "LegalCopyright", "Copyright (C) 2011-2014 William Feely"
|
 | 68 | + VALUE "LegalCopyright", "Copyright (C) 2011-2015 William Feely"
|
69 | 69 | VALUE "OriginalFilename", "DDraw.dll"
|
70 | 70 | VALUE "ProductName", "DXGL"
|
71 | 71 | VALUE "ProductVersion", DXGLVERSTRING
|
Index: ddraw/ddraw.vcxproj |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | <SubSystem>Windows</SubSystem>
|
122 | 122 | <GenerateDebugInformation>true</GenerateDebugInformation>
|
123 | 123 | <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
|
124 | Â | - <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
 | 124 | + <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
125 | 125 | </Link>
|
126 | 126 | <PreBuildEvent>
|
127 | 127 | <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
|
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | <SubSystem>Windows</SubSystem>
|
145 | 145 | <GenerateDebugInformation>true</GenerateDebugInformation>
|
146 | 146 | <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
|
147 | Â | - <AdditionalDependencies>$(OutDir)..\Debug\cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
 | 147 | + <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)..\Debug\cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
148 | 148 | </Link>
|
149 | 149 | <PreBuildEvent>
|
150 | 150 | <Command>"$(OutDir)..\Debug\buildtool.exe" makeheader $(SolutionDir)common</Command>
|
— | — | @@ -166,7 +166,7 @@ |
167 | 167 | <SubSystem>Windows</SubSystem>
|
168 | 168 | <GenerateDebugInformation>true</GenerateDebugInformation>
|
169 | 169 | <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
|
170 | Â | - <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
 | 170 | + <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
171 | 171 | <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
172 | 172 | </Link>
|
173 | 173 | <PreBuildEvent>
|
— | — | @@ -190,7 +190,7 @@ |
191 | 191 | <SubSystem>Windows</SubSystem>
|
192 | 192 | <GenerateDebugInformation>true</GenerateDebugInformation>
|
193 | 193 | <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
|
194 | Â | - <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
 | 194 | + <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
195 | 195 | <ImportLibrary>$(OutDir)ddraw.lib</ImportLibrary>
|
196 | 196 | </Link>
|
197 | 197 | <PostBuildEvent />
|
— | — | @@ -221,7 +221,7 @@ |
222 | 222 | <OptimizeReferences>true</OptimizeReferences>
|
223 | 223 | <SetChecksum>true</SetChecksum>
|
224 | 224 | <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
|
225 | Â | - <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
 | 225 | + <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
226 | 226 | </Link>
|
227 | 227 | <PreBuildEvent>
|
228 | 228 | <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
|
— | — | @@ -249,7 +249,7 @@ |
250 | 250 | <OptimizeReferences>true</OptimizeReferences>
|
251 | 251 | <SetChecksum>true</SetChecksum>
|
252 | 252 | <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
|
253 | Â | - <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
 | 253 | + <AdditionalDependencies>$(OutDir)libMinHook.x86.lib;$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
254 | 254 | <ImportLibrary>$(OutDir)ddraw.lib</ImportLibrary>
|
255 | 255 | </Link>
|
256 | 256 | <PostBuildEvent />
|
Index: ddraw/dllmain.cpp |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2011 William Feely
|
 | 3 | +// Copyright (C) 2011-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -17,6 +17,7 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 | #include "ddraw.h"
|
 | 21 | +#include "hooks.h"
|
21 | 22 | ATOM WindowClass = NULL;
|
22 | 23 | CRITICAL_SECTION dll_cs = {NULL,0,0,NULL,NULL,0};
|
23 | 24 | BOOL APIENTRY DllMain( HMODULE hModule,
|
— | — | @@ -28,11 +29,19 @@ |
29 | 30 | {
|
30 | 31 | case DLL_PROCESS_ATTACH:
|
31 | 32 | if(!dll_cs.LockCount && !dll_cs.OwningThread) InitializeCriticalSection(&dll_cs);
|
 | 33 | + if (!hook_cs.LockCount && !hook_cs.OwningThread) InitializeCriticalSection(&hook_cs);
|
 | 34 | + InitHooks();
|
32 | 35 | GetCurrentConfig(&dxglcfg, true);
|
33 | 36 | break;
|
34 | 37 | case DLL_THREAD_ATTACH:
|
35 | 38 | case DLL_THREAD_DETACH:
|
 | 39 | + break;
|
36 | 40 | case DLL_PROCESS_DETACH:
|
 | 41 | + ShutdownHooks();
|
 | 42 | + DeleteCriticalSection(&hook_cs);
|
 | 43 | + ZeroMemory(&hook_cs, sizeof(CRITICAL_SECTION));
|
 | 44 | + DeleteCriticalSection(&dll_cs);
|
 | 45 | + ZeroMemory(&dll_cs, sizeof(CRITICAL_SECTION));
|
37 | 46 | break;
|
38 | 47 | }
|
39 | 48 | return TRUE;
|
Index: ddraw/hooks.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2014 William Feely
|
 | 3 | +// Copyright (C) 2014-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -17,35 +17,245 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 | #include "hooks.h"
|
 | 21 | +#include <tlhelp32.h>
|
 | 22 | +#include "../minhook-1.3/include/MinHook.h"
|
21 | 23 |
|
22 | 24 | const TCHAR *wndprop = _T("DXGLWndProc");
|
23 | 25 | const TCHAR *wndpropdd7 = _T("DXGLWndDD7");
|
 | 26 | +static HWND_HOOK *hwndhooks = NULL;
|
 | 27 | +static int hwndhook_count = 0;
|
 | 28 | +static int hwndhook_max = 0;
|
 | 29 | +CRITICAL_SECTION hook_cs = { NULL, 0, 0, NULL, NULL, 0 };
|
 | 30 | +static BOOL hooks_init = FALSE;
|
24 | 31 |
|
 | 32 | +LONG(WINAPI *_SetWindowLongA)(HWND hWnd, int nIndex, LONG dwNewLong) = NULL;
|
 | 33 | +LONG(WINAPI *_SetWindowLongW)(HWND hWnd, int nIndex, LONG dwNewLong) = NULL;
|
 | 34 | +LONG(WINAPI *_GetWindowLongA)(HWND hWnd, int nIndex) = NULL;
|
 | 35 | +LONG(WINAPI *_GetWindowLongW)(HWND hWnd, int nIndex) = NULL;
|
 | 36 | +#ifdef _M_X64
|
 | 37 | +LONG_PTR(WINAPI *_SetWindowLongPtrA)(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
|
 | 38 | +LONG_PTR(WINAPI *_SetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
|
 | 39 | +LONG_PTR(WINAPI *_GetWindowLongPtrA)(HWND hWnd, int nIndex) = NULL;
|
 | 40 | +LONG_PTR(WINAPI *_GetWindowLongPtrW)(HWND hWnd, int nIndex) = NULL;
|
 | 41 | +#else
|
 | 42 | +#define _SetWindowLongPtrA _SetWindowLongA
|
 | 43 | +#define _SetWindowLongPtrW _SetWindowLongW
|
 | 44 | +#define _GetWindowLongPtrA _GetWindowLongA
|
 | 45 | +#define _GetWindowLongPtrW _GetWindowLongW
|
 | 46 | +#endif
|
 | 47 | +UINT wndhook_count = 0;
|
25 | 48 |
|
 | 49 | +int hwndhookcmp(const HWND_HOOK *key, const HWND_HOOK *cmp)
|
 | 50 | +{
|
 | 51 | + if (!cmp->hwnd) return 1; // Put blanks at end for cleanup
|
 | 52 | + if (key->hwnd < cmp->hwnd) return -1;
|
 | 53 | + if (key->hwnd == cmp->hwnd) return 0;
|
 | 54 | + if (key->hwnd > cmp->hwnd) return 1;
|
 | 55 | +}
|
 | 56 | +
|
 | 57 | +void SetHookWndProc(HWND hWnd, WNDPROC wndproc, LPDIRECTDRAW7 lpDD7, BOOL proconly, BOOL delete)
|
 | 58 | +{
|
 | 59 | + HWND_HOOK cmphook;
|
 | 60 | + HWND_HOOK *hook;
|
 | 61 | + cmphook.hwnd = hWnd;
|
 | 62 | + if (!hwndhooks)
|
 | 63 | + {
|
 | 64 | + hwndhooks = (HWND_HOOK*)malloc(16 * sizeof(HWND_HOOK));
|
 | 65 | + hwndhook_count = 0;
|
 | 66 | + hwndhook_max = 16;
|
 | 67 | + }
|
 | 68 | + hook = bsearch(&cmphook, hwndhooks, hwndhook_count, sizeof(HWND_HOOK), hwndhookcmp);
|
 | 69 | + if (delete)
|
 | 70 | + {
|
 | 71 | + if (!hook) return;
|
 | 72 | + hook->hwnd = NULL;
|
 | 73 | + hook->wndproc = NULL;
|
 | 74 | + hook->lpDD7 = NULL;
|
 | 75 | + qsort(hwndhooks, hwndhook_count, sizeof(HWND_HOOK), hwndhookcmp);
|
 | 76 | + hwndhook_count--;
|
 | 77 | + return;
|
 | 78 | + }
|
 | 79 | + if (!hook)
|
 | 80 | + {
|
 | 81 | + hwndhook_count++;
|
 | 82 | + if (hwndhook_count >= hwndhook_max)
|
 | 83 | + {
|
 | 84 | + hwndhook_max += 16;
|
 | 85 | + hwndhooks = (HWND_HOOK*)realloc(hwndhooks, hwndhook_max*sizeof(HWND_HOOK));
|
 | 86 | + }
|
 | 87 | + hook = &hwndhooks[hwndhook_count - 1];
|
 | 88 | + }
|
 | 89 | + hook->hwnd = hWnd;
|
 | 90 | + hook->wndproc = wndproc;
|
 | 91 | + if (!proconly) hook->lpDD7 = lpDD7;
|
 | 92 | + qsort(hwndhooks, hwndhook_count, sizeof(HWND_HOOK), hwndhookcmp);
|
 | 93 | +}
|
 | 94 | +
|
 | 95 | +HWND_HOOK *GetWndHook(HWND hWnd)
|
 | 96 | +{
|
 | 97 | + HWND_HOOK cmphook;
|
 | 98 | + cmphook.hwnd = hWnd;
|
 | 99 | + if (!hwndhooks) return NULL;
|
 | 100 | + return bsearch(&cmphook, hwndhooks, hwndhook_count, sizeof(HWND_HOOK), hwndhookcmp);
|
 | 101 | +}
|
 | 102 | +
|
 | 103 | +/**
|
 | 104 | +* This function is used by DirectDrawCreate to test if opengl32.dll is calling
|
 | 105 | +* these functions. If so, DirectDrawCreate will load the system ddraw.dll and
|
 | 106 | +* call its DirectDrawCreate function.
|
 | 107 | +* @param returnaddress
|
 | 108 | +* The address to evaluate whether it is from opengl32.dll or not.
|
 | 109 | +* The return address of the calling function may be obtained with the
|
 | 110 | +* _ReturnAddress() function.
|
 | 111 | +* @return
|
 | 112 | +* Returns nonzero if the address points to opengl32.dll, otherwise returns zero.
|
 | 113 | +*/
|
 | 114 | +BOOL IsCallerOpenGL(void *returnaddress)
|
 | 115 | +{
|
 | 116 | + HANDLE hSnapshot;
|
 | 117 | + int isgl = 0;
|
 | 118 | + MODULEENTRY32 modentry = { 0 };
|
 | 119 | + TRACE_ENTER(1, 14, returnaddress);
|
 | 120 | + hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
|
 | 121 | + modentry.dwSize = sizeof(MODULEENTRY32);
|
 | 122 | + Module32First(hSnapshot, &modentry);
|
 | 123 | + do
|
 | 124 | + {
|
 | 125 | + if ((modentry.modBaseAddr <= returnaddress) &&
|
 | 126 | + (modentry.modBaseAddr + modentry.modBaseSize > returnaddress))
|
 | 127 | + {
|
 | 128 | + if (!_tcsicmp(modentry.szModule, _T("opengl32.dll"))) isgl = 1;
|
 | 129 | + break;
|
 | 130 | + }
|
 | 131 | + } while (Module32Next(hSnapshot, &modentry));
|
 | 132 | + CloseHandle(hSnapshot);
|
 | 133 | + TRACE_EXIT(22, isgl);
|
 | 134 | + return isgl;
|
 | 135 | +}
|
 | 136 | +
|
 | 137 | +
|
26 | 138 | LRESULT CALLBACK nullwndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
27 | 139 | {
|
28 | 140 | return 0;
|
29 | 141 | }
|
30 | 142 |
|
 | 143 | +void InitHooks()
|
 | 144 | +{
|
 | 145 | + if (hooks_init) return;
|
 | 146 | + EnterCriticalSection(&hook_cs);
|
 | 147 | + wndhook_count = 0;
|
 | 148 | + MH_Initialize();
|
 | 149 | + MH_CreateHook(&SetWindowLongA, HookSetWindowLongA, &_SetWindowLongA);
|
 | 150 | + MH_CreateHook(&SetWindowLongW, HookSetWindowLongW, &_SetWindowLongW);
|
 | 151 | + MH_CreateHook(&GetWindowLongA, HookGetWindowLongA, &_GetWindowLongA);
|
 | 152 | + MH_CreateHook(&GetWindowLongW, HookGetWindowLongW, &_GetWindowLongW);
|
 | 153 | +#ifdef _M_X64
|
 | 154 | + MH_CreateHook(&SetWindowLongPtrA, HookSetWindowLongPtrA, &_SetWindowLongPtrA);
|
 | 155 | + MH_CreateHook(&SetWindowLongPtrW, HookSetWindowLongPtrW, &_SetWindowLongPtrW);
|
 | 156 | + MH_CreateHook(&GetWindowLongPtrA, HookGetWindowLongPtrA, &_GetWindowLongPtrA);
|
 | 157 | + MH_CreateHook(&GetWindowLongPtrW, HookGetWindowLongPtrW, &_GetWindowLongPtrW);
|
 | 158 | +#endif
|
 | 159 | + hooks_init = TRUE;
|
 | 160 | + LeaveCriticalSection(&hook_cs);
|
 | 161 | +}
|
 | 162 | +
|
 | 163 | +void ShutdownHooks()
|
 | 164 | +{
|
 | 165 | + if (!hooks_init) return;
|
 | 166 | + EnterCriticalSection(&hook_cs);
|
 | 167 | + MH_RemoveHook(&SetWindowLongA);
|
 | 168 | + MH_RemoveHook(&SetWindowLongW);
|
 | 169 | + MH_RemoveHook(&GetWindowLongA);
|
 | 170 | + MH_RemoveHook(&GetWindowLongW);
|
 | 171 | +#ifdef _M_X64
|
 | 172 | + MH_RemoveHook(&SetWindowLongPtrA);
|
 | 173 | + MH_RemoveHook(&SetWindowLongPtrW);
|
 | 174 | + MH_RemoveHook(&GetWindowLongPtrA);
|
 | 175 | + MH_RemoveHook(&GetWindowLongPtrW);
|
 | 176 | +#endif
|
 | 177 | + MH_Uninitialize();
|
 | 178 | + wndhook_count = 0;
|
 | 179 | + hooks_init = FALSE;
|
 | 180 | + LeaveCriticalSection(&hook_cs);
|
 | 181 | +}
|
 | 182 | +
|
 | 183 | +void EnableWindowLongHooks()
|
 | 184 | +{
|
 | 185 | + EnterCriticalSection(&hook_cs);
|
 | 186 | + wndhook_count++;
|
 | 187 | + if (wndhook_count == 1)
|
 | 188 | + {
|
 | 189 | + MH_EnableHook(&SetWindowLongA);
|
 | 190 | + MH_EnableHook(&SetWindowLongW);
|
 | 191 | + MH_EnableHook(&GetWindowLongA);
|
 | 192 | + MH_EnableHook(&GetWindowLongW);
|
 | 193 | +#ifdef _M_X64
|
 | 194 | + MH_EnableHook(&SetWindowLongPtrA);
|
 | 195 | + MH_EnableHook(&SetWindowLongPtrW);
|
 | 196 | + MH_EnableHook(&GetWindowLongPtrA);
|
 | 197 | + MH_EnableHook(&GetWindowLongPtrW);
|
 | 198 | +#endif
|
 | 199 | + }
|
 | 200 | + LeaveCriticalSection(&hook_cs);
|
 | 201 | +}
|
 | 202 | +
|
 | 203 | +void DisableWindowLongHooks(BOOL force)
|
 | 204 | +{
|
 | 205 | + if (!wndhook_count) return;
|
 | 206 | + EnterCriticalSection(&hook_cs);
|
 | 207 | + wndhook_count--;
|
 | 208 | + if (force) wndhook_count = 0;
|
 | 209 | + if (!wndhook_count)
|
 | 210 | + {
|
 | 211 | + MH_DisableHook(&SetWindowLongA);
|
 | 212 | + MH_DisableHook(&SetWindowLongW);
|
 | 213 | + MH_DisableHook(&GetWindowLongA);
|
 | 214 | + MH_DisableHook(&GetWindowLongW);
|
 | 215 | +#ifdef _M_X64
|
 | 216 | + MH_DisableHook(&SetWindowLongPtrA);
|
 | 217 | + MH_DisableHook(&SetWindowLongPtrW);
|
 | 218 | + MH_DisableHook(&GetWindowLongPtrA);
|
 | 219 | + MH_DisableHook(&GetWindowLongPtrW);
|
 | 220 | +#endif
|
 | 221 | + }
|
 | 222 | + LeaveCriticalSection(&hook_cs);
|
 | 223 | +}
|
 | 224 | +
|
31 | 225 | void InstallDXGLFullscreenHook(HWND hWnd, LPDIRECTDRAW7 lpDD7)
|
32 | 226 | {
|
33 | Â | - HANDLE wndproc = GetWindowLongPtr(hWnd, GWLP_WNDPROC);
|
34 | Â | - if (GetProp(hWnd, wndprop)) return;
|
35 | Â | - SetProp(hWnd, wndprop, wndproc);
|
36 | Â | - SetProp(hWnd, wndpropdd7, lpDD7);
|
37 | Â | - SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)DXGLWndHookProc);
|
 | 227 | + WNDPROC wndproc;
|
 | 228 | + HWND_HOOK *wndhook = GetWndHook(hWnd);
|
 | 229 | + if (wndhook)
|
 | 230 | + {
|
 | 231 | + if (lpDD7) wndhook->lpDD7 = lpDD7;
|
 | 232 | + return;
|
 | 233 | + }
|
 | 234 | + wndproc = _GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
|
 | 235 | + SetHookWndProc(hWnd, wndproc, lpDD7, FALSE, FALSE);
|
 | 236 | + _SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)DXGLWndHookProc);
|
 | 237 | + EnableWindowLongHooks();
|
38 | 238 | }
|
39 | 239 | void UninstallDXGLFullscreenHook(HWND hWnd)
|
40 | 240 | {
|
41 | Â | - if (!GetProp(hWnd, wndprop)) return;
|
42 | Â | - SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)GetProp(hWnd, wndprop));
|
43 | Â | - RemoveProp(hWnd, wndprop);
|
44 | Â | - RemoveProp(hWnd, wndpropdd7);
|
 | 241 | + HWND_HOOK *wndhook = GetWndHook(hWnd);
|
 | 242 | + if (!wndhook) return;
|
 | 243 | + _SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)wndhook->wndproc);
|
 | 244 | + SetHookWndProc(hWnd, NULL, NULL, FALSE, TRUE);
|
 | 245 | + DisableWindowLongHooks(FALSE);
|
45 | 246 | }
|
46 | 247 | LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
47 | 248 | {
|
48 | Â | - WNDPROC parentproc = (WNDPROC)GetProp(hWnd, wndprop);
|
49 | Â | - LPDIRECTDRAW7 lpDD7 = GetProp(hWnd, wndpropdd7);
|
 | 249 | + WNDPROC parentproc;
|
 | 250 | + HWND_HOOK *wndhook;
|
 | 251 | + LPDIRECTDRAW7 lpDD7;
|
 | 252 | + wndhook = GetWndHook(hWnd);
|
 | 253 | + if (!wndhook)
|
 | 254 | + {
|
 | 255 | + parentproc = nullwndproc;
|
 | 256 | + lpDD7 = NULL;
|
 | 257 | + }
|
 | 258 | + parentproc = wndhook->wndproc;
|
 | 259 | + lpDD7 = wndhook->lpDD7;
|
50 | 260 | switch (uMsg)
|
51 | 261 | {
|
52 | 262 | case WM_DESTROY:
|
— | — | @@ -61,3 +271,83 @@ |
62 | 272 | }
|
63 | 273 | return CallWindowProc(parentproc, hWnd, uMsg, wParam, lParam);
|
64 | 274 | }
|
 | 275 | +
|
 | 276 | +
|
 | 277 | +LONG WINAPI HookSetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLong)
|
 | 278 | +{
|
 | 279 | + LONG oldproc;
|
 | 280 | + HWND_HOOK *wndhook;
|
 | 281 | + if (nIndex != GWL_WNDPROC) return _SetWindowLongA(hWnd, nIndex, dwNewLong);
|
 | 282 | + wndhook = GetWndHook(hWnd);
|
 | 283 | + if (!wndhook) return _SetWindowLongA(hWnd, nIndex, dwNewLong);
|
 | 284 | + oldproc = (LONG)wndhook->wndproc;
|
 | 285 | + wndhook->wndproc = (WNDPROC)dwNewLong;
|
 | 286 | + return oldproc;
|
 | 287 | +}
|
 | 288 | +LONG WINAPI HookSetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong)
|
 | 289 | +{
|
 | 290 | + LONG oldproc;
|
 | 291 | + HWND_HOOK *wndhook;
|
 | 292 | + if (nIndex != GWL_WNDPROC) return _SetWindowLongW(hWnd, nIndex, dwNewLong);
|
 | 293 | + wndhook = GetWndHook(hWnd);
|
 | 294 | + if (!wndhook) return _SetWindowLongW(hWnd, nIndex, dwNewLong);
|
 | 295 | + oldproc = (LONG)wndhook->wndproc;
|
 | 296 | + wndhook->wndproc = (WNDPROC)dwNewLong;
|
 | 297 | + return oldproc;
|
 | 298 | +}
|
 | 299 | +LONG WINAPI HookGetWindowLongA(HWND hWnd, int nIndex)
|
 | 300 | +{
|
 | 301 | + HWND_HOOK *wndhook;
|
 | 302 | + if (nIndex != GWL_WNDPROC) return _GetWindowLongA(hWnd, nIndex);
|
 | 303 | + wndhook = GetWndHook(hWnd);
|
 | 304 | + if (!wndhook) return _GetWindowLongA(hWnd, nIndex);
|
 | 305 | + return (LONG)wndhook->wndproc;
|
 | 306 | +}
|
 | 307 | +LONG WINAPI HookGetWindowLongW(HWND hWnd, int nIndex)
|
 | 308 | +{
|
 | 309 | + HWND_HOOK *wndhook;
|
 | 310 | + if (nIndex != GWL_WNDPROC) return _GetWindowLongW(hWnd, nIndex);
|
 | 311 | + wndhook = GetWndHook(hWnd);
|
 | 312 | + if (!wndhook) return _GetWindowLongW(hWnd, nIndex);
|
 | 313 | + return (LONG)wndhook->wndproc;
|
 | 314 | +}
|
 | 315 | +#ifdef _M_X64
|
 | 316 | +LONG_PTR WINAPI HookSetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
|
 | 317 | +{
|
 | 318 | + LONG_PTR oldproc;
|
 | 319 | + HWND_HOOK *wndhook;
|
 | 320 | + if (nIndex != GWLP_WNDPROC) return _SetWindowLongPtrA(hWnd, nIndex, dwNewLong);
|
 | 321 | + wndhook = GetWndHook(hWnd);
|
 | 322 | + if (!wndhook) return _SetWindowLongPtrA(hWnd, nIndex, dwNewLong);
|
 | 323 | + oldproc = (LONG_PTR)wndhook->wndproc;
|
 | 324 | + wndhook->wndproc = (WNDPROC)dwNewLong;
|
 | 325 | + return oldproc;
|
 | 326 | +}
|
 | 327 | +LONG_PTR WINAPI HookSetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
|
 | 328 | +{
|
 | 329 | + LONG_PTR oldproc;
|
 | 330 | + HWND_HOOK *wndhook;
|
 | 331 | + if (nIndex != GWLP_WNDPROC) return _SetWindowLongPtrW(hWnd, nIndex, dwNewLong);
|
 | 332 | + wndhook = GetWndHook(hWnd);
|
 | 333 | + if (!wndhook) return _SetWindowLongPtrW(hWnd, nIndex, dwNewLong);
|
 | 334 | + oldproc = (LONG_PTR)wndhook->wndproc;
|
 | 335 | + wndhook->wndproc = (WNDPROC)dwNewLong;
|
 | 336 | + return oldproc;
|
 | 337 | +}
|
 | 338 | +LONG_PTR WINAPI HookGetWindowLongPtrA(HWND hWnd, int nIndex)
|
 | 339 | +{
|
 | 340 | + HWND_HOOK *wndhook;
|
 | 341 | + if (nIndex != GWLP_WNDPROC) return _GetWindowLongPtrA(hWnd, nIndex);
|
 | 342 | + wndhook = GetWndHook(hWnd);
|
 | 343 | + if (!wndhook) return _GetWindowLongPtrA(hWnd, nIndex);
|
 | 344 | + return (LONG_PTR)wndhook->wndproc;
|
 | 345 | +}
|
 | 346 | +LONG_PTR WINAPI HookGetWindowLongPtrW(HWND hWnd, int nIndex)
|
 | 347 | +{
|
 | 348 | + HWND_HOOK *wndhook;
|
 | 349 | + if (nIndex != GWLP_WNDPROC) return _GetWindowLongPtrW(hWnd, nIndex);
|
 | 350 | + wndhook = GetWndHook(hWnd);
|
 | 351 | + if (!wndhook) return _GetWindowLongPtrW(hWnd, nIndex);
|
 | 352 | + return (LONG_PTR)wndhook->wndproc;
|
 | 353 | +}
|
 | 354 | +#endif
|
Index: ddraw/hooks.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2014 William Feely
|
 | 3 | +// Copyright (C) 2014-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -21,10 +21,34 @@ |
22 | 22 | extern "C" {
|
23 | 23 | #endif
|
24 | 24 |
|
 | 25 | +typedef struct
|
 | 26 | +{
|
 | 27 | + HWND hwnd;
|
 | 28 | + WNDPROC wndproc;
|
 | 29 | + LPDIRECTDRAW7 lpDD7;
|
 | 30 | +} HWND_HOOK;
|
 | 31 | +
|
 | 32 | +extern CRITICAL_SECTION hook_cs;
|
 | 33 | +
|
 | 34 | +BOOL IsCallerOpenGL(void *returnaddress);
|
 | 35 | +
|
 | 36 | +void InitHooks();
|
 | 37 | +void ShutdownHooks();
|
25 | 38 | LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
26 | 39 | void InstallDXGLFullscreenHook(HWND hWnd, LPDIRECTDRAW7 lpDD7);
|
27 | 40 | void UninstallDXGLFullscreenHook(HWND hWnd);
|
28 | 41 |
|
 | 42 | +LONG WINAPI HookSetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLong);
|
 | 43 | +LONG WINAPI HookSetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong);
|
 | 44 | +LONG WINAPI HookGetWindowLongA(HWND hWnd, int nIndex);
|
 | 45 | +LONG WINAPI HookGetWindowLongW(HWND hWnd, int nIndex);
|
 | 46 | +#ifdef _M_X64
|
 | 47 | +LONG_PTR WINAPI HookSetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
|
 | 48 | +LONG_PTR WINAPI HookSetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
|
 | 49 | +LONG_PTR WINAPI HookGetWindowLongPtrA(HWND hWnd, int nIndex);
|
 | 50 | +LONG_PTR WINAPI HookGetWindowLongPtrW(HWND hWnd, int nIndex);
|
 | 51 | +#endif
|
 | 52 | +
|
29 | 53 | #ifdef __cplusplus
|
30 | 54 | }
|
31 | 55 | #endif
|
Index: dxglcfg2/dxglcfg2.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2011-2014 William Feely
|
 | 3 | +// Copyright (C) 2011-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | BOOL tristate;
|
87 | 87 | TCHAR strdefault[] = _T("(global default)");
|
88 | 88 | HWND hTab;
|
89 | Â | -HWND hTabs[5];
|
 | 89 | +HWND hTabs[6];
|
90 | 90 | int tabopen;
|
91 | 91 |
|
92 | 92 | static const TCHAR *colormodes[32] = {
|
Index: dxglcfg2/dxglcfg2.rc |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | Â | -// Copyright (C) 2011-2014 William Feely
|
 | 3 | +// Copyright (C) 2011-2015 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -189,7 +189,7 @@ |
190 | 190 | VALUE "FileDescription", "DXGL Configuration Program"
|
191 | 191 | VALUE "FileVersion", DXGLVERSTRING
|
192 | 192 | VALUE "InternalName", "DXGL"
|
193 | Â | - VALUE "LegalCopyright", "Copyright © 2011-2014 William Feely"
|
 | 193 | + VALUE "LegalCopyright", "Copyright © 2011-2015 William Feely"
|
194 | 194 | VALUE "OriginalFilename", "dxglcfg.exe"
|
195 | 195 | VALUE "ProductName", "DXGL"
|
196 | 196 | VALUE "ProductVersion", DXGLVERSTRING
|
Index: minhook-1.3/build/DXGL/libMinHook.vcxproj |
— | — | @@ -76,11 +76,10 @@ |
77 | 77 | <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
78 | 78 | <MinimalRebuild>false</MinimalRebuild>
|
79 | 79 | <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
80 | Â | - <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
81 | 80 | <WarningLevel>Level3</WarningLevel>
|
82 | Â | - <DebugInformationFormat>
|
83 | Â | - </DebugInformationFormat>
|
84 | 81 | <WholeProgramOptimization>false</WholeProgramOptimization>
|
 | 82 | + <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
 | 83 | + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
85 | 84 | </ClCompile>
|
86 | 85 | <Lib />
|
87 | 86 | </ItemDefinitionGroup>
|
— | — | @@ -109,7 +108,7 @@ |
110 | 109 | <AdditionalIncludeDirectories>$(ProjectDir)..\..\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
111 | 110 | <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
112 | 111 | <MinimalRebuild>false</MinimalRebuild>
|
113 | Â | - <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
 | 112 | + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
114 | 113 | <FunctionLevelLinking>true</FunctionLevelLinking>
|
115 | 114 | <WarningLevel>Level3</WarningLevel>
|
116 | 115 | <DebugInformationFormat>
|