feat(PC): 支持 PC 端明日方舟 (#15407)

* feat(controller): 集成 MaaWin32ControlUnit 支持 Win32 窗口截图与控制

- 提取公共滑动插值逻辑到 SwipeHelper.hpp,重构 Minitouch/PlayTools 控制器
- 新增 Win32ControlUnitLoader 动态加载 MaaWin32ControlUnit.dll
- 新增 Win32Controller 实现 ControllerAPI,适配 touch_down/move/up 接口
- 添加 AsstAsyncAttachWindow 公开 API 用于绑定 Win32 窗口
- 添加 Win32 截图/输入方式的类型定义和枚举常量

* feat(api): 增加同步版本的 AsstAttachWindow 接口

模仿 AsstConnect 实现同步绑定 Win32 窗口的接口,方便简单场景下直接调用。
该接口标记为 deprecated,建议使用异步版本 AsstAsyncAttachWindow。

* fix: can build MaaCore

* feat: 完成整体适配

* feat(ci): 添加 MaaFramework Win32ControlUnit 下载步骤

使用 robinraju/release-downloader 从 MaaFramework 最新 release 下载
win-x64 版本并提取 MaaWin32ControlUnit 到构建产物中

* docs: 添加 Win32Controller 调试所需 MaaWin32ControlUnit 的说明

在开发文档的环境配置步骤中说明调试 Win32Controller 需要手动下载
MaaWin32ControlUnit.dll,并欢迎社区贡献自动下载脚本

* fix(i18n): 修改 UseAttachWindowWarning 措辞为"仅供尝鲜"

* fix: 小细节修复

* ci: fix maafw filename

* feat: PC 移至连接配置

* feat: 调整描述

* chore: 调整 PC 在连接配置中的顺序

* feat: 设置指引和开始唤醒界面 PC 选项绑定

---------

Co-authored-by: uye <99072975+ABA2396@users.noreply.github.com>
This commit is contained in:
MistEO
2026-01-18 21:17:59 +08:00
committed by GitHub
parent 99bde4818e
commit a11660cbac
34 changed files with 2042 additions and 353 deletions

View File

@@ -0,0 +1,107 @@
#pragma once
#ifdef _WIN32
#include <cstdint>
#include <filesystem>
#include <memory>
#include <string>
#include "MaaUtils/SafeWindows.hpp"
#include "Common/AsstTypes.h"
#include "MaaUtils/NoWarningCVMat.hpp"
namespace asst
{
// 与 MaaFramework 的 ControlUnitAPI 接口保持 ABI 兼容
// 虚函数表布局必须与 MaaFramework 完全一致
class MaaControlUnitInterface
{
public:
virtual ~MaaControlUnitInterface() = default;
virtual bool connect() = 0;
virtual bool connected() const = 0;
virtual bool request_uuid(std::string& uuid) = 0;
virtual uint64_t get_features() const = 0;
virtual bool start_app(const std::string& intent) = 0;
virtual bool stop_app(const std::string& intent) = 0;
virtual bool screencap(cv::Mat& image) = 0;
virtual bool click(int x, int y) = 0;
virtual bool swipe(int x1, int y1, int x2, int y2, int duration) = 0;
virtual bool touch_down(int contact, int x, int y, int pressure) = 0;
virtual bool touch_move(int contact, int x, int y, int pressure) = 0;
virtual bool touch_up(int contact) = 0;
virtual bool click_key(int key) = 0;
virtual bool input_text(const std::string& text) = 0;
virtual bool key_down(int key) = 0;
virtual bool key_up(int key) = 0;
virtual bool scroll(int dx, int dy) = 0;
};
// 与 MaaFramework 的 MaaControllerFeature 兼容的常量
namespace MaaFeature
{
constexpr uint64_t None = 0;
constexpr uint64_t UseMouseDownAndUpInsteadOfClick = 1ULL << 1;
constexpr uint64_t UseKeyboardDownAndUpInsteadOfClick = 1ULL << 2;
} // namespace MaaFeature
// 动态加载 MaaWin32ControlUnit.dll
class Win32ControlUnitLoader
{
public:
Win32ControlUnitLoader();
~Win32ControlUnitLoader();
Win32ControlUnitLoader(const Win32ControlUnitLoader&) = delete;
Win32ControlUnitLoader& operator=(const Win32ControlUnitLoader&) = delete;
Win32ControlUnitLoader(Win32ControlUnitLoader&&) = delete;
Win32ControlUnitLoader& operator=(Win32ControlUnitLoader&&) = delete;
// 加载 DLL
bool load(const std::filesystem::path& dll_path);
// 卸载 DLL
void unload();
// 是否已加载
bool loaded() const noexcept { return m_module != nullptr; }
// 获取版本
const char* get_version() const;
// 创建控制单元
void* create(
void* hwnd,
Win32ScreencapMethod screencap_method,
Win32InputMethod mouse_method,
Win32InputMethod keyboard_method);
// 销毁控制单元
void destroy(void* handle);
private:
void* m_module = nullptr;
// 函数指针类型
using GetVersionFunc = const char* (*)();
using CreateFunc = void* (*)(void*, uint64_t, uint64_t, uint64_t);
using DestroyFunc = void (*)(void*);
GetVersionFunc m_get_version = nullptr;
CreateFunc m_create = nullptr;
DestroyFunc m_destroy = nullptr;
};
} // namespace asst
#endif // _WIN32