Merge pull request #743 from lhhxxxxx/feat/startup

[Done] [New Feature] 自动启动方舟
This commit is contained in:
MistEO
2022-06-05 18:56:18 +08:00
committed by GitHub
20 changed files with 258 additions and 23 deletions

View File

@@ -18,6 +18,10 @@
"cmdFormat_Doc": "命令格式,想打印详细信息可以尝试添加 -v -i"
}
},
"intent": {
"Official": "com.hypergryph.arknights/com.u8.sdk.U8UnityContext",
"Bilibili": "com.hypergryph.arknights.bilibili/com.u8.sdk.U8UnityContext"
},
"connection": {
"General": {
"devices": "[Adb] devices",
@@ -30,7 +34,8 @@
"displayFormat": " init=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"BlueStacks": {
"devices": "[Adb] devices",
@@ -43,7 +48,8 @@
"displayFormat": "cur=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"MuMuEmulator": {
"devices": "[Adb] devices",
@@ -56,7 +62,8 @@
"displayFormat": "cur=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"LDPlayer": {
"devices": "[Adb] devices",
@@ -69,7 +76,8 @@
"displayFormat": "cur=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] shell screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"Nox": {
"devices": "[Adb] devices",
@@ -82,7 +90,8 @@
"displayFormat": "cur=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"XYAZ": {
"devices": "[Adb] devices",
@@ -95,7 +104,8 @@
"displayFormat": " init=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] shell screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"WSA": {
"devices": "[Adb] devices",
@@ -109,7 +119,8 @@
"displayFormat": "Physical size:%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap -d [DisplayId] | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] shell screencap -d [DisplayId] -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
},
"Compatible": {
"devices": "[Adb] devices",
@@ -122,7 +133,8 @@
"displayFormat": " init=%dx%d",
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
"release": "[Adb] kill-server"
"release": "[Adb] kill-server",
"start": "[Adb] -s [Address] shell am start -n [Intent]"
}
}
}

View File

@@ -836,6 +836,7 @@
255
],
"next": [
"GameStart",
"StartToWakeUp",
"StartUpConnectingFlag",
"StartLoginBServer",

View File

@@ -158,6 +158,7 @@ namespace asst
double score = 0.0;
Rect rect;
};
}
namespace std

View File

@@ -522,6 +522,21 @@ cv::Mat asst::Controller::get_resized_image() const
return resized_mat;
}
std::optional<int> asst::Controller::start_game(const std::string& server_type, bool block)
{
if (auto intent_name = Resrc.cfg().get_intent_name(server_type))
{
std::string cur_cmd = utils::string_replace_all(m_adb.start, "[Intent]", intent_name.value());
int id = push_cmd(cur_cmd);
if (block)
{
wait(id);
}
return id;
}
return std::nullopt;
}
int asst::Controller::click(const Point& p, bool block)
{
int x = static_cast<int>(p.x * m_control_scale);
@@ -828,6 +843,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
m_adb.screencap_raw_with_gzip = cmd_replace(adb_cfg.screencap_raw_with_gzip);
m_adb.screencap_encode = cmd_replace(adb_cfg.screencap_encode);
m_adb.release = cmd_replace(adb_cfg.release);
m_adb.start = cmd_replace(adb_cfg.start);
return true;
}

View File

