Merge pull request #893 from MaaAssistantArknights/dev

Release v3.9.8
This commit is contained in:
MistEO
2022-06-16 02:11:07 +08:00
committed by GitHub
13 changed files with 18177 additions and 56 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,4 @@
- 支持美服 (YoStarEN) 的一些基础功能
- 修复自动战斗干员偶尔部署不上去的问题
- 修复自动战斗第十章部分地图格子错误
- 修复自动战斗在编队中的人识别不到的问题
- 修复肉鸽技能重复开的问题
- 修复一点模拟器连接问题
- 修复退出软件时不释放 adb 的问题
- 修复基建`清流`效率错误
- 其他一些小优化
- 更新支持 `尘影余音` EX 关卡数据
- 新增截图测速功能,会自动选择设备上最快的方式
- 优化启动模拟器功能
- 修复部分掉落识别错误的问题

View File

@@ -203,8 +203,11 @@
"action": "DoNothing",
"sub": [
"LE-Open",
"LEChapterToLE",
"StageLE-5"
"LEChapterToLE"
],
"next": [
"StageLE-5",
"SwapToStageLE-5"
]
},
"LE-6": {
@@ -212,8 +215,11 @@
"action": "DoNothing",
"sub": [
"LE-Open",
"LEChapterToLE",
"StageLE-6"
"LEChapterToLE"
],
"next": [
"StageLE-6",
"SwapToStageLE-6"
]
},
"LE-7": {
@@ -221,8 +227,11 @@
"action": "DoNothing",
"sub": [
"LE-Open",
"LEChapterToLE",
"StageLE-7"
"LEChapterToLE"
],
"next": [
"StageLE-7",
"SwapToStageLE-7"
]
},
"LE-Open": {
@@ -252,8 +261,31 @@
],
"action": "ClickSelf",
"sub": [
"SwipeToTheRight",
"SlowlySwipeToTheLeft"
"SwipeToTheRight"
]
},
"SwapToStageLE-5": {
"algorithm": "JustReturn",
"action": "SlowlySwipeToTheLeft",
"next": [
"StageLE-5",
"SwapToStageLE-5"
]
},
"SwapToStageLE-6": {
"algorithm": "JustReturn",
"action": "SlowlySwipeToTheLeft",
"next": [
"StageLE-6",
"SwapToStageLE-6"
]
},
"SwapToStageLE-7": {
"algorithm": "JustReturn",
"action": "SlowlySwipeToTheLeft",
"next": [
"StageLE-7",
"SwapToStageLE-7"
]
},
"StageLE-5": {
@@ -645,6 +677,10 @@
"^上$",
"山"
],
[
"^云$",
"山"
],
[
"姜哦",
"嵯峨"
@@ -6740,9 +6776,9 @@
"templThreshold_Doc": "这里用来作为字间距阈值",
"roi": [
62,
89,
90,
43,
23
22
],
"maskRange": [
150,

View File

@@ -60,7 +60,6 @@ bool asst::Assistant::connect(const std::string& adb_path, const std::string& ad
{
LogTraceFunction;
m_inited = false;
std::unique_lock<std::mutex> lock(m_mutex);
stop(false);
@@ -69,7 +68,6 @@ bool asst::Assistant::connect(const std::string& adb_path, const std::string& ad
if (ret) {
m_uuid = m_ctrler->get_uuid();
}
m_inited = ret;
return ret;
}
@@ -161,7 +159,7 @@ bool asst::Assistant::set_task_params(TaskId task_id, const std::string& params)
std::vector<uchar> asst::Assistant::get_image() const
{
if (!m_inited) {
if (!inited()) {
return {};
}
return m_ctrler->get_image_encode();
@@ -169,7 +167,7 @@ std::vector<uchar> asst::Assistant::get_image() const
bool asst::Assistant::ctrler_click(int x, int y, bool block)
{
if (!m_inited) {
if (!inited()) {
return false;
}
m_ctrler->click(Point(x, y), block);
@@ -181,7 +179,7 @@ bool asst::Assistant::start(bool block)
LogTraceFunction;
Log.trace("Start |", block ? "block" : "non block");
if (!m_thread_idle || !m_inited) {
if (!m_thread_idle || !inited()) {
return false;
}
std::unique_lock<std::mutex> lock;
@@ -325,3 +323,8 @@ void Assistant::clear_cache()
m_status->clear_rect();
m_status->clear_str();
}
bool asst::Assistant::inited() const noexcept
{
return m_ctrler && m_ctrler->inited();
}

View File

@@ -52,6 +52,7 @@ namespace asst
void append_callback(AsstMsg msg, json::value detail);
void clear_cache();
bool inited() const noexcept;
bool m_inited = false;
std::string m_uuid;

View File

@@ -281,8 +281,8 @@ std::optional<std::vector<unsigned char>> asst::Controller::call_command(const s
std::unique_lock<std::mutex> pipe_lock(m_pipe_mutex);
fd_set fdset = { 0 };
FD_SET(m_server_sock, &fdset);
constexpr int TimeoutMilliseconds = 10000;
timeval select_timeout = { TimeoutMilliseconds / 1000, (TimeoutMilliseconds % 1000) * 1000};
constexpr int TimeoutMilliseconds = 5000;
timeval select_timeout = { TimeoutMilliseconds / 1000, (TimeoutMilliseconds % 1000) * 1000 };
select(static_cast<int>(m_server_sock) + 1, &fdset, NULL, NULL, &select_timeout);
if (FD_ISSET(m_server_sock, &fdset)) {
SOCKET client_sock = ::accept(m_server_sock, NULL, NULL);
@@ -356,6 +356,7 @@ std::optional<std::vector<unsigned char>> asst::Controller::call_command(const s
else if (m_inited) {
// 之前可以运行,突然运行不了了,这种情况多半是 adb 炸了。所以重新连接一下
m_inited = false;
std::this_thread::sleep_for(std::chrono::seconds(10));
auto reconnect_ret = call_command(m_adb.connect, 60 * 1000);
bool is_reconnect_success = false;
if (reconnect_ret) {
@@ -380,6 +381,7 @@ std::optional<std::vector<unsigned char>> asst::Controller::call_command(const s
{ "cmd", cmd },
{ "recv_by_socket", recv_by_socket}
}} };
m_inited = false;
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
}
}
@@ -391,6 +393,7 @@ std::optional<std::vector<unsigned char>> asst::Controller::call_command(const s
{ "details", json::object {
{ "cmd", m_adb.connect }
}} };
m_inited = false;
m_callback(AsstMsg::ConnectionInfo, info, m_callback_arg);
}
}
@@ -557,17 +560,18 @@ bool asst::Controller::screencap()
{
LogTraceFunction;
//if (true) {
// std::unique_lock<std::shared_mutex> image_lock(m_image_mutex);
// m_cache_image = cv::imread("err/1.png");
// return true;
//}
if (true) {
m_inited = true;
std::unique_lock<std::shared_mutex> image_lock(m_image_mutex);
m_cache_image = cv::imread("err/1.png");
return true;
}
DecodeFunc decode_raw = [&](std::vector<uchar>& data) -> bool {
if (data.empty()) {
return false;
}
size_t std_size = m_width * m_height * 4;
size_t std_size = 4ULL * m_width * m_height;
if (data.size() < std_size) {
return false;
}
@@ -594,7 +598,7 @@ bool asst::Controller::screencap()
if (unzip_data.empty()) {
return false;
}
size_t std_size = m_width * m_height * 4;
size_t std_size = 4ULL * m_width * m_height;
if (unzip_data.size() < std_size) {
return false;
}
@@ -629,29 +633,60 @@ bool asst::Controller::screencap()
switch (m_adb.screencap_method) {
case AdbProperty::ScreencapMethod::UnknownYet:
{
Log.info("Try to find the fastest way to screencap");
m_inited = false;
auto min_cost = std::chrono::nanoseconds(MAXLONGLONG);
auto start_time = std::chrono::high_resolution_clock::now();
if (m_support_socket && m_server_started &&
screencap(m_adb.screencap_raw_by_nc, decode_raw, true)) {
m_adb.screencap_method = AdbProperty::ScreencapMethod::RawByNc;
Log.info("screencap by RawByNc");
m_inited = true;
return true;
}
else if (screencap(m_adb.screencap_raw_with_gzip, decode_raw_with_gzip)) {
m_adb.screencap_method = AdbProperty::ScreencapMethod::RawWithGzip;
Log.info("screencap by RawWithGzip");
m_inited = true;
return true;
}
else if (screencap(m_adb.screencap_encode, decode_encode)) {
m_adb.screencap_method = AdbProperty::ScreencapMethod::Encode;
Log.info("screencap by Encode");
m_inited = true;
return true;
auto duration = std::chrono::high_resolution_clock::now() - start_time;
if (duration < min_cost) {
m_adb.screencap_method = AdbProperty::ScreencapMethod::RawByNc;
m_inited = true;
min_cost = duration;
clear_lf_info();
}
Log.info("RawByNc cost", duration.count(), "ns");
}
else {
return false;
Log.info("RawByNc is not supported");
}
start_time = std::chrono::high_resolution_clock::now();
if (screencap(m_adb.screencap_raw_with_gzip, decode_raw_with_gzip)) {
auto duration = std::chrono::high_resolution_clock::now() - start_time;
if (duration < min_cost) {
m_adb.screencap_method = AdbProperty::ScreencapMethod::RawWithGzip;
m_inited = true;
min_cost = duration;
clear_lf_info();
}
Log.info("RawWithGzip cost", duration.count(), "ns");
}
else {
Log.info("RawWithGzip is not supported");
}
start_time = std::chrono::high_resolution_clock::now();
if (screencap(m_adb.screencap_encode, decode_encode)) {
auto duration = std::chrono::high_resolution_clock::now() - start_time;
if (duration < min_cost) {
m_adb.screencap_method = AdbProperty::ScreencapMethod::Encode;
m_inited = true;
min_cost = duration;
clear_lf_info();
}
Log.info("Encode cost", duration.count(), "ns");
}
else {
Log.info("Encode is not supported");
}
Log.info("The fastest way is", static_cast<int>(m_adb.screencap_method), ", cost:", min_cost.count(), "ns");
return m_inited;
}
break;
case AdbProperty::ScreencapMethod::RawByNc:
{
return screencap(m_adb.screencap_raw_by_nc, decode_raw, true);
@@ -717,6 +752,11 @@ bool asst::Controller::screencap(const std::string& cmd, const DecodeFunc& decod
}
}
void asst::Controller::clear_lf_info()
{
m_adb.screencap_end_of_line = AdbProperty::ScreencapEndOfLine::UnknownYet;
}
cv::Mat asst::Controller::get_resized_image() const
{
const static cv::Size dsize(m_scale_size.first, m_scale_size.second);
@@ -1109,6 +1149,9 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
}
}
// try to find the fastest way
screencap();
++m_instance_count;
return true;
}
@@ -1133,6 +1176,11 @@ bool asst::Controller::release()
}
}
bool asst::Controller::inited() const noexcept
{
return m_inited;
}
const std::string& asst::Controller::get_uuid() const
{
return m_uuid;
@@ -1148,6 +1196,8 @@ cv::Mat asst::Controller::get_image(bool raw)
}
// 截图之前正常,截图之后不正常了,说明截图过程中发现 adb 炸了
if (inited && !m_inited) {
const static cv::Size dsize(m_scale_size.first, m_scale_size.second);
m_cache_image = cv::Mat(dsize, CV_8UC3);
break;
}
}

View File

@@ -32,6 +32,7 @@ namespace asst
bool connect(const std::string& adb_path, const std::string& address, const std::string& config);
bool release();
bool inited() const noexcept;
const std::string& get_uuid() const;
cv::Mat get_image(bool raw = false);
@@ -71,6 +72,7 @@ namespace asst
using DecodeFunc = std::function<bool(std::vector<uchar>&)>;
bool screencap();
bool screencap(const std::string& cmd, const DecodeFunc& decode_func, bool by_nc = false);
void clear_lf_info();
cv::Mat get_resized_image() const;
Point rand_point_in_rect(const Rect& rect);
@@ -137,7 +139,7 @@ namespace asst
enum class ScreencapMethod
{
UnknownYet,
Default,
//Default,
RawByNc,
RawWithGzip,
Encode

View File

@@ -335,7 +335,7 @@
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties _1_1_4_1_1_4resource_4config_1json__JsonSchema="" _1_1_4_1_1_4resource_4tasks_1json__JsonSchema="../docs/maa_tasks_schema.json" />
<UserProperties _1_1_4_1_1_4resource_4config_1json__JsonSchema="" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@@ -14,6 +14,7 @@ using System.Windows.Threading;
using Stylet;
using StyletIoC;
using Microsoft.Toolkit.Uwp.Notifications;
using System.Runtime.InteropServices;
namespace MeoAsstGui
{
@@ -38,8 +39,14 @@ namespace MeoAsstGui
protected override void OnExit(ExitEventArgs e)
{
// MessageBox.Show("O(∩_∩)O 拜拜");
//关闭程序时清理操作中心中的通知
ToastNotificationManagerCompat.History.Clear();
var os = RuntimeInformation.OSDescription.ToString();
if (os.ToString().CompareTo("Microsoft Windows 10.0.10240") >= 0)
{
ToastNotificationManagerCompat.History.Clear();
}
ViewStatusStorage.Save();
}

View File

@@ -209,6 +209,8 @@ namespace MeoAsstGui
}
}
private bool connected = false;
private void procConnectInfo(JObject details)
{
var what = details["what"].ToString();
@@ -217,19 +219,23 @@ namespace MeoAsstGui
switch (what)
{
case "Connected":
connected = true;
svm.ConnectAddress = details["details"]["address"].ToString();
break;
case "UnsupportedResolution":
connected = false;
mainModel.AddLog("分辨率过低,请设置为 720p 或更高", "darkred");
break;
case "ResolutionError":
connected = false;
mainModel.AddLog("分辨率获取失败,建议重启电脑,或更换模拟器后再试", "darkred");
break;
case "Disconnect":
case "CommandExecFailed":
connected = false;
mainModel.AddLog("错误!连接断开!", "darkred");
AsstStop();
break;
@@ -706,6 +712,11 @@ namespace MeoAsstGui
return false;
}
if (connected)
{
return true;
}
var settings = _container.Get<SettingsViewModel>();
if (settings.AdbPath == String.Empty ||
settings.ConnectAddress == String.Empty)

View File

@@ -35,6 +35,10 @@
<Button Command="{s:Action SelectEmulatorExec}" Content="选择" Margin="10" />
</StackPanel>
<TextBox Text="{Binding EmulatorPath}" Margin="10" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Margin="10" Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center" Text="附加命令" />
</StackPanel>
<TextBox Text="{Binding EmulatorAddCommand}" Margin="10" />
<TextBlock Margin="10" Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center" Text="客户端版本" />
<ComboBox IsHitTestVisible ="{Binding Idle}" Margin="10"
ItemsSource="{Binding ClientTypeList}"

View File

@@ -208,6 +208,19 @@ namespace MeoAsstGui
}
}
private string _emulatorAddCommand = ViewStatusStorage.Get("Start.EmulatorAddCommand", string.Empty);
public string EmulatorAddCommand
{
get { return _emulatorAddCommand; }
set
{
SetAndNotify(ref _emulatorAddCommand, value);
ViewStatusStorage.Set("Start.EmulatorAddCommand", value);
}
}
private string _emulatorWaitSeconds = ViewStatusStorage.Get("Start.EmulatorWaitSeconds", "60");
public string EmulatorWaitSeconds
@@ -228,7 +241,25 @@ namespace MeoAsstGui
{
return;
}
System.Diagnostics.Process.Start(EmulatorPath);
if (EmulatorAddCommand.Length != 0)
{
string StartCommand = "";
if (EmulatorPath.StartsWith("\""))
{
StartCommand += EmulatorPath.ToString();
}
else StartCommand = "\"" + EmulatorPath.ToString() + "\"";
StartCommand += " ";
StartCommand += EmulatorAddCommand.ToString();
Process emuProcess = new Process();
emuProcess.StartInfo.FileName = "cmd.exe";
emuProcess.StartInfo.RedirectStandardInput = true;
emuProcess.StartInfo.UseShellExecute = false;
emuProcess.Start();
emuProcess.StandardInput.WriteLine(StartCommand);
emuProcess.StandardInput.WriteLine("exit");
}
else Process.Start(EmulatorPath);
int delay = 0;
if (!int.TryParse(EmulatorWaitSeconds, out delay))
{

View File

@@ -24,7 +24,7 @@ int main(/*int argc, char** argv*/)
return -1;
}
bool connected = AsstConnect(ptr, "adb", "127.0.0.1:5555", "DEBUG");
bool connected = AsstConnect(ptr, "adb", "127.0.0.1:5555", nullptr);
if (!connected) {
std::cerr << "connect failed" << std::endl;
AsstDestroy(ptr);
@@ -76,7 +76,7 @@ int main(/*int argc, char** argv*/)
//
// AsstAppendTask(ptr, "Roguelike", nullptr);
AsstAppendTask(ptr, "Debug", nullptr);
AsstAppendTask(ptr, "Depot", nullptr);
// AsstAppendTask(ptr, "Copilot", R"(
//{