1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

make windowed+stretching working for a lot of non-cnc games

This commit is contained in:
FunkyFr3sh 2018-11-01 20:09:42 +01:00
parent b566d78499
commit d56240e178
5 changed files with 150 additions and 45 deletions

View File

@ -2,7 +2,7 @@
#define vxstr(a,b,c,d) str(a##.##b##.##c##.##d)
#define str(s) #s
#define VERSION 1,2,3,0
#define VERSION 1,2,3,1
1 VERSIONINFO
FILEVERSION VERSION

View File

@ -54,7 +54,6 @@ typedef struct IDirectDrawImpl
BOOL windowed;
BOOL border;
BOOL boxing;
BOOL windowed_init;
DEVMODE mode;
struct IDirectDrawSurfaceImpl *primary;
char title[128];
@ -100,7 +99,6 @@ typedef struct IDirectDrawImpl
char screenshotKey;
BOOL fullscreen;
BOOL maintas;
BOOL fakecursorpos;
BOOL noactivateapp;
BOOL hidemouse;
char shader[MAX_PATH];

View File

@ -406,9 +406,6 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
SendMessage(This->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hsicon);
}
//lock mouse in windowed mode if resolution changed during runtime
BOOL lockMouse = (This->width || This->height) && (This->width != width || This->height != height);
This->render.width = WindowRect.right;
This->render.height = WindowRect.bottom;
@ -448,6 +445,7 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
This->render.run = TRUE;
BOOL lockMouse = ddraw->locked;
mouse_unlock();
memset(&This->render.mode, 0, sizeof(DEVMODE));
@ -577,7 +575,6 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
SetWindowPos(ddraw->hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
MoveWindow(This->hWnd, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), TRUE);
This->windowed_init = TRUE;
if (This->renderer == render_d3d9_main)
InitDirect3D9();
@ -678,7 +675,6 @@ void ToggleFullscreen()
MoveWindow(ddraw->hWnd, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), TRUE);
ddraw->windowed = TRUE;
ddraw->windowed_init = TRUE;
}
mouse_lock();
}
@ -776,6 +772,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
RECT clientrc = { 0 };
// maintain aspect ratio
if (ddraw->maintas &&
CopyRect(&clientrc, windowrc) &&
UnadjustWindowRectEx(&clientrc, GetWindowLong(hWnd, GWL_STYLE), FALSE, GetWindowLong(hWnd, GWL_EXSTYLE)) &&
@ -809,6 +806,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
//enforce minimum window size
if (CopyRect(&clientrc, windowrc) &&
UnadjustWindowRectEx(&clientrc, GetWindowLong(hWnd, GWL_STYLE), FALSE, GetWindowLong(hWnd, GWL_EXSTYLE)) &&
SetRect(&clientrc, 0, 0, clientrc.right - clientrc.left, clientrc.bottom - clientrc.top))
@ -860,6 +858,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
//save new window position
if (CopyRect(&clientrc, windowrc) &&
UnadjustWindowRectEx(&clientrc, GetWindowLong(hWnd, GWL_STYLE), FALSE, GetWindowLong(hWnd, GWL_EXSTYLE)))
{
WindowRect.left = clientrc.left;
WindowRect.top = clientrc.top;
WindowRect.right = clientrc.right - clientrc.left;
WindowRect.bottom = clientrc.bottom - clientrc.top;
}
return TRUE;
}
}
@ -879,16 +887,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
case WM_MOVE:
{
if (ddraw->windowed && ddraw->windowed_init)
if (ddraw->windowed)
{
int x = (int)(short)LOWORD(lParam);
int y = (int)(short)HIWORD(lParam);
if (x != -32000)
WindowRect.left = x; // -32000 = Exit/Minimize
if (y != -32000)
WindowRect.top = y;
if (inSizeMove)
{
int x = (int)(short)LOWORD(lParam);
int y = (int)(short)HIWORD(lParam);
if (x != -32000)
WindowRect.left = x; // -32000 = Exit/Minimize
if (y != -32000)
WindowRect.top = y;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam); /* Carmageddon fix */

View File

@ -104,18 +104,16 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
if (lpPoint)
{
if (ddraw->fakecursorpos)
{
lpPoint->x = (int)ddraw->cursor.x;
lpPoint->y = (int)ddraw->cursor.y;
}
else if (ddraw->locked || ddraw->devmode)
if (ddraw->devmode)
{
lpPoint->x = realpt.x;
lpPoint->y = realpt.y;
}
else
return FALSE;
{
lpPoint->x = (int)ddraw->cursor.x;
lpPoint->y = (int)ddraw->cursor.y;
}
}
return TRUE;
@ -319,11 +317,124 @@ void mouse_unlock()
}
}
BOOL WINAPI fake_GetWindowRect(HWND hWnd, LPRECT lpRect)
{
if (lpRect && ddraw && ddraw->hWnd == hWnd)
{
lpRect->bottom = ddraw->height;
lpRect->left = 0;
lpRect->right = ddraw->width;
lpRect->top = 0;
return TRUE;
}
return GetWindowRect(hWnd, lpRect);
}
BOOL WINAPI fake_GetClientRect(HWND hWnd, LPRECT lpRect)
{
if (lpRect && ddraw && ddraw->hWnd == hWnd)
{
lpRect->bottom = ddraw->height;
lpRect->left = 0;
lpRect->right = ddraw->width;
lpRect->top = 0;
return TRUE;
}
return GetClientRect(hWnd, lpRect);
}
BOOL WINAPI fake_ClientToScreen(HWND hWnd, LPPOINT lpPoint)
{
return TRUE;
}
BOOL WINAPI fake_ScreenToClient(HWND hWnd, LPPOINT lpPoint)
{
return TRUE;
}
BOOL WINAPI fake_SetCursorPos(int X, int Y)
{
POINT pt = { X, Y };
return ddraw && ClientToScreen(ddraw->hWnd, &pt) && SetCursorPos(pt.x, pt.y);
}
HWND WINAPI fake_WindowFromPoint(POINT Point)
{
POINT pt = { Point.x, Point.y };
return ddraw && ClientToScreen(ddraw->hWnd, &pt) ? WindowFromPoint(pt) : NULL;
}
BOOL WINAPI fake_GetClipCursor(LPRECT lpRect)
{
if (lpRect && ddraw)
{
lpRect->bottom = ddraw->height;
lpRect->left = 0;
lpRect->right = ddraw->width;
lpRect->top = 0;
return TRUE;
}
return FALSE;
}
BOOL WINAPI fake_GetCursorInfo(PCURSORINFO pci)
{
return pci && ddraw && GetCursorInfo(pci) && ScreenToClient(ddraw->hWnd, &pci->ptScreenPos);
}
int WINAPI fake_GetSystemMetrics(int nIndex)
{
if (ddraw)
{
if (nIndex == SM_CXSCREEN)
return ddraw->width;
if (nIndex == SM_CYSCREEN)
return ddraw->height;
}
return GetSystemMetrics(nIndex);
}
BOOL WINAPI fake_SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
{
if (ddraw && ddraw->hWnd == hWnd)
return TRUE;
return SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
}
BOOL WINAPI fake_MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint)
{
if (ddraw && ddraw->hWnd == hWnd)
return TRUE;
return MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint);
}
void mouse_init()
{
HookIAT(GetModuleHandle(NULL), "user32.dll", "GetCursorPos", (PROC)fake_GetCursorPos);
HookIAT(GetModuleHandle(NULL), "user32.dll", "ClipCursor", (PROC)fake_ClipCursor);
HookIAT(GetModuleHandle(NULL), "user32.dll", "ShowCursor", (PROC)fake_ShowCursor);
HookIAT(GetModuleHandle(NULL), "user32.dll", "SetCursor", (PROC)fake_SetCursor);
HookIAT(GetModuleHandle(NULL), "user32.dll", "GetWindowRect", (PROC)fake_GetWindowRect);
HookIAT(GetModuleHandle(NULL), "user32.dll", "GetClientRect", (PROC)fake_GetClientRect);
HookIAT(GetModuleHandle(NULL), "user32.dll", "ClientToScreen", (PROC)fake_ClientToScreen);
HookIAT(GetModuleHandle(NULL), "user32.dll", "ScreenToClient", (PROC)fake_ScreenToClient);
HookIAT(GetModuleHandle(NULL), "user32.dll", "SetCursorPos", (PROC)fake_SetCursorPos);
HookIAT(GetModuleHandle(NULL), "user32.dll", "GetClipCursor", (PROC)fake_GetClipCursor);
HookIAT(GetModuleHandle(NULL), "user32.dll", "WindowFromPoint", (PROC)fake_WindowFromPoint);
HookIAT(GetModuleHandle(NULL), "user32.dll", "GetCursorInfo", (PROC)fake_GetCursorInfo);
HookIAT(GetModuleHandle(NULL), "user32.dll", "GetSystemMetrics", (PROC)fake_GetSystemMetrics);
HookIAT(GetModuleHandle(NULL), "user32.dll", "SetWindowPos", (PROC)fake_SetWindowPos);
HookIAT(GetModuleHandle(NULL), "user32.dll", "MoveWindow", (PROC)fake_MoveWindow);
mouse_active = TRUE;
}

