2020-10-13 09:20:52 +02:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2010-10-24 01:02:08 +03:00
|
|
|
#include <windows.h>
|
2020-10-13 09:20:52 +02:00
|
|
|
#include "dd.h"
|
2019-03-19 06:57:49 +01:00
|
|
|
#include "hook.h"
|
2010-11-10 19:25:05 +02:00
|
|
|
|
|
|
|
|
2010-10-24 01:02:08 +03:00
|
|
|
void mouse_lock()
|
|
|
|
{
|
2010-11-17 18:57:22 +02:00
|
|
|
RECT rc;
|
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
if (g_ddraw->bnet_active)
|
2019-08-06 04:37:06 +02:00
|
|
|
return;
|
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
if (g_ddraw->devmode)
|
2012-08-09 14:35:28 +03:00
|
|
|
return;
|
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
if (g_hook_active && !g_ddraw->locked)
|
2010-10-24 01:02:08 +03:00
|
|
|
{
|
2021-06-11 20:30:43 +02:00
|
|
|
if (g_ddraw->adjmouse)
|
2018-03-15 20:49:27 +01:00
|
|
|
{
|
2021-06-16 05:57:19 +02:00
|
|
|
rc.top = g_ddraw->render.viewport.y;
|
|
|
|
rc.left = g_ddraw->render.viewport.x;
|
|
|
|
rc.right = g_ddraw->render.viewport.width + g_ddraw->render.viewport.x;
|
|
|
|
rc.bottom = g_ddraw->render.viewport.height + g_ddraw->render.viewport.y;
|
2018-03-15 20:49:27 +01:00
|
|
|
}
|
|
|
|
else
|
2018-03-11 21:23:22 +01:00
|
|
|
{
|
2021-06-16 05:57:19 +02:00
|
|
|
rc.top = g_ddraw->render.viewport.y;
|
|
|
|
rc.left = g_ddraw->render.viewport.x;
|
|
|
|
rc.right = g_ddraw->width + g_ddraw->render.viewport.x;
|
|
|
|
rc.bottom = g_ddraw->height + g_ddraw->render.viewport.y;
|
2018-03-11 21:23:22 +01:00
|
|
|
}
|
2018-03-09 13:50:56 +01:00
|
|
|
|
2021-06-11 20:30:43 +02:00
|
|
|
/* Convert the client area to screen coordinates */
|
2018-03-09 13:50:56 +01:00
|
|
|
POINT pt = { rc.left, rc.top };
|
|
|
|
POINT pt2 = { rc.right, rc.bottom };
|
2020-10-13 21:58:04 +02:00
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
real_ClientToScreen(g_ddraw->hwnd, &pt);
|
|
|
|
real_ClientToScreen(g_ddraw->hwnd, &pt2);
|
2021-06-11 20:30:43 +02:00
|
|
|
|
2018-03-09 13:50:56 +01:00
|
|
|
SetRect(&rc, pt.x, pt.y, pt2.x, pt2.y);
|
2021-06-11 20:30:43 +02:00
|
|
|
|
2021-05-10 04:00:45 +02:00
|
|
|
rc.bottom -= (LONG)((g_ddraw->mouse_y_adjust * 2) * g_ddraw->render.scale_h);
|
2018-03-11 21:23:22 +01:00
|
|
|
|
2021-06-11 20:30:43 +02:00
|
|
|
if (g_ddraw->adjmouse)
|
2018-03-11 21:23:22 +01:00
|
|
|
{
|
2019-03-19 06:57:49 +01:00
|
|
|
real_SetCursorPos(
|
2021-06-11 20:30:43 +02:00
|
|
|
(int)(rc.left + (g_ddraw->cursor.x * g_ddraw->render.scale_w)),
|
2021-05-10 04:00:45 +02:00
|
|
|
(int)(rc.top + ((g_ddraw->cursor.y - g_ddraw->mouse_y_adjust) * g_ddraw->render.scale_h)));
|
2018-03-11 21:23:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-13 09:20:52 +02:00
|
|
|
real_SetCursorPos(rc.left + g_ddraw->cursor.x, rc.top + g_ddraw->cursor.y - g_ddraw->mouse_y_adjust);
|
2018-03-11 21:23:22 +01:00
|
|
|
}
|
2010-11-17 18:57:22 +02:00
|
|
|
|
2021-06-16 05:57:19 +02:00
|
|
|
real_SetCursor(g_ddraw->old_cursor);
|
|
|
|
|
2021-06-17 04:12:05 +02:00
|
|
|
int cur_count = real_ShowCursor(TRUE) - 1;
|
|
|
|
real_ShowCursor(FALSE);
|
|
|
|
|
|
|
|
int game_count = InterlockedExchangeAdd(&g_ddraw->show_cursor_count, 0);
|
|
|
|
|
|
|
|
if (cur_count > game_count)
|
|
|
|
{
|
|
|
|
while (real_ShowCursor(FALSE) > game_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_count < game_count)
|
2018-11-15 10:47:18 +01:00
|
|
|
{
|
2021-06-17 04:12:05 +02:00
|
|
|
while (real_ShowCursor(TRUE) < game_count);
|
2018-11-15 10:47:18 +01:00
|
|
|
}
|
2021-06-12 05:45:28 +02:00
|
|
|
|
2021-06-16 05:57:19 +02:00
|
|
|
real_ClipCursor(&rc);
|
2018-10-26 05:27:10 +02:00
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
g_ddraw->locked = TRUE;
|
2010-10-24 01:02:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouse_unlock()
|
|
|
|
{
|
2011-09-11 16:10:43 +03:00
|
|
|
RECT rc;
|
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
if (g_ddraw->devmode)
|
2012-08-09 14:35:28 +03:00
|
|
|
return;
|
|
|
|
|
2020-10-13 21:58:04 +02:00
|
|
|
if (!g_hook_active)
|
2010-10-24 19:47:51 +03:00
|
|
|
return;
|
|
|
|
|
2020-10-13 21:58:04 +02:00
|
|
|
if (g_ddraw->locked)
|
2010-10-24 01:02:08 +03:00
|
|
|
{
|
2020-10-13 09:20:52 +02:00
|
|
|
g_ddraw->locked = FALSE;
|
2011-07-08 18:22:43 +03:00
|
|
|
|
2021-06-11 20:30:43 +02:00
|
|
|
/* Get the window client area */
|
2020-10-13 09:20:52 +02:00
|
|
|
real_GetClientRect(g_ddraw->hwnd, &rc);
|
2021-06-11 20:30:43 +02:00
|
|
|
|
|
|
|
/* Convert the client area to screen coordinates */
|
2018-03-09 13:50:56 +01:00
|
|
|
POINT pt = { rc.left, rc.top };
|
|
|
|
POINT pt2 = { rc.right, rc.bottom };
|
2020-10-13 21:58:04 +02:00
|
|
|
|
2020-10-13 09:20:52 +02:00
|
|
|
real_ClientToScreen(g_ddraw->hwnd, &pt);
|
|
|
|
real_ClientToScreen(g_ddraw->hwnd, &pt2);
|
2020-10-13 21:58:04 +02:00
|
|
|
|
2018-03-09 13:50:56 +01:00
|
|
|
SetRect(&rc, pt.x, pt.y, pt2.x, pt2.y);
|
2021-06-11 20:30:43 +02:00
|
|
|
|
2021-06-16 05:57:19 +02:00
|
|
|
CURSORINFO ci = { .cbSize = sizeof(CURSORINFO) };
|
|
|
|
if (real_GetCursorInfo(&ci) && ci.flags == 0)
|
2018-10-26 05:27:10 +02:00
|
|
|
{
|
2019-03-19 06:57:49 +01:00
|
|
|
while (real_ShowCursor(TRUE) < 0);
|
2018-11-16 08:43:28 +01:00
|
|
|
}
|
2010-11-17 18:57:22 +02:00
|
|
|
|
2021-06-12 05:45:28 +02:00
|
|
|
real_SetCursor(LoadCursor(NULL, IDC_ARROW));
|
|
|
|
|
2019-03-19 06:57:49 +01:00
|
|
|
real_ClipCursor(NULL);
|
2021-06-11 20:30:43 +02:00
|
|
|
|
2019-03-19 06:57:49 +01:00
|
|
|
real_SetCursorPos(
|
2021-06-11 20:30:43 +02:00
|
|
|
(int)(rc.left + g_ddraw->render.viewport.x + (g_ddraw->cursor.x * g_ddraw->render.scale_w)),
|
2021-05-10 04:00:45 +02:00
|
|
|
(int)(rc.top + g_ddraw->render.viewport.y + ((g_ddraw->cursor.y + g_ddraw->mouse_y_adjust) * g_ddraw->render.scale_h)));
|
2018-11-01 20:09:42 +01:00
|
|
|
}
|
2019-08-06 04:37:06 +02:00
|
|
|
}
|