1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-28 00:10:51 +01:00

d3d9exhook/sdvxhook2: add option to force monitor orientation

also adds adapter hook into sdvxhook2
This commit is contained in:
Will Xyen 2020-01-28 04:16:43 -05:00
parent a21e37c894
commit 2d07bd6f5a
5 changed files with 75 additions and 6 deletions

View File

@ -22,12 +22,18 @@ gfx.window_height=1920
# Forced refresh rate, -1 to not force any (try 59 or 60 if monitor check fails to lock on high refresh rate monitors) # Forced refresh rate, -1 to not force any (try 59 or 60 if monitor check fails to lock on high refresh rate monitors)
gfx.forced_refresh_rate=-1 gfx.forced_refresh_rate=-1
# D3D9ex device adapter (monitor), -1 to use default,0, 1, 2 etc. to use specified adapter # D3D9ex device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter
gfx.device_adapter=-1 gfx.device_adapter=-1
# Orientation to force monitor into, -1 to use default, 0, 1, 2, 3 to do 0, 90, 180, 270 degrees
gfx.force_orientation=-1
# Disables the camera emulation # Disables the camera emulation
cam.disable_emu=false cam.disable_emu=false
# Override camera device ID detection (copy from device manager, do not escape) # Override camera device ID detection (copy from device manager, do not escape)
cam.device_id1= cam.device_id1=
# IP of adapter to force override with
adapter.override_ip=

View File

@ -14,6 +14,7 @@
#define D3D9EXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY "gfx.window_height" #define D3D9EXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY "gfx.window_height"
#define D3D9EXHOOK_CONFIG_GFX_FORCED_REFRESHRATE_KEY "gfx.forced_refresh_rate" #define D3D9EXHOOK_CONFIG_GFX_FORCED_REFRESHRATE_KEY "gfx.forced_refresh_rate"
#define D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY "gfx.device_adapter" #define D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY "gfx.device_adapter"
#define D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY "gfx.force_orientation"
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE false #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE false
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false
@ -21,6 +22,7 @@
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE -1 #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE -1
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCED_RR_VALUE -1 #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCED_RR_VALUE -1
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE -1 #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE -1
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE -1
void d3d9exhook_config_gfx_init(struct cconfig *config) void d3d9exhook_config_gfx_init(struct cconfig *config)
{ {
@ -59,8 +61,15 @@ void d3d9exhook_config_gfx_init(struct cconfig *config)
config, config,
D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY, D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE, D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE,
"D3D9ex device adapter (monitor), -1 to use default," "D3D9ex device adapter (monitor), -1 to use default, "
"0, 1, 2 etc. to use specified adapter"); "0, 1, 2 etc. to use specified adapter");
cconfig_util_set_int(
config,
D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE,
"Orientation to force monitor into, -1 to use default, "
"0, 1, 2, 3 to do 0, 90, 180, 270 degrees");
} }
void d3d9exhook_config_gfx_get( void d3d9exhook_config_gfx_get(
@ -137,4 +146,16 @@ void d3d9exhook_config_gfx_get(
D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY, D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE); D3D9EXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE);
} }
if (!cconfig_util_get_int(
config,
D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY,
&config_gfx->force_orientation,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_ORIENTATION_VALUE);
}
} }

View File

