platform/amvideo.c: Add registry hooks

This commit is contained in:
Tau 2019-05-15 11:10:27 -04:00
parent ace7e726bd
commit e935c22206

View File

@ -6,6 +6,7 @@
#include "hook/table.h" #include "hook/table.h"
#include "hooklib/dll.h" #include "hooklib/dll.h"
#include "hooklib/reg.h"
#include "util/dprintf.h" #include "util/dprintf.h"
@ -16,6 +17,65 @@ static int amDllVideoClose(void *ctx);
static int amDllVideoSetResolution(void *ctx, void *param); static int amDllVideoSetResolution(void *ctx, void *param);
static int amDllVideoGetVBiosVersion(void *ctx, char *dest, size_t nchars); static int amDllVideoGetVBiosVersion(void *ctx, char *dest, size_t nchars);
static HRESULT amvideo_reg_read_name(void *bytes, uint32_t *nbytes);
static HRESULT amvideo_reg_read_port_X(void *bytes, uint32_t *nbytes);
static HRESULT amvideo_reg_read_resolution_1(void *bytes, uint32_t *nbytes);
static HRESULT amvideo_reg_read_use_segatiming(void *bytes, uint32_t *nbytes);
static const wchar_t amvideo_dll_name[] = L"$amvideo";
static const struct reg_hook_val amvideo_reg_vals[] = {
{
.name = L"name",
.read = amvideo_reg_read_name,
.type = REG_SZ,
}
};
static const struct reg_hook_val amvideo_reg_mode_vals[] = {
{
.name = L"port_1",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_2",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_3",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_4",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_5",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_6",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_7",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"port_8",
.read = amvideo_reg_read_port_X,
.type = REG_DWORD
}, {
.name = L"resolution_1",
.read = amvideo_reg_read_resolution_1,
.type = REG_SZ,
}, {
.name = L"use_segatiming",
.read = amvideo_reg_read_use_segatiming,
.type = REG_DWORD,
}
};
static const struct hook_symbol amvideo_syms[] = { static const struct hook_symbol amvideo_syms[] = {
{ {
.ordinal = 1, .ordinal = 1,
@ -38,11 +98,39 @@ static const struct hook_symbol amvideo_syms[] = {
HRESULT amvideo_hook_init(HMODULE redir_mod) HRESULT amvideo_hook_init(HMODULE redir_mod)
{ {
return dll_hook_push( HRESULT hr;
hr = reg_hook_push_key(
HKEY_LOCAL_MACHINE,
L"SYSTEM\\SEGA\\SystemProperty\\amVideo",
amvideo_reg_vals,
_countof(amvideo_reg_vals));
if (FAILED(hr)) {
return hr;
}
hr = reg_hook_push_key(
HKEY_LOCAL_MACHINE,
L"SYSTEM\\SEGA\\SystemProperty\\sgsetdisplaysetting\\CurrentSetting",
amvideo_reg_mode_vals,
_countof(amvideo_reg_mode_vals));
if (FAILED(hr)) {
return hr;
}
hr = dll_hook_push(
redir_mod, redir_mod,
L"$amvideo", amvideo_dll_name,
amvideo_syms, amvideo_syms,
_countof(amvideo_syms)); _countof(amvideo_syms));
if (FAILED(hr)) {
return hr;
}
return S_OK;
} }
static int amDllVideoOpen(void *ctx) static int amDllVideoOpen(void *ctx)
@ -73,3 +161,23 @@ static int amDllVideoGetVBiosVersion(void *ctx, char *dest, size_t nchars)
return 0; return 0;
} }
static HRESULT amvideo_reg_read_name(void *bytes, uint32_t *nbytes)
{
return reg_hook_read_wstr(bytes, nbytes, amvideo_dll_name);
}
static HRESULT amvideo_reg_read_port_X(void *bytes, uint32_t *nbytes)
{
return reg_hook_read_u32(bytes, nbytes, 1);
}
static HRESULT amvideo_reg_read_resolution_1(void *bytes, uint32_t *nbytes)
{
return reg_hook_read_wstr(bytes, nbytes, L"1920x1080");
}
static HRESULT amvideo_reg_read_use_segatiming(void *bytes, uint32_t *nbytes)
{
return reg_hook_read_u32(bytes, nbytes, 0);
}