DXGL r800 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r799‎ | r800 | r801 >
Date:22:02, 22 April 2018
Author:admin
Status:new
Tags:
Comment:
Add a patch contributed by Syahmi Azhar to help with compatibility for Atlantis 1.
Modified paths:
  • /ThirdParty.txt (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /ddraw/hooks.c (modified) (history)
  • /ddraw/hooks.h (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)
  • /patches (added) (history)
  • /patches/SetCursorPos+hack.patch (added) (history)
  • /patches/readme.txt (added) (history)

Diff [purge]

Index: ThirdParty.txt
@@ -217,3 +217,8 @@
218218
219219 Installer uses Nullsoft Scriptable Install System; the license for which
220220 can be viewed at http://nsis.sourceforge.net/License
 221+
 222+------------------------------------------------------------------------------
 223+
 224+Contains code contributed from the following:
 225+Syahmi Azhar (mouse cursor hacks)
\ No newline at end of file
Index: cfgmgr/cfgmgr.c
@@ -1,5 +1,6 @@
22 // DXGL
33 // Copyright (C) 2011-2018 William Feely
 4+// Portions copyright (C) 2018 Syahmi Azhar
45
56 // This library is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU Lesser General Public
@@ -665,6 +666,8 @@
666667 cfg->HackCrop640480to640400 = ReadBool(hKey, cfg->HackCrop640480to640400, &cfgmask->HackCrop640480to640400, _T("HackCrop640480to640400"));
667668 cfg->HackAutoScale512448to640480 = ReadBool(hKey, cfg->HackAutoScale512448to640480, &cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
668669 cfg->HackNoTVRefresh = ReadBool(hKey, cfg->HackNoTVRefresh, &cfgmask->HackNoTVRefresh, _T("HackNoTVRefresh"));
 670+ cfg->HackSetCursorPos = ReadBool(hKey, cfg->HackSetCursorPos, &cfgmask->HackSetCursorPos, _T("HackSetCursorPos"));
 671+ cfg->HackSetCursor = ReadBool(hKey, cfg->HackSetCursor, &cfgmask->HackSetCursor, _T("HackSetCursor"));
669672 if(!global && dll)
670673 {
671674 sizeout = 0;
@@ -815,6 +818,8 @@
816819 WriteBool(hKey, cfg->HackCrop640480to640400, cfgmask->HackCrop640480to640400, _T("HackCrop640480to640400"));
817820 WriteBool(hKey, cfg->HackAutoScale512448to640480, cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
818821 WriteBool(hKey, cfg->HackNoTVRefresh, cfgmask->HackNoTVRefresh, _T("HackNoTVRefresh"));
 822+ WriteBool(hKey, cfg->HackSetCursorPos, cfgmask->HackSetCursorPos, _T("HackSetCursorPos"));
 823+ WriteBool(hKey, cfg->HackSetCursor, cfgmask->HackSetCursor, _T("HackSetCursor"));
819824 }
820825
821826 TCHAR newregname[MAX_PATH+65];
@@ -1087,6 +1092,8 @@
10881093 if (!stricmp(section, "HackCrop640480to640400")) cfg->HackCrop640480to640400 = INIBoolValue(value);
10891094 if (!stricmp(section, "HackAutoScale512448to640480")) cfg->HackAutoScale512448to640480 = INIBoolValue(value);
10901095 if (!stricmp(section, "HackNoTVRefresh")) cfg->HackNoTVRefresh = INIBoolValue(value);
 1096+ if (!stricmp(section, "HackSetCursorPos")) cfg->HackSetCursorPos = INIBoolValue(value);
 1097+ if (!stricmp(section, "HackSetCursor")) cfg->HackSetCursor = INIBoolValue(value);
10911098 }
10921099 return 1;
10931100 }
Index: cfgmgr/cfgmgr.h
@@ -1,5 +1,6 @@
22 // DXGL
33 // Copyright (C) 2011-2018 William Feely
 4+// Portions copyright (C) 2018 Syahmi Azhar
45
56 // This library is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU Lesser General Public
@@ -93,6 +94,8 @@
9495 BOOL HackCrop640480to640400;
9596 BOOL HackAutoScale512448to640480;
9697 BOOL HackNoTVRefresh;
 98+ BOOL HackSetCursorPos;
 99+ BOOL HackSetCursor;
97100 // internal
98101 BOOL Windows8Detected;
99102 BOOL ParsedAddColorDepths;
Index: ddraw/hooks.c
@@ -1,5 +1,6 @@
22 // DXGL
33 // Copyright (C) 2014-2015 William Feely
 4+// Portions copyright (C) 2018 Syahmi Azhar
45
56 // This library is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU Lesser General Public
@@ -49,6 +50,8 @@
5051 #define _GetWindowLongPtrA _GetWindowLongA
5152 #define _GetWindowLongPtrW _GetWindowLongW
5253 #endif
 54+BOOL(WINAPI *_SetCursorPos)(int X, int Y) = NULL;
 55+HCURSOR(WINAPI *_SetCursor)(HCURSOR hCursor) = NULL;
5356 UINT wndhook_count = 0;
5457
5558 int hwndhookcmp(const HWND_HOOK *key, const HWND_HOOK *cmp)
@@ -161,6 +164,8 @@
162165 MH_CreateHook(&GetWindowLongPtrA, HookGetWindowLongPtrA, &_GetWindowLongPtrA);
163166 MH_CreateHook(&GetWindowLongPtrW, HookGetWindowLongPtrW, &_GetWindowLongPtrW);
164167 #endif
 168+ MH_CreateHook(&SetCursorPos, HookSetCursorPos, &_SetCursorPos);
 169+ MH_CreateHook(&SetCursor, HookSetCursor, &_SetCursor);
165170 hooks_init = TRUE;
166171 LeaveCriticalSection(&hook_cs);
167172 }
@@ -179,6 +184,8 @@
180185 MH_RemoveHook(&GetWindowLongPtrA);
181186 MH_RemoveHook(&GetWindowLongPtrW);
182187 #endif
 188+ MH_RemoveHook(&SetCursorPos);
 189+ MH_RemoveHook(&SetCursor);
