1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2025-01-31 12:13:42 +01:00

iidxhook3: Refactor to use new d3d9 module

This commit is contained in:
icex2 2019-10-06 21:22:38 +02:00
parent f201bff9ca
commit 53d61dcbbd

View File

@ -18,6 +18,7 @@
#include "ezusb2-iidx-emu/msg.h"
#include "hook/d3d9.h"
#include "hook/iohook.h"
#include "hook/table.h"
@ -54,6 +55,10 @@ static const irp_handler_t iidxhook_handlers[] = {
settings_hook_dispatch_irp,
};
static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = {
iidxhook_util_d3d9_irp_handler,
};
static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD);
static HANDLE (STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD);
static bool iidxhook_init_check;
@ -66,6 +71,45 @@ static const struct hook_symbol init_hook_syms[] = {
},
};
static void iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx)
{
struct iidxhook_util_d3d9_config d3d9_config;
iidxhook_util_d3d9_init_config(&d3d9_config);
d3d9_config.windowed = config_gfx->windowed;
d3d9_config.framed = config_gfx->framed;
d3d9_config.override_window_width = config_gfx->window_width;
d3d9_config.override_window_height = config_gfx->window_height;
d3d9_config.framerate_limit = config_gfx->frame_rate_limit;
d3d9_config.pci_vid = config_gfx->pci_id_vid;
d3d9_config.pci_pid = config_gfx->pci_id_pid;
/* Required for GOLD (and newer?) to not crash with NVIDIA cards */
d3d9_config.iidx11_to_17_fix_uvs_bg_videos = true;
d3d9_config.iidx14_to_19_nvidia_fix = true;
d3d9_config.scale_back_buffer_width = config_gfx->scale_back_buffer_width;
d3d9_config.scale_back_buffer_height = config_gfx->scale_back_buffer_height;
d3d9_config.scale_back_buffer_filter = config_gfx->scale_back_buffer_filter;
if (config_gfx->monitor_check == 0) {
log_info("Auto monitor check enabled");
d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate;
iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA);
} else if (config_gfx->monitor_check > 0) {
log_info("Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check);
iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA);
iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check);
}
iidxhook_util_d3d9_configure(&d3d9_config);
hook_d3d9_init(iidxhook_d3d9_handlers, lengthof(iidxhook_d3d9_handlers));
}
/**
* This seems to be a good entry point to intercept
* before the game calls anything important
@ -131,42 +175,7 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle,
/* Direct3D and USER32 hooks */
if (config_gfx.windowed) {
d3d9_set_windowed(config_gfx.framed, config_gfx.window_width,
config_gfx.window_height);
}
/* Empress onwards */
if (config_gfx.pci_id_pid != 0 && config_gfx.pci_id_vid != 0) {
d3d9_set_pci_id(config_gfx.pci_id_pid, config_gfx.pci_id_vid);
}
if (config_gfx.frame_rate_limit > 0) {
d3d9_set_frame_rate_limit(config_gfx.frame_rate_limit);
}
if (config_gfx.monitor_check == 0) {
log_info("Auto monitor check enabled");
d3d9_enable_monitor_check(iidxhook_util_chart_patch_set_refresh_rate);
iidxhook_util_chart_patch_init(
IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA);
} else if (config_gfx.monitor_check > 0) {
log_info("Manual monitor check, resulting refresh rate: %f",
config_gfx.monitor_check);
iidxhook_util_chart_patch_init(
IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA);
iidxhook_util_chart_patch_set_refresh_rate(config_gfx.monitor_check);
}
if (config_gfx.scale_back_buffer_width > 0 && config_gfx.scale_back_buffer_height > 0) {
d3d9_scale_back_buffer(config_gfx.scale_back_buffer_width, config_gfx.scale_back_buffer_height,
config_gfx.scale_back_buffer_filter);
}
/* Required for GOLD (and newer?) to not crash with NVIDIA cards */
d3d9_enable_nvidia_fix();
d3d9_bg_video_seams_fix();
iidxhook3_setup_d3d9_hooks(&config_gfx);
/* Disable operator menu clock setting system clock time */
@ -240,7 +249,6 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
acp_hook_init();
adapter_hook_init();
d3d9_hook_init();
eamuse_hook_init();
settings_hook_init();