From 8ae754448e74ed8867ff451d1c4d60580b7f206f Mon Sep 17 00:00:00 2001 From: undefined06855 Date: Wed, 4 Jun 2025 20:26:04 +0100 Subject: [PATCH 1/2] add controller detection support from launcher --- src/main.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d33e5b5..1e17c07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,10 @@ #include #include +#ifdef GEODE_IS_ANDROID +#include +#endif + #include #include "../include/Keybinds.hpp" @@ -240,8 +244,16 @@ class ControllerChecker : public CCObject { public: void checkController(float) { - //TODO: remove the android thingy once/if zmx figures out how to get the controller state through the launcher - bool controllerConnected = GEODE_ANDROID(true || ) PlatformToolbox::isControllerConnected(); +#ifdef GEODE_IS_ANDROID + bool controllerConnected = true; + JniMethodInfo info; + if (cocos2d::JniHelper::getStaticMethodInfo(info, "com/geode/launcher/utils/GeodeUtils", "getControllerCount", "()I")) { + int controllerCount = info.env->CallStaticIntMethod(info.classID, info.methodID); + controllerConnected = controllerCount > 0; + } +#else + bool controllerConnected = PlatformToolbox::isControllerConnected(); +#endif if (m_cached != controllerConnected) { m_cached = controllerConnected; if (m_cached) { @@ -262,10 +274,6 @@ class ControllerChecker : public CCObject { } } } - - ControllerChecker() { - this->retain(); - } }; $execute { From 7798d0b9339af786c04e937ea59a9be26bda17d6 Mon Sep 17 00:00:00 2001 From: undefined06855 Date: Mon, 9 Jun 2025 13:59:07 +0100 Subject: [PATCH 2/2] thank you github copilot --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 1e17c07..cc0fd29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -250,6 +250,7 @@ class ControllerChecker : public CCObject { if (cocos2d::JniHelper::getStaticMethodInfo(info, "com/geode/launcher/utils/GeodeUtils", "getControllerCount", "()I")) { int controllerCount = info.env->CallStaticIntMethod(info.classID, info.methodID); controllerConnected = controllerCount > 0; + info.env->DeleteLocalRef(info.classID); } #else bool controllerConnected = PlatformToolbox::isControllerConnected();