@ -16,6 +16,7 @@ struct d3d9exhook_config_gfx {
int32_t window_height; int32_t window_height;
int32_t forced_refresh_rate; int32_t forced_refresh_rate;
int32_t device_adapter; int32_t device_adapter;
int32_t force_orientation;
}; };
/** /**

View File

@ -87,6 +87,7 @@ static int32_t d3d9ex_window_width = -1;
static int32_t d3d9ex_window_height = -1; static int32_t d3d9ex_window_height = -1;
static bool d3d9ex_window_framed; static bool d3d9ex_window_framed;
static int32_t d3d9ex_device_adapter = -1; static int32_t d3d9ex_device_adapter = -1;
static int32_t d3d9ex_force_orientation = -1;
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -195,6 +196,12 @@ static HRESULT STDCALL my_CreateDeviceEx(
IDirect3D9Ex *real = COM_PROXY_UNWRAP(self); IDirect3D9Ex *real = COM_PROXY_UNWRAP(self);
HRESULT hr; HRESULT hr;
if (d3d9ex_device_adapter >= 0) {
log_info("Forcing adapter %d -> %d", adapter, d3d9ex_device_adapter);
adapter = d3d9ex_device_adapter;
}
if (d3d9ex_windowed) { if (d3d9ex_windowed) {
fdm = NULL; fdm = NULL;
pp->Windowed = TRUE; pp->Windowed = TRUE;
@ -210,11 +217,38 @@ static HRESULT STDCALL my_CreateDeviceEx(
fdm->RefreshRate = pp->FullScreen_RefreshRateInHz; fdm->RefreshRate = pp->FullScreen_RefreshRateInHz;
} }
} }
}
if (d3d9ex_device_adapter >= 0) { if (d3d9ex_force_orientation >= DMDO_DEFAULT && d3d9ex_force_orientation <= DMDO_270) {
log_info("Forcing adapter %d -> %d", adapter, d3d9ex_device_adapter); D3DADAPTER_IDENTIFIER9 adapter_ident;
adapter = d3d9ex_device_adapter; if (IDirect3D9Ex_GetAdapterIdentifier(real, adapter, 0, &adapter_ident) == D3D_OK) {
// straight outta MSDN
DEVMODE dm;
// initialize the DEVMODE structure
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
{
int32_t delta = d3d9ex_force_orientation - dm.dmDisplayOrientation;
if (delta % 2 != 0) {
// swap height and width
DWORD dwTemp = dm.dmPelsHeight;
dm.dmPelsHeight= dm.dmPelsWidth;
dm.dmPelsWidth = dwTemp;
}
dm.dmDisplayOrientation = d3d9ex_force_orientation;
long lRet = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
if (lRet == DISP_CHANGE_SUCCESSFUL) {
log_info("Overriding rotation suceeded");
} else {
log_info("Overriding rotation failed");
}
}
}
}
} }
hr = IDirect3D9Ex_CreateDeviceEx( hr = IDirect3D9Ex_CreateDeviceEx(
@ -279,6 +313,7 @@ void d3d9ex_configure(struct d3d9exhook_config_gfx *gfx_config)
d3d9ex_force_refresh_rate = gfx_config->forced_refresh_rate; d3d9ex_force_refresh_rate = gfx_config->forced_refresh_rate;
d3d9ex_device_adapter = gfx_config->device_adapter; d3d9ex_device_adapter = gfx_config->device_adapter;
d3d9ex_force_orientation = gfx_config->force_orientation;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */

View File

@ -13,6 +13,7 @@
#include "hooklib/acp.h" #include "hooklib/acp.h"
#include "hooklib/adapter.h" #include "hooklib/adapter.h"
#include "hooklib/app.h" #include "hooklib/app.h"
#include "hooklib/config-adapter.h"
#include "hooklib/rs232.h" #include "hooklib/rs232.h"
#include "bio2emu/emu.h" #include "bio2emu/emu.h"
@ -47,6 +48,7 @@ static const irp_handler_t sdvxhook_handlers[] = {
struct sdvxhook2_config_io config_io; struct sdvxhook2_config_io config_io;
struct camhook_config_cam config_cam; struct camhook_config_cam config_cam;
struct d3d9exhook_config_gfx config_gfx; struct d3d9exhook_config_gfx config_gfx;
struct hooklib_config_adapter config_adapter;
static struct bio2emu_port bio2_emu = { static struct bio2emu_port bio2_emu = {
.port = "COM4", .port = "COM4",
@ -65,6 +67,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
sdvxhook2_config_io_init(config); sdvxhook2_config_io_init(config);
d3d9exhook_config_gfx_init(config); d3d9exhook_config_gfx_init(config);
camhook_config_cam_init(config, 1); camhook_config_cam_init(config, 1);
hooklib_config_adapter_init(config);
if (!cconfig_hook_config_init( if (!cconfig_hook_config_init(
config, config,
@ -77,6 +80,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
sdvxhook2_config_io_get(&config_io, config); sdvxhook2_config_io_get(&config_io, config);
camhook_config_cam_get(&config_cam, config, 1); camhook_config_cam_get(&config_cam, config, 1);
d3d9exhook_config_gfx_get(&config_gfx, config); d3d9exhook_config_gfx_get(&config_gfx, config);
hooklib_config_adapter_get(&config_adapter, config);
cconfig_finit(config); cconfig_finit(config);
@ -129,6 +133,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
camhook_init(&config_cam); camhook_init(&config_cam);
} }
adapter_hook_override(config_adapter.override_ip);
log_info("--- End sdvxhook dll_entry_init ---"); log_info("--- End sdvxhook dll_entry_init ---");
return app_hook_invoke_init(sidcode, param); return app_hook_invoke_init(sidcode, param);