1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-25 10:07:47 +01:00

#118 merge latest sir-tech fixes

(cherry picked from commit 994d4c646fafe58c49631283c72b755d81dbf865)
This commit is contained in:
FunkyFr3sh 2021-09-09 03:49:54 +02:00
parent 31119eacb8
commit ebda8282b2
7 changed files with 94 additions and 4 deletions

View File

@ -125,6 +125,7 @@ typedef struct CNCDDRAW
BOOL fixpitch; BOOL fixpitch;
int fixchilds; int fixchilds;
BOOL fixwndprochook; BOOL fixwndprochook;
BOOL fixmousehook;
BOOL fixnotresponding; BOOL fixnotresponding;
BOOL d3d9linear; BOOL d3d9linear;
BOOL gdilinear; BOOL gdilinear;

View File

@ -3,6 +3,9 @@
void mouse_lock(); void mouse_lock();
void mouse_unlock(); void mouse_unlock();
LRESULT CALLBACK mouse_hook_proc(int Code, WPARAM wParam, LPARAM lParam);
extern HHOOK g_mouse_hook;
extern HOOKPROC g_mouse_proc;
#endif #endif

View File

@ -62,6 +62,7 @@ void cfg_load()
g_ddraw->fixpitch = cfg_get_bool("fixpitch", FALSE); g_ddraw->fixpitch = cfg_get_bool("fixpitch", FALSE);
g_ddraw->fixchilds = cfg_get_int("fixchilds", FIX_CHILDS_DETECT_PAINT); g_ddraw->fixchilds = cfg_get_int("fixchilds", FIX_CHILDS_DETECT_PAINT);
g_ddraw->fixwndprochook = cfg_get_bool("fixwndprochook", FALSE); g_ddraw->fixwndprochook = cfg_get_bool("fixwndprochook", FALSE);
g_ddraw->fixmousehook = cfg_get_bool("fixmousehook", FALSE);
g_ddraw->fixnotresponding = cfg_get_bool("fixnotresponding", FALSE); g_ddraw->fixnotresponding = cfg_get_bool("fixnotresponding", FALSE);
g_ddraw->d3d9linear = cfg_get_bool("d3d9linear", TRUE); g_ddraw->d3d9linear = cfg_get_bool("d3d9linear", TRUE);
g_ddraw->gdilinear = cfg_get_bool("gdilinear", FALSE); g_ddraw->gdilinear = cfg_get_bool("gdilinear", FALSE);
@ -722,7 +723,15 @@ static void cfg_create_ini()
"\n" "\n"
"; Jagged Alliance 2\n" "; Jagged Alliance 2\n"
"[ja2]\n" "[ja2]\n"
"hook=0\n" "fixmousehook=true\n"
"\n"
"; Jagged Alliance 2: Wildfire\n"
"[WF6]\n"
"fixmousehook=true\n"
"\n"
"; Jagged Alliance 2 - UC mod\n"
"[JA2_UC]\n"
"fixmousehook=true\n"
"\n" "\n"
"; Kings Quest 8\n" "; Kings Quest 8\n"
"[Mask]\n" "[Mask]\n"

View File

@ -566,6 +566,7 @@ void hook_early_init()
hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput8.dll", "DirectInput8Create", (PROC)fake_DirectInput8Create); hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput8.dll", "DirectInput8Create", (PROC)fake_DirectInput8Create);
hook_patch_iat(GetModuleHandle(NULL), FALSE, "user32.dll", "GetClientRect", (PROC)fake_GetClientRect); //anno 1602 hook_patch_iat(GetModuleHandle(NULL), FALSE, "user32.dll", "GetClientRect", (PROC)fake_GetClientRect); //anno 1602
hook_patch_iat(GetModuleHandle("AcGenral"), FALSE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA); hook_patch_iat(GetModuleHandle("AcGenral"), FALSE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA);
hook_patch_iat(GetModuleHandle(NULL), FALSE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA);
} }
void hook_exit() void hook_exit()
@ -621,4 +622,5 @@ void hook_exit()
hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput8.dll", "DirectInput8Create", (PROC)fake_DirectInput8Create); hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput8.dll", "DirectInput8Create", (PROC)fake_DirectInput8Create);
hook_patch_iat(GetModuleHandle(NULL), TRUE, "user32.dll", "GetClientRect", (PROC)fake_GetClientRect); //anno 1602 hook_patch_iat(GetModuleHandle(NULL), TRUE, "user32.dll", "GetClientRect", (PROC)fake_GetClientRect); //anno 1602
hook_patch_iat(GetModuleHandle("AcGenral"), TRUE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA); hook_patch_iat(GetModuleHandle("AcGenral"), TRUE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA);
hook_patch_iat(GetModuleHandle(NULL), TRUE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA);
} }

