Files
spice2x.github.io/src/spice2x/games/nost/nost.cpp
T
bicarus bd2fbfcb67 touch: restore wintouchemu, fall back to it when native touch hooks fail (#834)
## Link to GitHub Issue or related Pull Request, if one exists
Fixes #833

## Description of change
Last couple PRs - such as #820 #827 #828 - made the native touch hook &
touch injection using `InjectTouchInput` the default path, since it
performs much more reliably with both real touch screens and mouse (or
any other synthetic source).

However, user has reported that WINE lacks `InjectTouchInput` which
means this won't work.

As a fix, revive the old wintouchemu code. Native touch is still the
default, but under following circumstances:

1. if `-touchemuforce` is set, or
2. if any of the required Windows touch APIs are unavailable

then we fail over from native touch to wintouchemu code. 

For Linux, condition #2 would be hit during init, and gracefully switch
over.

Caveat: the poke code for IIDX and Nost will continue to require native
touch, I do not want to maintain two paths for this. This means that
iidx poke will stop working on Linux, unfortunately.

## Testing
Tested on Windows with `-touchemuforce` set. This is mostly reverting
Linux code path back to where we were last release, so this should just
work with wine.
2026-07-26 04:29:45 -07:00

72 lines
1.9 KiB
C++

#include "nost.h"
#include "poke.h"
#include "touch_mode.h"
#include "hooks/setupapihook.h"
#include "misc/wintouchemu.h"
#include "touch/native/nativetouchhook.h"
#include "avs/game.h"
namespace games::nost {
bool ENABLE_POKE = false;
bool ENABLE_TOUCH_MODE = false;
NostGame::NostGame() : Game("Nostalgia") {
}
void NostGame::attach() {
Game::attach();
// fake touchscreen
///////////////////
SETUPAPI_SETTINGS touch_settings{};
// GUID must be set to 0 to make SETUPAPI hook working
touch_settings.class_guid[0] = 0x00000000;
touch_settings.class_guid[1] = 0x00000000;
touch_settings.class_guid[2] = 0x00000000;
touch_settings.class_guid[3] = 0x00000000;
/*
* set hardware ID containing VID and PID
* there is 3 known VID/PID combinations known to the game:
* VID_04DD&PID_97CB
* VID_0EEF&PID_C000
* VID_29BD&PID_4101
*/
const char touch_hardwareid[] = "VID_29BD&PID_4101";
memcpy(touch_settings.property_hardwareid, touch_hardwareid, sizeof(touch_hardwareid));
// apply settings
setupapihook_init(avs::game::DLL_INSTANCE);
setupapihook_add(touch_settings);
const auto native_touch_ready = !wintouchemu::FORCE &&
nativetouch::hook(avs::game::DLL_INSTANCE);
if (!native_touch_ready) {
wintouchemu::FORCE = true;
wintouchemu::hook("nostalgia", avs::game::DLL_INSTANCE, 20);
} else {
if (ENABLE_TOUCH_MODE) {
touch_mode::enable();
}
}
}
void NostGame::post_attach() {
if (ENABLE_POKE) {
poke::enable();
}
}
void NostGame::detach() {
if (ENABLE_TOUCH_MODE) {
touch_mode::disable();
}
if (ENABLE_POKE) {
poke::disable();
}
}
}