diff --git a/dist/sdvx5/sdvxhook2.conf b/dist/sdvx5/sdvxhook2.conf index 05a5c82..87e4d57 100644 --- a/dist/sdvx5/sdvxhook2.conf +++ b/dist/sdvx5/sdvxhook2.conf @@ -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) 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 +# 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 cam.disable_emu=false # Override camera device ID detection (copy from device manager, do not escape) cam.device_id1= +# IP of adapter to force override with +adapter.override_ip= + diff --git a/src/main/d3d9exhook/config-gfx.c b/src/main/d3d9exhook/config-gfx.c index d1cf7c9..e32f256 100644 --- a/src/main/d3d9exhook/config-gfx.c +++ b/src/main/d3d9exhook/config-gfx.c @@ -14,6 +14,7 @@ #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_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_WINDOWED_VALUE false @@ -21,6 +22,7 @@ #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_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_FORCE_ORIENTATION_VALUE -1 void d3d9exhook_config_gfx_init(struct cconfig *config) { @@ -59,8 +61,15 @@ void d3d9exhook_config_gfx_init(struct cconfig *config) config, D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY, 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"); + + 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( @@ -137,4 +146,16 @@ void d3d9exhook_config_gfx_get( D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY, 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); + } } diff --git a/src/main/d3d9exhook/config-gfx.h b/src/main/d3d9exhook/config-gfx.h index 5623228..cac6cdd 100644 --- a/src/main/d3d9exhook/config-gfx.h +++ b/src/main/d3d9exhook/config-gfx.h @@ -16,6 +16,7 @@ struct d3d9exhook_config_gfx { int32_t window_height; int32_t forced_refresh_rate; int32_t device_adapter; + int32_t force_orientation; }; /** diff --git a/src/main/d3d9exhook/d3d9ex.c b/src/main/d3d9exhook/d3d9ex.c index 5de9503..412b0c5 100644 --- a/src/main/d3d9exhook/d3d9ex.c +++ b/src/main/d3d9exhook/d3d9ex.c @@ -87,6 +87,7 @@ static int32_t d3d9ex_window_width = -1; static int32_t d3d9ex_window_height = -1; static bool d3d9ex_window_framed; 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); HRESULT hr; + + if (d3d9ex_device_adapter >= 0) { + log_info("Forcing adapter %d -> %d", adapter, d3d9ex_device_adapter); + adapter = d3d9ex_device_adapter; + } + if (d3d9ex_windowed) { fdm = NULL; pp->Windowed = TRUE; @@ -210,11 +217,38 @@ static HRESULT STDCALL my_CreateDeviceEx( fdm->RefreshRate = pp->FullScreen_RefreshRateInHz; } } - } - if (d3d9ex_device_adapter >= 0) { - log_info("Forcing adapter %d -> %d", adapter, d3d9ex_device_adapter); - adapter = d3d9ex_device_adapter; + if (d3d9ex_force_orientation >= DMDO_DEFAULT && d3d9ex_force_orientation <= DMDO_270) { + D3DADAPTER_IDENTIFIER9 adapter_ident; + 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( @@ -279,6 +313,7 @@ void d3d9ex_configure(struct d3d9exhook_config_gfx *gfx_config) d3d9ex_force_refresh_rate = gfx_config->forced_refresh_rate; d3d9ex_device_adapter = gfx_config->device_adapter; + d3d9ex_force_orientation = gfx_config->force_orientation; } /* ------------------------------------------------------------------------- */ diff --git a/src/main/sdvxhook2/dllmain.c b/src/main/sdvxhook2/dllmain.c index abb36d7..71fcde8 100644 --- a/src/main/sdvxhook2/dllmain.c +++ b/src/main/sdvxhook2/dllmain.c @@ -13,6 +13,7 @@ #include "hooklib/acp.h" #include "hooklib/adapter.h" #include "hooklib/app.h" +#include "hooklib/config-adapter.h" #include "hooklib/rs232.h" #include "bio2emu/emu.h" @@ -47,6 +48,7 @@ static const irp_handler_t sdvxhook_handlers[] = { struct sdvxhook2_config_io config_io; struct camhook_config_cam config_cam; struct d3d9exhook_config_gfx config_gfx; +struct hooklib_config_adapter config_adapter; static struct bio2emu_port bio2_emu = { .port = "COM4", @@ -65,6 +67,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) sdvxhook2_config_io_init(config); d3d9exhook_config_gfx_init(config); camhook_config_cam_init(config, 1); + hooklib_config_adapter_init(config); if (!cconfig_hook_config_init( config, @@ -77,6 +80,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) sdvxhook2_config_io_get(&config_io, config); camhook_config_cam_get(&config_cam, config, 1); d3d9exhook_config_gfx_get(&config_gfx, config); + hooklib_config_adapter_get(&config_adapter, config); cconfig_finit(config); @@ -129,6 +133,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) camhook_init(&config_cam); } + adapter_hook_override(config_adapter.override_ip); + log_info("--- End sdvxhook dll_entry_init ---"); return app_hook_invoke_init(sidcode, param);