@@ -37,7 +37,9 @@ namespace asst
cv::Mat get_image(bool raw = false);
std::vector<uchar> get_image_encode() const;
// 点击和滑动都是异步执行返回该任务的id
// 开启/置顶游戏、点击和滑动都是异步执行返回该任务的id
std::optional<int> start_game(const std::string& server_type = "", bool block = true);
int click(const Point& p, bool block = true);
int click(const Rect& rect, bool block = true);
int click_without_scale(const Point& p, bool block = true);
@@ -108,6 +110,8 @@ namespace asst
std::string screencap_encode;
std::string release;
std::string start;
/* propertities */
enum class ScreencapEndOfLine
{

View File

@@ -28,6 +28,12 @@ bool asst::GeneralConfiger::parse(const json::value& json)
m_options.aip_ocr.client_id = aip_ocr.get("clientId", std::string());
m_options.aip_ocr.client_secret = aip_ocr.get("clientSerect", std::string());
}
}
for (const auto& [server_type, intent_name] : json.at("intent").as_object())
{
m_intent_name[server_type]=intent_name.as_string();
}
for (const auto& [name, cfg_json] : json.at("connection").as_object()) {
@@ -45,6 +51,7 @@ bool asst::GeneralConfiger::parse(const json::value& json)
adb.screencap_raw_with_gzip = cfg_json.at("screencapRawWithGzip").as_string();
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.pullscreen = cfg_json.at("pullscreen").as_string();
m_adb_cfg[name] = std::move(adb);

View File

@@ -53,6 +53,7 @@ namespace asst
std::string screencap_raw_with_gzip;
std::string screencap_encode;
std::string release;
std::string start;
};
class GeneralConfiger : public AbstractConfiger
@@ -83,6 +84,16 @@ namespace asst
}
}
[[nodiscard]] std::optional<std::string> get_intent_name(const std::string& server_type) const
{
if (auto iter = m_intent_name.find(server_type);
iter != m_intent_name.cend())
{
return iter->second;
}
return std::nullopt;
}
void set_options(Options opt) noexcept
{
m_options = std::move(opt);
@@ -94,5 +105,6 @@ namespace asst
std::string m_version;
Options m_options;
std::unordered_map<std::string, AdbCfg> m_adb_cfg;
std::unordered_map<std::string, std::string> m_intent_name;
};
}

View File

@@ -86,6 +86,7 @@
<ClInclude Include="StageDropsConfiger.h" />
<ClInclude Include="StageDropsImageAnalyzer.h" />
<ClInclude Include="StageDropsTaskPlugin.h" />
<ClInclude Include="StartGameTask.h" />
<ClInclude Include="StartUpTask.h" />
<ClInclude Include="TaskData.h" />
<ClInclude Include="MatchImageAnalyzer.h" />
@@ -165,6 +166,7 @@
<ClCompile Include="StageDropsConfiger.cpp" />
<ClCompile Include="StageDropsImageAnalyzer.cpp" />
<ClCompile Include="StageDropsTaskPlugin.cpp" />
<ClCompile Include="StartGameTask.cpp" />
<ClCompile Include="StartUpTask.cpp" />
<ClCompile Include="TaskData.cpp" />
<ClCompile Include="MatchImageAnalyzer.cpp" />
@@ -334,4 +336,4 @@
<UserProperties _1_1_4_1_1_4resource_4config_1json__JsonSchema="" _1_1_4_1_1_4resource_4tasks_1json__JsonSchema="../docs/maa_tasks_schema.json" />
</VisualStudio>
</ProjectExtensions>
</Project>
</Project>

View File

@@ -240,6 +240,9 @@
<ClInclude Include="RecruitCalcTask.h">
<Filter>头文件\Task\Sub</Filter>
</ClInclude>
<ClInclude Include="StartGameTask.h">
<Filter>头文件\Task\Sub</Filter>
</ClInclude>
<ClInclude Include="BattleImageAnalyzer.h">
<Filter>头文件\ImageAnalyzer\Final</Filter>
</ClInclude>
@@ -473,6 +476,9 @@
<ClCompile Include="ProcessTask.cpp">
<Filter>源文件\Task\Sub</Filter>
</ClCompile>
<ClCompile Include="StartGameTask.cpp">
<Filter>源文件\Task\Sub</Filter>
</ClCompile>
<ClCompile Include="BattleImageAnalyzer.cpp">
<Filter>源文件\ImageAnalyzer\Final</Filter>
</ClCompile>
@@ -578,4 +584,4 @@
<Filter>资源文件</Filter>
</None>
</ItemGroup>
</Project>
</Project>

View File