183190 MH_Uninitialize();
184191 wndhook_count = 0;
185192 hooks_init = FALSE;
@@ -201,6 +208,8 @@
202209 MH_EnableHook(&GetWindowLongPtrA);
203210 MH_EnableHook(&GetWindowLongPtrW);
204211 #endif
 212+ MH_EnableHook(&SetCursorPos);
 213+ MH_EnableHook(&SetCursor);
205214 }
206215 LeaveCriticalSection(&hook_cs);
207216 }
@@ -223,6 +232,8 @@
224233 MH_DisableHook(&GetWindowLongPtrA);
225234 MH_DisableHook(&GetWindowLongPtrW);
226235 #endif
 236+ MH_DisableHook(&SetCursorPos);
 237+ MH_DisableHook(&SetCursor);
227238 }
228239 LeaveCriticalSection(&hook_cs);
229240 }
@@ -480,3 +491,46 @@
481492 return (LONG_PTR)wndhook->wndproc;
482493 }
483494 #endif
 495+BOOL WINAPI HookSetCursorPos(int x, int y)
 496+{
 497+ HWND_HOOK *wndhook;
 498+ LONG sizes[6];
 499+ POINT pt;
 500+ int winWidth, winHeight;
 501+
 502+ if (!dxglcfg.HackSetCursorPos) {
 503+ return _SetCursorPos(x, y);
 504+ }
 505+
 506+ wndhook = GetWndHook(GetActiveWindow());
 507+ if (!wndhook) {
 508+ return _SetCursorPos(x, y);
 509+ }
 510+
 511+ pt.x = 0;
 512+ pt.y = 0;
 513+ glDirectDraw7_GetSizes(wndhook->lpDD7, sizes);
 514+ ClientToScreen(wndhook->hwnd, &pt);
 515+
 516+ return _SetCursorPos(x * sizes[4] / sizes[2] + pt.x, y * sizes[5] / sizes[3] + pt.y);
 517+}
 518+HCURSOR WINAPI HookSetCursor(HCURSOR hCursor)
 519+{
 520+ static HCURSOR prevCursor = NULL;
 521+ static BOOLEAN prevCursorSet = FALSE;
 522+
 523+ if (!dxglcfg.HackSetCursor) {
 524+ return _SetCursor(hCursor);
 525+ }
 526+
 527+ if (!prevCursorSet) {
 528+ prevCursorSet = TRUE;
 529+ prevCursor = GetCursor();
 530+ }
 531+
 532+ if (hCursor == NULL) {
 533+ prevCursor = _SetCursor(hCursor);
 534+ }
 535+
 536+ return prevCursor;
 537+}
