diff --git a/common/hooklib/config.c b/common/hooklib/config.c index b7a84cf..b603e45 100644 --- a/common/hooklib/config.c +++ b/common/hooklib/config.c @@ -24,6 +24,7 @@ void touch_screen_config_load(struct touch_screen_config *cfg, const wchar_t *fi cfg->enable = GetPrivateProfileIntW(L"touch", L"enable", 1, filename); cfg->remap = GetPrivateProfileIntW(L"touch", L"remap", 1, filename); cfg->cursor = GetPrivateProfileIntW(L"touch", L"cursor", 1, filename); + cfg->setwndptr = GetPrivateProfileIntW(L"touch", L"setwndptr", 0, filename); } void printer_config_load(struct printer_config *cfg, const wchar_t *filename) diff --git a/common/hooklib/touch.c b/common/hooklib/touch.c index a76692a..ae86cb6 100644 --- a/common/hooklib/touch.c +++ b/common/hooklib/touch.c @@ -43,6 +43,8 @@ static BOOL WINAPI hook_GetTouchInputInfo( static HCURSOR WINAPI hook_SetCursor(HCURSOR cursor); +static LONG_PTR WINAPI hook_SetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong); + /* Link pointers */ static ATOM (WINAPI *next_RegisterClassExA)( @@ -67,6 +69,8 @@ static BOOL (WINAPI *next_GetTouchInputInfo)( static HCURSOR(WINAPI *next_SetCursor)(HCURSOR cursor); +static LONG_PTR (WINAPI *next_SetWindowLongPtrA)(HWND hWnd, int nIndex, LONG_PTR dwNewLong); + static bool touch_hook_initted; static bool touch_held; static HWND registered_hWnd; @@ -100,6 +104,11 @@ static const struct hook_symbol touch_hooks[] = { .patch = hook_SetCursor, .link = (void **) &next_SetCursor }, + { + .name = "SetWindowLongPtrA", + .patch = hook_SetWindowLongPtrA, + .link = (void**) &next_SetWindowLongPtrA + }, }; void touch_screen_hook_init(const struct touch_screen_config *cfg, HINSTANCE self) @@ -152,7 +161,7 @@ static LRESULT hook_wndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { static ATOM WINAPI hook_RegisterClassExA( WNDCLASSEXA* wndClass ) { - if (wndClass->lpfnWndProc) { + if (!touch_config.setwndptr && wndClass->lpfnWndProc) { orig_wndProc = wndClass->lpfnWndProc; wndClass->lpfnWndProc = (WNDPROC) hook_wndProc; } @@ -182,6 +191,17 @@ static BOOL WINAPI hook_RegisterTouchWindow( return true; } +// Soul Reverse uses this to initialize wndprocs handling input + +static LONG_PTR WINAPI hook_SetWindowLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong) { + if (touch_config.setwndptr && nIndex == -4) { + orig_wndProc = (WNDPROC) dwNewLong; + dwNewLong = (LONG_PTR) hook_wndProc; + } + + return next_SetWindowLongPtrA(hWnd, nIndex, dwNewLong); +} + // Converting mouse event to touch event static BOOL WINAPI hook_GetTouchInputInfo( HANDLE hTouchInput, @@ -231,7 +251,7 @@ static BOOL WINAPI hook_GetTouchInputInfo( touch_input->x = cursorPos.x * 100; touch_input->y = cursorPos.y * 100; touch_input->hSource = hTouchInput; - touch_input->dwID = 0; + touch_input->dwID = 1; touch_input->dwFlags = 0; if (mouse_state && !mouse_state_old) { touch_input->dwFlags |= TOUCHEVENTF_DOWN; diff --git a/common/hooklib/touch.h b/common/hooklib/touch.h index dcb9082..04b1031 100644 --- a/common/hooklib/touch.h +++ b/common/hooklib/touch.h @@ -8,6 +8,7 @@ struct touch_screen_config { bool enable; bool remap; bool cursor; + bool setwndptr; }; /* Init is not thread safe because API hook init is not thread safe blah diff --git a/dist/soul/segatools.ini b/dist/soul/segatools.ini index 4915b41..9f382db 100644 --- a/dist/soul/segatools.ini +++ b/dist/soul/segatools.ini @@ -104,8 +104,10 @@ dipsw1=1 [touch] ; WinTouch emulation setting. enable=1 -remap=1 +remap=0 cursor=1 +; Alternative hooking method for Soul Reverse +setwndptr=1 ; ----------------------------------------------------------------------------- ; Custom IO settings