Android port (Adreno): Vulkan backend, GameActivity app, touch HUD, lifecycle, minimap quest goals

- host/android: Vulkan replay backend (nvn_vk.c) with pipeline/descriptor caching, ADPF,
  AChoreographer present link; Linux compat layer; Makefile.android (headless dmhost + APK lib)
- android/app: GameActivity shell without Gradle (build_apk.sh), AAudio output, touch HUD port
  (touch_app.c + TouchOverlay.java, three layers: body / joystick / minimap goals),
  lifecycle save-on-background like iOS, art_from_ipa.py for touch / HUD / mapgoal art
- touch: shared touch controls moved from ios/Sources to dm/touch
- patch_nso.py Android ruleset, dmsh_vk.py shader pack, DM_TOUCH_PRODUCT defaults
- hle_audio: AAudio resume waits through STARTING and reopens once on failure
- .gitignore: local resources/ (original game data) never committed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-14 14:55:05 +09:00
co-authored by Claude Opus 5.5
parent 5bc5a01087
commit 4d91f80bae
106 changed files with 7009 additions and 181 deletions
+54 -4
View File
@@ -28,6 +28,41 @@ static pthread_key_t key_value(unsigned i) {
case KEY_KASPECT: return g_keyaspect; default: return g_keyaspectui;
}
}
#ifndef __APPLE__
// Linux / Android:槽块挂在 tp[2](bionic TLS_SLOT_APP,留给应用、libc 不用);块随线程退出释放并清 tp[2]
// Linux / Android: the slot block hangs off tp[2] (bionic TLS_SLOT_APP, reserved for the app and unused by libc); the block is freed and tp[2] cleared when the thread exits
#define SLOT_N 16
static pthread_key_t g_slot_owner;
static pthread_once_t g_slot_once = PTHREAD_ONCE_INIT;
static void slot_free(void *p) {
uint64_t *tp = __builtin_thread_pointer();
if (tp[2] == (uint64_t)p) tp[2] = 0;
free(p);
}
static void slot_once(void) { if (pthread_key_create(&g_slot_owner, slot_free)) die("创建槽块键失败"); }
uint64_t *dm_slot_block(void) {
uint64_t *tp = __builtin_thread_pointer();
if (tp[2]) return (uint64_t *)tp[2];
pthread_once(&g_slot_once, slot_once);
uint64_t *b = calloc(SLOT_N, 8);
if (!b || pthread_setspecific(g_slot_owner, b)) die("分配槽块失败");
tp[2] = (uint64_t)b;
return b;
}
void dm_slot_set(pthread_key_t k, void *v) {
if (!k || k >= SLOT_N) die("槽号越界 %lu", (unsigned long)k);
dm_slot_block()[k] = (uint64_t)v;
}
static void create_keys(void) {
// 键号从 1 起(键页项为 0 视为没建)
// Key numbers start at 1 (a key page entry of 0 means "not created")
pthread_key_t *ks[] = {&g_key18, &g_keytls, &g_keytlr, &g_keygate, &g_keyres[0], &g_keyres[1], &g_keyaspect, &g_keyaspectui};
for (unsigned i = 0; i < 8; i++) *ks[i] = i + 1;
LOG("槽号 K18=%lu KTLS=%lu KTLR=%lu KGATE=%lu KRES0=%lu KRES1=%lu KASPECT=%lu KASPECTUI=%lu",
(unsigned long)g_key18, (unsigned long)g_keytls, (unsigned long)g_keytlr, (unsigned long)g_keygate,
(unsigned long)g_keyres[0], (unsigned long)g_keyres[1], (unsigned long)g_keyaspect, (unsigned long)g_keyaspectui);
}
#else
static void create_keys(void) {
if (pthread_key_create(&g_key18, NULL) || pthread_key_create(&g_keytls, NULL) ||
pthread_key_create(&g_keytlr, NULL) || pthread_key_create(&g_keygate, NULL)) die("创建宿主键失败");
@@ -38,15 +73,20 @@ static void create_keys(void) {
LOG("键号 K18=%lu KTLS=%lu KTLR=%lu KGATE=%lu KRES0=%lu KRES1=%lu KASPECT=%lu KASPECTUI=%lu",
g_key18, g_keytls, g_keytlr, g_keygate, g_keyres[0], g_keyres[1], g_keyaspect, g_keyaspectui);
}
#endif
// K 槽校验:pthread TSD 布局固定,槽 = tpidrro_el0 + 8*key
// K slot check: the pthread TSD layout is fixed, slot = tpidrro_el0 + 8*key
static void tsd_check(void) {
pthread_setspecific(g_key18, (void *)0x1234);
dm_slot_set(g_key18, (void *)0x1234);
#ifdef __APPLE__
uint64_t base; __asm__ volatile("mrs %0, tpidrro_el0" : "=r"(base));
#else
uint64_t base = ((uint64_t *)__builtin_thread_pointer())[2];
#endif
uint64_t off = *(uint64_t *)(g_mod[0].base + g_mod[0].key_page_off + g_mod[0].key_idx[KEY_K18] * 8);
if (((uint64_t *)(base & ~7ull))[off / 8] != 0x1234) die("TSD 布局不符");
pthread_setspecific(g_key18, 0);
dm_slot_set(g_key18, 0);
}
static void build_symhash(module_t *m);
@@ -154,8 +194,12 @@ static void read_layout(module_t *m, const char *dir) {
FILE *f = fopen(path, "r");
if (!f) die("open %s", path);
static const char *kn[8] = {"K18", "KTLS", "KTLR", "KGATE", "KRES0", "KRES1", "KASPECT", "KASPECTUI"};
char line[256], key[32]; unsigned long v; unsigned seen = 0;
char line[256], key[32], abi[32] = "apple"; unsigned long v, tp_off = 0; unsigned seen = 0;
while (fgets(line, sizeof line, f)) {
// 改写器 ABI(DM_ABI=android 出 linux-bionic,槽基址取 [tpidr_el0 + TP_SLOT_OFF]);Apple 产物没有这行
// Rewriter ABI (DM_ABI=android emits linux-bionic, slot base taken from [tpidr_el0 + TP_SLOT_OFF]); Apple outputs have no such line
if (sscanf(line, "# ABI %31s", abi) == 1) continue;
if (sscanf(line, "# TP_SLOT_OFF %lx", &tp_off) == 1) continue;
if (sscanf(line, "# %31s %lx", key, &v) != 2) die("%s: 产物是旧改写器出的,换成当前代号(dm/PRODUCT)的产物", path);
if (!strcmp(key, "PATCH_OFF")) m->patch_off = v;
else if (!strcmp(key, "KEY_PAGE_OFF")) m->key_page_off = v;
@@ -171,6 +215,11 @@ static void read_layout(module_t *m, const char *dir) {
}
}
fclose(f);
#ifdef __APPLE__
if (strcmp(abi, "apple")) die("%s: 产物 ABI 是 %s,Apple 宿主要 DM_ABI=apple 的产物", path, abi);
#else
if (strcmp(abi, "linux-bionic") || tp_off != 0x10) die("%s: 产物 ABI 是 %s(TP_SLOT_OFF %#lx),Android 宿主要 DM_ABI=android 的产物", path, abi, tp_off);
#endif
if (!m->patch_off || m->key_page_off % 0x4000 || m->key_page_size != 0x4000 || seen != 0xff)
die("%s: 产物是旧改写器出的,换成当前代号(dm/PRODUCT)的产物", path);
}
@@ -196,7 +245,8 @@ static void register_gates(module_t *m, const char *dir) {
if (sscanf(line, "%lx %15s %d %lx", &ret, kind, &arg, &orig) == 4) { gate_register((uint64_t)m->base + ret, kind, arg, orig); ng++; }
fclose(f);
}
LOG("%s: gates %d patch_off %#llx keys %lu/%lu/%lu/%lu", m->name, ng, m->patch_off, g_key18, g_keytls, g_keytlr, g_keygate);
LOG("%s: gates %d patch_off %#llx keys %lu/%lu/%lu/%lu", m->name, ng, m->patch_off,
(unsigned long)g_key18, (unsigned long)g_keytls, (unsigned long)g_keytlr, (unsigned long)g_keygate);
}
static void relocate(module_t *m) {