Index: ddraw/hooks.h
@@ -1,5 +1,6 @@
22 // DXGL
33 // Copyright (C) 2014-2015 William Feely
 4+// Portions copyright (C) 2018 Syahmi Azhar
45
56 // This library is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU Lesser General Public
@@ -48,6 +49,8 @@
4950 LONG_PTR WINAPI HookGetWindowLongPtrA(HWND hWnd, int nIndex);
5051 LONG_PTR WINAPI HookGetWindowLongPtrW(HWND hWnd, int nIndex);
5152 #endif
 53+BOOL WINAPI HookSetCursorPos(int x, int y);
 54+HCURSOR WINAPI HookSetCursor(HCURSOR hCursor);
5255
5356 #ifdef __cplusplus
5457 }
Index: dxglcfg/dxglcfg.cpp
@@ -1,5 +1,6 @@
22 // DXGL
33 // Copyright (C) 2011-2018 William Feely
 4+// Portions copyright (C) 2018 Syahmi Azhar
45
56 // This library is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU Lesser General Public
@@ -2295,6 +2296,14 @@
22962297 *value = cfg->HackNoTVRefresh;
22972298 *mask = cfgmask->HackNoTVRefresh;
22982299 break;
 2300+ case 3:
 2301+ *value = cfg->HackSetCursorPos;
 2302+ *mask = cfgmask->HackSetCursorPos;
 2303+ break;
 2304+ case 4:
 2305+ *value = cfg->HackSetCursor;
 2306+ *mask = cfgmask->HackSetCursor;
 2307+ break;
22992308 default:
23002309 *value = FALSE;
23012310 *mask = FALSE;
@@ -2317,6 +2326,15 @@
23182327 case 2:
23192328 cfg->HackNoTVRefresh = value;
23202329 cfgmask->HackNoTVRefresh = mask;
 2330+ break;
 2331+ case 3:
 2332+ cfg->HackSetCursorPos = value;
 2333+ cfgmask->HackSetCursorPos = mask;
 2334+ break;
 2335+ case 4:
 2336+ cfg->HackSetCursor = value;
 2337+ cfgmask->HackSetCursor = mask;
 2338+ break;
23212339 default:
23222340 break;
23232341 }
@@ -3143,6 +3161,10 @@
31443162 SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
31453163 _tcscpy(buffer, _T("Remove TV-compatible refresh rates"));
31463164 SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
 3165+ _tcscpy(buffer, _T("SetCursorPos centered"));
 3166+ SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
 3167+ _tcscpy(buffer, _T("SetCursor hide visibility"));
 3168+ SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
