Nemirtingas / ingame_overlay

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

Hook on macOS non-responsive #6

Closed jaroen007 closed 1 year ago

jaroen007 commented 1 year ago

Hello,

I am getting very weird behavior when using the overlay_example to hook onto a game called Tibia (on macOS, using openGL). I can toggle the imgui menu fine but anything inside it is unresponsive (as long as the menu is active, nothing responds to input). besides that, the cursor goes from the default mac cursor to the custom tibia cursor repeatedly and very quickly (the game still recognizes inputs as long as the menu is not active). It looks like this: image

I don't have a lot of experience on this kinda stuff and im still learning it. I hope you can help me with this issue.

EDIT: so i looked through a ton of the project some more and found i can simply always return false on the key combination callback to allow inputs to go through so that problem is solved. however, the problem with the cursor flickering and the imgui window not being responsive still persists

Nemirtingas commented 1 year ago

Hi, the overlay on MacOS is highly experimental. I don't have a proper Mac to test. When the overlay is shown, it will try to block all inputs sent to the game so only the overlay is affected by inputs. If you always return false in the overlay callback, the library is running code as if the overlay was hidden and will send inputs to the game and ignore overlay inputs. See https://github.com/Nemirtingas/ingame_overlay/blob/7464c28207fc2ca12e1d39bfb18246b479d708e7/src/macosx/NSView_Hook.mm#L142-L145

If you always return false, this code is not run and ImGui will not be updated with new inputs. This prevents the overlay to get inputs while the game is also getting inputs, so your character doesn't move while you are navigating the ImGui menu.

jaroen007 commented 1 year ago

so what you are saying is that the overlay should be responsive if i don't return false? because it isn't. neither the game (which you explained) nor the overlay is responding to anything (which is the strange part). is there a way to make it listen to both game inputs and the imgui overlay button presses etc while the menu shows?

also could the cursor blinking problem be a reason the imgui overlay is not responding to inputs when returning true?

Nemirtingas commented 1 year ago

Yes, it should be responsive if you don't return false. Did you try the macos_opengl2 example app ? If you want both the game and the overlay to listen to inputs, you should change the code at https://github.com/Nemirtingas/ingame_overlay/blob/7464c28207fc2ca12e1d39bfb18246b479d708e7/src/macosx/NSView_Hook.mm#L142-L147 into

        ImGui_ImplOSX_HandleEvent(event, view);

        return event;
jaroen007 commented 1 year ago

i have not tried changing that yet but i will later today (ill let you know). something else i don't quite get is that im hooking with openGL. does the NSView_Hook.mm file u are referencing actually get used? aren't openGL and NS two seperate hooking methods?

Nemirtingas commented 1 year ago

They are different, but NSView_Hook is the event and window hook, while OpenGL_Hook is the OpenGL renderer hook, there will be a Metal_Hook too, but the Metal_Hook will still use NSView_Hook to hook events. Metal and OpenGL are renderers and I hook them to be able to draw stuff on the application's Window.

jaroen007 commented 1 year ago

I tried your solution and i can now interact with the game even when returning true. however, no matter what i do i cannot interact with the imgui window (not moving it, not clicking on a button, etc..) do you have any ideas what the problem could be with this? (could it be the mouse flickering?).

if you have discord you could add me so we can chat easier: Neoray#9573 I could also help with programming things for the mac section of it once i get the hang of how it all works :)

EDIT: the macos_opengl2_app example works fine. everything interacts like it should

Nemirtingas commented 1 year ago

The overlay mouse Y coordinate was wrong and will be fixed by: https://github.com/Nemirtingas/imgui/commit/2e36b12af64b07c26142c23687202c6dde86e12f

Nemirtingas commented 1 year ago

Fixed in https://github.com/Nemirtingas/ingame_overlay/commit/5203c1c10cf340d5f989c1a292707a5444353feb Added an API to enable/disable app/overlay inputs: https://github.com/Nemirtingas/ingame_overlay/blob/master/include/ingame_overlay/Renderer_Hook.h#L60-L78