From bbcbeeb4df86a215fb2a219a76b7cffa811e7e4b Mon Sep 17 00:00:00 2001 From: alexytomi <60690056+alexytomi@users.noreply.github.com> Date: Sat, 13 Sep 2025 00:51:52 +0800 Subject: [PATCH] [HACK][REVERTME] fix: l4j doesn't init SDL Legacy4J has code that traps us inside GLFW only, soo this is a hacky workaround. It works but I'd prefer we don't have it at all. --- .../java/net/kdt/pojavlaunch/MainActivity.java | 1 + .../src/main/java/net/kdt/pojavlaunch/Tools.java | 2 ++ app_pojavlauncher/src/main/jni/Android.mk | 1 + app_pojavlauncher/src/main/jni/input_bridge_v3.c | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java index ff67ffe87..6b3b97eec 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -131,6 +131,7 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe motionListener = (View.OnGenericMotionListener) runMethodbyReflection("org.libsdl.app.SDLActivity", "getMotionListener"); + Tools.SDL.initializeControllerSubsystems(); } catch (UnsatisfiedLinkError ignored) { // Ignore because if SDL.setupJNI(); fails, SDL wasn't loaded. } catch (ReflectiveOperationException e) { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index c2c796774..c64d6abaf 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -1586,6 +1586,8 @@ public final class Tools { } static class SDL { + + public static native void initializeControllerSubsystems(); public static native void onNativeMouse(int button, int action, float x, float y, boolean relative); public static native void onNativeTouch(int touchDevId, int pointerFingerId, int action, float x, diff --git a/app_pojavlauncher/src/main/jni/Android.mk b/app_pojavlauncher/src/main/jni/Android.mk index c42559bb0..8de08a3cb 100644 --- a/app_pojavlauncher/src/main/jni/Android.mk +++ b/app_pojavlauncher/src/main/jni/Android.mk @@ -15,6 +15,7 @@ include $(CLEAR_VARS) # Link GLESv2 for test LOCAL_LDLIBS := -ldl -llog -landroid # -lGLESv2 +LOCAL_SHARED_LIBRARIES := SDL3 LOCAL_MODULE := pojavexec # LOCAL_CFLAGS += -DDEBUG # -DGLES_TEST diff --git a/app_pojavlauncher/src/main/jni/input_bridge_v3.c b/app_pojavlauncher/src/main/jni/input_bridge_v3.c index 27a743c84..0108b8b5c 100644 --- a/app_pojavlauncher/src/main/jni/input_bridge_v3.c +++ b/app_pojavlauncher/src/main/jni/input_bridge_v3.c @@ -553,4 +553,17 @@ Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadButtonBuffer(JNIEnv *env, JNIEXPORT jobject JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadAxisBuffer(JNIEnv *env, jclass clazz) { return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.axes, sizeof(pojav_environ->gamepadState.axes)); -} \ No newline at end of file +} + +// HACK: Legacy4J has faulty detection that hardwires us to GLFW unless we init SDL ourselves. +// This is a horribly made function that should really have more checks around it but meh. +#include + +static inline void initSubsystem(void) { + SDL_Init(SDL_INIT_GAMEPAD | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS); +} +JNIEXPORT void JNICALL +Java_net_kdt_pojavlaunch_Tools_00024SDL_initializeControllerSubsystems(JNIEnv *env, jclass clazz){ + // Please ensure that you have already dlopen'ed SDL3 before calling this. + initSubsystem(); +}