From 954e6022d9d6764962949a5841ffca968ee73816 Mon Sep 17 00:00:00 2001 From: bicarus <202771338+bicarus-dev@users.noreply.github.com> Date: Fri, 27 Feb 2026 14:22:56 -0800 Subject: [PATCH] sdvx, touch: hook Windows touch API when main monitor is rotated 270 degrees (portrait flipped) (#558) ## Link to GitHub Issue, if one exists n/a ## Description of change Game expects primary monitor to be in 90 deg rotation, and does the touch calculation accordingly. If the user does 270 deg rotation ("portrait, flipped") then the game's touch calculation is flipped upside down. Detect this and provide the fixed up values in the touch hook. ## Testing Tested with SDVX in 90 deg, 270 deg rotation, and 1080p, forced 1440p. --- src/spice2x/games/sdvx/sdvx.cpp | 11 +++++++---- src/spice2x/misc/nativetouchhook.cpp | 29 +++++++++++++++++++++++++++- src/spice2x/rawinput/touch.cpp | 8 ++++---- src/spice2x/rawinput/touch.h | 6 ++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/spice2x/games/sdvx/sdvx.cpp b/src/spice2x/games/sdvx/sdvx.cpp index b4f02c7..20a7265 100644 --- a/src/spice2x/games/sdvx/sdvx.cpp +++ b/src/spice2x/games/sdvx/sdvx.cpp @@ -21,8 +21,9 @@ #include "util/socd_cleaner.h" #include "util/time.h" #include "util/libutils.h" -#include "misc/wintouchemu.h" #include "misc/eamuse.h" +#include "misc/nativetouchhook.h" +#include "misc/wintouchemu.h" #include "bi2x_hook.h" #include "camera.h" #include "io.h" @@ -416,9 +417,11 @@ namespace games::sdvx { } if (is_valkyrie_model()) { - // hook touch window - // in windowed mode, game can accept mouse input on the second screen - if (!NATIVETOUCH && !GRAPHICS_WINDOWED) { + if (NATIVETOUCH) { + nativetouchhook::hook(avs::game::DLL_INSTANCE); + } else if (!NATIVETOUCH && !GRAPHICS_WINDOWED) { + // hook touch window + // in windowed mode, game can accept mouse input on the second screen wintouchemu::FORCE = true; wintouchemu::INJECT_MOUSE_AS_WM_TOUCH = true; wintouchemu::hook_title_ends( diff --git a/src/spice2x/misc/nativetouchhook.cpp b/src/spice2x/misc/nativetouchhook.cpp index 92b5298..8441653 100644 --- a/src/spice2x/misc/nativetouchhook.cpp +++ b/src/spice2x/misc/nativetouchhook.cpp @@ -2,7 +2,10 @@ // mingw otherwise doesn't load touch stuff #define _WIN32_WINNT 0x0601 +#include "avs/game.h" #include "wintouchemu.h" +#include "rawinput/touch.h" +#include "hooks/graphics/graphics.h" #include "util/detour.h" #include "util/logging.h" @@ -63,6 +66,11 @@ namespace nativetouchhook { point->cyContact = 0; } + static void flip_touch_points(PTOUCHINPUT point) { + point->x = rawinput::touch::DISPLAY_SIZE_X * 100 - point->x; + point->y = rawinput::touch::DISPLAY_SIZE_Y * 100 - point->y; + } + static BOOL WINAPI GetTouchInputInfoHook( HTOUCHINPUT hTouchInput, UINT cInputs, PTOUCHINPUT pInputs, int cbSize) { @@ -72,9 +80,28 @@ namespace nativetouchhook { return result; } + bool flip_values = false; + if (avs::game::is_model("KFC") && rawinput::touch::DISPLAY_INITIALIZED) { + log_debug( + "touch::native", "DISPLAY_ORIENTATION = {}, DISPLAY_SIZE_X = {}, DISPLAY_SIZE_Y = {}", + rawinput::touch::DISPLAY_ORIENTATION, + rawinput::touch::DISPLAY_SIZE_X, + rawinput::touch::DISPLAY_SIZE_Y); + if (rawinput::touch::DISPLAY_ORIENTATION == DMDO_270) { + flip_values = true; + } + } + for (size_t i = 0; i < cInputs; i++) { PTOUCHINPUT point = &pInputs[i]; - strip_contact_size(point); + + if (avs::game::is_model("LDJ")) { + strip_contact_size(point); + } + + if (flip_values) { + flip_touch_points(point); + } } return result; diff --git a/src/spice2x/rawinput/touch.cpp b/src/spice2x/rawinput/touch.cpp index 7b7ac70..530acc1 100644 --- a/src/spice2x/rawinput/touch.cpp +++ b/src/spice2x/rawinput/touch.cpp @@ -26,10 +26,10 @@ namespace rawinput::touch { bool INVERTED = false; // state - static bool DISPLAY_INITIALIZED = false; - static DWORD DISPLAY_ORIENTATION = DMDO_DEFAULT; - static long DISPLAY_SIZE_X = 1920L; - static long DISPLAY_SIZE_Y = 1080L; + DWORD DISPLAY_ORIENTATION = DMDO_DEFAULT; + long DISPLAY_SIZE_X = 1920L; + long DISPLAY_SIZE_Y = 1080L; + bool DISPLAY_INITIALIZED = false; bool is_touchscreen(Device *device) { diff --git a/src/spice2x/rawinput/touch.h b/src/spice2x/rawinput/touch.h index a301111..2c527a5 100644 --- a/src/spice2x/rawinput/touch.h +++ b/src/spice2x/rawinput/touch.h @@ -9,6 +9,12 @@ namespace rawinput::touch { extern bool DISABLED; extern bool INVERTED; + // global state + extern DWORD DISPLAY_ORIENTATION; + extern long DISPLAY_SIZE_X; + extern long DISPLAY_SIZE_Y; + extern bool DISPLAY_INITIALIZED; + bool is_touchscreen(Device *device); void enable(Device *device); void disable(Device *device);