View File

@ -38,7 +38,6 @@ void Settings_Load()
ddraw->adjmouse = GetBool("adjmouse", FALSE);
ddraw->devmode = GetBool("devmode", FALSE);
ddraw->vsync = GetBool("vsync", FALSE);
ddraw->fakecursorpos = GetBool("fakecursorpos", TRUE);
ddraw->noactivateapp = GetBool("noactivateapp", FALSE);
ddraw->vhack = GetBool("vhack", FALSE);
ddraw->hidemouse = GetBool("hidemouse", TRUE);
@ -190,8 +189,6 @@ static void CreateSettingsIni()
"posY=-32000\n"
"; Screenshot Hotkey, default = CTRL + G\n"
"screenshotKey=G\n"
"; Fake cursor position for games that use GetCursorPos and expect to be in fullscreen\n"
"fakecursorpos=true\n"
"; Hide WM_ACTIVATEAPP messages to prevent freezing on alt+tab (Carmageddon)\n"
"noactivateapp=false\n"
"; developer mode (don't lock the cursor)\n"
@ -205,7 +202,6 @@ static void CreateSettingsIni()
"\n"
"[CARMA95]\n"
"renderer=opengl\n"
"fakecursorpos=false\n"
"noactivateapp=true\n"
"maxgameticks=30\n"
"\n"
@ -214,40 +210,29 @@ static void CreateSettingsIni()
"\n"
"[empires]\n"
"hidemouse=false\n"
"border=false\n"
"posX=0\n"
"posY=0\n"
"\n"
"[empiresx]\n"
"hidemouse=false\n"
"border=false\n"
"posX=0\n"
"posY=0\n"
"\n"
"[EMPIRES2]\n"
"hidemouse=false\n"
"border=false\n"
"posX=0\n"
"posY=0\n"
"\n"
"[age2_x1]\n"
"hidemouse=false\n"
"border=false\n"
"posX=0\n"
"posY=0\n"
"\n"
"[olwin]\n"
"noactivateapp=true\n"
"maxgameticks=60\n"
"\n"
"[KEEPER95]\n"
"border=false\n"
"posX=0\n"
"posY=0\n"
"\n"
"[DKReign]\n"
"maxgameticks=60\n"
"\n"
"[battlegrounds]\n"
"hidemouse=false\n"
"\n"
"[battlegrounds_x1]\n"
"hidemouse=false\n"
"\n"
, fh);
fclose(fh);