diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-09-04 20:34:03 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-09-04 20:50:46 +0300 |
commit | ac9d8a241c1f5eda33718b8dd1ccdd2094a1825f (patch) | |
tree | 9bec564f245b06bbdad2ad1a7413a18c5e23f696 | |
parent | b76bd91beef9a279cc730ce7167408b2c01953b7 (diff) |
hacky input
-rw-r--r-- | src/app.c | 10 | ||||
-rw-r--r-- | src/jvm/jvm.c | 6 | ||||
-rw-r--r-- | src/libjvm-android.c | 43 |
3 files changed, 58 insertions, 1 deletions
@@ -55,6 +55,7 @@ main(int argc, const char *argv[]) void (*native_init_web_request)(JNIEnv*, jobject, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeInitWebRequest"); // void (*native_add_vsync_time)(JNIEnv*, jobject, jlong) = jvm_get_native_method(&jvm, unity_player_class, "nativeAddVSyncTime"); // void (*native_forward_events_to_dalvik)(JNIEnv*, jobject, jboolean) = jvm_get_native_method(&jvm, unity_player_class, "nativeForwardEventsToDalvik"); + void (*native_inject_event)(JNIEnv*, jobject, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeInjectEvent"); native_init_jni(&jvm.env, context, context); #if WOLF native_file(&jvm.env, context, jvm.env->NewStringUTF(&jvm.env, "/mnt/media/dev/android2gnulinux/apks/wolf.apk")); @@ -71,7 +72,14 @@ main(int argc, const char *argv[]) native_done(&jvm.env, context); // native_add_vsync_time(&jvm.env, context, 0); - while (native_render(&jvm.env, context)); + while (native_render(&jvm.env, context)) { + static int i = 0; + if (++i >= 10) { + native_inject_event(&jvm.env, context, jvm.native.AllocObject(&jvm.env, jvm.native.FindClass(&jvm.env, "android/view/MotionEvent"))); + i = 0; + } + } + printf("unloading module: %s\n", argv[1]); bionic_dlclose(handle); jvm_release(&jvm); diff --git a/src/jvm/jvm.c b/src/jvm/jvm.c index f54aad5..bbba360 100644 --- a/src/jvm/jvm.c +++ b/src/jvm/jvm.c @@ -541,9 +541,15 @@ static jboolean JNIEnv_IsInstanceOf(JNIEnv* p0, jobject p1, jclass p2) { assert(p0 && p1 && p2); + // FIXME: we don't have inheritance verbose("%u, %u", (uint32_t)(uintptr_t)p1, (uint32_t)(uintptr_t)p2); verbose("%s", jvm_get_object(jnienv_get_jvm(p0), jvm_get_object(jnienv_get_jvm(p0), p1)->this_klass)->klass.name.data); verbose("%s", jvm_get_object(jnienv_get_jvm(p0), p2)->klass.name.data); + + if (strstr(jvm_get_object(jnienv_get_jvm(p0), jvm_get_object(jnienv_get_jvm(p0), p1)->this_klass)->klass.name.data, "MotionEvent") || + strstr(jvm_get_object(jnienv_get_jvm(p0), p2)->klass.name.data, "MotionEvent")) + return true; + return jvm_get_object(jnienv_get_jvm(p0), p1)->this_klass == p2; } diff --git a/src/libjvm-android.c b/src/libjvm-android.c index 52273bc..b2079df 100644 --- a/src/libjvm-android.c +++ b/src/libjvm-android.c @@ -152,3 +152,46 @@ android_os_Bundle_getString(JNIEnv *env, jobject object, va_list args) (*env)->GetStringUTFChars(env, str1, NULL); return NULL; } + +jintArray +android_view_InputDevice_getDeviceIds(JNIEnv *env, jobject object, va_list args) +{ + assert(env && object); + return (*env)->NewIntArray(env, 1); +} + +jint +android_view_InputEvent_getSource(JNIEnv *env, jobject object, va_list args) +{ + assert(env && object); + return 0x00001002; // SOURCE_TOUCHSCREEN +} + +jint +android_view_MotionEvent_getAction(JNIEnv *env, jobject object, va_list args) +{ + assert(env && object); + static int action; + return (action = !action); +} + +jfloat +android_view_MotionEvent_getX(JNIEnv *env, jobject object, va_list args) +{ + assert(env && object); + return 1024/2; +} + +jfloat +android_view_MotionEvent_getY(JNIEnv *env, jobject object, va_list args) +{ + assert(env && object); + return 700; +} + +jint +android_view_MotionEvent_getPointerCount(JNIEnv *env, jobject object, va_list args) +{ + assert(env && object); + return 1; +} |