mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
make bnet moveable
This commit is contained in:
parent
af281c38d2
commit
18f2e16bb0
@ -3,8 +3,6 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
typedef HFONT(__stdcall* CREATEFONTINDIRECTA)(CONST LOGFONT*);
|
||||
|
||||
typedef BOOL (WINAPI* GETCURSORPOSPROC)(LPPOINT);
|
||||
typedef BOOL(WINAPI* CLIPCURSORPROC)(const RECT*);
|
||||
typedef int (WINAPI* SHOWCURSORPROC)(BOOL);
|
||||
@ -22,6 +20,9 @@ typedef BOOL (WINAPI* SETWINDOWPOSPROC)(HWND, HWND, int, int, int, int, UINT);
|
||||
typedef BOOL (WINAPI* MOVEWINDOWPROC)(HWND, int, int, int, int, BOOL);
|
||||
typedef LRESULT (WINAPI* SENDMESSAGEAPROC)(HWND, UINT, WPARAM, LPARAM);
|
||||
typedef LONG (WINAPI* SETWINDOWLONGAPROC)(HWND, int, LONG);
|
||||
typedef BOOL (WINAPI* ENABLEWINDOWPROC)(HWND, BOOL);
|
||||
typedef HWND (WINAPI* CREATEWINDOWEXAPROC)(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
|
||||
typedef BOOL (WINAPI* DESTROYWINDOWPROC)(HWND);
|
||||
|
||||
extern GETCURSORPOSPROC real_GetCursorPos;
|
||||
extern CLIPCURSORPROC real_ClipCursor;
|
||||
@ -40,6 +41,9 @@ extern SETWINDOWPOSPROC real_SetWindowPos;
|
||||
extern MOVEWINDOWPROC real_MoveWindow;
|
||||
extern SENDMESSAGEAPROC real_SendMessageA;
|
||||
extern SETWINDOWLONGAPROC real_SetWindowLongA;
|
||||
extern ENABLEWINDOWPROC real_EnableWindow;
|
||||
extern CREATEWINDOWEXAPROC real_CreateWindowExA;
|
||||
extern DESTROYWINDOWPROC real_DestroyWindow;
|
||||
|
||||
extern BOOL Hook_Active;
|
||||
|
||||
|
@ -23,5 +23,10 @@ BOOL WINAPI fake_SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int
|
||||
BOOL WINAPI fake_MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint);
|
||||
LRESULT WINAPI fake_SendMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
LONG WINAPI fake_SetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLong);
|
||||
BOOL WINAPI fake_EnableWindow(HWND hWnd, BOOL bEnable);
|
||||
BOOL WINAPI fake_DestroyWindow(HWND hWnd);
|
||||
HWND WINAPI fake_CreateWindowExA(
|
||||
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y,
|
||||
int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
|
||||
|
||||
#endif
|
||||
|
10
src/hook.c
10
src/hook.c
@ -22,6 +22,10 @@ SETWINDOWPOSPROC real_SetWindowPos = SetWindowPos;
|
||||
MOVEWINDOWPROC real_MoveWindow = MoveWindow;
|
||||
SENDMESSAGEAPROC real_SendMessageA = SendMessageA;
|
||||
SETWINDOWLONGAPROC real_SetWindowLongA = SetWindowLongA;
|
||||
ENABLEWINDOWPROC real_EnableWindow = EnableWindow;
|
||||
CREATEWINDOWEXAPROC real_CreateWindowExA = CreateWindowExA;
|
||||
DESTROYWINDOWPROC real_DestroyWindow = DestroyWindow;
|
||||
|
||||
|
||||
void Hook_PatchIAT(HMODULE hMod, char *moduleName, char *functionName, PROC newFunction)
|
||||
{
|
||||
@ -146,6 +150,9 @@ void Hook_TryHotPatch(char *moduleName, char *functionName, PROC newFunction, PR
|
||||
else
|
||||
{
|
||||
Hook_PatchIAT(GetModuleHandle(NULL), moduleName, functionName, newFunction);
|
||||
|
||||
if (ddraw->bnetHack)
|
||||
Hook_PatchIAT(GetModuleHandle("storm.dll"), moduleName, functionName, newFunction);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,6 +179,9 @@ void Hook_Init()
|
||||
Hook_TryHotPatch("user32.dll", "MoveWindow", (PROC)fake_MoveWindow, (PROC *)&real_MoveWindow);
|
||||
Hook_TryHotPatch("user32.dll", "SendMessageA", (PROC)fake_SendMessageA, (PROC *)&real_SendMessageA);
|
||||
Hook_TryHotPatch("user32.dll", "SetWindowLongA", (PROC)fake_SetWindowLongA, (PROC *)&real_SetWindowLongA);
|
||||
Hook_TryHotPatch("user32.dll", "EnableWindow", (PROC)fake_EnableWindow, (PROC *)&real_EnableWindow);
|
||||
Hook_TryHotPatch("user32.dll", "CreateWindowExA", (PROC)fake_CreateWindowExA, (PROC *)&real_CreateWindowExA);
|
||||
Hook_TryHotPatch("user32.dll", "DestroyWindow", (PROC)fake_DestroyWindow, (PROC *)&real_DestroyWindow);
|
||||
|
||||
//Hook_PatchIAT(GetModuleHandle(NULL), "user32.dll", "GetCursorPos", (PROC)fake_GetCursorPos);
|
||||
}
|
||||
|
73
src/main.c
73
src/main.c
@ -196,6 +196,28 @@ void LimitGameTicks()
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateBnetPos(int oldX, int oldY, int newX, int newY)
|
||||
{
|
||||
HWND hWnd = FindWindowEx(HWND_DESKTOP, NULL, "SDlgDialog", NULL);
|
||||
|
||||
while (hWnd != NULL)
|
||||
{
|
||||
RECT rc;
|
||||
real_GetWindowRect(hWnd, &rc);
|
||||
|
||||
real_SetWindowPos(
|
||||
hWnd,
|
||||
0,
|
||||
rc.left + (newX - oldX),
|
||||
rc.top + (newY - oldY),
|
||||
0,
|
||||
0,
|
||||
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
|
||||
hWnd = FindWindowEx(HWND_DESKTOP, hWnd, "SDlgDialog", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_Compact(IDirectDrawImpl *This)
|
||||
{
|
||||
printf("DirectDraw::Compact(This=%p) ???\n", This);
|
||||
@ -776,7 +798,6 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
|
||||
int y = (WindowRect.top != -32000) ? WindowRect.top : (This->mode.dmPelsHeight / 2) - (This->render.height / 2);
|
||||
RECT dst = { x, y, This->render.width + x, This->render.height + y };
|
||||
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
|
||||
real_SetWindowPos(ddraw->hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
real_MoveWindow(This->hWnd, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), TRUE);
|
||||
|
||||
if (This->renderer == render_d3d9_main)
|
||||
@ -833,6 +854,9 @@ HRESULT __stdcall ddraw_SetDisplayMode2(IDirectDrawImpl *This, DWORD width, DWOR
|
||||
|
||||
void ToggleFullscreen()
|
||||
{
|
||||
if (ddraw->bnetHack)
|
||||
return;
|
||||
|
||||
if (ddraw->windowed)
|
||||
{
|
||||
mouse_unlock();
|
||||
@ -1083,6 +1107,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
if (CopyRect(&clientrc, windowrc) &&
|
||||
UnadjustWindowRectEx(&clientrc, GetWindowLong(hWnd, GWL_STYLE), FALSE, GetWindowLong(hWnd, GWL_EXSTYLE)))
|
||||
{
|
||||
if (ddraw->bnetHack && WindowRect.left != -32000)
|
||||
UpdateBnetPos(WindowRect.left, WindowRect.top, clientrc.left, clientrc.top);
|
||||
|
||||
WindowRect.left = clientrc.left;
|
||||
WindowRect.top = clientrc.top;
|
||||
WindowRect.right = clientrc.right - clientrc.left;
|
||||
@ -1129,11 +1156,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (ddraw->windowed)
|
||||
{
|
||||
int x = (int)(short)LOWORD(lParam);
|
||||
int y = (int)(short)HIWORD(lParam);
|
||||
|
||||
if (x != -32000)
|
||||
{
|
||||
if (ddraw->bnetHack && WindowRect.left != -32000)
|
||||
UpdateBnetPos(WindowRect.left, WindowRect.top, x, y);
|
||||
}
|
||||
|
||||
if (inSizeMove || ddraw->wine)
|
||||
{
|
||||
int x = (int)(short)LOWORD(lParam);
|
||||
int y = (int)(short)HIWORD(lParam);
|
||||
|
||||
if (x != -32000)
|
||||
WindowRect.left = x; // -32000 = Exit/Minimize
|
||||
|
||||
@ -1182,38 +1215,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
mouse_unlock();
|
||||
return 0;
|
||||
|
||||
|
||||
case WM_ENABLE:
|
||||
{
|
||||
if (ddraw->bnetHack)
|
||||
{
|
||||
if (wParam)
|
||||
mouse_lock();
|
||||
else
|
||||
mouse_unlock();
|
||||
|
||||
HWND hWnd = FindWindowEx(HWND_DESKTOP, NULL, "SDlgDialog", NULL);
|
||||
if (hWnd)
|
||||
{
|
||||
BOOL hideCursor = TRUE;
|
||||
|
||||
do
|
||||
{
|
||||
RECT rc;
|
||||
if (real_GetWindowRect(hWnd, &rc) && rc.bottom - rc.top == 479)
|
||||
hideCursor = FALSE;
|
||||
|
||||
} while ((hWnd = FindWindowEx(HWND_DESKTOP, hWnd, "SDlgDialog", NULL)));
|
||||
|
||||
if (hideCursor)
|
||||
while (real_ShowCursor(FALSE) > 0);
|
||||
}
|
||||
|
||||
ddraw->bnetActive = !wParam;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_ACTIVATE:
|
||||
{
|
||||
return 0;
|
||||
|
71
src/mouse.c
71
src/mouse.c
@ -142,6 +142,9 @@ void mouse_lock()
|
||||
{
|
||||
RECT rc;
|
||||
|
||||
if (ddraw->bnetHack && ddraw->bnetActive)
|
||||
return;
|
||||
|
||||
if (ddraw->devmode)
|
||||
{
|
||||
if (ddraw->handlemouse)
|
||||
@ -277,7 +280,14 @@ BOOL WINAPI fake_GetWindowRect(HWND hWnd, LPRECT lpRect)
|
||||
}
|
||||
else
|
||||
{
|
||||
return real_GetWindowRect(hWnd, lpRect) && MapWindowPoints(HWND_DESKTOP, ddraw->hWnd, (LPPOINT)lpRect, 2);
|
||||
if (real_GetWindowRect(hWnd, lpRect))
|
||||
{
|
||||
MapWindowPoints(HWND_DESKTOP, ddraw->hWnd, (LPPOINT)lpRect, 2);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,3 +408,62 @@ LONG WINAPI fake_SetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLong)
|
||||
|
||||
return real_SetWindowLongA(hWnd, nIndex, dwNewLong);
|
||||
}
|
||||
|
||||
BOOL WINAPI fake_EnableWindow(HWND hWnd, BOOL bEnable)
|
||||
{
|
||||
if (ddraw && ddraw->hWnd == hWnd)
|
||||
{
|
||||
if (ddraw->bnetHack)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return real_EnableWindow(hWnd, bEnable);
|
||||
}
|
||||
|
||||
BOOL WINAPI fake_DestroyWindow(HWND hWnd)
|
||||
{
|
||||
BOOL result = real_DestroyWindow(hWnd);
|
||||
|
||||
if (ddraw && ddraw->hWnd != hWnd && ddraw->bnetActive && ddraw->bnetHack && !FindWindowEx(HWND_DESKTOP, NULL, "SDlgDialog", NULL))
|
||||
{
|
||||
ddraw->bnetActive = FALSE;
|
||||
mouse_lock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HWND WINAPI fake_CreateWindowExA(
|
||||
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y,
|
||||
int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
|
||||
{
|
||||
HWND hWnd = real_CreateWindowExA(
|
||||
dwExStyle,
|
||||
lpClassName,
|
||||
lpWindowName,
|
||||
dwStyle | WS_CLIPCHILDREN,
|
||||
X,
|
||||
Y,
|
||||
nWidth,
|
||||
nHeight,
|
||||
hWndParent,
|
||||
hMenu,
|
||||
hInstance,
|
||||
lpParam);
|
||||
|
||||
if (_strcmpi(lpClassName, "SDlgDialog") == 0 && ddraw && ddraw->bnetHack)
|
||||
{
|
||||
if (!ddraw->bnetActive)
|
||||
{
|
||||
ddraw->bnetActive = TRUE;
|
||||
mouse_unlock();
|
||||
}
|
||||
|
||||
POINT pt = { 0, 0 };
|
||||
real_ClientToScreen(ddraw->hWnd, &pt);
|
||||
|
||||
real_SetWindowPos(hWnd, 0, pt.x + X, pt.y + Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
return hWnd;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "main.h"
|
||||
#include "hook.h"
|
||||
#include "surface.h"
|
||||
#include "mouse.h"
|
||||
#include "scale_pattern.h"
|
||||
|
||||
// enables redraw via blt/unlock if there wasn't any flip for X ms
|
||||
@ -1010,7 +1011,7 @@ HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRe
|
||||
do
|
||||
{
|
||||
RECT rc;
|
||||
if (real_GetWindowRect(hWnd, &rc))
|
||||
if (fake_GetWindowRect(hWnd, &rc))
|
||||
{
|
||||
if (rc.bottom - rc.top == 479)
|
||||
erase = TRUE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user