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
+58 -21
View File
@@ -226,7 +226,13 @@ nwin_ref = sum(1 for o in ind if o in inwin)
# ④ 补丁区干净
# ④ Patch area is clean
P = llvm_dis(pat[PO:], PO)
left = sorted(o for o, t in P.items() if RX18.search(t) or sysk(t) not in (None, 'tpidrro_r'))
# 槽块基址前缀(nsoimg.slot_base_words)所在偏移:apple 为 mrs tpidrro,linux-bionic 为 mrs tpidr_el0 + ldr [tp,#TP_SLOT_OFF],只在这些位置放行
# Offsets of slot block base prefixes (nsoimg.slot_base_words): apple = mrs tpidrro, linux-bionic = mrs tpidr_el0 + ldr [tp,#TP_SLOT_OFF]; allowed only at these positions
def is_base(o):
bw = nsoimg.slot_base_words(h, W(pat, o) & 31)
return o + 4 * len(bw) <= len(pat) and all(W(pat, o + 4 * i) == x for i, x in enumerate(bw))
BASE_K = 'tpidrro_r' if h['ABI'] == 'apple' else 'tpidr_r'
left = sorted(o for o, t in P.items() if RX18.search(t) or (sysk(t) is not None and not (sysk(t) == BASE_K and is_base(o))))
if left: bad(f'补丁区残留 x18/系统寄存器/svc:{len(left)} 例 {[(hex(x), P[x]) for x in left[:5]]}')
# ⑤ 宿主门
@@ -235,9 +241,11 @@ KEY = {k[4:-4]: v for k, v in h.items() if k.startswith('KEY_') and k.endswith('
from capstone import Cs, CS_ARCH_ARM64, CS_MODE_ARM
_md = Cs(CS_ARCH_ARM64, CS_MODE_ARM); _md.detail = True
def keyseq(at):
q = list(_md.disasm(pat[at:at + 20], at))
if len(q) < 5 or q[0].mnemonic != 'mrs' or 'tpidrro_el0' not in q[0].op_str \
or q[1].mnemonic != 'adrp' or q[1].operands[1].imm != h['KEY_PAGE_OFF'] \
q = list(_md.disasm(pat[at:at + 24], at))
sb = nsoimg.slot_base(q, 0, h)
if not sb: return None
q = q[sb[1] - 1:] # 基址前缀折成一条 | Fold the base prefix into one
if len(q) < 5 or q[1].mnemonic != 'adrp' or q[1].operands[1].imm != h['KEY_PAGE_OFF'] \
or q[2].mnemonic != 'ldr' or q[2].operands[1].mem.base != q[1].operands[0].reg \
or q[3].mnemonic != 'add' or q[3].operands[0].reg != q[0].operands[0].reg \
or q[3].operands[1].reg != q[0].operands[0].reg:
@@ -245,21 +253,31 @@ def keyseq(at):
d = q[2].operands[1].mem.disp
return (q[3].address + 4, d // 8) if d % 8 == 0 and 0 <= d // 8 < 8 else None
def paramseq(at, r):
q = list(_md.disasm(pat[at:at + 40], at))
q = list(_md.disasm(pat[at:at + 44], at))
sb = nsoimg.slot_base(q, 1, h)
if not sb: return None
q = q[:2] + q[1 + sb[1]:] # 基址前缀折成一条(留 mrs)| Fold the base prefix into one (keep the mrs)
tmp = 17 if r == 16 else 16
rn = lambda ins, i: ins.reg_name(ins.operands[i].reg)
if len(q) < 8 or q[0].mnemonic not in ('stur', 'str') or rn(q[0], 0) != f'x{tmp}' \
or q[0].operands[1].mem.base != capstone.arm64_const.ARM64_REG_SP or q[0].operands[1].mem.disp not in (-16, -24) \
if h['ABI'] != 'apple':
# android 没有红区:stp xtmp,xzr,[sp,#-16]! … ldp xtmp,xzr,[sp],#16 | android has no red zone: stp xtmp,xzr,[sp,#-16]! ... ldp xtmp,xzr,[sp],#16
ok_save = len(q) >= 8 and q[0].mnemonic == 'stp' and rn(q[0], 0) == f'x{tmp}' and rn(q[0], 1) == 'xzr' and q[0].writeback \
and q[0].operands[2].mem.base == capstone.arm64_const.ARM64_REG_SP and q[0].operands[2].mem.disp == -16
ok_rest = len(q) >= 8 and q[6].mnemonic == 'ldp' and rn(q[6], 0) == f'x{tmp}' and rn(q[6], 1) == 'xzr' and q[6].writeback \
and q[6].operands[2].mem.base == capstone.arm64_const.ARM64_REG_SP and q[6].operands[-1].imm == 16
else:
ok_save = len(q) >= 8 and q[0].mnemonic in ('stur', 'str') and rn(q[0], 0) == f'x{tmp}' \
and q[0].operands[1].mem.base == capstone.arm64_const.ARM64_REG_SP and q[0].operands[1].mem.disp in (-16, -24)
ok_rest = len(q) >= 8 and q[6].mnemonic in ('ldur', 'ldr') and rn(q[6], 0) == f'x{tmp}' \
and q[6].operands[1].mem.base == capstone.arm64_const.ARM64_REG_SP and q[6].operands[1].mem.disp == q[0].operands[1].mem.disp
if not ok_save or not ok_rest \
or q[1].mnemonic != 'mrs' or rn(q[1], 0) != f'x{r}' \
or 'tpidrro_el0' not in q[1].op_str or q[2].mnemonic != 'adrp' \
or q[2].mnemonic != 'adrp' \
or q[2].operands[1].imm != h['KEY_PAGE_OFF'] or q[3].mnemonic != 'ldr' \
or q[3].operands[1].mem.base != q[2].operands[0].reg or q[4].mnemonic != 'add' \
or q[4].operands[0].reg != q[1].operands[0].reg or q[4].operands[1].reg != q[1].operands[0].reg \
or q[5].mnemonic != 'ldr' or q[5].operands[0].reg != q[1].operands[0].reg \
or q[5].operands[1].mem.base != q[4].operands[0].reg or q[6].mnemonic not in ('ldur', 'ldr') \
or rn(q[6], 0) != f'x{tmp}' \
or q[6].operands[1].mem.base != capstone.arm64_const.ARM64_REG_SP \
or q[6].operands[1].mem.disp != q[0].operands[1].mem.disp or q[7].mnemonic != 'b':
or q[5].operands[1].mem.base != q[4].operands[0].reg or q[7].mnemonic != 'b':
return None
d = q[3].operands[1].mem.disp
return (q[6].address + 4, d // 8)
@@ -342,10 +360,10 @@ if set(KEY) != {'K18', 'KTLS', 'KTLR', 'KGATE', 'KRES0', 'KRES1', 'KASPECT', 'KA
kv = {v: k for k, v in KEY.items()}; nk = {}
for o in range(PO, len(pat) - 4, 4):
w = W(pat, o)
if w & 0xFFFFFFE0 != 0xD53BD060: continue # mrs xN, tpidrro_el0
if w & 0xFFFFFFE0 != nsoimg.slot_base_words(h, 0)[0]: continue # mrs xN, tpidrro_el0(apple)/ tpidr_el0(linux-bionic)
n = w & 31; ks = keyseq(o); k = kv.get(ks[1]) if ks else None
if not ks or k is None:
bad(f'补丁区 {o:#x} 读 tpidrro 后不是键页间接槽序列'); continue
bad(f'补丁区 {o:#x} 读线程寄存器后不是键页间接槽序列'); continue
nk[k] = nk.get(k, 0) + 1
expected = {}
for kind in sites.values():
@@ -456,6 +474,19 @@ def _mem_sp(ins, load):
if op.mem.disp < 0: return op.mem.disp
if load and ins.mnemonic == 'ldp' and op.mem.disp == 0: return -16
return None
def _sp_mem(ins, cur):
"""android:块内 sp 相对入口的偏移 cur 逐条累计(stp/ldp 前后变址写回、sub/add sp,sp,#imm),返回 (本条访问地址相对入口 sp 的偏移或 None, 新 cur)。
android: accumulate the block's sp offset cur relative to entry instruction by instruction (pre/post-index writeback of stp/ldp, sub/add sp,sp,#imm); returns (this access's address offset relative to entry sp or None, new cur)."""
ops = ins.operands
if ins.mnemonic in ('sub', 'add') and len(ops) == 3 and ops[0].type == capstone.arm64_const.ARM64_OP_REG and ins.reg_name(ops[0].reg) == 'sp' \
and ins.reg_name(ops[1].reg) == 'sp' and ops[2].type == capstone.arm64_const.ARM64_OP_IMM:
sh = ops[2].shift.value if ops[2].shift.type else 0
return None, cur + (ops[2].imm << sh) * (-1 if ins.mnemonic == 'sub' else 1)
mem = next((op for op in ops if op.type == capstone.arm64_const.ARM64_OP_MEM), None)
if mem is None or ins.reg_name(mem.mem.base) != 'sp': return None, cur
if ins.writeback and getattr(ins, 'post_index', False): return cur, cur + ops[-1].imm
if ins.writeback: return cur + mem.mem.disp, cur + mem.mem.disp
return cur + mem.mem.disp, cur
def _block(start):
out = []
for ins in _md.disasm(pat[start:start + 256], start):
@@ -479,22 +510,28 @@ for a, allowed in static_entries:
allowed.update(('x0', 'x1'))
saved = {}
restored = {}
_cur = 0; _abs = []
for ins in block:
d, _cur = _sp_mem(ins, _cur); _abs.append(d)
def _msp(i, ins, load):
if h['ABI'] == 'apple': return _mem_sp(ins, load)
return _abs[i] if ins.mnemonic.startswith('ld' if load else 'st') else None
for i, ins in enumerate(block):
d = _mem_sp(ins, False)
d = _msp(i, ins, False)
if d is not None:
regs = [op.reg for op in ins.operands[:2] if op.type == capstone.arm64_const.ARM64_OP_REG]
for reg in regs:
for j, reg in enumerate(regs):
name = ins.reg_name(reg); name = 'x29' if name == 'fp' else 'x30' if name == 'lr' else re.sub(r'^[wx]', 'x', name)
saved.setdefault(name, []).append((d, i))
d = _mem_sp(ins, True)
saved.setdefault(name, []).append((d + 8 * j if h['ABI'] != 'apple' else d, i)) # android 按真实地址:成对的第二个寄存器在 +8 | android uses the real address: the second register of a pair is at +8
d = _msp(i, ins, True)
if d is not None:
regs = [op.reg for op in ins.operands[:2] if op.type == capstone.arm64_const.ARM64_OP_REG]
for reg in regs:
for j, reg in enumerate(regs):
name = ins.reg_name(reg); name = 'x29' if name == 'fp' else 'x30' if name == 'lr' else re.sub(r'^[wx]', 'x', name)
restored.setdefault(name, []).append((d, i))
restored.setdefault(name, []).append((d + 8 * j if h['ABI'] != 'apple' else d, i)) # android 按真实地址:成对的第二个寄存器在 +8 | android uses the real address: the second register of a pair is at +8
writes = set().union(*(_writes(ins) for ins in block)) if block else set()
for reg in sorted(writes - allowed):
wi = [i for i, ins in enumerate(block) if reg in _writes(ins) and not (i > 0 and _mem_sp(ins, True) is not None)]
wi = [i for i, ins in enumerate(block) if reg in _writes(ins) and not (i > 0 and _msp(i, ins, True) is not None)]
dead = any(ins.mnemonic in ('br', 'blr') and ins.operands and ins.reg_name(ins.operands[0].reg) in (reg, reg[1:]) for ins in block)
ok = dead or any(sd == rd and si < min(wi, default=10**9) and ri > max(wi, default=-1)
for sd, si in saved.get(reg, []) for rd, ri in restored.get(reg, []))