View File

@ -1,10 +1,13 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include "debug.h" #include "debug.h"
#include "winapi_hooks.h"
#include "dd.h" #include "dd.h"
#include "hook.h" #include "hook.h"
HHOOK g_mouse_hook;
HOOKPROC g_mouse_proc;
void mouse_lock() void mouse_lock()
{ {
if (g_ddraw->devmode || g_ddraw->bnet_active) if (g_ddraw->devmode || g_ddraw->bnet_active)
@ -93,3 +96,51 @@ void mouse_unlock()
(int)(rc.top + g_ddraw->render.viewport.y + ((cur_y + g_ddraw->mouse_y_adjust) * g_ddraw->render.scale_h))); (int)(rc.top + g_ddraw->render.viewport.y + ((cur_y + g_ddraw->mouse_y_adjust) * g_ddraw->render.scale_h)));
} }
} }
LRESULT CALLBACK mouse_hook_proc(int Code, WPARAM wParam, LPARAM lParam)
{
if (!g_ddraw || !g_ddraw->fixmousehook)
return g_mouse_proc(Code, wParam, lParam);
if (Code < 0)
return CallNextHookEx(g_mouse_hook, Code, wParam, lParam);
switch (wParam)
{
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
{
if (!g_ddraw->devmode && !g_ddraw->locked)
{
mouse_lock();
return CallNextHookEx(g_mouse_hook, Code, wParam, lParam);
}
break;
}
/* down messages are ignored if we have no cursor lock */
case WM_XBUTTONDBLCLK:
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
case WM_MOUSEWHEEL:
case WM_MOUSEHOVER:
case WM_LBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_MOUSEMOVE:
{
if (!g_ddraw->devmode && !g_ddraw->locked)
{
return CallNextHookEx(g_mouse_hook, Code, wParam, lParam);
}
break;
}
}
fake_GetCursorPos(&((MOUSEHOOKSTRUCT*)lParam)->pt);
return g_mouse_proc(Code, wParam, lParam);
}

View File

@ -492,6 +492,12 @@ HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, D
return NULL; return NULL;
} }
if (idHook == WH_MOUSE && lpfn && !g_mouse_hook)
{
g_mouse_proc = lpfn;
return g_mouse_hook = real_SetWindowsHookExA(idHook, mouse_hook_proc, hmod, dwThreadId);
}
return real_SetWindowsHookExA(idHook, lpfn, hmod, dwThreadId); return real_SetWindowsHookExA(idHook, lpfn, hmod, dwThreadId);
} }
@ -589,6 +595,12 @@ HWND WINAPI fake_CreateWindowExA(
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y,
int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{ {
/* Fix for SMACKW32.DLL creating another window that steals the focus */
if (HIWORD(lpClassName) && _strcmpi(lpClassName, "MouseTypeWind") == 0 && g_ddraw)
{
dwStyle &= ~WS_VISIBLE;
}
if (HIWORD(lpClassName) && _strcmpi(lpClassName, "SDlgDialog") == 0 && g_ddraw) if (HIWORD(lpClassName) && _strcmpi(lpClassName, "SDlgDialog") == 0 && g_ddraw)
{ {
if (!g_ddraw->bnet_active) if (!g_ddraw->bnet_active)

View File

@ -539,8 +539,20 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
break; break;
} }
if (wParam && g_ddraw->alt_key_down) /* jagged alliance 2 */
PostMessageA(g_ddraw->hwnd, WM_SYSKEYUP, VK_MENU, 0); if (wParam)
{
INPUT ip;
memset(&ip, 0, sizeof(ip));
ip.type = INPUT_KEYBOARD;
ip.ki.wVk = VK_MENU;
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(ip));
}
//if (wParam && g_ddraw->alt_key_down)
// PostMessageA(g_ddraw->hwnd, WM_SYSKEYUP, VK_MENU, 0);
return 0; return 0;
} }