mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
Merge branch 'dev'
This commit is contained in:
@@ -22,11 +22,7 @@
|
||||
|
||||
## 夜神模拟器 安卓 9
|
||||
|
||||
支持。但可能存在一直识别出错的问题
|
||||
|
||||
- 请手动修改 `resource/config.json` 文件中 `"Nox"` - `"adb"`
|
||||
1. `"screencap"` 字段值为 `"[Adb] -s [Address] exec-out screencap -p"`
|
||||
2. `"screencapGzip"` 字段值为 `false`
|
||||
完美支持
|
||||
|
||||
## MuMu 模拟器
|
||||
|
||||
@@ -59,6 +55,10 @@
|
||||
|
||||
不支持。WSA 目前没有实现 AOSP screencap 需要的接口,无法进行截图。等微软支持后会尝试适配
|
||||
|
||||
## AVD
|
||||
|
||||
支持。
|
||||
|
||||
## 自定义连接
|
||||
|
||||
1. 下载 [adb](https://dl.google.com/android/repository/platform-tools-latest-windows.zip) ,将 `platform-tools` 文件夹解压到 `MeoAsstGui.exe` 的同级目录
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
@@ -62,8 +62,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
@@ -84,8 +84,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
@@ -107,8 +107,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] shell screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
@@ -130,8 +130,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
@@ -152,8 +152,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] shell screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
@@ -174,8 +174,8 @@
|
||||
"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",
|
||||
"screencap": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapGzip": true,
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2316,7 +2316,8 @@
|
||||
520,
|
||||
180
|
||||
],
|
||||
"rearDelay": 1000
|
||||
"preDelay": 1000,
|
||||
"rearDelay": 2000
|
||||
},
|
||||
"InfrastDormConfirmButton": {
|
||||
"template": "DormConfirm.png",
|
||||
|
||||
@@ -239,12 +239,28 @@ namespace asst
|
||||
std::string swipe;
|
||||
std::string display;
|
||||
std::string display_format;
|
||||
std::string screencap;
|
||||
bool screencap_gzip = false;
|
||||
std::string screencap_raw_with_gzip;
|
||||
std::string screencap_encode;
|
||||
std::string release;
|
||||
//std::string pullscreen;
|
||||
int display_width = 0;
|
||||
int display_height = 0;
|
||||
|
||||
enum class ScreencapEndOfLine
|
||||
{
|
||||
UnknownYet,
|
||||
CRLF,
|
||||
LF,
|
||||
CR
|
||||
} screencap_end_of_line = ScreencapEndOfLine::UnknownYet;
|
||||
|
||||
enum class ScreencapMethod
|
||||
{
|
||||
UnknownYet,
|
||||
Default,
|
||||
RawWithGzip,
|
||||
Encode
|
||||
} screencap_method = ScreencapMethod::UnknownYet;
|
||||
};
|
||||
|
||||
struct EmulatorInfo
|
||||
|
||||
@@ -157,7 +157,8 @@ bool asst::Controller::connect_adb(const std::string & address)
|
||||
|
||||
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 = utils::string_replace_all(utils::string_replace_all(m_emulator_info.adb.screencap, "[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);
|
||||
m_emulator_info.adb.release = utils::string_replace_all(m_emulator_info.adb.release, "[Adb]", m_emulator_info.adb.path);
|
||||
|
||||
return true;
|
||||
@@ -579,54 +580,103 @@ bool asst::Controller::screencap()
|
||||
LogTraceFunction;
|
||||
|
||||
auto& adb = m_emulator_info.adb;
|
||||
auto ret = call_command(adb.screencap);
|
||||
|
||||
DecodeFunc decode_raw_with_gzip = [&](const std::vector<uchar>& data) -> bool {
|
||||
auto unzip_data = gzip::decompress(data.data(), data.size());
|
||||
Log.trace("unzip data size:", unzip_data.size());
|
||||
if (unzip_data.empty()) {
|
||||
return false;
|
||||
}
|
||||
size_t std_size = adb.display_height * adb.display_width * 4;
|
||||
if (unzip_data.size() < std_size) {
|
||||
return false;
|
||||
}
|
||||
size_t header_size = unzip_data.size() - std_size;
|
||||
Log.trace("header size:", header_size);
|
||||
m_cache_image = cv::Mat(
|
||||
adb.display_height,
|
||||
adb.display_width,
|
||||
CV_8UC4,
|
||||
unzip_data.data() + header_size);
|
||||
cv::cvtColor(m_cache_image, m_cache_image, cv::COLOR_RGB2BGR);
|
||||
return !m_cache_image.empty();
|
||||
};
|
||||
|
||||
DecodeFunc decode_encode = [&](const std::vector<uchar>& data) -> bool {
|
||||
m_cache_image = cv::imdecode(data, cv::IMREAD_COLOR);
|
||||
return !m_cache_image.empty();
|
||||
};
|
||||
|
||||
switch (adb.screencap_method) {
|
||||
case AdbCmd::ScreencapMethod::UnknownYet:
|
||||
{
|
||||
if (screencap(adb.screencap_raw_with_gzip, decode_raw_with_gzip)) {
|
||||
adb.screencap_method = AdbCmd::ScreencapMethod::RawWithGzip;
|
||||
return true;
|
||||
}
|
||||
else if (screencap(adb.screencap_encode, decode_encode)) {
|
||||
adb.screencap_method = AdbCmd::ScreencapMethod::Encode;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case AdbCmd::ScreencapMethod::RawWithGzip:
|
||||
{
|
||||
return screencap(adb.screencap_raw_with_gzip, decode_raw_with_gzip);
|
||||
}
|
||||
break;
|
||||
case AdbCmd::ScreencapMethod::Encode:
|
||||
{
|
||||
return screencap(adb.screencap_encode, decode_encode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool asst::Controller::screencap(const std::string & cmd, DecodeFunc decode_func)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
auto& adb = m_emulator_info.adb;
|
||||
auto ret = call_command(cmd);
|
||||
|
||||
if (!ret || ret.value().empty()) {
|
||||
Log.error("Data is empty!");
|
||||
Log.error("data is empty!");
|
||||
return false;
|
||||
}
|
||||
auto data = std::move(ret).value();
|
||||
if (m_image_convert_lf) {
|
||||
|
||||
if (adb.screencap_end_of_line == AdbCmd::ScreencapEndOfLine::CRLF) {
|
||||
convert_lf(data);
|
||||
}
|
||||
|
||||
std::function<bool(const std::vector<uchar>&)> decode_func = nullptr;
|
||||
if (adb.screencap_gzip) {
|
||||
decode_func = [&](const std::vector<uchar>& data) -> bool {
|
||||
auto unzip_data = gzip::decompress(data.data(), data.size());
|
||||
Log.trace("unzip data size:", unzip_data.size());
|
||||
if (unzip_data.empty()) {
|
||||
return false;
|
||||
}
|
||||
constexpr static int BmpHeaderSize = 12;
|
||||
size_t std_size = adb.display_height * adb.display_width * 4 + BmpHeaderSize;
|
||||
if (unzip_data.size() != std_size) {
|
||||
return false;
|
||||
}
|
||||
m_cache_image = cv::Mat(adb.display_height, adb.display_width, CV_8UC4, unzip_data.data() + BmpHeaderSize);
|
||||
cv::cvtColor(m_cache_image, m_cache_image, cv::COLOR_RGB2BGR);
|
||||
return !m_cache_image.empty();
|
||||
};
|
||||
}
|
||||
else {
|
||||
decode_func = [&](const std::vector<uchar>& data) -> bool {
|
||||
m_cache_image = cv::imdecode(data, cv::IMREAD_COLOR);
|
||||
return !m_cache_image.empty();
|
||||
};
|
||||
}
|
||||
|
||||
if (!decode_func(data)) {
|
||||
Log.info("Data is not empty, but image is empty, try to convert lf");
|
||||
convert_lf(data);
|
||||
if (!decode_func(data)) {
|
||||
m_image_convert_lf = false;
|
||||
Log.error("convert lf and retry decode falied!");
|
||||
return false;
|
||||
if (decode_func(data)) {
|
||||
if (adb.screencap_end_of_line == AdbCmd::ScreencapEndOfLine::UnknownYet) {
|
||||
adb.screencap_end_of_line = AdbCmd::ScreencapEndOfLine::LF;
|
||||
}
|
||||
m_image_convert_lf = true;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
else {
|
||||
Log.info("data is not empty, but image is empty");
|
||||
|
||||
if (adb.screencap_end_of_line == AdbCmd::ScreencapEndOfLine::UnknownYet) {
|
||||
Log.info("try to cvt lf");
|
||||
convert_lf(data);
|
||||
|
||||
if (decode_func(data)) {
|
||||
adb.screencap_end_of_line = AdbCmd::ScreencapEndOfLine::CRLF;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Log.error("convert lf and retry decode falied!");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int asst::Controller::click(const Point & p, bool block)
|
||||
@@ -750,11 +800,12 @@ cv::Mat asst::Controller::get_image(bool raw)
|
||||
return m_cache_image;
|
||||
}
|
||||
else {
|
||||
const static cv::Size dsize(m_scale_size.first, m_scale_size.second);
|
||||
if (m_cache_image.empty()) {
|
||||
return m_cache_image;
|
||||
Log.error("image is empty");
|
||||
return cv::Mat(dsize, CV_8UC3);
|
||||
}
|
||||
cv::Mat resized_mat;
|
||||
const static cv::Size dsize(m_scale_size.first, m_scale_size.second);
|
||||
cv::resize(m_cache_image, resized_mat, dsize);
|
||||
return resized_mat;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ namespace asst
|
||||
std::optional<std::vector<unsigned char>> call_command(const std::string& cmd);
|
||||
int push_cmd(const std::string& cmd);
|
||||
bool screencap();
|
||||
using DecodeFunc = std::function<bool(const std::vector<uchar>&)>;
|
||||
bool screencap(const std::string& cmd, DecodeFunc decode_func);
|
||||
Point rand_point_in_rect(const Rect& rect);
|
||||
|
||||
void random_delay() const;
|
||||
@@ -89,7 +91,6 @@ namespace asst
|
||||
|
||||
//std::shared_mutex m_image_mutex;
|
||||
cv::Mat m_cache_image;
|
||||
bool m_image_convert_lf = false;
|
||||
|
||||
constexpr static int PipeBuffSize = 4 * 1024 * 1024; // 管道缓冲区大小
|
||||
std::unique_ptr<uchar[]> m_pipe_buffer = nullptr;
|
||||
|
||||
@@ -51,8 +51,8 @@ bool asst::GeneralConfiger::parse(const json::value& json)
|
||||
emulator_info.adb.swipe = adb_json.at("swipe").as_string();
|
||||
emulator_info.adb.display = adb_json.at("display").as_string();
|
||||
emulator_info.adb.display_format = adb_json.at("displayFormat").as_string();
|
||||
emulator_info.adb.screencap = adb_json.at("screencap").as_string();
|
||||
emulator_info.adb.screencap_gzip = adb_json.get("screencapGzip", false);
|
||||
emulator_info.adb.screencap_raw_with_gzip = adb_json.at("screencapRawWithGzip").as_string();
|
||||
emulator_info.adb.screencap_encode = adb_json.at("screencapEncode").as_string();
|
||||
emulator_info.adb.release = adb_json.at("release").as_string();
|
||||
//emulator_info.adb.pullscreen = adb_json.at("pullscreen").as_string();
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ bool asst::InfrastAbstractTask::click_confirm_button()
|
||||
// 识别“正在提交反馈至神经”,如果网不好一直确认不了,就多等一会
|
||||
OcrImageAnalyzer analyzer;
|
||||
analyzer.set_task_info(*task_ptr);
|
||||
for (int i = 0; i != m_retry_times; ++i) {
|
||||
for (int i = 0; i <= m_retry_times; ++i) {
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ bool asst::InfrastDormTask::opers_choose()
|
||||
// // 识别“正在提交反馈至神经”,如果网不好一直确认不了,就多等一会
|
||||
// OcrImageAnalyzer analyzer;
|
||||
// analyzer.set_task_info(*task_ptr);
|
||||
// for (int i = 0; i != m_retry_times; ++i) {
|
||||
// for (int i = 0; i <= m_retry_times; ++i) {
|
||||
// if (need_exit()) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@@ -26,7 +26,7 @@ asst::ProcessTask::ProcessTask(AbstractTask&& abs, std::vector<std::string> task
|
||||
|
||||
bool asst::ProcessTask::run()
|
||||
{
|
||||
for (m_cur_retry = 0; m_cur_retry < m_retry_times; ++m_cur_retry) {
|
||||
for (m_cur_retry = 0; m_cur_retry <= m_retry_times; ++m_cur_retry) {
|
||||
if (_run()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
namespace asst
|
||||
{
|
||||
constexpr static const char* Version = "v2.7.4";
|
||||
constexpr static const char* Version = "v2.7.6";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user