From 88c2e5c691a9a2c28aed95cf5ea5f408541d1339 Mon Sep 17 00:00:00 2001 From: MistEO Date: Fri, 18 Nov 2022 21:38:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dminitouch=E7=AB=96?= =?UTF-8?q?=E5=B1=8F=E4=B8=8B=E7=9A=84=E6=93=8D=E4=BD=9C=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/2794 --- resource/config.json | 9 +++++ src/MeoAssistant/Controller.cpp | 9 +++++ src/MeoAssistant/Controller.h | 35 ++++++++++++++++--- src/MeoAssistant/Resource/GeneralConfiger.cpp | 1 + src/MeoAssistant/Resource/GeneralConfiger.h | 1 + 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/resource/config.json b/resource/config.json index d6d812cf65..1a04dda4a6 100644 --- a/resource/config.json +++ b/resource/config.json @@ -59,6 +59,7 @@ "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" @@ -81,6 +82,7 @@ "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" @@ -103,6 +105,7 @@ "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" @@ -125,6 +128,7 @@ "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" @@ -147,6 +151,7 @@ "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" @@ -169,6 +174,7 @@ "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" @@ -192,6 +198,7 @@ "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" @@ -214,6 +221,7 @@ "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" @@ -236,6 +244,7 @@ "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" diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index 5fd225a0af..253c439a41 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -681,6 +681,7 @@ void asst::Controller::clear_info() noexcept m_control_scale = 1.0; m_minitouch_avaiable = false; m_scale_size = { WindowWidthDefault, WindowHeightDefault }; + m_minitouch_props = decltype(m_minitouch_props)(); } void asst::Controller::close_socket() noexcept @@ -1401,6 +1402,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a } } Log.info("The optimal abi is", optimal_abi); + auto minitouch_cmd_rep = [&](const std::string& cfg_cmd) -> std::string { using namespace asst::utils::path_literals; return utils::string_replace_all( @@ -1417,6 +1419,13 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a call_and_hup_minitouch(minitouch_cmd_rep(adb_cfg.call_minitouch)); + std::string orientation_str = call_command(cmd_replace(adb_cfg.orientation)).value_or("0"); + auto [beg, end] = ranges::remove_if(orientation_str, [](char ch) -> bool { return !std::isdigit(ch); }); + orientation_str.erase(beg, end); + if (!orientation_str.empty()) { + m_minitouch_props.orientation = std::stoi(orientation_str); + } + // try to find the fastest way if (!screencap()) { Log.error("Cannot find a proper way to screencap!"); diff --git a/src/MeoAssistant/Controller.h b/src/MeoAssistant/Controller.h index bf1285b216..c4bdc4b88e 100644 --- a/src/MeoAssistant/Controller.h +++ b/src/MeoAssistant/Controller.h @@ -204,6 +204,7 @@ namespace asst double x_scaling = 0; double y_scaling = 0; + int orientation = 0; } m_minitouch_props; class Minitoucher @@ -258,7 +259,8 @@ namespace asst // std::string str = std::format("d {} {} {} {}\n", contact, x, y, pressure); char buff[64] = { 0 }; - sprintf(buff, "d %d %d %d %d\n", contact, scale_x(x), scale_y(y), m_props.max_pressure); + auto [c_x, c_y] = scale(x, y); + sprintf(buff, "d %d %d %d %d\n", contact, c_x, c_y, m_props.max_pressure); std::string str = buff; if (with_commit) str += commit_cmd(); @@ -270,7 +272,8 @@ namespace asst int contact = 0) { char buff[64] = { 0 }; - sprintf(buff, "m %d %d %d %d\n", contact, scale_x(x), scale_y(y), m_props.max_pressure); + auto [c_x, c_y] = scale(x, y); + sprintf(buff, "m %d %d %d %d\n", contact, c_x, c_y, m_props.max_pressure); std::string str = buff; if (with_commit) str += commit_cmd(); @@ -307,8 +310,32 @@ namespace asst } private: - int scale_x(int x) const noexcept { return static_cast(x * m_props.x_scaling); } - int scale_y(int y) const noexcept { return static_cast(y * m_props.y_scaling); } + Point scale(int x, int y) const noexcept + { + switch (m_props.orientation) { + case 0: + default: + return { + static_cast(x * m_props.x_scaling), + static_cast(y * m_props.y_scaling), + }; + case 1: + return { + m_props.max_y - static_cast(y * m_props.y_scaling), + static_cast(x * m_props.x_scaling), + }; + case 2: + return { + m_props.max_x - static_cast(x * m_props.x_scaling), + m_props.max_y - static_cast(y * m_props.y_scaling), + }; + case 3: + return { + static_cast(y * m_props.y_scaling), + m_props.max_x - static_cast(x * m_props.x_scaling), + }; + } + } const std::function m_input_func = nullptr; const MinitouchProps& m_props; diff --git a/src/MeoAssistant/Resource/GeneralConfiger.cpp b/src/MeoAssistant/Resource/GeneralConfiger.cpp index 8ef8fbc146..68fa5a4843 100644 --- a/src/MeoAssistant/Resource/GeneralConfiger.cpp +++ b/src/MeoAssistant/Resource/GeneralConfiger.cpp @@ -49,6 +49,7 @@ bool asst::GeneralConfiger::parse(const json::value& json) 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(); diff --git a/src/MeoAssistant/Resource/GeneralConfiger.h b/src/MeoAssistant/Resource/GeneralConfiger.h index 3a3681833f..c82bb2f86b 100644 --- a/src/MeoAssistant/Resource/GeneralConfiger.h +++ b/src/MeoAssistant/Resource/GeneralConfiger.h @@ -71,6 +71,7 @@ namespace asst std::string start; std::string stop; std::string abilist; + std::string orientation; std::string push_minitouch; std::string chmod_minitouch; std::string call_minitouch;