Skip to content

Commit

Permalink
hook DefWindowProcA
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Dec 18, 2024
1 parent 34250bf commit f70f678
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
1 change: 0 additions & 1 deletion inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ typedef struct CNCDDRAWCONFIG
BOOL no_dinput_hook;
BOOL direct3d_passthrough;
BOOL center_cursor_fix;
BOOL allow_wm_nchittest;
char fake_mode[128];
BOOL lock_mouse_top_left;
char win_version[32];
Expand Down
4 changes: 3 additions & 1 deletion inc/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef struct HOOKLISTDATA {
HMODULE mod;
} HOOKLISTDATA;

typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[35]; } HOOKLIST;
typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[36]; } HOOKLIST;

typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT);
typedef BOOL(WINAPI* CLIPCURSORPROC)(const RECT*);
Expand Down Expand Up @@ -59,6 +59,7 @@ typedef BOOL(WINAPI* GETMESSAGEAPROC)(LPMSG, HWND, UINT, UINT);
typedef BOOL(WINAPI* GETWINDOWPLACEMENTPROC)(HWND, WINDOWPLACEMENT*);
typedef BOOL(WINAPI* SETWINDOWPLACEMENTPROC)(HWND, const WINDOWPLACEMENT*);
typedef BOOL(WINAPI* ENUMDISPLAYSETTINGSAPROC)(LPCSTR, DWORD, DEVMODEA*);
typedef LRESULT(WINAPI* DEFWINDOWPROCAPROC)(HWND, UINT, WPARAM, LPARAM);
typedef SHORT(WINAPI* GETKEYSTATEPROC)(int);
typedef SHORT(WINAPI* GETASYNCKEYSTATEPROC)(int);

Expand Down Expand Up @@ -117,6 +118,7 @@ extern GETMESSAGEAPROC real_GetMessageA;
extern GETWINDOWPLACEMENTPROC real_GetWindowPlacement;
extern SETWINDOWPLACEMENTPROC real_SetWindowPlacement;
extern ENUMDISPLAYSETTINGSAPROC real_EnumDisplaySettingsA;
extern DEFWINDOWPROCAPROC real_DefWindowProcA;
extern GETKEYSTATEPROC real_GetKeyState;
extern GETASYNCKEYSTATEPROC real_GetAsyncKeyState;
extern GETDEVICECAPSPROC real_GetDeviceCaps;
Expand Down
1 change: 1 addition & 0 deletions inc/winapi_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wM
BOOL WINAPI fake_GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT* lpwndpl);
BOOL WINAPI fake_SetWindowPlacement(HWND hWnd, const WINDOWPLACEMENT* lpwndpl);
BOOL WINAPI fake_EnumDisplaySettingsA(LPCSTR lpszDeviceName, DWORD iModeNum, DEVMODEA* lpDevMode);
LRESULT WINAPI fake_DefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
SHORT WINAPI fake_GetKeyState(int nVirtKey);
SHORT WINAPI fake_GetAsyncKeyState(int vKey);
int WINAPI fake_GetDeviceCaps(HDC hdc, int index);
Expand Down
6 changes: 0 additions & 6 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void cfg_load()
GET_BOOL(g_config.no_dinput_hook, "no_dinput_hook", FALSE);
GET_BOOL(g_config.direct3d_passthrough, "direct3d_passthrough", FALSE);
GET_BOOL(g_config.center_cursor_fix, "center_cursor_fix", FALSE);
GET_BOOL(g_config.allow_wm_nchittest, "allow_wm_nchittest", FALSE);
GET_STRING("fake_mode", "", g_config.fake_mode, sizeof(g_config.fake_mode));
GET_BOOL(g_config.lock_mouse_top_left, "lock_mouse_top_left", FALSE);
GET_STRING("win_version", "", g_config.win_version, sizeof(g_config.win_version));
Expand Down Expand Up @@ -395,7 +394,6 @@ static void cfg_create_ini()
"; 7th Legion\n"
"[legion]\n"
"maxgameticks=25\n"
"allow_wm_nchittest=true\n"
"singlecpu=false\n"
"\n"
"; Atrox\n"
Expand Down Expand Up @@ -1331,10 +1329,6 @@ static void cfg_create_ini()
"checkfile=.\\nox.cfg\n"
"maxgameticks=125\n"
"\n"
"; Nightlong - Union City Conspiracy\n"
"[NL]\n"
"allow_wm_nchittest=true\n"
"\n"
"; Outlaws\n"
"[olwin]\n"
"noactivateapp=true\n"
Expand Down
2 changes: 2 additions & 0 deletions src/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ GETMESSAGEAPROC real_GetMessageA = GetMessageA;
GETWINDOWPLACEMENTPROC real_GetWindowPlacement = GetWindowPlacement;
SETWINDOWPLACEMENTPROC real_SetWindowPlacement = SetWindowPlacement;
ENUMDISPLAYSETTINGSAPROC real_EnumDisplaySettingsA = EnumDisplaySettingsA;
DEFWINDOWPROCAPROC real_DefWindowProcA = DefWindowProcA;
GETKEYSTATEPROC real_GetKeyState = GetKeyState;
GETASYNCKEYSTATEPROC real_GetAsyncKeyState = GetAsyncKeyState;
GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps;
Expand Down Expand Up @@ -108,6 +109,7 @@ HOOKLIST g_hook_hooklist[] =
{ "GetWindowPlacement", (PROC)fake_GetWindowPlacement, (PROC*)&real_GetWindowPlacement, 0 },
{ "SetWindowPlacement", (PROC)fake_SetWindowPlacement, (PROC*)&real_SetWindowPlacement, 0 },
{ "EnumDisplaySettingsA", (PROC)fake_EnumDisplaySettingsA, (PROC*)&real_EnumDisplaySettingsA, 0 },
{ "DefWindowProcA", (PROC)fake_DefWindowProcA, (PROC*)&real_DefWindowProcA, 0 },
{ "GetKeyState", (PROC)fake_GetKeyState, (PROC*)&real_GetKeyState, 0 },
{ "GetAsyncKeyState", (PROC)fake_GetAsyncKeyState, (PROC*)&real_GetAsyncKeyState, 0 },
{ "SetForegroundWindow", (PROC)fake_SetForegroundWindow, (PROC*)&real_SetForegroundWindow, 0 },
Expand Down
11 changes: 11 additions & 0 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,17 @@ BOOL WINAPI fake_EnumDisplaySettingsA(LPCSTR lpszDeviceName, DWORD iModeNum, DEV
return result;
}

