summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-11-19 13:24:35 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-11-19 13:24:35 +0200
commit5568b3760eb518f4ab727dec66d5a528d6f919ac (patch)
tree7f9da96ea084903234770db378319564c789ac68
parent39f0b37c3703ef1765c91f5ae847f4315e0bb66a (diff)
remove hard coded paths, add andre-apk.sh
-rw-r--r--andre-apk.sh39
-rw-r--r--src/libjvm-android.c25
-rw-r--r--src/libjvm-java.c28
-rw-r--r--src/loader.c30
4 files changed, 62 insertions, 60 deletions
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: <apk>'
+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 <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"));