This is the AMP version of this page.
If you want to load the real page instead, click this text.

Discussion Touches registering to game

MinimalXenon

Platinian
C++:
HOOKAF(void, Input, void *thiz, void *ex_ab, void *ex_ac)
{
    origInput(thiz, ex_ab, ex_ac);
    ImGui_ImplAndroid_HandleInputEvent((AInputEvent *)thiz);
    return;
}

Has anyone figured out a way to fix the issue where when using the imgui the touches also register to the background (the game)?
 
You might want to modify your hook to check if ImGui has handled the input. If it has, you can prevent the game from processing the touch event further:


Code:
cpp
HOOKAF(bool, Input, void *thiz, void *ex_ab, void *ex_ac)
{
    // Call ImGui to handle the input event
    bool handled = ImGui_ImplAndroid_HandleInputEvent((AInputEvent *)thiz);

    // If ImGui handled the event, return true to stop further processing
    if (handled) {
        return true; // Prevent the game from receiving the event
    }

    // If not handled, call the original input function
    return origInput(thiz, ex_ab, ex_ac);
}
 
Crashes the game upon touch.
 
if its a unity game you can use the native input event to get the positions, it has worked for me on my Xposed ImGui template, you should try it:


Remember to hook the native input method

C++:
do {
    sleep(1);
    unityMaps = ElfScanner::createWithPath("libunity.so");
} while (!unityMaps.isValid());

// input native function
RegisterNativeFn nativeInjectEventFn = KittyScanner::findRegisterNativeFn(unityMaps, "nativeInjectEvent");
 
forgot to also mention you hook nativeInjectEvent function from JNIStuff.h on the pointer nativeInjectEventFn.fnPtr
 

Thanks for the suggestion. I'll try implementing it.
 
In the meantime, I have found a temporary solution to the problem.
It should be easier to implement to any projects that experiences this annoying behavior.



(Only for Unity Games)

The solution requires one to hook into Input.GetTouch of UnityEngine.
Code:
public static Touch GetTouch(int index) { }

1. Find the "Touch" struct of the game in the dump and define it in your project.
C++:
struct Touch {
    int m_FingerId;
    Vector2 m_Position;
    Vector2 m_RawPosition;
    Vector2 m_PositionDelta;
    float m_TimeDelta;
    int m_TapCount;
    int m_Phase; // Enum TouchPhase
    int m_Type;  // Enum TouchType
    float m_Pressure;
    float m_MaximumPossiblePressure;
    float m_Radius;
    float m_RadiusVariance;
    float m_AltitudeAngle;
    float m_AzimuthAngle;
};

2. Make a hook for Input.GetTouch
C++:
Touch (*old_GetTouch)(int index);
Touch GetTouch(int index) {
    return old_GetTouch(index;
}

// Then hook it
DobbyHook(..., (void*)GetTouch, (void*)old_GetTouch



Now we need to check if we're interacting with ImGui.

The way to do this would be, according to DearImGui's official docs, to check if io.WantCaptureMouse is true.

If its true, we want to stop the interaction with the game by modifying the m_Phase of the Touch struct.
We want to instead pass this:
Code:
public const TouchPhase Began = 0;

With this, we'll modify our hook.
C++:
Touch (*old_GetTouch)(int index);
Touch GetTouch(int index) {
    Touch touch = old_GetTouch(index);

    if (GetIO().WantCaptureMouse) {
        touch.m_Phase = 0;
    }
 
    return touch;
}
 
The universal way to correctly handle touches on unity games is through hooking into the GetTouch method. All you need to do is check if an imgui item has been hovered and if so then reset the touch struct to not allow the game to register your touch. You also need to handle mouse stuff but that should be straightforward.