LRESULT WINAPI fake_DefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (g_ddraw.ref && g_ddraw.hwnd && g_ddraw.hwnd == hWnd)
{
if (Msg == WM_NCHITTEST)
return HTCLIENT;
}

return real_DefWindowProcA(hWnd, Msg, wParam, lParam);
}

SHORT WINAPI fake_GetKeyState(int nVirtKey)
{
if (g_config.windowed && g_ddraw.ref && g_ddraw.hwnd && !util_in_foreground())
Expand Down
22 changes: 11 additions & 11 deletions src/wndproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
case WM_CANCELMODE:
case WM_DISPLAYCHANGE:
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
case WM_GETMINMAXINFO:
{
Expand Down Expand Up @@ -88,20 +88,20 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
return 0;
}

return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
case WM_NCACTIVATE:
{
if (g_config.noactivateapp)
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);
}

break;
}
case WM_NCHITTEST:
{
if (g_config.allow_wm_nchittest && (g_mouse_locked || g_config.devmode))
if (g_mouse_locked || g_config.devmode)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };

Expand All @@ -128,7 +128,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
CallWindowProcA(g_ddraw.wndproc, hWnd, uMsg, wParam, MAKELPARAM(pt.x, pt.y));
}

LRESULT result = DefWindowProc(hWnd, uMsg, wParam, lParam);
LRESULT result = real_DefWindowProcA(hWnd, uMsg, wParam, lParam);

if (!g_config.resizable)
{
Expand Down Expand Up @@ -173,7 +173,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
case HTTOP:
case HTTOPLEFT:
case HTTOPRIGHT:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);
case HTCLIENT:
if (!g_mouse_locked && !g_config.devmode)
{
Expand Down Expand Up @@ -548,7 +548,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
}

return DefWindowProc(hWnd, uMsg, wParam, lParam); /* Carmageddon fix */
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam); /* Carmageddon fix */
}
case WM_MOVE:
{
Expand All @@ -575,7 +575,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
if (g_ddraw.got_child_windows)
RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);

return DefWindowProc(hWnd, uMsg, wParam, lParam); /* Carmageddon fix */
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam); /* Carmageddon fix */
}
case WM_RESTORE_STYLE:
{
Expand Down Expand Up @@ -606,7 +606,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
if (wParam == SC_MAXIMIZE)
{
if (IsWine())
return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);

if (g_config.resizable)
{
Expand All @@ -626,7 +626,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
return 0;

if (!GameHandlesClose)
return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);

break;
}
Expand Down Expand Up @@ -855,7 +855,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
{
if (wParam == VK_TAB || (wParam && wParam == g_config.hotkeys.toggle_fullscreen))
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
return real_DefWindowProcA(hWnd, uMsg, wParam, lParam);
}

break;
Expand Down

0 comments on commit f70f678

Please sign in to comment.