@@ -0,0 +1,26 @@
#include "StartGameTask.h"
#include "Controller.h"
using namespace asst;
bool StartGameTask::_run()
{
if(m_ctrler->start_game(m_client_type))
{
return true;
}
return false;
}
StartGameTask& StartGameTask::set_param(std::string client_type) noexcept
{
m_client_type = client_type;
return *this;
}
StartGameTask& StartGameTask::set_enable(bool enable) noexcept
{
AbstractTask::set_enable(enable);
return *this;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "AbstractTask.h"
#include "AsstTypes.h"
namespace asst
{
class StartGameTask : public AbstractTask
{
public:
using AbstractTask::AbstractTask;
~StartGameTask() override = default;
StartGameTask& set_param(std::string server_type = "") noexcept;
StartGameTask& set_enable(bool enable = false) noexcept override;
protected:
bool _run() override;
std::string m_client_type = "";
};
}

View File

@@ -4,10 +4,19 @@
asst::StartUpTask::StartUpTask(AsstCallback callback, void* callback_arg)
: PackageTask(callback, callback_arg, TaskType),
m_start_up_task_ptr(std::make_shared<ProcessTask>(m_callback, m_callback_arg, TaskType))
m_start_game_task_ptr(std::make_shared<StartGameTask>(m_callback, m_callback_arg, TaskType)),
m_start_up_task_ptr(std::make_shared<ProcessTask>(m_callback, m_callback_arg, TaskType))
{
m_start_up_task_ptr->set_tasks({ "StartUp" })
.set_times_limit("ReturnToTerminal", 0)
.set_times_limit("Terminal", 0);
m_start_up_task_ptr->set_tasks({"StartUp"})
.set_times_limit("ReturnToTerminal", 0)
.set_times_limit("Terminal", 0);
m_subtasks.emplace_back(m_start_game_task_ptr);
m_subtasks.emplace_back(m_start_up_task_ptr);
}
bool asst::StartUpTask::set_params(const json::value& params)
{
m_start_game_task_ptr->set_param(params.get("client_type", ""))
.set_enable(params.get("start_game_enable",false));
return true;
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include "PackageTask.h"
#include "StartGameTask.h"
namespace asst
{
@@ -11,9 +12,11 @@ namespace asst
StartUpTask(AsstCallback callback, void* callback_arg);
virtual ~StartUpTask() = default;
bool set_params(const json::value& params) override;
static constexpr const char* TaskType = "StartUp";
private:
std::shared_ptr<StartGameTask> m_start_game_task_ptr = nullptr;
std::shared_ptr<ProcessTask> m_start_up_task_ptr = nullptr;
};
}

View File

@@ -254,6 +254,10 @@ namespace MeoAsstGui
switch (subTask)
{
case "StartGameTask":
mainModel.AddLog("打开客户端失败,请\n检查配置文件", "darkred");
break;
case "AutoRecruitTask":
mainModel.AddLog("公招识别错误,已返回", "darkred");
break;
@@ -687,9 +691,12 @@ namespace MeoAsstGui
return AsstAppendTaskWithEncoding("Award");
}
public bool AsstAppendStartUp()
public bool AsstAppendStartUp(string server_type, bool enable)
{
return AsstAppendTaskWithEncoding("StartUp");
var task_params = new JObject();
task_params["client_type"] = server_type;
task_params["start_game_enable"] = enable;
return AsstAppendTaskWithEncoding("StartUp", task_params);
}
public bool AsstAppendVisit()

View File

@@ -101,6 +101,9 @@
<Compile Include="Helper\ViewStatusStorage.cs" />
<Compile Include="Helper\FlowDocumentPagePadding.cs" />
<Compile Include="Helper\WinAdapter.cs" />
<Compile Include="UserControl\StartSettingsUserControl.xaml.cs">
<DependentUpon>StartSettingsUserControl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\TimerSettingsUserControl.xaml.cs">
<DependentUpon>TimerSettingsUserControl.xaml</DependentUpon>
</Compile>
@@ -153,6 +156,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UserControl\StartSettingsUserControl.xaml" />
<Page Include="UserControl\TimerSettingsUserControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@@ -0,0 +1,31 @@
<UserControl x:Class="MeoAsstGui.StartSettingsUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:dd="urn:gong-wpf-dragdrop"
mc:Ignorable="d"
xmlns:vm="clr-namespace:MeoAsstGui;assembly=MeoAsstGui"
d:DataContext="{d:DesignInstance {x:Type vm:SettingsViewModel}}"
d:DesignHeight="300" d:DesignWidth="550">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" IsChecked="{Binding StartGameEnable}" Block.TextAlignment="Center" Margin="10"
HorizontalAlignment="Center" VerticalAlignment="Center"
Content="开始唤醒时自动启动游戏客户端" />
<StackPanel Grid.Row="1" IsEnabled="{Binding StartGameEnable}" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center"
Text="客户端版本" Margin="10" />
<ComboBox Width="200" Margin="10"
IsHitTestVisible ="{Binding Path=Idle}"
ItemsSource="{Binding ServerTypeList}"
DisplayMemberPath="Display"
SelectedValuePath="Value"
SelectedValue="{Binding ServerType}" />
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
// MeoAsstGui - A part of the MeoAssistantArknights project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
using System.Windows.Controls;
namespace MeoAsstGui
{
/// <summary>
/// StartSettingsUserControl.xaml 的交互逻辑
/// </summary>
public partial class StartSettingsUserControl : UserControl
{
public StartSettingsUserControl()
{
InitializeComponent();
}
}
}

View File

@@ -48,6 +48,7 @@ namespace MeoAsstGui
_listTitle.Add("自动公招");
_listTitle.Add("信用商店");
_listTitle.Add("定时执行");
_listTitle.Add("唤醒设置");
_listTitle.Add("企鹅数据");
_listTitle.Add("连接设置");
_listTitle.Add("通知显示");
@@ -132,6 +133,12 @@ namespace MeoAsstGui
new CombData { Display = "刷源石锭投资,第一层商店后直接退出", Value = "1" },
new CombData { Display = "刷源石锭投资,投资过后退出", Value = "2" }
};
ServerTypeList = new List<CombData>
{
new CombData { Display = "官服", Value = "Official" },
new CombData { Display = "Bilibili服", Value = "Bilibili" }
};
}
private bool _idle = true;
@@ -145,12 +152,39 @@ namespace MeoAsstGui
}
}
/* 唤醒设置 */
private bool _startGameEnable = Convert.ToBoolean(ViewStatusStorage.Get("Start.StartGameEnable", bool.FalseString));
public bool StartGameEnable
{
get { return _startGameEnable; }
set
{
SetAndNotify(ref _startGameEnable, value);
ViewStatusStorage.Set("Start.StartGameEnable", value.ToString());
}
}
private string _serverType = ViewStatusStorage.Get("Start.ServerType", "Official");
public string ServerType
{
get { return _serverType; }
set
{
SetAndNotify(ref _serverType, value);
ViewStatusStorage.Set("Start.ServerType", value);
}
}
/* 基建设置 */
public Dictionary<string, string> FacilityKey = new Dictionary<string, string>();
public ObservableCollection<DragItemViewModel> InfrastItemViewModels { get; set; }
public List<CombData> UsesOfDronesList { get; set; }
public List<CombData> RoguelikeModeList { get; set; }
public List<CombData> ServerTypeList { get; set; }
public List<CombData> ConnectConfigList { get; set; }
private int _dormThreshold = Convert.ToInt32(ViewStatusStorage.Get("Infrast.DormThreshold", "30"));

