From d06b8bd7318c651ffa3115671893c113a9cce14f Mon Sep 17 00:00:00 2001 From: duel0213 <156279499+duel0213@users.noreply.github.com> Date: Wed, 26 Nov 2025 10:14:07 +0900 Subject: [PATCH] mfc: fix 2025 version touch (#426) ## Link to GitHub Issue, if one exists n/a ## Description of change HG cabinet uses wintouch and it requires TOUCHEVENTF_PRIMARY flag in order to accept touch inputs. Added wintouchemu on game hook and TOUCHEVENTF_PRIMARY flag on wintouchemu. ## Testing The game boots into test menu, touch now works. (tested in I/O TEST -> TOUCH PANEL CHECK with '-s' flag) TDJ subscreen overlay and nostalgia seems works fine regardless added TOUCHEVENTF_PRIMARY flag but more testing required. --- src/spice2x/games/mfc/mfc.cpp | 13 ++++++++-- src/spice2x/games/mfc/mfc.h | 2 ++ .../graphics/backends/d3d9/d3d9_backend.cpp | 6 +++++ src/spice2x/misc/wintouchemu.cpp | 25 +++++++++++++++++++ src/spice2x/misc/wintouchemu.h | 1 + 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/spice2x/games/mfc/mfc.cpp b/src/spice2x/games/mfc/mfc.cpp index 0f3984f..afc3c68 100644 --- a/src/spice2x/games/mfc/mfc.cpp +++ b/src/spice2x/games/mfc/mfc.cpp @@ -4,6 +4,7 @@ #include "avs/game.h" #include "hooks/graphics/graphics.h" #include "misc/eamuse.h" +#include "misc/wintouchemu.h" #include "touch/touch.h" #include "util/detour.h" #include "util/libutils.h" @@ -32,6 +33,8 @@ namespace games::mfc { static uint8_t CARD_TYPE = 0; static uint8_t CARD_UID[8]; + bool HG_MODE = false; + typedef int (__cdecl *inifile_param_num_t)(const char *, int *); static inifile_param_num_t inifile_param_num_real; @@ -50,8 +53,10 @@ namespace games::mfc { static void __cdecl touch_init(int width, int height) { log_info("mfc", "call touch_init(width: {}, height: {})", width, height); - // attach touch module - if (!TOUCH_ATTACHED) { + if (HG_MODE) { + wintouchemu::ADD_TOUCH_FLAG_PRIMARY = true; + wintouchemu::hook("MFC9", avs::game::DLL_INSTANCE); + } else if (!TOUCH_ATTACHED) { // attach touch module // store touch size specification TOUCH_MAX_X = width; @@ -328,6 +333,10 @@ namespace games::mfc { if (allinone_module == nullptr) { log_misc("mfc", "using system.dll instead of allinone.dll for i/o hooks"); allinone_module = system_module; + + if (avs::game::SPEC[0] == 'F') { + HG_MODE = true; + } } // network fix diff --git a/src/spice2x/games/mfc/mfc.h b/src/spice2x/games/mfc/mfc.h index 941e18c..30fa610 100644 --- a/src/spice2x/games/mfc/mfc.h +++ b/src/spice2x/games/mfc/mfc.h @@ -4,6 +4,8 @@ namespace games::mfc { + extern bool HG_MODE; + struct joystick_state { bool up = false; bool down = false; diff --git a/src/spice2x/hooks/graphics/backends/d3d9/d3d9_backend.cpp b/src/spice2x/hooks/graphics/backends/d3d9/d3d9_backend.cpp index fc818ed..4804151 100644 --- a/src/spice2x/hooks/graphics/backends/d3d9/d3d9_backend.cpp +++ b/src/spice2x/hooks/graphics/backends/d3d9/d3d9_backend.cpp @@ -15,6 +15,7 @@ #include "cfg/screen_resize.h" #include "games/iidx/iidx.h" #include "games/sdvx/sdvx.h" +#include "games/mfc/mfc.h" #include "games/io.h" #include "hooks/graphics/graphics.h" #include "launcher/launcher.h" @@ -1360,6 +1361,11 @@ void graphics_d3d9_on_present( graphics_d3d9_ldj_on_present(wrapped_device); } + const bool is_mfc = avs::game::is_model("KK9") && games::mfc::HG_MODE; + if (is_mfc) { + wintouchemu::update(); + } + // check screenshot key static bool trigger_last = false; auto buttons = games::get_buttons_overlay(eamuse_get_game()); diff --git a/src/spice2x/misc/wintouchemu.cpp b/src/spice2x/misc/wintouchemu.cpp index ce91830..1311034 100644 --- a/src/spice2x/misc/wintouchemu.cpp +++ b/src/spice2x/misc/wintouchemu.cpp @@ -34,6 +34,7 @@ namespace wintouchemu { bool FORCE = false; bool INJECT_MOUSE_AS_WM_TOUCH = false; bool LOG_FPS = false; + bool ADD_TOUCH_FLAG_PRIMARY = false; static inline bool is_emu_enabled() { return FORCE || !is_touch_available("wintouchemu::is_emu_enabled") || GRAPHICS_SHOW_CURSOR; @@ -187,16 +188,28 @@ namespace wintouchemu { switch (touch_event->type) { case TOUCH_DOWN: if (valid) { + if (ADD_TOUCH_FLAG_PRIMARY) { + touch_input->dwFlags |= TOUCHEVENTF_PRIMARY; + } + touch_input->dwFlags |= TOUCHEVENTF_DOWN; } break; case TOUCH_MOVE: if (valid) { + if (ADD_TOUCH_FLAG_PRIMARY) { + touch_input->dwFlags |= TOUCHEVENTF_PRIMARY; + } + touch_input->dwFlags |= TOUCHEVENTF_MOVE; } break; case TOUCH_UP: // don't check valid so that this touch ID can be released + if (ADD_TOUCH_FLAG_PRIMARY) { + touch_input->dwFlags |= TOUCHEVENTF_PRIMARY; + } + touch_input->dwFlags |= TOUCHEVENTF_UP; break; } @@ -238,16 +251,28 @@ namespace wintouchemu { switch (mouse_state.touch_event) { case TOUCHEVENTF_DOWN: if (valid) { + if (ADD_TOUCH_FLAG_PRIMARY) { + touch_input->dwFlags |= TOUCHEVENTF_PRIMARY; + } + touch_input->dwFlags |= TOUCHEVENTF_DOWN; } break; case TOUCHEVENTF_MOVE: if (valid) { + if (ADD_TOUCH_FLAG_PRIMARY) { + touch_input->dwFlags |= TOUCHEVENTF_PRIMARY; + } + touch_input->dwFlags |= TOUCHEVENTF_MOVE; } break; case TOUCHEVENTF_UP: // don't check valid so that this touch ID can be released + if (ADD_TOUCH_FLAG_PRIMARY) { + touch_input->dwFlags |= TOUCHEVENTF_PRIMARY; + } + touch_input->dwFlags |= TOUCHEVENTF_UP; break; } diff --git a/src/spice2x/misc/wintouchemu.h b/src/spice2x/misc/wintouchemu.h index fc49d6c..c1e6eb4 100644 --- a/src/spice2x/misc/wintouchemu.h +++ b/src/spice2x/misc/wintouchemu.h @@ -8,6 +8,7 @@ namespace wintouchemu { extern bool FORCE; extern bool INJECT_MOUSE_AS_WM_TOUCH; extern bool LOG_FPS; + extern bool ADD_TOUCH_FLAG_PRIMARY; void hook(const char *window_title, HMODULE module = nullptr, int delay_in_s=0); void hook_title_ends(