From 8b34ec65ad5d1c82c639d4fa5f3509b61021741d Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Mon, 20 Nov 2017 00:56:56 +0100 Subject: [PATCH] automatic stretching/window mode for invalid resolutions --- ddraw.rc | 8 ++++---- src/main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ddraw.rc b/ddraw.rc index 62e831b..08a851c 100644 --- a/ddraw.rc +++ b/ddraw.rc @@ -1,6 +1,6 @@ 1 VERSIONINFO -FILEVERSION 1,1,2,0 -PRODUCTVERSION 1,1,2,0 +FILEVERSION 1,1,3,0 +PRODUCTVERSION 1,1,3,0 { BLOCK "StringFileInfo" { @@ -8,13 +8,13 @@ PRODUCTVERSION 1,1,2,0 { VALUE "CompanyName", "cncnet.org" VALUE "FileDescription", "DirectDraw replacement for C&C95 and Red Alert" - VALUE "FileVersion", "1.1.2.0" + VALUE "FileVersion", "1.1.3.0" VALUE "InternalName", "ddraw" VALUE "LegalCopyright", "Copyright (c) 2010-2017" VALUE "LegalTrademarks", "" VALUE "OriginalFileName", "ddraw.dll" VALUE "ProductName", "DirectDraw replacement for C&C95 and Red Alert" - VALUE "ProductVersion", "1.1.2.0" + VALUE "ProductVersion", "1.1.3.0" VALUE "Comments", "https://cncnet.org" } } diff --git a/src/main.c b/src/main.c index 334d8d8..b0e06ee 100644 --- a/src/main.c +++ b/src/main.c @@ -276,6 +276,57 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD This->render.mode.dmBitsPerPel = This->render.bpp; } + if(!This->windowed) + { + // Making sure the chosen resolution is valid + if(!This->devmode) + { + int width = This->render.width; + int height = This->render.height; + + if (ChangeDisplaySettings(&This->render.mode, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + { + // fail... compare resolutions + if (This->render.width > This->mode.dmPelsWidth || This->render.height > This->mode.dmPelsHeight) + { + // chosen game resolution higher than current resolution, use window mode for this case + This->windowed = TRUE; + } + else + { + // Try 2x scaling + This->render.width *= 2; + This->render.height *= 2; + + This->render.mode.dmPelsWidth = This->render.width; + This->render.mode.dmPelsHeight = This->render.height; + + if (ChangeDisplaySettings(&This->render.mode, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + { + // try current display settings + This->render.width = This->mode.dmPelsWidth; + This->render.height = This->mode.dmPelsHeight; + + This->render.mode.dmPelsWidth = This->render.width; + This->render.mode.dmPelsHeight = This->render.height; + + if (ChangeDisplaySettings(&This->render.mode, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + { + // everything failed, use window mode instead + This->render.width = width; + This->render.height = height; + + This->render.mode.dmPelsWidth = This->render.width; + This->render.mode.dmPelsHeight = This->render.height; + + This->windowed = TRUE; + } + } + } + } + } + } + if(This->windowed) { if(!This->windowed_init)