DXGL r580 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r579‎ | r580 | r581 >
Date:01:16, 2 January 2015
Author:admin
Status:new
Tags:
Comment:
Use MinHook to hook the GetWindowLong/SetWindowLong(Ptr) functions with parameter GWL_WNDPROC/GWLP_WNDPROC. Fixes P.E.Op.S Soft Driver under PCSXR.
Modified paths:
  • /Installer/dxgl.nsi (modified) (history)
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/ddraw.rc (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/dllmain.cpp (modified) (history)
  • /ddraw/hooks.c (modified) (history)
  • /ddraw/hooks.h (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)
  • /dxglcfg2/dxglcfg2.rc (modified) (history)
  • /minhook-1.3/build/DXGL/libMinHook.vcxproj (modified) (history)

Diff [purge]

Index: Installer/dxgl.nsi
——@@ -84,7 +84,7 @@
8585 VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "DXGL ${PRODUCT_VERSION} Installer"
8686 VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${PRODUCT_VERSION}"
8787 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"
8989 VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "DXGL-${PRODUCT_VERSION}-win32.exe"
9090 VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "DXGL"
9191 VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "${PRODUCT_VERSION}"
Index: ddraw/ddraw.cpp
——@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -25,8 +25,8 @@
2626 #include "glDirectDrawClipper.h"
2727 #include "timer.h"
2828 #include "glRenderer.h"
 29+#include "hooks.h"
2930 #include <intrin.h>
30 -#include <tlhelp32.h>
3131
3232 DXGLCFG dxglcfg;
3333 DWORD gllock = 0;
——@@ -109,39 +109,6 @@
110110 }
111111
112112 /**
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 -/**
146113 * Creates an IDirectDraw compatible interface to the DXGL graphics library.
147114 * @param lpGUID
148115 * Address to the GUID of the device to be created, or NULL for the current
Index: ddraw/ddraw.rc
——@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -64,7 +64,7 @@
6565 VALUE "FileDescription", "DXGL DDraw Library"
6666 VALUE "FileVersion", DXGLVERSTRING
6767 VALUE "InternalName", "DXGL"
68 - VALUE "LegalCopyright", "Copyright (C) 2011-2014 William Feely"
 68+ VALUE "LegalCopyright", "Copyright (C) 2011-2015 William Feely"
6969 VALUE "OriginalFilename", "DDraw.dll"
7070 VALUE "ProductName", "DXGL"
7171 VALUE "ProductVersion", DXGLVERSTRING
Index: ddraw/ddraw.vcxproj
——@@ -120,7 +120,7 @@
121121 <SubSystem>Windows</SubSystem>
122122 <GenerateDebugInformation>true</GenerateDebugInformation>
123123 <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>
125125 </Link>
126126 <PreBuildEvent>
127127 <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
——@@ -143,7 +143,7 @@
144144 <SubSystem>Windows</SubSystem>
145145 <GenerateDebugInformation>true</GenerateDebugInformation>
146146 <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>
148148 </Link>
149149 <PreBuildEvent>
150150 <Command>"$(OutDir)..\Debug\buildtool.exe" makeheader $(SolutionDir)common</Command>
——@@ -166,7 +166,7 @@
167167 <SubSystem>Windows</SubSystem>
168168 <GenerateDebugInformation>true</GenerateDebugInformation>
169169 <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>
171171 <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
172172 </Link>
173173 <PreBuildEvent>
——@@ -190,7 +190,7 @@
191191 <SubSystem>Windows</SubSystem>
192192 <GenerateDebugInformation>true</GenerateDebugInformation>
193193 <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>
195195 <ImportLibrary>$(OutDir)ddraw.lib</ImportLibrary>
196196 </Link>
197197 <PostBuildEvent />
——@@ -221,7 +221,7 @@
222222 <OptimizeReferences>true</OptimizeReferences>
223223 <SetChecksum>true</SetChecksum>
224224 <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>
226226 </Link>
227227 <PreBuildEvent>
228228 <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
——@@ -249,7 +249,7 @@
250250 <OptimizeReferences>true</OptimizeReferences>
251251 <SetChecksum>true</SetChecksum>
252252 <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>
254254 <ImportLibrary>$(OutDir)ddraw.lib</ImportLibrary>
255255 </Link>
256256 <PostBuildEvent />
Index: ddraw/dllmain.cpp
——@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -17,6 +17,7 @@
1818
1919 #include "common.h"
2020 #include "ddraw.h"
 21+#include "hooks.h"
2122 ATOM WindowClass = NULL;
2223 CRITICAL_SECTION dll_cs = {NULL,0,0,NULL,NULL,0};
2324 BOOL APIENTRY DllMain( HMODULE hModule,
——@@ -28,11 +29,19 @@
2930 {
3031 case DLL_PROCESS_ATTACH:
3132 if(!dll_cs.LockCount && !dll_cs.OwningThread) InitializeCriticalSection(&dll_cs);
 33+ if (!hook_cs.LockCount && !hook_cs.OwningThread) InitializeCriticalSection(&hook_cs);
 34+ InitHooks();
3235 GetCurrentConfig(&dxglcfg, true);
3336 break;
3437 case DLL_THREAD_ATTACH:
3538 case DLL_THREAD_DETACH:
 39+ break;
3640 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));
3746 break;
3847 }
3948 return TRUE;
Index: ddraw/hooks.c
——@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2014 William Feely
 3+// Copyright (C) 2014-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -17,35 +17,245 @@
1818
1919 #include "common.h"
2020 #include "hooks.h"
 21+#include <tlhelp32.h>
 22+#include "../minhook-1.3/include/MinHook.h"
2123
2224 const TCHAR *wndprop = _T("DXGLWndProc");
2325 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;
2431
 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;
2548
 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+
26138 LRESULT CALLBACK nullwndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
27139 {
28140 return 0;
29141 }
30142
 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+
31225 void InstallDXGLFullscreenHook(HWND hWnd, LPDIRECTDRAW7 lpDD7)
32226 {
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();
38238 }
39239 void UninstallDXGLFullscreenHook(HWND hWnd)
40240 {
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);
45246 }
46247 LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
47248 {
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;
50260 switch (uMsg)
51261 {
52262 case WM_DESTROY:
——@@ -61,3 +271,83 @@
62272 }
63273 return CallWindowProc(parentproc, hWnd, uMsg, wParam, lParam);
64274 }
 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 @@
22 // DXGL
3 -// Copyright (C) 2014 William Feely
 3+// Copyright (C) 2014-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -21,10 +21,34 @@
2222 extern "C" {
2323 #endif
2424
 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();
2538 LRESULT CALLBACK DXGLWndHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
2639 void InstallDXGLFullscreenHook(HWND hWnd, LPDIRECTDRAW7 lpDD7);
2740 void UninstallDXGLFullscreenHook(HWND hWnd);
2841
 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+
2953 #ifdef __cplusplus
3054 }
3155 #endif
Index: dxglcfg2/dxglcfg2.c
——@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -85,7 +85,7 @@
8686 BOOL tristate;
8787 TCHAR strdefault[] = _T("(global default)");
8888 HWND hTab;
89 -HWND hTabs[5];
 89+HWND hTabs[6];
9090 int tabopen;
9191
9292 static const TCHAR *colormodes[32] = {
Index: dxglcfg2/dxglcfg2.rc
——@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
——@@ -189,7 +189,7 @@
190190 VALUE "FileDescription", "DXGL Configuration Program"
191191 VALUE "FileVersion", DXGLVERSTRING
192192 VALUE "InternalName", "DXGL"
193 - VALUE "LegalCopyright", "Copyright © 2011-2014 William Feely"
 193+ VALUE "LegalCopyright", "Copyright © 2011-2015 William Feely"
194194 VALUE "OriginalFilename", "dxglcfg.exe"
195195 VALUE "ProductName", "DXGL"
196196 VALUE "ProductVersion", DXGLVERSTRING
Index: minhook-1.3/build/DXGL/libMinHook.vcxproj
——@@ -76,11 +76,10 @@
7777 <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
7878 <MinimalRebuild>false</MinimalRebuild>
7979 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
80 - <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
8180 <WarningLevel>Level3</WarningLevel>
82 - <DebugInformationFormat>
83 - </DebugInformationFormat>
8481 <WholeProgramOptimization>false</WholeProgramOptimization>
 82+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
 83+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
8584 </ClCompile>
8685 <Lib />
8786 </ItemDefinitionGroup>
——@@ -109,7 +108,7 @@
110109 <AdditionalIncludeDirectories>$(ProjectDir)..\..\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
111110 <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
112111 <MinimalRebuild>false</MinimalRebuild>
113 - <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
 112+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
114113 <FunctionLevelLinking>true</FunctionLevelLinking>
115114 <WarningLevel>Level3</WarningLevel>
116115 <DebugInformationFormat>