Update to spice2x-25-04-25 (pre-apply)
> broken commit
This commit is contained in:
+60
-32
@@ -4,11 +4,16 @@
|
||||
|
||||
#include "wintouchemu.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
|
||||
#include "cfg/screen_resize.h"
|
||||
#include "games/iidx/iidx.h"
|
||||
#include "hooks/graphics/graphics.h"
|
||||
#include "overlay/overlay.h"
|
||||
#include "overlay/windows/generic_sub.h"
|
||||
#include "touch/touch.h"
|
||||
#include "util/detour.h"
|
||||
#include "util/logging.h"
|
||||
@@ -31,7 +36,7 @@ namespace wintouchemu {
|
||||
bool LOG_FPS = false;
|
||||
|
||||
static inline bool is_emu_enabled() {
|
||||
return FORCE || !is_touch_available() || GRAPHICS_SHOW_CURSOR;
|
||||
return FORCE || !is_touch_available("wintouchemu::is_emu_enabled") || GRAPHICS_SHOW_CURSOR;
|
||||
}
|
||||
|
||||
static decltype(GetSystemMetrics) *GetSystemMetrics_orig = nullptr;
|
||||
@@ -75,10 +80,10 @@ namespace wintouchemu {
|
||||
HMODULE HOOKED_MODULE = nullptr;
|
||||
std::string WINDOW_TITLE_START = "";
|
||||
std::optional<std::string> WINDOW_TITLE_END = std::nullopt;
|
||||
bool INITIALIZED = false;
|
||||
volatile bool INITIALIZED = false;
|
||||
mouse_state_t mouse_state;
|
||||
|
||||
void hook(const char *window_title, HMODULE module) {
|
||||
void hook(const char *window_title, HMODULE module, int delay_in_s) {
|
||||
|
||||
// hooks
|
||||
auto system_metrics_hook = detour::iat_try(
|
||||
@@ -97,7 +102,20 @@ namespace wintouchemu {
|
||||
// set module and title
|
||||
HOOKED_MODULE = module;
|
||||
WINDOW_TITLE_START = window_title;
|
||||
INITIALIZED = true;
|
||||
|
||||
if (0 < delay_in_s) {
|
||||
// some games crash when touch events are injected too early during boot
|
||||
std::thread t([&]() {
|
||||
log_misc("wintouchemu", "defer initialization until later (with delay of {}s)", delay_in_s);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(delay_in_s));
|
||||
log_misc("wintouchemu", "initializing", delay_in_s);
|
||||
INITIALIZED = true;
|
||||
});
|
||||
t.detach();
|
||||
} else {
|
||||
log_misc("wintouchemu", "initializing");
|
||||
INITIALIZED = true;
|
||||
}
|
||||
}
|
||||
|
||||
void hook_title_ends(const char *window_title_start, const char *window_title_end, HMODULE module) {
|
||||
@@ -145,8 +163,20 @@ namespace wintouchemu {
|
||||
auto x = touch_event->x;
|
||||
auto y = touch_event->y;
|
||||
auto valid = true;
|
||||
if (overlay::OVERLAY) {
|
||||
|
||||
// log_misc("wintouchemu", "touch event ({}, {})", to_string(x), to_string(y));
|
||||
|
||||
if (GRAPHICS_IIDX_WSUB) {
|
||||
// touch was received on subscreen window.
|
||||
RECT clientRect {};
|
||||
GetClientRect(TDJ_SUBSCREEN_WINDOW, &clientRect);
|
||||
x = (float) x / clientRect.right * SPICETOUCH_TOUCH_WIDTH + SPICETOUCH_TOUCH_X;
|
||||
y = (float) y / clientRect.bottom * SPICETOUCH_TOUCH_HEIGHT + SPICETOUCH_TOUCH_Y;
|
||||
} else if (overlay::OVERLAY) {
|
||||
// touch was received on global coords
|
||||
valid = overlay::OVERLAY->transform_touch_point(&x, &y);
|
||||
} else {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
touch_input->x = x * 100;
|
||||
@@ -185,6 +215,14 @@ namespace wintouchemu {
|
||||
result = true;
|
||||
touch_input->x = mouse_state.pos.x;
|
||||
touch_input->y = mouse_state.pos.y;
|
||||
|
||||
if (GRAPHICS_WINDOWED) {
|
||||
touch_input->x -= SPICETOUCH_TOUCH_X;
|
||||
touch_input->y -= SPICETOUCH_TOUCH_Y;
|
||||
}
|
||||
|
||||
// log_misc("wintouchemu", "mouse state ({}, {})", to_string(touch_input->x), to_string(touch_input->y));
|
||||
|
||||
auto valid = true;
|
||||
if (overlay::OVERLAY) {
|
||||
valid = overlay::OVERLAY->transform_touch_point(
|
||||
@@ -222,7 +260,7 @@ namespace wintouchemu {
|
||||
// reset it since the event was consumed & propagated as touch
|
||||
mouse_state.touch_event = 0;
|
||||
}
|
||||
} else {
|
||||
} else if (!GRAPHICS_IIDX_WSUB) {
|
||||
|
||||
/*
|
||||
* For some reason, Nostalgia won't show an active touch point unless a move event
|
||||
@@ -319,39 +357,29 @@ namespace wintouchemu {
|
||||
|
||||
// check if windowed
|
||||
if (GRAPHICS_WINDOWED) {
|
||||
log_info("wintouchemu", "activating window hooks");
|
||||
|
||||
// get client size
|
||||
RECT rect {};
|
||||
GetClientRect(hWnd, &rect);
|
||||
|
||||
// remove style borders
|
||||
LONG lStyle = GetWindowLong(hWnd, GWL_STYLE);
|
||||
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
|
||||
SetWindowLongPtr(hWnd, GWL_STYLE, lStyle);
|
||||
|
||||
// remove ex style borders
|
||||
LONG lExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
|
||||
lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
|
||||
SetWindowLongPtr(hWnd, GWL_EXSTYLE, lExStyle);
|
||||
|
||||
// update window
|
||||
AdjustWindowRect(&rect, lStyle, FALSE);
|
||||
SetWindowPos(hWnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
|
||||
SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
|
||||
// create touch window - create overlay if not yet existing at this point
|
||||
touch_create_wnd(hWnd, overlay::ENABLED && !overlay::OVERLAY);
|
||||
USE_MOUSE = false;
|
||||
if (GRAPHICS_IIDX_WSUB) {
|
||||
// no handling is needed here
|
||||
// graphics::MoveWindow_hook will attach hook to windowed subscreen
|
||||
log_info("wintouchemu", "attach touch hook to windowed subscreen for TDJ");
|
||||
USE_MOUSE = false;
|
||||
} else if (avs::game::is_model("LDJ") && !GENERIC_SUB_WINDOW_FULLSIZE) {
|
||||
// overlay subscreen in IIDX
|
||||
// use mouse position as ImGui overlay will block the touch window
|
||||
log_info("wintouchemu", "use mouse cursor API for overlay subscreen");
|
||||
USE_MOUSE = true;
|
||||
} else {
|
||||
// create touch window - create overlay if not yet existing at this point
|
||||
log_info("wintouchemu", "create touch window relative to main game window");
|
||||
touch_create_wnd(hWnd, overlay::ENABLED && !overlay::OVERLAY);
|
||||
USE_MOUSE = false;
|
||||
}
|
||||
} else if (INJECT_MOUSE_AS_WM_TOUCH) {
|
||||
log_info(
|
||||
"wintouchemu",
|
||||
"using raw mouse cursor API in full screen and injecting them as WM_TOUCH events");
|
||||
USE_MOUSE = true;
|
||||
|
||||
} else {
|
||||
log_info("wintouchemu", "activating DirectX hooks");
|
||||
|
||||
// mouse position based input only
|
||||
touch_attach_dx_hook();
|
||||
USE_MOUSE = false;
|
||||
|
||||
Reference in New Issue
Block a user