From 54d6ff5112fb6236c5dc1c7383a073b10f64ed77 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Wed, 8 May 2024 05:54:56 +0200 Subject: [PATCH] add support for woms 2 high resolution patch zoom --- inc/dd.h | 1 + src/dd.c | 5 +++-- src/render_ogl.c | 6 ++++-- src/utils.c | 34 ++++++++++++++++++++++++++++++++++ src/winapi_hooks.c | 2 +- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/inc/dd.h b/inc/dd.h index 5fdc857..01e535e 100644 --- a/inc/dd.h +++ b/inc/dd.h @@ -123,6 +123,7 @@ typedef struct CNCDDRAW BOOL isredalert; BOOL iscnc1; BOOL iskkndx; + BOOL isworms2; LONG upscale_hack_active; HCURSOR old_cursor; int show_cursor_count; diff --git a/src/dd.c b/src/dd.c index 576a521..94147ab 100644 --- a/src/dd.c +++ b/src/dd.c @@ -1190,8 +1190,9 @@ HRESULT dd_SetCooperativeLevel(HWND hwnd, DWORD dwFlags) g_ddraw.isredalert = strcmp(g_ddraw.title, "Red Alert") == 0; g_ddraw.iscnc1 = strcmp(g_ddraw.title, "Command & Conquer") == 0; g_ddraw.iskkndx = strcmp(g_ddraw.title, "KKND Xtreme") == 0; + g_ddraw.isworms2 = strcmp(g_ddraw.title, "worms2") == 0; - if (g_ddraw.iskkndx) + if (g_ddraw.iskkndx || g_ddraw.isworms2) { g_ddraw.upscale_hack_width = 640; g_ddraw.upscale_hack_height = 480; @@ -1202,7 +1203,7 @@ HRESULT dd_SetCooperativeLevel(HWND hwnd, DWORD dwFlags) g_ddraw.upscale_hack_height = 400; } - if (g_config.vhack && !g_ddraw.isredalert && !g_ddraw.iscnc1 && !g_ddraw.iskkndx) + if (g_config.vhack && !g_ddraw.isredalert && !g_ddraw.iscnc1 && !g_ddraw.iskkndx && !g_ddraw.isworms2) { g_config.vhack = 0; } diff --git a/src/render_ogl.c b/src/render_ogl.c index f208ab6..8e50e38 100644 --- a/src/render_ogl.c +++ b/src/render_ogl.c @@ -174,13 +174,15 @@ static void ogl_build_programs() if (!is_upscaler || g_ddraw.render.viewport.width != g_ddraw.width || - g_ddraw.render.viewport.height != g_ddraw.height) + g_ddraw.render.viewport.height != g_ddraw.height || + g_config.vhack) { g_ogl.scale_program = oglu_build_program_from_file(shader_path, core_profile); if (!g_ogl.scale_program && (g_ddraw.render.viewport.width != g_ddraw.width || - g_ddraw.render.viewport.height != g_ddraw.height)) + g_ddraw.render.viewport.height != g_ddraw.height || + g_config.vhack)) { g_ogl.scale_program = oglu_build_program( diff --git a/src/utils.c b/src/utils.c index 347a143..f15316d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -635,9 +635,29 @@ static unsigned char util_get_pixel(int x, int y) BOOL util_detect_low_res_screen() { + /* struct Copied from wkReSolution */ + typedef struct + { + PVOID UnkTable1; + DWORD Unk1, Unk2, Unk3, Unk4; + PVOID UnkDD, UnkTable2; + DWORD Unk5; + DWORD RenderWidth, RenderHeight; + DWORD Unk6, Unk7; + DWORD WidthRT, HeightRT; + DWORD HalfWidth, HalfHeight; + DWORD Unk8; + PCHAR UnkC; + LPDIRECTDRAW lpDD; + } W2DDSTRUCT, * LPW2DDSTRUCT; + static int* in_movie = (int*)0x00665F58; static int* is_vqa_640 = (int*)0x0065D7BC; static BYTE* should_stretch = (BYTE*)0x00607D78; + static LPW2DDSTRUCT* pW2DS; + + if (!pW2DS) + pW2DS = (char*)GetModuleHandleA(NULL) + 0x799C4; if (g_ddraw.width <= g_ddraw.upscale_hack_width || g_ddraw.height <= g_ddraw.upscale_hack_height) { @@ -663,6 +683,20 @@ BOOL util_detect_low_res_screen() { return util_get_pixel(g_ddraw.width - 3, 3) == 0; } + else if (g_ddraw.isworms2) + { + if ((*pW2DS)->RenderWidth < g_ddraw.width && (*pW2DS)->RenderHeight < g_ddraw.height) + { + if (g_ddraw.upscale_hack_width != (*pW2DS)->RenderWidth || g_ddraw.upscale_hack_height != (*pW2DS)->RenderHeight) + { + g_ddraw.upscale_hack_width = (*pW2DS)->RenderWidth; + g_ddraw.upscale_hack_height = (*pW2DS)->RenderHeight; + InterlockedExchange(&g_ddraw.upscale_hack_active, FALSE); + } + + return TRUE; + } + } return FALSE; } diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index 28e29c3..6b229ed 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -84,7 +84,7 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint) y = min(pt.y, g_ddraw.height - 1); } - if (g_config.vhack && InterlockedExchangeAdd(&g_ddraw.upscale_hack_active, 0)) + if (g_config.vhack && !g_ddraw.isworms2 && InterlockedExchangeAdd(&g_ddraw.upscale_hack_active, 0)) { diffx = 0; diffy = 0;