31473169 // About text
31483170 _tcscpy(abouttext, _T("DXGL\r\nVersion "));
31493171 _tcscat(abouttext, _T(DXGLVERSTRING));
Index: patches/SetCursorPos hack.patch
@@ -0,0 +1,202 @@
 2+Index: cfgmgr/cfgmgr.c
 3+===================================================================
 4+--- cfgmgr/cfgmgr.c (revision 798)
 5+@@ -665,6 +665,8 @@
 6+ cfg->HackCrop640480to640400 = ReadBool(hKey, cfg->HackCrop640480to640400, &cfgmask->HackCrop640480to640400, _T("HackCrop640480to640400"));
 7+ cfg->HackAutoScale512448to640480 = ReadBool(hKey, cfg->HackAutoScale512448to640480, &cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
 8+ cfg->HackNoTVRefresh = ReadBool(hKey, cfg->HackNoTVRefresh, &cfgmask->HackNoTVRefresh, _T("HackNoTVRefresh"));
 9++ cfg->HackSetCursorPos = ReadBool(hKey, cfg->HackSetCursorPos, &cfgmask->HackSetCursorPos, _T("HackSetCursorPos"));
 10++ cfg->HackSetCursor = ReadBool(hKey, cfg->HackSetCursor, &cfgmask->HackSetCursor, _T("HackSetCursor"));
 11+ if(!global && dll)
 12+ {
 13+ sizeout = 0;
 14+@@ -815,6 +817,8 @@
 15+ WriteBool(hKey, cfg->HackCrop640480to640400, cfgmask->HackCrop640480to640400, _T("HackCrop640480to640400"));
 16+ WriteBool(hKey, cfg->HackAutoScale512448to640480, cfgmask->HackAutoScale512448to640480, _T("HackAutoScale512448to640480"));
 17+ WriteBool(hKey, cfg->HackNoTVRefresh, cfgmask->HackNoTVRefresh, _T("HackNoTVRefresh"));
 18++ WriteBool(hKey, cfg->HackSetCursorPos, cfgmask->HackSetCursorPos, _T("HackSetCursorPos"));
 19++ WriteBool(hKey, cfg->HackSetCursor, cfgmask->HackSetCursor, _T("HackSetCursor"));
 20+ }
 21+
 22+ TCHAR newregname[MAX_PATH+65];
 23+@@ -1087,6 +1091,8 @@
 24+ if (!stricmp(section, "HackCrop640480to640400")) cfg->HackCrop640480to640400 = INIBoolValue(value);
 25+ if (!stricmp(section, "HackAutoScale512448to640480")) cfg->HackAutoScale512448to640480 = INIBoolValue(value);
 26+ if (!stricmp(section, "HackNoTVRefresh")) cfg->HackNoTVRefresh = INIBoolValue(value);
 27++ if (!stricmp(section, "HackSetCursorPos")) cfg->HackSetCursorPos = INIBoolValue(value);
 28++ if (!stricmp(section, "HackSetCursor")) cfg->HackSetCursor = INIBoolValue(value);
 29+ }
 30+ return 1;
 31+ }
 32+Index: cfgmgr/cfgmgr.h
 33+===================================================================
 34+--- cfgmgr/cfgmgr.h (revision 798)
 35+@@ -93,6 +93,8 @@
 36+ BOOL HackCrop640480to640400;
 37+ BOOL HackAutoScale512448to640480;
 38+ BOOL HackNoTVRefresh;
 39++ BOOL HackSetCursorPos;
 40++ BOOL HackSetCursor;
 41+ // internal
 42+ BOOL Windows8Detected;
 43+ BOOL ParsedAddColorDepths;
 44+Index: ddraw/hooks.c
 45+===================================================================
 46+--- ddraw/hooks.c (revision 798)
 47+@@ -38,6 +38,8 @@
 48+ LONG(WINAPI *_SetWindowLongW)(HWND hWnd, int nIndex, LONG dwNewLong) = NULL;
 49+ LONG(WINAPI *_GetWindowLongA)(HWND hWnd, int nIndex) = NULL;
 50+ LONG(WINAPI *_GetWindowLongW)(HWND hWnd, int nIndex) = NULL;
 51++BOOL(WINAPI *_SetCursorPos)(int X, int Y) = NULL;
 52++HCURSOR (WINAPI *_SetCursor)(HCURSOR hCursor) = NULL;
 53+ #ifdef _M_X64
 54+ LONG_PTR(WINAPI *_SetWindowLongPtrA)(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
 55+ LONG_PTR(WINAPI *_SetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
 56+@@ -155,6 +157,8 @@
 57+ MH_CreateHook(&SetWindowLongW, HookSetWindowLongW, &_SetWindowLongW);
 58+ MH_CreateHook(&GetWindowLongA, HookGetWindowLongA, &_GetWindowLongA);
 59+ MH_CreateHook(&GetWindowLongW, HookGetWindowLongW, &_GetWindowLongW);
 60++ MH_CreateHook(&SetCursorPos, HookSetCursorPos, &_SetCursorPos);
 61++ MH_CreateHook(&SetCursor, HookSetCursor, &_SetCursor);
 62+ #ifdef _M_X64
 63+ MH_CreateHook(&SetWindowLongPtrA, HookSetWindowLongPtrA, &_SetWindowLongPtrA);
 64+ MH_CreateHook(&SetWindowLongPtrW, HookSetWindowLongPtrW, &_SetWindowLongPtrW);
 65+@@ -173,6 +177,8 @@
 66+ MH_RemoveHook(&SetWindowLongW);
 67+ MH_RemoveHook(&GetWindowLongA);
 68+ MH_RemoveHook(&GetWindowLongW);
 69++ MH_RemoveHook(&SetCursorPos);
 70++ MH_RemoveHook(&SetCursor);
 71+ #ifdef _M_X64
 72+ MH_RemoveHook(&SetWindowLongPtrA);
 73+ MH_RemoveHook(&SetWindowLongPtrW);
 74+@@ -195,6 +201,8 @@
 75+ MH_EnableHook(&SetWindowLongW);
 76+ MH_EnableHook(&GetWindowLongA);
 77+ MH_EnableHook(&GetWindowLongW);
 78++ MH_EnableHook(&SetCursorPos);
 79++ MH_EnableHook(&SetCursor);
 80+ #ifdef _M_X64
 81+ MH_EnableHook(&SetWindowLongPtrA);
 82+ MH_EnableHook(&SetWindowLongPtrW);
 83+@@ -217,6 +225,8 @@
 84+ MH_DisableHook(&SetWindowLongW);
 85+ MH_DisableHook(&GetWindowLongA);
 86+ MH_DisableHook(&GetWindowLongW);
 87++ MH_DisableHook(&SetCursorPos);
 88++ MH_DisableHook(&SetCursor);
 89+ #ifdef _M_X64
 90+ MH_DisableHook(&SetWindowLongPtrA);
 91+ MH_DisableHook(&SetWindowLongPtrW);
 92+@@ -440,6 +450,49 @@
 93+ if (!wndhook) return _GetWindowLongW(hWnd, nIndex);
 94+ return (LONG)wndhook->wndproc;
 95+ }
 96++BOOL WINAPI HookSetCursorPos(int x, int y)
 97++{
 98++ HWND_HOOK *wndhook;
 99++ LONG sizes[6];
 100++ POINT pt;
 101++ int winWidth, winHeight;
 102++
 103++ if (!dxglcfg.HackSetCursorPos) {
 104++ return _SetCursorPos(x, y);
 105++ }
 106++
 107++ wndhook = GetWndHook(GetActiveWindow());
 108++ if (!wndhook) {
 109++ return _SetCursorPos(x, y);
 110++ }
 111++
 112++ pt.x = 0;
 113++ pt.y = 0;
 114++ glDirectDraw7_GetSizes(wndhook->lpDD7, sizes);
 115++ ClientToScreen(wndhook->hwnd, &pt);
 116++
 117++ return _SetCursorPos(x * sizes[4] / sizes[2] + pt.x, y * sizes[5] / sizes[3] + pt.y);
 118++}
 119++HCURSOR WINAPI HookSetCursor(HCURSOR hCursor)
 120++{
 121++ static HCURSOR prevCursor = NULL;
 122++ static BOOLEAN prevCursorSet = FALSE;
 123++
 124++ if (!dxglcfg.HackSetCursor) {
 125++ return _SetCursor(hCursor);
 126++ }
 127++
 128++ if (!prevCursorSet) {
 129++ prevCursorSet = TRUE;
 130++ prevCursor = GetCursor();
 131++ }
 132++
 133++ if (hCursor == NULL) {
 134++ prevCursor = _SetCursor(hCursor);
 135++ }
 136++
 137++ return prevCursor;
 138++}
 139+ #ifdef _M_X64
 140+ LONG_PTR WINAPI HookSetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
 141+ {
 142+Index: ddraw/hooks.h
 143+===================================================================
 144+--- ddraw/hooks.h (revision 798)
 145+@@ -42,6 +42,8 @@
 146+ LONG WINAPI HookSetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong);
 147+ LONG WINAPI HookGetWindowLongA(HWND hWnd, int nIndex);
 148+ LONG WINAPI HookGetWindowLongW(HWND hWnd, int nIndex);
 149++BOOL WINAPI HookSetCursorPos(int x, int y);
 150++HCURSOR WINAPI HookSetCursor(HCURSOR hCursor);
 151+ #ifdef _M_X64
 152+ LONG_PTR WINAPI HookSetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
 153+ LONG_PTR WINAPI HookSetWindowLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
 154+Index: dxglcfg/dxglcfg.cpp
 155+===================================================================
 156+--- dxglcfg/dxglcfg.cpp (revision 798)
 157+@@ -2295,6 +2295,14 @@
 158+ *value = cfg->HackNoTVRefresh;
 159+ *mask = cfgmask->HackNoTVRefresh;
 160+ break;
 161++ case 3:
 162++ *value = cfg->HackSetCursorPos;
 163++ *mask = cfgmask->HackSetCursorPos;
 164++ break;
 165++ case 4:
 166++ *value = cfg->HackSetCursor;
 167++ *mask = cfgmask->HackSetCursor;
 168++ break;
 169+ default:
 170+ *value = FALSE;
 171+ *mask = FALSE;
 172+@@ -2317,6 +2325,15 @@
 173+ case 2:
 174+ cfg->HackNoTVRefresh = value;
 175+ cfgmask->HackNoTVRefresh = mask;
 176++ break;
 177++ case 3:
 178++ cfg->HackSetCursorPos = value;
 179++ cfgmask->HackSetCursorPos = mask;
 180++ break;
 181++ case 4:
 182++ cfg->HackSetCursor = value;
 183++ cfgmask->HackSetCursor = mask;
 184++ break;
 185+ default:
 186+ break;
 187+ }
 188+@@ -3143,6 +3160,10 @@
 189+ SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
 190+ _tcscpy(buffer, _T("Remove TV-compatible refresh rates"));
 191+ SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
 192++ _tcscpy(buffer, _T("SetCursorPos centered"));
 193++ SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
 194++ _tcscpy(buffer, _T("SetCursor hide visibility"));
 195++ SendDlgItemMessage(hTabs[5], IDC_HACKSLIST, LB_ADDSTRING, 0, (LPARAM)buffer);
 196+ // About text
 197+ _tcscpy(abouttext, _T("DXGL\r\nVersion "));
 198+ _tcscat(abouttext, _T(DXGLVERSTRING));
\ No newline at end of file
Index: patches/readme.txt
@@ -0,0 +1,3 @@
 2+These files have already been merged into DXGL, but are provided for reference purposes.
 3+
 4+SetCursorPos hack.patch - Copyright (C) 2018 Syahmi Azhar - Merged manually against revision 799.
\ No newline at end of file