Skip to content

Commit 7dad1eb

Browse files
authored
Merge pull request #8 from iidamie/feature/android17-java-input-only
feat(android): use Java Activity input bridge only
2 parents 896abb0 + 3b8c234 commit 7dad1eb

11 files changed

Lines changed: 1415 additions & 179 deletions

File tree

‎Android/library/src/main/cpp/CMakeLists.txt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ add_compile_options(-Wno-deprecated-declarations)
2323
# ---- Source files ----
2424
set(MODMANAGER_SOURCES
2525
core/dobby_hook.cpp
26-
core/jni_helper.c
27-
core/misc.c
26+
core/java_input_bridge.cpp
27+
core/jni_helper.c
28+
core/misc.c
2829
)
2930

3031
set(MONODROID_SOURCES

‎Android/library/src/main/cpp/core/dobby_hook.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <jni.h>
21
#include <cstdint>
32
#include <android/log.h>
43

‎Android/library/src/main/cpp/core/java_input_bridge.cpp‎

Lines changed: 545 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#ifndef STARRAY_JAVA_INPUT_BRIDGE_H
2+
#define STARRAY_JAVA_INPUT_BRIDGE_H
3+
4+
#include <stdint.h>
5+
6+
#define MODMANAGER_JAVA_INPUT_ABI_VERSION 2
7+
#define MODMANAGER_JAVA_INPUT_MAX_POINTERS 32
8+
#define MODMANAGER_JAVA_INPUT_MAX_HISTORY_SAMPLES 256
9+
#define MODMANAGER_JAVA_INPUT_AXIS_COUNT 64
10+
11+
typedef struct ModManagerJavaInputPointer {
12+
int32_t id;
13+
int32_t tool_type;
14+
float x;
15+
float y;
16+
float raw_x;
17+
float raw_y;
18+
float pressure;
19+
float size;
20+
float touch_major;
21+
float touch_minor;
22+
float tool_major;
23+
float tool_minor;
24+
float orientation;
25+
float tilt;
26+
float distance;
27+
float axis_values[MODMANAGER_JAVA_INPUT_AXIS_COUNT];
28+
} ModManagerJavaInputPointer;
29+
30+
#pragma pack(push, 4)
31+
typedef struct ModManagerJavaInputHistorySample {
32+
int32_t pointer_count;
33+
int32_t stored_pointer_count;
34+
int64_t event_time_nanos;
35+
const ModManagerJavaInputPointer *pointers;
36+
} ModManagerJavaInputHistorySample;
37+
38+
typedef struct ModManagerJavaInputEvent {
39+
int32_t struct_size;
40+
int32_t abi_version;
41+
int32_t type;
42+
int32_t is_generic_motion;
43+
int32_t full_data_included;
44+
int32_t action;
45+
int32_t action_index;
46+
int32_t pointer_count;
47+
int32_t stored_pointer_count;
48+
int32_t source;
49+
int32_t device_id;
50+
int32_t flags;
51+
int32_t meta_state;
52+
int32_t button_state;
53+
int32_t action_button;
54+
int32_t key_code;
55+
int32_t scan_code;
56+
int32_t repeat_count;
57+
int32_t unicode_code_point;
58+
int32_t viewport_width;
59+
int32_t viewport_height;
60+
int32_t raw_action;
61+
int64_t event_time_nanos;
62+
int64_t down_time_nanos;
63+
float horizontal_scroll;
64+
float vertical_scroll;
65+
int32_t history_sample_count;
66+
int32_t stored_history_sample_count;
67+
const ModManagerJavaInputHistorySample *history_samples;
68+
ModManagerJavaInputPointer pointers[MODMANAGER_JAVA_INPUT_MAX_POINTERS];
69+
} ModManagerJavaInputEvent;
70+
#pragma pack(pop)
71+
72+
typedef void (*ModManagerJavaInputCallback)(const ModManagerJavaInputEvent *event);
73+
74+
#ifdef __cplusplus
75+
extern "C" {
76+
#endif
77+
78+
void modmanager_set_java_input_callback(void *callback);
79+
void modmanager_set_java_input_capture_state(int overlay_visible,
80+
int capture_mouse,
81+
int capture_keyboard);
82+
void modmanager_set_java_input_full_data_enabled(int enabled);
83+
84+
#ifdef __cplusplus
85+
}
86+
#endif
87+
88+
#endif

‎Android/library/src/main/java/net/dot/MonoRunner.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package net.dot;
55

6+
import starray.android.modmanager.ModManagerUtils;
67
import android.util.Log;
78
import java.util.ArrayList;
89

@@ -26,6 +27,7 @@ public final class MonoRunner {
2627
System.loadLibrary("System.Security.Cryptography.Native.Android");
2728
System.loadLibrary("monodroid");
2829
System.loadLibrary("modmanager");
30+
ModManagerUtils.registerHostInputBridge();
2931
}
3032

3133
// ========================================================================

‎Android/library/src/main/java/starray/android/modmanager/ModManagerUtils.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ public static Activity getUnityActivity() {
3838
return null;
3939
}
4040

41+
/**
42+
* Activate the Java input bridge exposed by patched host Activities.
43+
* Reflection avoids a hard class/method dependency; unpatched hosts can load the AAR,
44+
* but they do not provide input events on the bridge-only input path.
45+
*/
46+
public static boolean registerHostInputBridge() {
47+
Activity activity = getUnityActivity();
48+
if (activity == null) return false;
49+
50+
try {
51+
java.lang.reflect.Method method = activity.getClass()
52+
.getMethod("registerJavaInputBridge");
53+
Object result = method.invoke(activity);
54+
return result instanceof Boolean && (Boolean) result;
55+
} catch (Exception | LinkageError ignored) {
56+
return false;
57+
}
58+
}
59+
4160
/** showSoftInput 前调用,把 ImGui 已有文本同步到 EditText */
4261
public static void setInputText(String text) {
4362
if (unityActivity == null) return;

0 commit comments

Comments
 (0)