diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-11-19 13:24:35 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-11-19 13:24:35 +0200 |
commit | 5568b3760eb518f4ab727dec66d5a528d6f919ac (patch) | |
tree | 7f9da96ea084903234770db378319564c789ac68 /src | |
parent | 39f0b37c3703ef1765c91f5ae847f4315e0bb66a (diff) |
remove hard coded paths, add andre-apk.sh
Diffstat (limited to 'src')
-rw-r--r-- | src/libjvm-android.c | 25 | ||||
-rw-r--r-- | src/libjvm-java.c | 28 | ||||
-rw-r--r-- | src/loader.c | 30 |
3 files changed, 23 insertions, 60 deletions
diff --git a/src/libjvm-android.c b/src/libjvm-android.c index 3758113..e0ff8e7 100644 --- a/src/libjvm-android.c +++ b/src/libjvm-android.c @@ -1,5 +1,6 @@ #include <stdarg.h> #include <stddef.h> +#include <stdlib.h> #include <limits.h> #include <assert.h> #include "jvm/jni.h" @@ -61,34 +62,14 @@ jstring android_content_Context_getPackageName(JNIEnv *env, jobject object, va_list args) { assert(env && object); -#if WOLF - return (*env)->NewStringUTF(env, "com.swiftappskom.thewolfrpg"); -#elif STARLIGHT - return (*env)->NewStringUTF(env, "jp.co.bandainamcoent.BNEI0242"); -#elif SHADOWVERSE - return (*env)->NewStringUTF(env, "com.cygames.Shadowverse"); -#elif HEARTHSTONE - return (*env)->NewStringUTF(env, "com.blizzard.wtcg.hearthstone"); -#else - return (*env)->NewStringUTF(env, "com.miHoYo.bh3oversea"); -#endif + return (*env)->NewStringUTF(env, getenv("ANDROID_PACKAGE_NAME")); } jstring android_content_Context_getPackageCodePath(JNIEnv *env, jobject object, va_list args) { assert(env && object); -#if WOLF - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/apks/wolf"); -#elif STARLIGHT - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/apks/starlight"); -#elif SHADOWVERSE - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/apks/shadowverse"); -#elif HEARTHSTONE - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/apks/hearthstone"); -#else - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/apks/honkai"); -#endif + return (*env)->NewStringUTF(env, getenv("ANDROID_PACKAGE_CODE_PATH")); } jstring diff --git a/src/libjvm-java.c b/src/libjvm-java.c index 197df0d..baa3e29 100644 --- a/src/libjvm-java.c +++ b/src/libjvm-java.c @@ -2,6 +2,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdbool.h> +#include <libgen.h> #include <string.h> #include <assert.h> #include <err.h> @@ -137,33 +138,16 @@ java_io_File_getPath(JNIEnv *env, jobject object, va_list args) { assert(env && object); // FIXME: see comment on `android_content_Context_getExternalFilesDir` -#if WOLF - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.swiftappskom.thewolfrpg/files"); -#elif STARLIGHT - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/jp.co.bandainamcoent.BNEI0242/files"); -#elif SHADOWVERSE - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.cygames.Shadowverse/files"); -#elif HEARTHSTONE - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.blizzard.wtcg.hearthstone/files"); -#else - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.miHoYo.bh3oversea/files"); -#endif + return (*env)->NewStringUTF(env, getenv("ANDROID_EXTERNAL_FILES_DIR")); } jstring java_io_File_getParent(JNIEnv *env, jobject object, va_list args) { -#if WOLF - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.swiftappskom.thewolfrpg"); -#elif STARLIGHT - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/jp.co.bandainamcoent.BNEI0242"); -#elif SHADOWVERSE - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.cygames.Shadowverse"); -#elif HEARTHSTONE - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.blizzard.wtcg.hearthstone"); -#else - return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.miHoYo.bh3oversea"); -#endif + // FIXME: see comment on `android_content_Context_getExternalFilesDir` + char path[4096]; + snprintf(path, sizeof(path), "%s", getenv("ANDROID_EXTERNAL_FILES_DIR")); + return (*env)->NewStringUTF(env, dirname(path)); } jboolean diff --git a/src/loader.c b/src/loader.c index 326fd3a..7e2a472 100644 --- a/src/loader.c +++ b/src/loader.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> +#include <dirent.h> #include <libgen.h> #include <dlfcn.h> #include <elf.h> @@ -124,22 +125,19 @@ run_jni_game(struct jvm *jvm) const jobject context = jvm->native.AllocObject(&jvm->env, jvm->native.FindClass(&jvm->env, "android/app/Activity")); unity.native_init_jni.fun(&jvm->env, context, context); -#if WOLF - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/apks/wolf.apk")); -#elif STARLIGHT - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/apks/starlight.apk")); -#elif STAROCEAN - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/apks/starocean.apk")); -#elif SHADOWVERSE - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/apks/shadowverse.apk")); -#elif HEARTHSTONE - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/apks/hearthstone.apk")); - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/local/obb/com.blizzard.wtcg.hearthstone/patch.1561502.com.blizzard.wtcg.hearthstone.obb")); - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/local/obb/com.blizzard.wtcg.hearthstone/main.1561502.com.blizzard.wtcg.hearthstone.obb")); -#else - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/apks/honkai.apk")); - unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, "/mnt/media/dev/android2gnulinux/local/obb/com.miHoYo.bh3oversea/main.100.com.miHoYo.bh3oversea.obb")); -#endif + unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, getenv("ANDROID_PACKAGE_FILE"))); + + { + DIR *dir; + const char *obb_dir = getenv("ANDROID_EXTERNAL_OBB_DIR"); + if (obb_dir && (dir = opendir(obb_dir))) { + for (struct dirent *d; (d = readdir(dir));) { + char path[4096]; + snprintf(path, sizeof(path), "%s/%s", obb_dir, d->d_name); + unity.native_file.fun(&jvm->env, context, jvm->env->NewStringUTF(&jvm->env, path)); + } + } + } // unity.native_forward_events_to_dalvik.fun(&jvm->env, context, true); unity.native_init_www.fun(&jvm->env, context, jvm->env->FindClass(&jvm->env, "com/unity3d/player/WWW")); |