2019-05-15 00:03:25 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
2019-09-01 17:40:25 +02:00
|
|
|
#include <assert.h>
|
2019-05-15 00:03:25 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "hook/table.h"
|
|
|
|
|
|
|
|
#include "hooklib/dll.h"
|
2019-05-15 17:10:27 +02:00
|
|
|
#include "hooklib/reg.h"
|
2019-05-15 00:03:25 +02:00
|
|
|
|
2019-05-18 05:10:09 +02:00
|
|
|
#include "platform/amvideo.h"
|
|
|
|
|
2019-05-15 00:03:25 +02:00
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
|
|
|
/* Hook functions */
|
|
|
|
|
2019-05-15 17:10:27 +02:00
|
|
|
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);
|
2019-08-31 00:46:04 +02:00
|
|
|
static HRESULT amvideo_reg_read_setting(void *bytes, uint32_t *nbytes);
|
2019-05-15 17:10:27 +02:00
|
|
|
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,
|
2022-12-11 04:01:52 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = L"name_x86",
|
|
|
|
.read = amvideo_reg_read_name,
|
|
|
|
.type = REG_SZ,
|
2019-05-15 17:10:27 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct reg_hook_val amvideo_reg_mode_vals[] = {
|
|
|
|
{
|
2019-08-31 00:46:04 +02:00
|
|
|
.name = L"monitor_setting_1",
|
|
|
|
.read = amvideo_reg_read_setting,
|
|
|
|
.type = REG_SZ,
|
|
|
|
}, {
|
|
|
|
.name = L"monitor_setting_2",
|
|
|
|
.read = amvideo_reg_read_setting,
|
|
|
|
.type = REG_SZ,
|
|
|
|
}, {
|
2019-05-15 17:10:27 +02:00
|
|
|
.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,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-18 05:10:09 +02:00
|
|
|
HRESULT amvideo_hook_init(const struct amvideo_config *cfg, HMODULE redir_mod)
|
2019-05-15 00:03:25 +02:00
|
|
|
{
|
2019-05-15 17:10:27 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-05-18 05:10:09 +02:00
|
|
|
assert(cfg != NULL);
|
|
|
|
|
|
|
|
if (!cfg->enable) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:10:27 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-05-22 18:29:39 +02:00
|
|
|
hr = dll_hook_push(redir_mod, amvideo_dll_name);
|
2019-05-15 17:10:27 +02:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2019-05-15 00:03:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-22 18:29:39 +02:00
|
|
|
int amDllVideoOpen(void *ctx)
|
2019-05-15 00:03:25 +02:00
|
|
|
{
|
2020-05-19 01:02:11 +02:00
|
|
|
dprintf("AmVideo: %s\n", __func__);
|
2019-05-15 00:03:25 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-22 18:29:39 +02:00
|
|
|
int amDllVideoClose(void *ctx)
|
2019-05-15 00:03:25 +02:00
|
|
|
{
|
2020-05-19 01:02:11 +02:00
|
|
|
dprintf("AmVideo: %s\n", __func__);
|
2019-05-15 00:03:25 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-22 18:29:39 +02:00
|
|
|
int amDllVideoSetResolution(void *ctx, void *param)
|
2019-05-15 00:03:25 +02:00
|
|
|
{
|
2019-11-04 01:54:41 +01:00
|
|
|
dprintf("AmVideo: %s\n", __func__);
|
2019-05-15 00:03:25 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-22 18:29:39 +02:00
|
|
|
int amDllVideoGetVBiosVersion(void *ctx, char *dest, size_t nchars)
|
2019-05-15 00:03:25 +02:00
|
|
|
{
|
2019-11-04 01:54:41 +01:00
|
|
|
dprintf("AmVideo: %s\n", __func__);
|
2019-05-15 00:03:25 +02:00
|
|
|
strcpy(dest, "01.02.03.04.05");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-15 17:10:27 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2019-08-31 00:46:04 +02:00
|
|
|
static HRESULT amvideo_reg_read_setting(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_wstr(bytes, nbytes, L"0");
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:10:27 +02:00
|
|
|
static HRESULT amvideo_reg_read_use_segatiming(void *bytes, uint32_t *nbytes)
|
|
|
|
{
|
|
|
|
return reg_hook_read_u32(bytes, nbytes, 0);
|
|
|
|
}
|