Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook on Linux x11 non-responsive #22

Open
detiam opened this issue Mar 31, 2024 · 8 comments
Open

Hook on Linux x11 non-responsive #22

detiam opened this issue Mar 31, 2024 · 8 comments

Comments

@detiam
Copy link

detiam commented Mar 31, 2024

This is similar to #6, hooks to the game Stellaris.

I added the line

SPDLOG_TRACE("Event type: {}", (int)event.type);

to line 267 of X11Hook.cpp, launch game and keeps typing the key combination whole time, get the result:

[00:52:30.591](274517)[info] - StartHook{126} - Hooked X11
[00:52:30.591](274517)[info] - StartHook{59} - Hooked OpenGLX
[00:52:33.879](274513)[trace] - _CheckForOverlay{268} - Event type: 2
[00:52:33.879](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:33.879](274513)[trace] - _CheckForOverlay{268} - Event type: 2
[00:52:33.879](274513)[trace] - _CheckForOverlay{268} - Event type: 28
[00:52:34.287](274513)[trace] - _CheckForOverlay{268} - Event type: 2
[00:52:34.287](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:34.838](274513)[trace] - _CheckForOverlay{268} - Event type: 2
[00:52:34.838](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:34.838](274513)[trace] - _CheckForOverlay{268} - Event type: 2
[00:52:34.838](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:34.838](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:34.838](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:34.982](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:34.982](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 3
[00:52:36.150](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:36.216](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:36.435](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:37.158](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:37.883](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:38.131](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:38.253](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:40.431](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:40.486](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:41.948](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:42.355](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:42.821](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:43.216](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:43.493](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:43.741](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:43.985](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:44.388](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:44.652](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:44.921](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:45.194](274513)[trace] - _CheckForOverlay{268} - Event type: 6
[00:52:45.198](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:45.404](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:45.605](274513)[trace] - _CheckForOverlay{268} - Event type: 85
[00:52:45.790](274513)[trace] - _CheckForOverlay{268} - Event type: 85

When the game just launched, I can get the normal 2 (KeyPress), 3 (KeyRelease) and 6 (MotionNotify) event and open overlay, then it changes to these unknown 85 events and key press not respond anymore.


https://github.com/otavepto/gbe_fork/issues/20#issuecomment-2028833242

@Nemirtingas
Copy link
Owner

Nemirtingas commented Mar 31, 2024

Hi,
Not much I can do if there is no reproductible issue. If you encounter an unknown event, I don't see what could be done here. Maybe you are using Wayland and XWayland ?

@Nemirtingas
Copy link
Owner

Nemirtingas commented Apr 1, 2024

Must investigate how the game actually gets its events, but spamming the game with events makes the overlay receive events.
Like, hold SHIFT, then press a lot of your keyboard keys while pressing the open overlay key, then it will sometimes open.

I guess the game use something else than XEventsQueued or XPending to get its events.
InGameOverlay hooks only XEventsQueued and XPending, the game probably use one of thoses: XPeekEvent, XPending, XEventsQueued, XNextEvent

@detiam
Copy link
Author

detiam commented Apr 1, 2024

Hi,
Not much I can do if there is no reproductible issue. If you encounter an unknown event, I don't see what could be done here. Maybe you are using Wayland and XWayland ?

I'm on kde5, pure x11 session on Arch Linux

extra/libx11 1.8.8-2
extra/xorg-server 21.1.11-2

Must investigate how the game actually gets its events, but spamming the game with events makes the overlay receive events. Like, hold SHIFT, then press a lot of your keyboard keys while pressing the open overlay key, then it will sometimes open.

I guess the game use something else than XEventsQueued or XPending to get its events. InGameOverlay hooks only XEventsQueued and XPending, the game probably use one of thoses: XPeekEvent, XPending, XEventsQueued, XNextEvent

@_@

@Nemirtingas
Copy link
Owner

Nemirtingas commented Apr 1, 2024

Mystery solved, this game doesn't use libX11, it uses libxcb:

[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{88} - xcb_poll_for_event BEGIN
[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{90} - xcb_poll_for_event END
[00:54:57.329](6135)[debug] - MyXPending{393} - XPending(0x67998e0) -> 1
[00:54:57.329](6135)[info] - _CheckForOverlay{293} - Event type: 3
[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{88} - xcb_poll_for_event BEGIN
[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{90} - xcb_poll_for_event END

I need a new driver for libxcb alongside libX11: #23

Anyway, developpers should stop doing strange stuff. Why would you use both libX11 AND libxcb for your X server events ?

@detiam
Copy link
Author

detiam commented Apr 5, 2024

Mystery solved, this game doesn't use libX11, it uses libxcb:

[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{88} - xcb_poll_for_event BEGIN
[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{90} - xcb_poll_for_event END
[00:54:57.329](6135)[debug] - MyXPending{393} - XPending(0x67998e0) -> 1
[00:54:57.329](6135)[info] - _CheckForOverlay{293} - Event type: 3
[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{88} - xcb_poll_for_event BEGIN
[00:54:57.329](6135)[debug] - Myxcb_poll_for_event{90} - xcb_poll_for_event END

I need a new driver for libxcb alongside libX11: #23

Anyway, developpers should stop doing strange stuff. Why would you use both libX11 AND libxcb for your X server events ?

Found a new game that influenced by this issue and have exactly same behavior, Factorio.
Dig it a little and find both of them load /usr/lib/libX11-xcb.so, wondering if this is related, and using both libX11 and libxcb seems to be officially supported.

@Nemirtingas
Copy link
Owner

I agree the fact that using both libraries is valid, but what is incorrect is to use both libraries to get the X server events. That makes conflicts like in Stellaris when the X event queue gets clogged, both xcb and libX return events

@detiam
Copy link
Author

detiam commented Apr 7, 2024

Tested the new commit, it give me this error undefined symbol: xcb_key_symbols_alloc and crash for both Factorio and Stellaris.
If I use env var LD_PRELOAD to preload my so, it will print error _StartXcbHook{136} - Failed to hook xcb_query_pointer_reply and when I press anything, game crash like above.

@Nemirtingas
Copy link
Owner

The xcb hook branch is absolutely not ready. I didn't encounter any of your issue, this is surely because you didn't link the correct xcb libraries.

Right now the issue is that I don't know how to get the same behavior with xcb as X11 hooks, it always hangs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants