mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
feat: auto retry start on app startup crash (#8966)
This commit is contained in:
@@ -85,6 +85,7 @@
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"PACKAGE_NAME=$(dumpsys activity activities 2>/dev/null | grep -i -o -E '(packageName|Activities)=.+arknights' 2>/dev/null | grep -i -o -E '[^= ]*arknights[^ /]*' | head -n 1); if [ -n \\\"$PACKAGE_NAME\\\" ]; then echo \\\"Closing $PACKAGE_NAME\\\"; am force-stop $PACKAGE_NAME; else echo \\\"app not running or arknights package name not found\\\"; fi\"",
|
||||
"abilist": "[Adb] -s [AdbSerial] shell getprop ro.product.cpu.abilist",
|
||||
"version": "[Adb] -s [AdbSerial] shell getprop ro.build.version.release",
|
||||
"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]\"",
|
||||
|
||||
@@ -96,6 +96,7 @@ bool asst::GeneralConfig::parse(const json::value& json)
|
||||
adb.start = cfg_json.get("start", base_cfg.start);
|
||||
adb.stop = cfg_json.get("stop", base_cfg.stop);
|
||||
adb.abilist = cfg_json.get("abilist", base_cfg.abilist);
|
||||
adb.version = cfg_json.get("version", base_cfg.version);
|
||||
adb.orientation = cfg_json.get("orientation", base_cfg.orientation);
|
||||
adb.push_minitouch = cfg_json.get("pushMinitouch", base_cfg.push_minitouch);
|
||||
adb.chmod_minitouch = cfg_json.get("chmodMinitouch", base_cfg.chmod_minitouch);
|
||||
|
||||
@@ -78,6 +78,7 @@ struct AdbCfg
|
||||
std::string start;
|
||||
std::string stop;
|
||||
std::string abilist;
|
||||
std::string version;
|
||||
std::string orientation;
|
||||
std::string push_minitouch;
|
||||
std::string chmod_minitouch;
|
||||
|
||||
@@ -156,6 +156,7 @@ std::optional<std::string> asst::AdbController::call_command(
|
||||
", socket size:",
|
||||
sock_data.size());
|
||||
if (!pipe_data.empty() && pipe_data.size() < 4096) {
|
||||
m_pipe_data_size = pipe_data.size();
|
||||
Log.trace("stdout output:", Logger::separator::newline, pipe_data);
|
||||
}
|
||||
if (recv_by_socket && !sock_data.empty() && sock_data.size() < 4096) {
|
||||
@@ -178,6 +179,16 @@ std::optional<std::string> asst::AdbController::call_command(
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
size_t asst::AdbController::get_pipe_data_size() const noexcept
|
||||
{
|
||||
return m_pipe_data_size;
|
||||
}
|
||||
|
||||
size_t asst::AdbController::get_version() const noexcept
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
void asst::AdbController::callback(AsstMsg msg, const json::value& details)
|
||||
{
|
||||
if (m_callback) {
|
||||
@@ -760,6 +771,23 @@ bool asst::AdbController::connect(
|
||||
info["details"]["uuid"] = m_uuid;
|
||||
callback(AsstMsg::ConnectionInfo, info);
|
||||
}
|
||||
/* get android version */
|
||||
{
|
||||
auto version_ret = call_command(cmd_replace(adb_cfg.version));
|
||||
if (!version_ret) {
|
||||
json::value info = get_info_json()
|
||||
| json::object {
|
||||
{ "what", "ConnectFailed" },
|
||||
{ "why", "Android version command failed to exec" },
|
||||
};
|
||||
callback(AsstMsg::ConnectionInfo, info);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& version_str = version_ret.value();
|
||||
convert_lf(version_str);
|
||||
m_version = std::stoul(version_str);
|
||||
}
|
||||
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
|
||||
@@ -35,6 +35,10 @@ public:
|
||||
|
||||
virtual const std::string& get_uuid() const override;
|
||||
|
||||
virtual size_t get_pipe_data_size() const noexcept override;
|
||||
|
||||
virtual size_t get_version() const noexcept override;
|
||||
|
||||
virtual bool screencap(cv::Mat& image_payload, bool allow_reconnect = false) override;
|
||||
|
||||
virtual bool start_game(const std::string& client_type) override;
|
||||
@@ -128,6 +132,8 @@ protected:
|
||||
std::string start;
|
||||
std::string stop;
|
||||
|
||||
std::string version;
|
||||
|
||||
std::string back_to_home;
|
||||
|
||||
/* properties */
|
||||
@@ -151,6 +157,8 @@ protected:
|
||||
} m_adb;
|
||||
|
||||
std::string m_uuid;
|
||||
size_t m_pipe_data_size = 0;
|
||||
size_t m_version = 0;
|
||||
std::pair<int, int> m_screen_size = { 0, 0 };
|
||||
int m_width = 0;
|
||||
int m_height = 0;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4068)
|
||||
#pragma warning(disable: 4068)
|
||||
#endif
|
||||
#include <zlib/decompress.hpp>
|
||||
#ifdef _MSC_VER
|
||||
@@ -25,7 +25,9 @@
|
||||
#include "Utils/Logger.hpp"
|
||||
|
||||
asst::Controller::Controller(const AsstCallback& callback, Assistant* inst)
|
||||
: InstHelper(inst), m_callback(callback), m_rand_engine(std::random_device {}())
|
||||
: InstHelper(inst)
|
||||
, m_callback(callback)
|
||||
, m_rand_engine(std::random_device {}())
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
@@ -37,6 +39,17 @@ asst::Controller::~Controller()
|
||||
LogTraceFunction;
|
||||
}
|
||||
|
||||
size_t asst::Controller::get_pipe_data_size() const noexcept
|
||||
{
|
||||
return m_controller->get_pipe_data_size();
|
||||
}
|
||||
|
||||
size_t asst::Controller::get_version() const noexcept
|
||||
{
|
||||
return m_controller->get_version();
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> asst::Controller::get_scale_size() const noexcept
|
||||
{
|
||||
return m_scale_size;
|
||||
@@ -114,15 +127,27 @@ bool asst::Controller::click(const Rect& rect)
|
||||
return m_scale_proxy->click(rect);
|
||||
}
|
||||
|
||||
bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe, double slope_in,
|
||||
double slope_out, bool with_pause)
|
||||
bool asst::Controller::swipe(
|
||||
const Point& p1,
|
||||
const Point& p2,
|
||||
int duration,
|
||||
bool extra_swipe,
|
||||
double slope_in,
|
||||
double slope_out,
|
||||
bool with_pause)
|
||||
{
|
||||
CHECK_EXIST(m_controller, false);
|
||||
return m_scale_proxy->swipe(p1, p2, duration, extra_swipe, slope_in, slope_out, with_pause);
|
||||
}
|
||||
|
||||
bool asst::Controller::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double slope_in,
|
||||
double slope_out, bool with_pause)
|
||||
bool asst::Controller::swipe(
|
||||
const Rect& r1,
|
||||
const Rect& r2,
|
||||
int duration,
|
||||
bool extra_swipe,
|
||||
double slope_in,
|
||||
double slope_out,
|
||||
bool with_pause)
|
||||
{
|
||||
CHECK_EXIST(m_controller, false);
|
||||
return m_scale_proxy->swipe(r1, r2, duration, extra_swipe, slope_in, slope_out, with_pause);
|
||||
@@ -148,14 +173,18 @@ asst::ControlFeat::Feat asst::Controller::support_features()
|
||||
return m_controller->support_features();
|
||||
}
|
||||
|
||||
bool asst::Controller::connect(const std::string& adb_path, const std::string& address, const std::string& config)
|
||||
bool asst::Controller::connect(
|
||||
const std::string& adb_path,
|
||||
const std::string& address,
|
||||
const std::string& config)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
clear_info();
|
||||
|
||||
m_controller =
|
||||
m_controller_factory->create_controller(m_controller_type, adb_path, address, config, m_platform_type);
|
||||
m_controller_factory
|
||||
->create_controller(m_controller_type, adb_path, address, config, m_platform_type);
|
||||
|
||||
if (!m_controller) {
|
||||
Log.error("connect failed");
|
||||
@@ -192,7 +221,8 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
|
||||
};
|
||||
|
||||
try {
|
||||
m_scale_proxy = std::make_shared<ControlScaleProxy>(m_controller, m_controller_type, proxy_callback);
|
||||
m_scale_proxy =
|
||||
std::make_shared<ControlScaleProxy>(m_controller, m_controller_type, proxy_callback);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Log.error("Cannot create controller proxy: {}", e.what());
|
||||
|
||||
@@ -28,80 +28,98 @@
|
||||
|
||||
namespace asst
|
||||
{
|
||||
class Assistant;
|
||||
class Assistant;
|
||||
|
||||
class Controller : private InstHelper
|
||||
{
|
||||
public:
|
||||
Controller(const AsstCallback& callback, Assistant* inst);
|
||||
Controller(const Controller&) = delete;
|
||||
Controller(Controller&&) = delete;
|
||||
~Controller();
|
||||
class Controller : private InstHelper
|
||||
{
|
||||
public:
|
||||
Controller(const AsstCallback& callback, Assistant* inst);
|
||||
Controller(const Controller&) = delete;
|
||||
Controller(Controller&&) = delete;
|
||||
~Controller();
|
||||
|
||||
bool connect(const std::string& adb_path, const std::string& address, const std::string& config);
|
||||
bool inited() noexcept;
|
||||
void set_touch_mode(const TouchMode& mode) noexcept;
|
||||
void set_swipe_with_pause(bool enable) noexcept;
|
||||
void set_adb_lite_enabled(bool enable) noexcept;
|
||||
void set_kill_adb_on_exit(bool enable) noexcept;
|
||||
bool
|
||||
connect(const std::string& adb_path, const std::string& address, const std::string& config);
|
||||
bool inited() noexcept;
|
||||
void set_touch_mode(const TouchMode& mode) noexcept;
|
||||
void set_swipe_with_pause(bool enable) noexcept;
|
||||
void set_adb_lite_enabled(bool enable) noexcept;
|
||||
void set_kill_adb_on_exit(bool enable) noexcept;
|
||||
|
||||
const std::string& get_uuid() const;
|
||||
cv::Mat get_image(bool raw = false);
|
||||
cv::Mat get_image_cache() const;
|
||||
bool screencap(bool allow_reconnect = false);
|
||||
const std::string& get_uuid() const;
|
||||
|
||||
bool start_game(const std::string& client_type);
|
||||
bool stop_game();
|
||||
size_t get_pipe_data_size() const noexcept;
|
||||
|
||||
bool click(const Point& p);
|
||||
bool click(const Rect& rect);
|
||||
size_t get_version() const noexcept;
|
||||
|
||||
bool swipe(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false, double slope_in = 1,
|
||||
double slope_out = 1, bool with_pause = false);
|
||||
bool swipe(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false, double slope_in = 1,
|
||||
double slope_out = 1, bool with_pause = false);
|
||||
cv::Mat get_image(bool raw = false);
|
||||
cv::Mat get_image_cache() const;
|
||||
bool screencap(bool allow_reconnect = false);
|
||||
|
||||
bool inject_input_event(InputEvent& event);
|
||||
bool start_game(const std::string& client_type);
|
||||
bool stop_game();
|
||||
|
||||
bool press_esc();
|
||||
ControlFeat::Feat support_features();
|
||||
bool click(const Point& p);
|
||||
bool click(const Rect& rect);
|
||||
|
||||
std::pair<int, int> get_scale_size() const noexcept;
|
||||
bool swipe(
|
||||
const Point& p1,
|
||||
const Point& p2,
|
||||
int duration = 0,
|
||||
bool extra_swipe = false,
|
||||
double slope_in = 1,
|
||||
double slope_out = 1,
|
||||
bool with_pause = false);
|
||||
bool swipe(
|
||||
const Rect& r1,
|
||||
const Rect& r2,
|
||||
int duration = 0,
|
||||
bool extra_swipe = false,
|
||||
double slope_in = 1,
|
||||
double slope_out = 1,
|
||||
bool with_pause = false);
|
||||
|
||||
Controller& operator=(const Controller&) = delete;
|
||||
Controller& operator=(Controller&&) = delete;
|
||||
bool inject_input_event(InputEvent& event);
|
||||
|
||||
bool back_to_home();
|
||||
bool press_esc();
|
||||
ControlFeat::Feat support_features();
|
||||
|
||||
private:
|
||||
cv::Mat get_resized_image_cache() const;
|
||||
std::pair<int, int> get_scale_size() const noexcept;
|
||||
|
||||
void clear_info() noexcept;
|
||||
void callback(AsstMsg msg, const json::value& details);
|
||||
void sync_params();
|
||||
Controller& operator=(const Controller&) = delete;
|
||||
Controller& operator=(Controller&&) = delete;
|
||||
|
||||
AsstCallback m_callback = nullptr;
|
||||
bool back_to_home();
|
||||
|
||||
std::minstd_rand m_rand_engine;
|
||||
private:
|
||||
cv::Mat get_resized_image_cache() const;
|
||||
|
||||
PlatformType m_platform_type = PlatformType::Native;
|
||||
void clear_info() noexcept;
|
||||
void callback(AsstMsg msg, const json::value& details);
|
||||
void sync_params();
|
||||
|
||||
ControllerType m_controller_type = ControllerType::Minitouch;
|
||||
AsstCallback m_callback = nullptr;
|
||||
|
||||
std::shared_ptr<ControllerAPI> m_controller = nullptr;
|
||||
std::minstd_rand m_rand_engine;
|
||||
|
||||
std::unique_ptr<ControllerFactory> m_controller_factory = nullptr;
|
||||
PlatformType m_platform_type = PlatformType::Native;
|
||||
|
||||
std::shared_ptr<ControlScaleProxy> m_scale_proxy = nullptr;
|
||||
ControllerType m_controller_type = ControllerType::Minitouch;
|
||||
|
||||
std::string m_uuid;
|
||||
std::shared_ptr<ControllerAPI> m_controller = nullptr;
|
||||
|
||||
std::pair<int, int> m_scale_size = { WindowWidthDefault, WindowHeightDefault };
|
||||
std::unique_ptr<ControllerFactory> m_controller_factory = nullptr;
|
||||
|
||||
bool m_swipe_with_pause = false;
|
||||
bool m_kill_adb_on_exit = false;
|
||||
std::shared_ptr<ControlScaleProxy> m_scale_proxy = nullptr;
|
||||
|
||||
mutable std::shared_mutex m_image_mutex;
|
||||
cv::Mat m_cache_image;
|
||||
};
|
||||
std::string m_uuid;
|
||||
|
||||
std::pair<int, int> m_scale_size = { WindowWidthDefault, WindowHeightDefault };
|
||||
|
||||
bool m_swipe_with_pause = false;
|
||||
bool m_kill_adb_on_exit = false;
|
||||
|
||||
mutable std::shared_mutex m_image_mutex;
|
||||
cv::Mat m_cache_image;
|
||||
};
|
||||
} // namespace asst
|
||||
|
||||
@@ -7,70 +7,85 @@
|
||||
|
||||
namespace asst
|
||||
{
|
||||
struct InputEvent;
|
||||
struct InputEvent;
|
||||
|
||||
enum class ControllerType
|
||||
enum class ControllerType
|
||||
{
|
||||
Adb,
|
||||
Minitouch,
|
||||
Maatouch,
|
||||
MacPlayTools,
|
||||
};
|
||||
|
||||
class ControllerAPI
|
||||
{
|
||||
public:
|
||||
virtual ~ControllerAPI() = default;
|
||||
|
||||
virtual bool connect(
|
||||
const std::string& adb_path,
|
||||
const std::string& address,
|
||||
const std::string& config) = 0;
|
||||
virtual bool inited() const noexcept = 0;
|
||||
|
||||
virtual void set_swipe_with_pause([[maybe_unused]] bool enable) noexcept {}
|
||||
|
||||
virtual void set_kill_adb_on_exit([[maybe_unused]] bool enable) noexcept {}
|
||||
|
||||
virtual const std::string& get_uuid() const = 0;
|
||||
|
||||
virtual size_t get_pipe_data_size() const noexcept = 0;
|
||||
|
||||
virtual size_t get_version() const noexcept = 0;
|
||||
|
||||
virtual bool screencap(cv::Mat& image_payload, bool allow_reconnect = false) = 0;
|
||||
|
||||
virtual bool start_game(const std::string& client_type) = 0;
|
||||
virtual bool stop_game() = 0;
|
||||
|
||||
virtual bool click(const Point& p) = 0;
|
||||
|
||||
virtual bool swipe(
|
||||
const Point& p1,
|
||||
const Point& p2,
|
||||
int duration = 0,
|
||||
bool extra_swipe = false,
|
||||
double slope_in = 1,
|
||||
double slope_out = 1,
|
||||
bool with_pause = false) = 0;
|
||||
// TODO: 抽象出gesture类
|
||||
|
||||
virtual bool inject_input_event(const InputEvent& event) = 0;
|
||||
|
||||
virtual bool press_esc() = 0;
|
||||
virtual ControlFeat::Feat support_features() const noexcept = 0;
|
||||
|
||||
virtual std::pair<int, int> get_screen_res() const noexcept = 0;
|
||||
|
||||
ControllerAPI& operator=(const ControllerAPI&) = delete;
|
||||
ControllerAPI& operator=(ControllerAPI&&) = delete;
|
||||
|
||||
virtual void back_to_home() noexcept {}
|
||||
};
|
||||
|
||||
struct InputEvent
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
Adb,
|
||||
Minitouch,
|
||||
Maatouch,
|
||||
MacPlayTools,
|
||||
};
|
||||
TOUCH_DOWN,
|
||||
TOUCH_UP,
|
||||
TOUCH_MOVE,
|
||||
TOUCH_RESET,
|
||||
KEY_DOWN,
|
||||
KEY_UP,
|
||||
WAIT_MS,
|
||||
COMMIT,
|
||||
UNKNOWN = INT_MAX
|
||||
} type = Type::UNKNOWN;
|
||||
|
||||
class ControllerAPI
|
||||
{
|
||||
public:
|
||||
virtual ~ControllerAPI() = default;
|
||||
|
||||
virtual bool connect(const std::string& adb_path, const std::string& address, const std::string& config) = 0;
|
||||
virtual bool inited() const noexcept = 0;
|
||||
virtual void set_swipe_with_pause([[maybe_unused]] bool enable) noexcept {}
|
||||
virtual void set_kill_adb_on_exit([[maybe_unused]] bool enable) noexcept {}
|
||||
|
||||
virtual const std::string& get_uuid() const = 0;
|
||||
|
||||
virtual bool screencap(cv::Mat& image_payload, bool allow_reconnect = false) = 0;
|
||||
|
||||
virtual bool start_game(const std::string& client_type) = 0;
|
||||
virtual bool stop_game() = 0;
|
||||
|
||||
virtual bool click(const Point& p) = 0;
|
||||
|
||||
virtual bool swipe(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false,
|
||||
double slope_in = 1, double slope_out = 1, bool with_pause = false) = 0;
|
||||
// TODO: 抽象出gesture类
|
||||
|
||||
virtual bool inject_input_event(const InputEvent& event) = 0;
|
||||
|
||||
virtual bool press_esc() = 0;
|
||||
virtual ControlFeat::Feat support_features() const noexcept = 0;
|
||||
|
||||
virtual std::pair<int, int> get_screen_res() const noexcept = 0;
|
||||
|
||||
ControllerAPI& operator=(const ControllerAPI&) = delete;
|
||||
ControllerAPI& operator=(ControllerAPI&&) = delete;
|
||||
|
||||
virtual void back_to_home() noexcept {}
|
||||
};
|
||||
|
||||
struct InputEvent
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
TOUCH_DOWN,
|
||||
TOUCH_UP,
|
||||
TOUCH_MOVE,
|
||||
TOUCH_RESET,
|
||||
KEY_DOWN,
|
||||
KEY_UP,
|
||||
WAIT_MS,
|
||||
COMMIT,
|
||||
UNKNOWN = INT_MAX
|
||||
} type = Type::UNKNOWN;
|
||||
|
||||
int pointerId = 0;
|
||||
asst::Point point = { 0, 0 };
|
||||
int keycode = 0;
|
||||
long milisec = 0;
|
||||
};
|
||||
int pointerId = 0;
|
||||
asst::Point point = { 0, 0 };
|
||||
int keycode = 0;
|
||||
long milisec = 0;
|
||||
};
|
||||
} // namespace asst
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
using asio::ip::tcp;
|
||||
namespace socket_ops = asio::detail::socket_ops;
|
||||
|
||||
asst::PlayToolsController::PlayToolsController(const AsstCallback& callback, Assistant* inst,
|
||||
PlatformType type [[maybe_unused]])
|
||||
: InstHelper(inst), m_callback(callback), m_socket(m_context)
|
||||
asst::PlayToolsController::PlayToolsController(
|
||||
const AsstCallback& callback,
|
||||
Assistant* inst,
|
||||
PlatformType type [[maybe_unused]])
|
||||
: InstHelper(inst)
|
||||
, m_callback(callback)
|
||||
, m_socket(m_context)
|
||||
{
|
||||
LogTraceFunction;
|
||||
}
|
||||
@@ -20,8 +24,10 @@ asst::PlayToolsController::~PlayToolsController()
|
||||
close();
|
||||
}
|
||||
|
||||
bool asst::PlayToolsController::connect(const std::string& adb_path [[maybe_unused]], const std::string& address,
|
||||
const std::string& config [[maybe_unused]])
|
||||
bool asst::PlayToolsController::connect(
|
||||
const std::string& adb_path [[maybe_unused]],
|
||||
const std::string& address,
|
||||
const std::string& config [[maybe_unused]])
|
||||
{
|
||||
if (m_address != address) {
|
||||
close();
|
||||
@@ -42,7 +48,19 @@ const std::string& asst::PlayToolsController::get_uuid() const
|
||||
return uuid;
|
||||
}
|
||||
|
||||
bool asst::PlayToolsController::screencap(cv::Mat& image_payload, bool allow_reconnect [[maybe_unused]])
|
||||
size_t asst::PlayToolsController::get_pipe_data_size() const noexcept
|
||||
{
|
||||
return size_t();
|
||||
}
|
||||
|
||||
size_t asst::PlayToolsController::get_version() const noexcept
|
||||
{
|
||||
return size_t();
|
||||
}
|
||||
|
||||
bool asst::PlayToolsController::screencap(
|
||||
cv::Mat& image_payload,
|
||||
bool allow_reconnect [[maybe_unused]])
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
@@ -103,8 +121,14 @@ bool asst::PlayToolsController::click(const Point& p)
|
||||
return toucher_down(p) && toucher_up(p);
|
||||
}
|
||||
|
||||
bool asst::PlayToolsController::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe, double slope_in,
|
||||
double slope_out, bool with_pause [[maybe_unused]])
|
||||
bool asst::PlayToolsController::swipe(
|
||||
const Point& p1,
|
||||
const Point& p2,
|
||||
int duration,
|
||||
bool extra_swipe,
|
||||
double slope_in,
|
||||
double slope_out,
|
||||
bool with_pause [[maybe_unused]])
|
||||
{
|
||||
int x1 = p1.x, y1 = p1.y;
|
||||
int x2 = p2.x, y2 = p2.y;
|
||||
@@ -129,8 +153,10 @@ bool asst::PlayToolsController::swipe(const Point& p1, const Point& p2, int dura
|
||||
}; // TODO: move this to math.hpp
|
||||
|
||||
const auto progressive_move = [&](int _x1, int _y1, int _x2, int _y2, int _duration) {
|
||||
for (int cur_time = DefaultSwipeDelay; cur_time < _duration; cur_time += DefaultSwipeDelay) {
|
||||
double progress = cubic_spline(slope_in, slope_out, static_cast<double>(cur_time) / duration);
|
||||
for (int cur_time = DefaultSwipeDelay; cur_time < _duration;
|
||||
cur_time += DefaultSwipeDelay) {
|
||||
double progress =
|
||||
cubic_spline(slope_in, slope_out, static_cast<double>(cur_time) / duration);
|
||||
int cur_x = static_cast<int>(std::lerp(_x1, _x2, progress));
|
||||
int cur_y = static_cast<int>(std::lerp(_y1, _y2, progress));
|
||||
if (cur_x < 0 || cur_x > width || cur_y < 0 || cur_y > height) {
|
||||
@@ -149,7 +175,12 @@ bool asst::PlayToolsController::swipe(const Point& p1, const Point& p2, int dura
|
||||
|
||||
if (extra_swipe && opt.minitouch_extra_swipe_duration > 0) {
|
||||
toucher_wait(opt.minitouch_swipe_extra_end_delay); // 停留终点
|
||||
progressive_move(x2, y2, x2, y2 - opt.minitouch_extra_swipe_dist, opt.minitouch_extra_swipe_duration);
|
||||
progressive_move(
|
||||
x2,
|
||||
y2,
|
||||
x2,
|
||||
y2 - opt.minitouch_extra_swipe_dist,
|
||||
opt.minitouch_extra_swipe_duration);
|
||||
}
|
||||
|
||||
return toucher_up(p2);
|
||||
@@ -290,7 +321,10 @@ bool asst::PlayToolsController::fetch_screen_res()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asst::PlayToolsController::toucher_commit(const TouchPhase phase, const Point& p, const int delay)
|
||||
bool asst::PlayToolsController::toucher_commit(
|
||||
const TouchPhase phase,
|
||||
const Point& p,
|
||||
const int delay)
|
||||
{
|
||||
open();
|
||||
uint16_t x = socket_ops::host_to_network_short(static_cast<uint16_t>(p.x));
|
||||
|
||||
@@ -13,73 +13,94 @@
|
||||
|
||||
namespace asst
|
||||
{
|
||||
class PlayToolsController : public ControllerAPI, protected InstHelper
|
||||
class PlayToolsController
|
||||
: public ControllerAPI
|
||||
, protected InstHelper
|
||||
{
|
||||
public:
|
||||
PlayToolsController(const AsstCallback& callback, Assistant* inst, PlatformType type);
|
||||
PlayToolsController(const PlayToolsController&) = delete;
|
||||
PlayToolsController(PlayToolsController&&) = delete;
|
||||
virtual ~PlayToolsController();
|
||||
|
||||
virtual bool connect(
|
||||
const std::string& adb_path,
|
||||
const std::string& address,
|
||||
const std::string& config) override;
|
||||
virtual bool inited() const noexcept override;
|
||||
|
||||
virtual const std::string& get_uuid() const override;
|
||||
|
||||
virtual size_t get_pipe_data_size() const noexcept override;
|
||||
|
||||
virtual size_t get_version() const noexcept override;
|
||||
|
||||
virtual bool screencap(cv::Mat& image_payload, bool allow_reconnect = false) override;
|
||||
|
||||
virtual bool start_game(const std::string& client_type) override;
|
||||
virtual bool stop_game() override;
|
||||
|
||||
virtual bool click(const Point& p) override;
|
||||
|
||||
virtual bool swipe(
|
||||
const Point& p1,
|
||||
const Point& p2,
|
||||
int duration = 0,
|
||||
bool extra_swipe = false,
|
||||
double slope_in = 1,
|
||||
double slope_out = 1,
|
||||
bool with_pause = false) override;
|
||||
|
||||
virtual bool inject_input_event([[maybe_unused]] const InputEvent& event) override
|
||||
{
|
||||
public:
|
||||
PlayToolsController(const AsstCallback& callback, Assistant* inst, PlatformType type);
|
||||
PlayToolsController(const PlayToolsController&) = delete;
|
||||
PlayToolsController(PlayToolsController&&) = delete;
|
||||
virtual ~PlayToolsController();
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool connect(const std::string& adb_path, const std::string& address,
|
||||
const std::string& config) override;
|
||||
virtual bool inited() const noexcept override;
|
||||
virtual bool press_esc() override;
|
||||
|
||||
virtual const std::string& get_uuid() const override;
|
||||
virtual ControlFeat::Feat support_features() const noexcept override
|
||||
{
|
||||
return ControlFeat::NONE;
|
||||
}
|
||||
|
||||
virtual bool screencap(cv::Mat& image_payload, bool allow_reconnect = false) override;
|
||||
virtual std::pair<int, int> get_screen_res() const noexcept override;
|
||||
|
||||
virtual bool start_game(const std::string& client_type) override;
|
||||
virtual bool stop_game() override;
|
||||
PlayToolsController& operator=(const PlayToolsController&) = delete;
|
||||
PlayToolsController& operator=(PlayToolsController&&) = delete;
|
||||
|
||||
virtual bool click(const Point& p) override;
|
||||
virtual void back_to_home() noexcept override;
|
||||
|
||||
virtual bool swipe(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false,
|
||||
double slope_in = 1, double slope_out = 1, bool with_pause = false) override;
|
||||
protected:
|
||||
AsstCallback m_callback;
|
||||
|
||||
virtual bool inject_input_event([[maybe_unused]] const InputEvent& event) override { return false; }
|
||||
asio::io_context m_context;
|
||||
asio::ip::tcp::socket m_socket;
|
||||
|
||||
virtual bool press_esc() override;
|
||||
virtual ControlFeat::Feat support_features() const noexcept override { return ControlFeat::NONE; }
|
||||
std::string m_address;
|
||||
std::pair<int, int> m_screen_size = { 0, 0 };
|
||||
|
||||
virtual std::pair<int, int> get_screen_res() const noexcept override;
|
||||
|
||||
PlayToolsController& operator=(const PlayToolsController&) = delete;
|
||||
PlayToolsController& operator=(PlayToolsController&&) = delete;
|
||||
|
||||
virtual void back_to_home() noexcept override;
|
||||
|
||||
protected:
|
||||
AsstCallback m_callback;
|
||||
|
||||
asio::io_context m_context;
|
||||
asio::ip::tcp::socket m_socket;
|
||||
|
||||
std::string m_address;
|
||||
std::pair<int, int> m_screen_size = { 0, 0 };
|
||||
|
||||
enum class TouchPhase
|
||||
{
|
||||
Began = 0,
|
||||
Moved = 1,
|
||||
Ended = 3,
|
||||
};
|
||||
|
||||
static constexpr int DefaultClickDelay = 50;
|
||||
static constexpr int DefaultSwipeDelay = 5;
|
||||
|
||||
bool toucher_down(const Point& p, const int delay = DefaultClickDelay);
|
||||
bool toucher_move(const Point& p, const int delay = DefaultSwipeDelay);
|
||||
bool toucher_up(const Point& p, const int delay = DefaultClickDelay);
|
||||
|
||||
void toucher_wait(const int delay);
|
||||
|
||||
private:
|
||||
static constexpr int MinimalVersion = 2;
|
||||
void close();
|
||||
bool open();
|
||||
bool check_version();
|
||||
bool fetch_screen_res();
|
||||
bool toucher_commit(const TouchPhase phase, const Point& p, const int delay);
|
||||
enum class TouchPhase
|
||||
{
|
||||
Began = 0,
|
||||
Moved = 1,
|
||||
Ended = 3,
|
||||
};
|
||||
|
||||
static constexpr int DefaultClickDelay = 50;
|
||||
static constexpr int DefaultSwipeDelay = 5;
|
||||
|
||||
bool toucher_down(const Point& p, const int delay = DefaultClickDelay);
|
||||
bool toucher_move(const Point& p, const int delay = DefaultSwipeDelay);
|
||||
bool toucher_up(const Point& p, const int delay = DefaultClickDelay);
|
||||
|
||||
void toucher_wait(const int delay);
|
||||
|
||||
private:
|
||||
static constexpr int MinimalVersion = 2;
|
||||
void close();
|
||||
bool open();
|
||||
bool check_version();
|
||||
bool fetch_screen_res();
|
||||
bool toucher_commit(const TouchPhase phase, const Point& p, const int delay);
|
||||
};
|
||||
} // namespace asst
|
||||
|
||||
@@ -9,7 +9,49 @@ bool StartGameTaskPlugin::_run()
|
||||
if (m_client_type.empty()) {
|
||||
return false;
|
||||
}
|
||||
return ctrler()->start_game(m_client_type);
|
||||
|
||||
// check for android version, because it leads to different magic values
|
||||
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/8966#issuecomment-2094369694
|
||||
if (ctrler()->get_version() > 8) {
|
||||
do {
|
||||
if (!ctrler()->start_game(m_client_type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/8961#issue-2277568882
|
||||
// 167: magic value needs to be >164 but <172 (as that's max)
|
||||
if (ctrler()->get_pipe_data_size() > 167) {
|
||||
return true;
|
||||
}
|
||||
|
||||
sleep(1500);
|
||||
|
||||
} while (true);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
if (!ctrler()->start_game(m_client_type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 145: needs to be >85 but <153 (as that's max)
|
||||
// magic value lowered because of different android version
|
||||
if (ctrler()->get_pipe_data_size() > 145) {
|
||||
// As there's no way to know (in Android < 8) if Ark has correctly started
|
||||
// we run the command a few more times to be sure
|
||||
for (auto _ = 3; _--;) {
|
||||
sleep(1500);
|
||||
if (!ctrler()->start_game(m_client_type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
sleep(1500);
|
||||
|
||||
} while (true);
|
||||
}
|
||||
}
|
||||
|
||||
StartGameTaskPlugin& StartGameTaskPlugin::set_client_type(std::string client_type) noexcept
|
||||
|
||||
Reference in New Issue
Block a user