From 5568b3760eb518f4ab727dec66d5a528d6f919ac Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 19 Nov 2018 13:24:35 +0200 Subject: remove hard coded paths, add andre-apk.sh --- andre-apk.sh | 39 +++++++++++++++++++++++++++++++++++++++ src/libjvm-android.c | 25 +++---------------------- src/libjvm-java.c | 28 ++++++---------------------- src/loader.c | 30 ++++++++++++++---------------- 4 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 andre-apk.sh diff --git a/andre-apk.sh b/andre-apk.sh new file mode 100644 index 0000000..90afffa --- /dev/null +++ b/andre-apk.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +argv0="$0" +msg() { printf -- '%s: %s\n' "$(basename "$argv0")" "$@" 1>&2; } +err() { msg "$@"; exit 1; } + +[ -z "$1" ] && err 'usage: ' +pkgfile="$(realpath "$1")" + +arch="$(file ./andre | awk -F', ' '{print $2}')" +case "$arch" in + 'Intel 80386') + arch="x86" + ;; + 'ARM') + arch="armeabi-v7a" + ;; + *) + err "dont know how to convert from elf arch '$arch' to android arch" + ;; +esac + +pkgname="$(aapt2 dump --file AndroidManifest.xml "$1" | grep -o '^ \+A: package="[a-zA-Z0-9._]\+"' | awk -F'"' '{print $2}')" +[ -z "$pkgname" ] && err "not a valid apk (missing package name)" + +tmpdir="$(mktemp -d)" +trap 'rm -rf "$tmpdir"' EXIT +unzip "$1" -d "$tmpdir" + +export ANDROID_PACKAGE_FILE="$pkgfile" +export ANDROID_PACKAGE_CODE_PATH="$tmpdir" +export ANDROID_PACKAGE_NAME="$pkgname" + +# TODO: when we have first release, make this follow XDG spec +export ANDROID_EXTERNAL_FILES_DIR="$PWD/local/data/$pkgname/files" +export ANDROID_EXTERNAL_OBB_DIR="$PWD/local/data/$pkgname/obb" + +# XXX: We only work with unity stuff for now +./andre "$tmpdir/lib/$arch/libunity.so" 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 #include +#include #include #include #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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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")); -- cgit v1.2.3-70-g09d2