From d90c6e9631f01a39c8e42095d76099449a228e85 Mon Sep 17 00:00:00 2001 From: Alaric Gilbert Date: Sat, 19 Feb 2022 23:01:32 +0800 Subject: [PATCH] =?UTF-8?q?feat.=20=E5=A2=9E=E5=8A=A0WSA=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/config.json | 31 ++++++++++++++++++ src/MeoAssistant/AsstDef.h | 1 + src/MeoAssistant/AsstUtils.hpp | 9 +++++ src/MeoAssistant/Controller.cpp | 49 ++++++++++++++++++++++++---- src/MeoAssistant/GeneralConfiger.cpp | 3 +- 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/resource/config.json b/resource/config.json index 679c2e6412..45bb9ada46 100644 --- a/resource/config.json +++ b/resource/config.json @@ -40,6 +40,7 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '", "displayFormat": "cur=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] exec-out screencap -p", "release": "[Adb] kill-server" @@ -62,6 +63,7 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '", "displayFormat": "cur=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] exec-out screencap -p", "release": "[Adb] kill-server" @@ -84,6 +86,7 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '", "displayFormat": "cur=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] exec-out screencap -p", "release": "[Adb] kill-server" @@ -107,6 +110,7 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '", "displayFormat": "cur=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] shell screencap -p", "release": "[Adb] kill-server" @@ -130,6 +134,7 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '", "displayFormat": "cur=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] exec-out screencap -p", "release": "[Adb] kill-server" @@ -153,6 +158,7 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '", "displayFormat": "cur=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] exec-out screencap -p", "release": "[Adb] kill-server" @@ -175,11 +181,35 @@ "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init=", "displayFormat": " init=%dx%d", + "displayId": "", "screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] shell screencap -p", "release": "[Adb] kill-server" } }, + "WSA": { + "handle": { + "class": "com.hypergryph.arknights", + "window": "明日方舟" + }, + "adb": { + "path": "[ExecDir]platform-tools\\adb.exe", + "addresses": [ + "127.0.0.1:58526" + ], + "devices": "[Adb] devices", + "addressRegex": "(.+)\tdevice", + "connect": "[Adb] connect [Address]", + "click": "[Adb] -s [Address] shell input -d [DisplayId] tap [x] [y]", + "swipe": "[Adb] -s [Address] shell input -d [DisplayId] swipe [x1] [y1] [x2] [y2] [duration]", + "display": "[Adb] -s [Address] shell \"wm size -d [DisplayId]\"", + "displayFormat": "Physical size:%dx%d", + "displayId": "[Adb] -s [Address] shell dumpsys display | grep mUniqueId=virtual:com.microsoft.windows.systemapp:com.hypergryph.arknights", + "screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap -d [DisplayId] | gzip -1\"", + "screencapEncode": "[Adb] -s [Address] shell screencap -d [DisplayId] -p", + "release": "[Adb] kill-server" + } + }, "Custom": { "handle": { "class": "Custom Class", @@ -196,6 +226,7 @@ "click": "[Adb] -s [Address] shell input tap [x] [y]", "swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]", "display": "[Adb] -s [Address] shell dumpsys window displays | grep init=", + "displayId": "", "displayFormat": " init=%dx%d", "screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"", "screencapEncode": "[Adb] -s [Address] exec-out screencap -p", diff --git a/src/MeoAssistant/AsstDef.h b/src/MeoAssistant/AsstDef.h index de26dced7e..98d4ca8d87 100644 --- a/src/MeoAssistant/AsstDef.h +++ b/src/MeoAssistant/AsstDef.h @@ -274,6 +274,7 @@ namespace asst std::string swipe; std::string display; std::string display_format; + std::string display_id; std::string screencap_raw_with_gzip; std::string screencap_encode; std::string release; diff --git a/src/MeoAssistant/AsstUtils.hpp b/src/MeoAssistant/AsstUtils.hpp index b1b6a65157..849a5d889c 100644 --- a/src/MeoAssistant/AsstUtils.hpp +++ b/src/MeoAssistant/AsstUtils.hpp @@ -31,6 +31,15 @@ namespace asst return str; } + inline std::string string_replace_all_batch(const std::string& src, const std::vector>& replace_pairs) + { + std::string str = src; + for (auto &[old_value, new_value] : replace_pairs) { + str = string_replace_all(str, old_value, new_value); + } + return str; + } + inline std::vector string_split(const std::string& str, const std::string& delimiter) { std::string::size_type pos1 = 0; diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index 5e5f80a747..cbfe83d578 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -116,9 +116,38 @@ bool asst::Controller::connect_adb(const std::string & address) return false; } + // 按需获取display ID 信息 + if (!m_emulator_info.adb.display_id.empty()) { + std::string display_id_cmd = utils::string_replace_all( + utils::string_replace_all(m_emulator_info.adb.display_id, "[Adb]", m_emulator_info.adb.path), + "[Address]", address); + auto display_id_ret = call_command(display_id_cmd); + if (!display_id_ret) { + return false; + } + + auto& display_id_result = display_id_ret.value(); + convert_lf(display_id_result); + std::string display_id_pipe_str( + std::make_move_iterator(display_id_result.begin()), + std::make_move_iterator(display_id_result.end())); + auto last = display_id_pipe_str.rfind(':'); + if (last == std::string::npos) { + return false; + } + + m_emulator_info.adb.display_id = display_id_pipe_str.substr(last + 1); + // 去掉换行 + m_emulator_info.adb.display_id.pop_back(); + } + + std::string display_cmd = utils::string_replace_all( + utils::string_replace_all( utils::string_replace_all(m_emulator_info.adb.display, "[Adb]", m_emulator_info.adb.path), - "[Address]", address); + "[Address]", address), + "[DisplayId]", m_emulator_info.adb.display_id); + auto display_ret = call_command(display_cmd); if (!display_ret) { return false; @@ -154,11 +183,19 @@ bool asst::Controller::connect_adb(const std::string & address) m_scale_size = std::make_pair(WindowWidthDefault, scale_height); m_control_scale = static_cast(m_emulator_info.adb.display_width) / static_cast(WindowWidthDefault); } - - m_emulator_info.adb.click = utils::string_replace_all(utils::string_replace_all(m_emulator_info.adb.click, "[Adb]", m_emulator_info.adb.path), "[Address]", address); - m_emulator_info.adb.swipe = utils::string_replace_all(utils::string_replace_all(m_emulator_info.adb.swipe, "[Adb]", m_emulator_info.adb.path), "[Address]", address); - m_emulator_info.adb.screencap_raw_with_gzip = utils::string_replace_all(utils::string_replace_all(m_emulator_info.adb.screencap_raw_with_gzip, "[Adb]", m_emulator_info.adb.path), "[Address]", address); - m_emulator_info.adb.screencap_encode = utils::string_replace_all(utils::string_replace_all(m_emulator_info.adb.screencap_encode, "[Adb]", m_emulator_info.adb.path), "[Address]", address); + std::vector> replaces = { + {"[Adb]", m_emulator_info.adb.path}, + {"[Address]", address}, + {"[DisplayId]", m_emulator_info.adb.display_id} + }; + m_emulator_info.adb.click = utils::string_replace_all_batch( + m_emulator_info.adb.click, replaces); + m_emulator_info.adb.swipe = utils::string_replace_all_batch( + m_emulator_info.adb.swipe, replaces); + m_emulator_info.adb.screencap_raw_with_gzip = + utils::string_replace_all_batch( + m_emulator_info.adb.screencap_raw_with_gzip, replaces); + m_emulator_info.adb.screencap_encode = utils::string_replace_all_batch(m_emulator_info.adb.screencap_encode, replaces); m_emulator_info.adb.release = utils::string_replace_all(m_emulator_info.adb.release, "[Adb]", m_emulator_info.adb.path); return true; diff --git a/src/MeoAssistant/GeneralConfiger.cpp b/src/MeoAssistant/GeneralConfiger.cpp index 74399af223..30cc836c07 100644 --- a/src/MeoAssistant/GeneralConfiger.cpp +++ b/src/MeoAssistant/GeneralConfiger.cpp @@ -50,6 +50,7 @@ bool asst::GeneralConfiger::parse(const json::value& json) emulator_info.adb.click = adb_json.at("click").as_string(); emulator_info.adb.swipe = adb_json.at("swipe").as_string(); emulator_info.adb.display = adb_json.at("display").as_string(); + emulator_info.adb.display_id = adb_json.at("displayId").as_string(); emulator_info.adb.display_format = adb_json.at("displayFormat").as_string(); emulator_info.adb.screencap_raw_with_gzip = adb_json.at("screencapRawWithGzip").as_string(); emulator_info.adb.screencap_encode = adb_json.at("screencapEncode").as_string(); @@ -60,4 +61,4 @@ bool asst::GeneralConfiger::parse(const json::value& json) } return true; -} \ No newline at end of file +}