From 3c787f608b5a371a973d9732be3e1f1f8ac7adce Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 3 Dec 2022 14:10:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20config?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20maatouch=20=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/config.json | 227 +++++---------------------- src/MaaCore/Config/GeneralConfig.cpp | 52 +++--- src/MaaCore/Config/GeneralConfig.h | 6 +- src/MaaCore/Controller.cpp | 60 +++---- src/MaaCore/Controller.h | 3 +- src/MaaCore/Utils/StringMisc.hpp | 2 +- 6 files changed, 101 insertions(+), 249 deletions(-) diff --git a/resource/config.json b/resource/config.json index 7d6d7976cd..6dc10d60cc 100644 --- a/resource/config.json +++ b/resource/config.json @@ -21,8 +21,7 @@ "x86", "arm64-v8a", "armeabi-v7a", - "armeabi", - "maatouch" + "armeabi" ], "swipeWithPauseRequiredDistance": 50, "swipeWithPauseRequiredDistance_Doc": "暂停下干员滑动多远距离后开始按暂停", @@ -50,8 +49,9 @@ "YoStarKR": "com.YoStarKR.Arknights/com.u8.sdk.U8UnityContext", "txwy": "tw.txwy.and.arknights/com.u8.sdk.U8UnityContext" }, - "connection": { - "General": { + "connection": [ + { + "configName": "General", "devices": "[Adb] devices", "addressRegex": "(.+)\tdevice", "connect": "[Adb] connect [AdbSerial]", @@ -73,200 +73,53 @@ "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i", + "callMaatouch": "[Adb] -s [AdbSerial] shell \"export CLASSPATH=/data/local/tmp/[minitouchWorkingFile]; app_process /data/local/tmp com.shxyke.MaaTouch.App\"" }, - "BlueStacks": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, - "screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" - }, - "MuMuEmulator": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, - "screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" - }, - "LDPlayer": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", + { + "configName": "CapWithShell", + "baseConfig": "General", "screencapRawByNC": "[Adb] -s [AdbSerial] shell \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, "screencapRawWithGzip": "[Adb] -s [AdbSerial] shell \"screencap | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] shell screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + "screencapEncode": "[Adb] -s [AdbSerial] shell screencap -p" }, - "Nox": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, - "screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + { + "configName": "BlueStacks", + "baseConfig": "General" }, - "XYAZ": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, - "screencapRawWithGzip": "[Adb] -s [AdbSerial] shell \"screencap | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] shell screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + { + "configName": "MuMuEmulator", + "baseConfig": "General" }, - "WSA": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", + { + "configName": "LDPlayer", + "baseConfig": "CapWithShell" + }, + { + "configName": "Nox" + }, + { + "configName": "XYAZ", + "baseConfig": "CapWithShell" + }, + { + "configName": "WSA", + "baseConfig": "CapWithShell", "displayId": "[Adb] -s [AdbSerial] shell dumpsys display | grep mUniqueId=virtual:com.microsoft.windows.systemapp:com.hypergryph.arknights", - "uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id", "click": "[Adb] -s [AdbSerial] shell input -d [DisplayId] tap [x] [y]", "swipe": "[Adb] -s [AdbSerial] shell input -d [DisplayId] swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell \"wm size -d [DisplayId] | grep -o -E [0-9]+\"", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, - "screencapRawWithGzip": "[Adb] -s [AdbSerial] shell \"screencap -d [DisplayId] | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] shell screencap -d [DisplayId] -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + "display": "[Adb] -s [AdbSerial] shell \"wm size -d [DisplayId] | grep -o -E [0-9]+\"" }, - "Compatible": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell echo 111111", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", - "ncAddress": "[Adb] -s [AdbSerial] shell \" cat /proc/net/arp | grep : \"", - "ncPort": 6723, - "screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"", - "screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + { + "configName": "Compatible", + "baseConfig": "General", + "uuid": "[Adb] -s [AdbSerial] shell echo 111111" }, - "CompatMac": { - "devices": "[Adb] devices", - "addressRegex": "(.+)\tdevice", - "connect": "[Adb] connect [AdbSerial]", - "uuid": "[Adb] -s [AdbSerial] shell echo 111111", - "click": "[Adb] -s [AdbSerial] shell input tap [x] [y]", - "swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]", - "pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111", - "display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+", - "displayFormat": "%d%d", - "screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"", + { + "configName": "CompatMac", + "baseConfig": "Compatible", "ncAddress": "[Adb] -s [AdbSerial] shell \"cat /proc/net/arp | grep : | sort\"", - "ncPort": 6723, - "screencapRawWithGzip": "", - "screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p", - "release": "[Adb] kill-server", - "start": "[Adb] -s [AdbSerial] shell am start -n [Intent]", - "stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\"", - "abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist", - "orientation": "[Adb] -s [AdbSerial] shell dumpsys input | grep SurfaceOrientation | grep -m 1 -o -E [0-9]", - "pushMinitouch": "[Adb] -s [AdbSerial] push \"[minitouchLocalPath]\" \"/data/local/tmp/[minitouchWorkingFile]\"", - "chmodMinitouch": "[Adb] -s [AdbSerial] shell chmod 700 \"/data/local/tmp/[minitouchWorkingFile]\"", - "callMinitouch": "[Adb] -s [AdbSerial] shell \"/data/local/tmp/[minitouchWorkingFile]\" -i" + "screencapRawWithGzip": "" } - } + ] } diff --git a/src/MaaCore/Config/GeneralConfig.cpp b/src/MaaCore/Config/GeneralConfig.cpp index 84eef95bc3..30dfb878d8 100644 --- a/src/MaaCore/Config/GeneralConfig.cpp +++ b/src/MaaCore/Config/GeneralConfig.cpp @@ -33,34 +33,34 @@ bool asst::GeneralConfig::parse(const json::value& json) m_intent_name[client_type] = intent_name.as_string(); } - for (const auto& [name, cfg_json] : json.at("connection").as_object()) { + for (const auto& cfg_json : json.at("connection").as_array()) { + auto base_it = m_adb_cfg.find(cfg_json.get("baseConfig", "General")); + const AdbCfg& base_cfg = base_it == m_adb_cfg.end() ? AdbCfg() : base_it->second; + AdbCfg adb; + adb.connect = cfg_json.get("connect", base_cfg.connect); + adb.display_id = cfg_json.get("displayId", base_cfg.display_id); + adb.uuid = cfg_json.get("uuid", base_cfg.uuid); + adb.click = cfg_json.get("click", base_cfg.click); + adb.swipe = cfg_json.get("swipe", base_cfg.swipe); + adb.press_esc = cfg_json.get("pressEsc", base_cfg.press_esc); + adb.display = cfg_json.get("display", base_cfg.display); + adb.screencap_raw_with_gzip = cfg_json.get("screencapRawWithGzip", base_cfg.screencap_raw_with_gzip); + adb.screencap_raw_by_nc = cfg_json.get("screencapRawByNC", base_cfg.screencap_raw_by_nc); + adb.nc_address = cfg_json.get("ncAddress", base_cfg.nc_address); + adb.nc_port = static_cast(cfg_json.get("ncPort", base_cfg.nc_port)); + adb.screencap_encode = cfg_json.get("screencapEncode", base_cfg.screencap_encode); + adb.release = cfg_json.get("release", base_cfg.release); + adb.start = cfg_json.get("start", base_cfg.start); + adb.stop = cfg_json.get("stop", base_cfg.stop); + adb.abilist = cfg_json.get("abilist", base_cfg.abilist); + adb.orientation = cfg_json.get("orientation", base_cfg.orientation); + adb.push_minitouch = cfg_json.get("pushMinitouch", base_cfg.push_minitouch); + adb.chmod_minitouch = cfg_json.get("chmodMinitouch", base_cfg.chmod_minitouch); + adb.call_minitouch = cfg_json.get("callMinitouch", base_cfg.call_minitouch); + adb.call_maatouch = cfg_json.get("callMaatouch", base_cfg.call_maatouch); - adb.devices = cfg_json.at("devices").as_string(); - adb.address_regex = cfg_json.at("addressRegex").as_string(); - adb.connect = cfg_json.at("connect").as_string(); - adb.display_id = cfg_json.get("displayId", std::string()); - adb.uuid = cfg_json.at("uuid").as_string(); - adb.click = cfg_json.at("click").as_string(); - adb.swipe = cfg_json.at("swipe").as_string(); - adb.press_esc = cfg_json.get("pressEsc", std::string()); - adb.display = cfg_json.at("display").as_string(); - adb.display_format = cfg_json.at("displayFormat").as_string(); - adb.screencap_raw_with_gzip = cfg_json.at("screencapRawWithGzip").as_string(); - adb.screencap_raw_by_nc = cfg_json.at("screencapRawByNC").as_string(); - adb.nc_address = cfg_json.at("ncAddress").as_string(); - adb.nc_port = static_cast(cfg_json.at("ncPort").as_integer()); - adb.screencap_encode = cfg_json.at("screencapEncode").as_string(); - adb.release = cfg_json.at("release").as_string(); - adb.start = cfg_json.at("start").as_string(); - adb.stop = cfg_json.at("stop").as_string(); - adb.abilist = cfg_json.at("abilist").as_string(); - adb.orientation = cfg_json.at("orientation").as_string(); - adb.push_minitouch = cfg_json.at("pushMinitouch").as_string(); - adb.chmod_minitouch = cfg_json.at("chmodMinitouch").as_string(); - adb.call_minitouch = cfg_json.at("callMinitouch").as_string(); - - m_adb_cfg[name] = std::move(adb); + m_adb_cfg[cfg_json.at("configName").as_string()] = std::move(adb); } return true; diff --git a/src/MaaCore/Config/GeneralConfig.h b/src/MaaCore/Config/GeneralConfig.h index 0e2d64f593..f7c616845f 100644 --- a/src/MaaCore/Config/GeneralConfig.h +++ b/src/MaaCore/Config/GeneralConfig.h @@ -52,12 +52,7 @@ namespace asst struct AdbCfg { - /* format */ - std::string address_regex; - std::string display_format; - /* command */ - std::string devices; std::string connect; std::string display_id; std::string uuid; @@ -78,6 +73,7 @@ namespace asst std::string push_minitouch; std::string chmod_minitouch; std::string call_minitouch; + std::string call_maatouch; }; class GeneralConfig final : public SingletonHolder, public AbstractConfig diff --git a/src/MaaCore/Controller.cpp b/src/MaaCore/Controller.cpp index fcbaa57911..0794e06a35 100644 --- a/src/MaaCore/Controller.cpp +++ b/src/MaaCore/Controller.cpp @@ -411,7 +411,7 @@ std::optional asst::Controller::call_command(const std::string& cmd is_reconnect_success = reconnect_str.find("error") == std::string::npos; } if (is_reconnect_success) { - if (call_and_hup_minitouch(m_adb.call_minitouch)) { + if (call_and_hup_minitouch()) { m_minitouch_avaiable = true; } auto recall_ret = call_command(cmd, timeout, false /* 禁止重连避免无限递归 */, recv_by_socket); @@ -446,11 +446,12 @@ void asst::Controller::callback(AsstMsg msg, const json::value& details) } } -bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) +bool asst::Controller::call_and_hup_minitouch() { LogTraceFunction; release_minitouch(true); + std::string cmd = m_use_maa_touch ? m_adb.call_maatouch : m_adb.call_minitouch; Log.info(cmd); constexpr int PipeReadBuffSize = 4096ULL; @@ -1399,17 +1400,11 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a callback(AsstMsg::ConnectionInfo, info); return false; } - - auto& display_pipe_str = display_ret.value(); + std::stringstream display_ss(display_ret.value()); int size_value1 = 0; int size_value2 = 0; -#ifdef _MSC_VER - sscanf_s(display_pipe_str.c_str(), adb_cfg.display_format.c_str(), &size_value1, &size_value2); -#else - sscanf(display_pipe_str.c_str(), adb_cfg.display_format.c_str(), &size_value1, &size_value2); -#endif - // 为了防止抓取句柄的时候手机是竖屏的(还没进游戏),这里取大的值为宽,小的为高 - // 总不能有人竖屏玩明日方舟吧(? + display_ss >> size_value1 >> size_value2; + m_width = (std::max)(size_value1, size_value2); m_height = (std::min)(size_value1, size_value2); @@ -1523,16 +1518,30 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a while (m_minitouch_enabled) { m_minitouch_avaiable = false; - std::string abilist = - m_use_maa_touch ? "maatouch" : call_command(cmd_replace(adb_cfg.abilist)).value_or("maatouch"); - std::string_view optimal_abi; - for (const auto& abi : Config.get_options().minitouch_programs_order) { - if (abilist.find(abi) != std::string::npos) { - optimal_abi = abi; - break; + std::string_view touch_program; + if (m_use_maa_touch) { + touch_program = "maatouch"; + m_minitouch_props.orientation = 0; + } + else { + std::string abilist = call_command(cmd_replace(adb_cfg.abilist)).value_or(std::string()); + for (const auto& abi : Config.get_options().minitouch_programs_order) { + if (abilist.find(abi) != std::string::npos) { + touch_program = abi; + break; + } + } + std::string orientation_str = call_command(cmd_replace(adb_cfg.orientation)).value_or("0"); + if (!orientation_str.empty()) { + char first = orientation_str.front(); + if (first == '0' || first == '1' || first == '2' || first == '3') { + m_minitouch_props.orientation = static_cast(first - '0'); + } } } - Log.info("The optimal abi is", optimal_abi); + Log.info("touch_program", touch_program, "orientation", m_minitouch_props.orientation); + + if (touch_program.empty()) break; auto minitouch_cmd_rep = [&](const std::string& cfg_cmd) -> std::string { using namespace asst::utils::path_literals; @@ -1540,7 +1549,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a cmd_replace(cfg_cmd), { { "[minitouchLocalPath]", - utils::path_to_utf8_string(ResDir.get() / "minitouch"_p / optimal_abi / "minitouch"_p) }, + utils::path_to_utf8_string(ResDir.get() / "minitouch"_p / touch_program / "minitouch"_p) }, { "[minitouchWorkingFile]", m_uuid }, }); }; @@ -1549,16 +1558,9 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a if (!call_command(minitouch_cmd_rep(adb_cfg.chmod_minitouch))) break; m_adb.call_minitouch = minitouch_cmd_rep(adb_cfg.call_minitouch); - if (!call_and_hup_minitouch(m_adb.call_minitouch)) break; + m_adb.call_maatouch = minitouch_cmd_rep(adb_cfg.call_maatouch); - std::string orientation_str = - m_use_maa_touch ? "0" : call_command(cmd_replace(adb_cfg.orientation)).value_or("0"); - if (!orientation_str.empty()) { - char first = orientation_str.front(); - if (first == '0' || first == '1' || first == '2' || first == '3') { - m_minitouch_props.orientation = static_cast(first - '0'); - } - } + if (!call_and_hup_minitouch()) break; m_minitouch_avaiable = true; break; diff --git a/src/MaaCore/Controller.h b/src/MaaCore/Controller.h index 07743f772a..a8b1901eb0 100644 --- a/src/MaaCore/Controller.h +++ b/src/MaaCore/Controller.h @@ -90,7 +90,7 @@ namespace asst void clear_info() noexcept; void callback(AsstMsg msg, const json::value& details); - bool call_and_hup_minitouch(const std::string& cmd); + bool call_and_hup_minitouch(); bool input_to_minitouch(const std::string& cmd); void release_minitouch(bool force = false); @@ -128,6 +128,7 @@ namespace asst /* command */ std::string connect; std::string call_minitouch; + std::string call_maatouch; std::string click; std::string swipe; std::string press_esc; diff --git a/src/MaaCore/Utils/StringMisc.hpp b/src/MaaCore/Utils/StringMisc.hpp index 75eedaf348..2b36d72958 100644 --- a/src/MaaCore/Utils/StringMisc.hpp +++ b/src/MaaCore/Utils/StringMisc.hpp @@ -33,7 +33,7 @@ namespace asst::utils inline constexpr void string_replace_all_in_place(StringT& str, detail::sv_type from, detail::sv_type to) { - for (StringT::size_type pos(0);; pos += to.length()) { + for (size_t pos(0);; pos += to.length()) { if ((pos = str.find(from, pos)) == StringT::npos) return; str.replace(pos, from.length(), to); }