View File

@@ -257,7 +257,7 @@ namespace MeoAsstGui
}
else if (item.Name == "开始唤醒")
{
ret &= asstProxy.AsstAppendStartUp();
ret &= appendStart();
}
else if (item.Name == "刷理智")
{
@@ -334,6 +334,15 @@ namespace MeoAsstGui
ViewStatusStorage.Set("MainFunction.TimesLimited.Quantity", MaxTimes);
}
private bool appendStart()
{
var settings = _container.Get<SettingsViewModel>();
var asstProxy = _container.Get<AsstProxy>();
var mode = settings.ServerType;
var enable = settings.StartGameEnable;
return asstProxy.AsstAppendStartUp(mode, enable);
}
private bool appendFight()
{
int medicine = 0;

View File

@@ -41,18 +41,21 @@
<local:TimerSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[5]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:PenguinReportSettingsUserControl Margin="20" />
<local:StartSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[6]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:ConnectSettingsUserControl Margin="20" />
<local:PenguinReportSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[7]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:ToastSettingsUserControl Margin="20" />
<local:ConnectSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[8]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:VersionUpdateSettingsUserControl Margin="20" />
<local:ToastSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[9]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:VersionUpdateSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[10]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:AboutUserControl Margin="20" />
<!--<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />-->
</StackPanel>