匹配 ReDroid 的 ADB 设备名并指定 MaaFramework 库目录。运行 MaaEnd 时切换至 720p,退出后恢复 1080p。基质刷取改用四号谷地枢纽区。
83 lines
3.2 KiB
Python
83 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""MaaEnd 只补齐当前官方终端包的路径和 ADB 界面适配。"""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from ArknightsMaaConfig.maa import ADDRESS, REDROID, DIRECT, command, wait_android
|
|
|
|
|
|
def prepare(configure=False):
|
|
source = Path("/app/maaend")
|
|
version = json.loads((source / "interface.json").read_text())["version"]
|
|
target = Path("/state") / f"maaend-{version}"
|
|
if not target.exists():
|
|
shutil.copytree(source, target, symlinks=True)
|
|
# 保留原文件;CLI 不支持 hotkey 设置,ADB 使用原始 pipeline 的默认值。
|
|
original = target / "interface.upstream.json"
|
|
if not original.exists():
|
|
shutil.copyfile(target / "interface.json", original)
|
|
interface = json.loads(original.read_text())
|
|
interface["controller"] = [c for c in interface["controller"] if c["name"] == "ADB"]
|
|
interface["import"] = [p for p in interface["import"] if p != "tasks/setting/Keymap.json"]
|
|
(target / "interface.json").write_text(json.dumps(interface, ensure_ascii=False, indent=2))
|
|
work = target / "maafw"
|
|
config = json.loads(Path(__file__).with_name("maa_pi_config.json").read_text())
|
|
if not configure and not config.get("task"):
|
|
raise RuntimeError("请先配置 MaaEnd 任务并提交到 MAAsConfig,再启用 maaend。")
|
|
config["adb"].update(address=ADDRESS, adb_path="/usr/bin/adb")
|
|
(work / "config").mkdir(exist_ok=True)
|
|
(work / "config/maa_pi_config.json").write_text(json.dumps(config, ensure_ascii=False, indent=2))
|
|
return work
|
|
|
|
|
|
def set_display_size(size, expected):
|
|
args = ["adb", "-s", ADDRESS, "shell", "wm", "size"]
|
|
try:
|
|
subprocess.run([*args, size], env=DIRECT, check=True, timeout=10)
|
|
result = subprocess.run(args, env=DIRECT, check=True, timeout=10,
|
|
stdout=subprocess.PIPE, text=True)
|
|
except (OSError, subprocess.SubprocessError) as error:
|
|
print(f"设置 ReDroid 分辨率失败(wm size {size}):{error}", flush=True)
|
|
return False
|
|
|
|
sizes = result.stdout.strip().splitlines()
|
|
if sizes[-1:] != [expected]:
|
|
print(f"ReDroid 分辨率核验失败,预期 {expected},实际 {sizes}", flush=True)
|
|
return False
|
|
print(f"ReDroid 分辨率已确认:{sizes[-1]}", flush=True)
|
|
return True
|
|
|
|
|
|
def main():
|
|
configure = sys.argv[1:] == ["configure"]
|
|
work = prepare(configure)
|
|
if command(["docker", "restart", REDROID]):
|
|
return 1
|
|
ready = False
|
|
result = 1
|
|
try:
|
|
ready = wait_android()
|
|
if ready and set_display_size("1280x720", "Override size: 1280x720"):
|
|
result = subprocess.run(
|
|
[str(work / "MaaPiCli")] + ([] if configure else ["-d"]),
|
|
cwd=work,
|
|
env={**DIRECT, "MAAFW_BINARY_PATH": str(work)},
|
|
).returncode
|
|
finally:
|
|
try:
|
|
if ready and not set_display_size("reset", "Physical size: 1920x1080"):
|
|
result = result or 1
|
|
finally:
|
|
if command(["docker", "stop", REDROID]):
|
|
result = result or 1
|
|
return result
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|