Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Android/library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ add_compile_options(-Wno-deprecated-declarations)
# ---- Source files ----
set(MODMANAGER_SOURCES
core/dobby_hook.cpp
core/jni_helper.c
core/misc.c
core/java_input_bridge.cpp
core/jni_helper.c
core/misc.c
)

set(MONODROID_SOURCES
Expand Down
1 change: 0 additions & 1 deletion Android/library/src/main/cpp/core/dobby_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <jni.h>
#include <cstdint>
#include <android/log.h>

Expand Down
545 changes: 545 additions & 0 deletions Android/library/src/main/cpp/core/java_input_bridge.cpp

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions Android/library/src/main/cpp/core/java_input_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef STARRAY_JAVA_INPUT_BRIDGE_H
#define STARRAY_JAVA_INPUT_BRIDGE_H

#include <stdint.h>

#define MODMANAGER_JAVA_INPUT_ABI_VERSION 2
#define MODMANAGER_JAVA_INPUT_MAX_POINTERS 32
#define MODMANAGER_JAVA_INPUT_MAX_HISTORY_SAMPLES 256
#define MODMANAGER_JAVA_INPUT_AXIS_COUNT 64

typedef struct ModManagerJavaInputPointer {
int32_t id;
int32_t tool_type;
float x;
float y;
float raw_x;
float raw_y;
float pressure;
float size;
float touch_major;
float touch_minor;
float tool_major;
float tool_minor;
float orientation;
float tilt;
float distance;
float axis_values[MODMANAGER_JAVA_INPUT_AXIS_COUNT];
} ModManagerJavaInputPointer;

#pragma pack(push, 4)
typedef struct ModManagerJavaInputHistorySample {
int32_t pointer_count;
int32_t stored_pointer_count;
int64_t event_time_nanos;
const ModManagerJavaInputPointer *pointers;
} ModManagerJavaInputHistorySample;

typedef struct ModManagerJavaInputEvent {
int32_t struct_size;
int32_t abi_version;
int32_t type;
int32_t is_generic_motion;
int32_t full_data_included;
int32_t action;
int32_t action_index;
int32_t pointer_count;
int32_t stored_pointer_count;
int32_t source;
int32_t device_id;
int32_t flags;
int32_t meta_state;
int32_t button_state;
int32_t action_button;
int32_t key_code;
int32_t scan_code;
int32_t repeat_count;
int32_t unicode_code_point;
int32_t viewport_width;
int32_t viewport_height;
int32_t raw_action;
int64_t event_time_nanos;
int64_t down_time_nanos;
float horizontal_scroll;
float vertical_scroll;
int32_t history_sample_count;
int32_t stored_history_sample_count;
const ModManagerJavaInputHistorySample *history_samples;
ModManagerJavaInputPointer pointers[MODMANAGER_JAVA_INPUT_MAX_POINTERS];
} ModManagerJavaInputEvent;
#pragma pack(pop)

typedef void (*ModManagerJavaInputCallback)(const ModManagerJavaInputEvent *event);

#ifdef __cplusplus
extern "C" {
#endif

void modmanager_set_java_input_callback(void *callback);
void modmanager_set_java_input_capture_state(int overlay_visible,
int capture_mouse,
int capture_keyboard);
void modmanager_set_java_input_full_data_enabled(int enabled);

#ifdef __cplusplus
}
#endif

#endif
2 changes: 2 additions & 0 deletions Android/library/src/main/java/net/dot/MonoRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package net.dot;

import starray.android.modmanager.ModManagerUtils;
import android.util.Log;
import java.util.ArrayList;

Expand All @@ -26,6 +27,7 @@ public final class MonoRunner {
System.loadLibrary("System.Security.Cryptography.Native.Android");
System.loadLibrary("monodroid");
System.loadLibrary("modmanager");
ModManagerUtils.registerHostInputBridge();
}

// ========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ public static Activity getUnityActivity() {
return null;
}

/**
* Activate the Java input bridge exposed by patched host Activities.
* Reflection avoids a hard class/method dependency; unpatched hosts can load the AAR,
* but they do not provide input events on the bridge-only input path.
*/
public static boolean registerHostInputBridge() {
Activity activity = getUnityActivity();
if (activity == null) return false;

try {
java.lang.reflect.Method method = activity.getClass()
.getMethod("registerJavaInputBridge");
Object result = method.invoke(activity);
return result instanceof Boolean && (Boolean) result;
} catch (Exception | LinkageError ignored) {
return false;
}
}

/** showSoftInput 前调用,把 ImGui 已有文本同步到 EditText */
public static void setInputText(String text) {
if (unityActivity == null) return;
Expand Down
Loading
Loading