Nemirtingas / ingame_overlay

GNU General Public License v3.0
14 stars 4 forks source link

Hook on Linux x11 non-responsive #22

Open detiam opened 3 months ago

detiam commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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: https://github.com/Nemirtingas/ingame_overlay/issues/23

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

detiam commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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.