From 7c721aa1f89ef41c7324d401594b0517fd973686 Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 19 Oct 2019 17:04:34 -0400 Subject: [PATCH] hooklib/gfx.c: Wire up gfx config --- chunihook/config.c | 3 +++ chunihook/config.h | 3 +++ chunihook/dllmain.c | 3 +-- hooklib/gfx.c | 22 ++++++++++++---------- hooklib/gfx.h | 5 +++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/chunihook/config.c b/chunihook/config.c index d2fe313..9f534b4 100644 --- a/chunihook/config.c +++ b/chunihook/config.c @@ -7,6 +7,8 @@ #include "chunihook/config.h" +#include "hooklib/config.h" + #include "platform/config.h" void chuni_hook_config_load( @@ -20,4 +22,5 @@ void chuni_hook_config_load( nu_config_load(&cfg->nu, filename); amex_config_load(&cfg->amex, filename); + gfx_config_load(&cfg->gfx, filename); } diff --git a/chunihook/config.h b/chunihook/config.h index f62459a..5444a79 100644 --- a/chunihook/config.h +++ b/chunihook/config.h @@ -4,11 +4,14 @@ #include "amex/config.h" +#include "hooklib/config.h" + #include "platform/config.h" struct chuni_hook_config { struct nu_config nu; struct amex_config amex; + struct gfx_config gfx; }; void chuni_hook_config_load( diff --git a/chunihook/dllmain.c b/chunihook/dllmain.c index f2fc035..9a14b4b 100644 --- a/chunihook/dllmain.c +++ b/chunihook/dllmain.c @@ -47,7 +47,7 @@ static DWORD CALLBACK chuni_pre_startup(void) /* Hook Win32 APIs */ - gfx_hook_init(); + gfx_hook_init(&chuni_hook_cfg.gfx); serial_hook_init(); /* Initialize emulation hooks */ @@ -64,7 +64,6 @@ static DWORD CALLBACK chuni_pre_startup(void) /* Initialize debug helpers */ spike_hook_init(L".\\segatools.ini"); - gfx_set_windowed(); dprintf("--- End chuni_pre_startup ---\n"); diff --git a/hooklib/gfx.c b/hooklib/gfx.c index 185798e..c89ee54 100644 --- a/hooklib/gfx.c +++ b/hooklib/gfx.c @@ -1,12 +1,14 @@ #include #include +#include #include #include #include "hook/com-proxy.h" #include "hook/table.h" +#include "hooklib/config.h" #include "hooklib/gfx.h" #include "util/dprintf.h" @@ -19,12 +21,10 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice( DWORD flags, D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev); - static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver); - static IDirect3D9 * (WINAPI *next_Direct3DCreate9)(UINT sdk_ver); -static bool gfx_windowed; +static struct gfx_config gfx_config; static const struct hook_symbol gfx_hooks[] = { { @@ -34,14 +34,16 @@ static const struct hook_symbol gfx_hooks[] = { }, }; -void gfx_hook_init(void) +void gfx_hook_init(const struct gfx_config *cfg) { - hook_table_apply(NULL, "d3d9.dll", gfx_hooks, _countof(gfx_hooks)); -} + assert(cfg != NULL); -void gfx_set_windowed(void) -{ - gfx_windowed = true; + if (!cfg->enable) { + return; + } + + memcpy(&gfx_config, cfg, sizeof(*cfg)); + hook_table_apply(NULL, "d3d9.dll", gfx_hooks, _countof(gfx_hooks)); } static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver) @@ -99,7 +101,7 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice( proxy = com_proxy_downcast(self); real = proxy->real; - if (gfx_windowed) { + if (gfx_config.windowed) { pp->Windowed = TRUE; pp->FullScreen_RefreshRateInHz = 0; } diff --git a/hooklib/gfx.h b/hooklib/gfx.h index 5c77059..85b9bfc 100644 --- a/hooklib/gfx.h +++ b/hooklib/gfx.h @@ -1,4 +1,5 @@ #pragma once -void gfx_hook_init(void); -void gfx_set_windowed(void); +#include "hooklib/config.h" + +void gfx_hook_init(const struct gfx_config *cfg);