hooklib/gfx.c: Wire up gfx config

This commit is contained in:
Tau 2019-10-19 17:04:34 -04:00
parent 871b82a8ad
commit 7c721aa1f8
5 changed files with 22 additions and 14 deletions

View File

@ -7,6 +7,8 @@
#include "chunihook/config.h" #include "chunihook/config.h"
#include "hooklib/config.h"
#include "platform/config.h" #include "platform/config.h"
void chuni_hook_config_load( void chuni_hook_config_load(
@ -20,4 +22,5 @@ void chuni_hook_config_load(
nu_config_load(&cfg->nu, filename); nu_config_load(&cfg->nu, filename);
amex_config_load(&cfg->amex, filename); amex_config_load(&cfg->amex, filename);
gfx_config_load(&cfg->gfx, filename);
} }

View File

@ -4,11 +4,14 @@
#include "amex/config.h" #include "amex/config.h"
#include "hooklib/config.h"
#include "platform/config.h" #include "platform/config.h"
struct chuni_hook_config { struct chuni_hook_config {
struct nu_config nu; struct nu_config nu;
struct amex_config amex; struct amex_config amex;
struct gfx_config gfx;
}; };
void chuni_hook_config_load( void chuni_hook_config_load(

View File

@ -47,7 +47,7 @@ static DWORD CALLBACK chuni_pre_startup(void)
/* Hook Win32 APIs */ /* Hook Win32 APIs */
gfx_hook_init(); gfx_hook_init(&chuni_hook_cfg.gfx);
serial_hook_init(); serial_hook_init();
/* Initialize emulation hooks */ /* Initialize emulation hooks */
@ -64,7 +64,6 @@ static DWORD CALLBACK chuni_pre_startup(void)
/* Initialize debug helpers */ /* Initialize debug helpers */
spike_hook_init(L".\\segatools.ini"); spike_hook_init(L".\\segatools.ini");
gfx_set_windowed();
dprintf("--- End chuni_pre_startup ---\n"); dprintf("--- End chuni_pre_startup ---\n");

View File

@ -1,12 +1,14 @@
#include <windows.h> #include <windows.h>
#include <d3d9.h> #include <d3d9.h>
#include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "hook/com-proxy.h" #include "hook/com-proxy.h"
#include "hook/table.h" #include "hook/table.h"
#include "hooklib/config.h"
#include "hooklib/gfx.h" #include "hooklib/gfx.h"
#include "util/dprintf.h" #include "util/dprintf.h"
@ -19,12 +21,10 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice(
DWORD flags, DWORD flags,
D3DPRESENT_PARAMETERS *pp, D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev); IDirect3DDevice9 **pdev);
static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver); static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver);
static IDirect3D9 * (WINAPI *next_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[] = { 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) if (!cfg->enable) {
{ return;
gfx_windowed = true; }
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) static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver)
@ -99,7 +101,7 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice(
proxy = com_proxy_downcast(self); proxy = com_proxy_downcast(self);
real = proxy->real; real = proxy->real;
if (gfx_windowed) { if (gfx_config.windowed) {
pp->Windowed = TRUE; pp->Windowed = TRUE;
pp->FullScreen_RefreshRateInHz = 0; pp->FullScreen_RefreshRateInHz = 0;
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
void gfx_hook_init(void); #include "hooklib/config.h"
void gfx_set_windowed(void);
void gfx_hook_init(const struct gfx_config *cfg);