Skip to content

Commit d9f6f00

Browse files
CopilotMistEOmoomiji
authored
feat: update C API bindings to MaaFramework v5.10.5 (#27)
* Add missing C# bindings for MaaFramework C API - Add MaaMacOSControllerCreate, MaaAndroidNativeControllerCreate, MaaReplayControllerCreate, MaaRecordControllerCreate P/Invoke - Add MaaControllerPostRelativeMove P/Invoke - Add MaaTaskerGetWaitFreezesDetail P/Invoke - Add MaaToolkitMacOS P/Invoke (CheckPermission, RequestPermission, RevealPermissionSettings) - Update MaaDbgControllerCreate to new 1-param signature - Add MaaMacOSController, MaaAndroidNativeController, MaaReplayController, MaaRecordController wrapper classes - Update MaaDbgController wrapper for new API - Add RelativeMove to IMaaController/MaaController - Add GetWaitFreezesDetail to IMaaTasker/MaaTasker - Add MacOSScreencapMethod, MacOSInputMethod, MacOSPermission enums - Add MaaWfId type alias - Add IMaaToolkitMacOS interface and implementation - Add Node.WaitFreezes messages to MaaMsg Agent-Logs-Url: https://github.com/MaaXYZ/MaaFramework.Binding.CSharp/sessions/201d767e-cec0-4888-b09f-8b7a74837c9a Co-authored-by: MistEO <18511905+MistEO@users.noreply.github.com> * feat(controller): add MaaControllerPostMouseMoveRelative (MaaXYZ/MaaFramework#1189) * feat(win32): 废弃 `PostThreadMessage` (MaaXYZ/MaaFramework@2fdec3a) * feat: 完整的 macOS 原生截图和控制以及 MaaToolkit 的 DesktopWindow 支持 (MaaXYZ/MaaFramework#1116) * feat: macos utils (MaaXYZ/MaaFramework#1214) * feat: Record & Replay Controller (MaaXYZ/MaaFramework#1146) * feat: android native support (MaaXYZ/MaaFramework#1222) * feat(win32): 添加鼠标锁定跟随模式,支持后台 TPS/FPS 视角控制 (MaaXYZ/MaaFramework#1232) * feat: add optional anchor info for reco sink (MaaXYZ/MaaFramework#1187) * feat: controller ScreenshotResizeMethod (MaaXYZ/MaaFramework#1243) * feat: wait_freezes msg (MaaXYZ/MaaFramework#1178) * feat(wlroots): 支持将按键视为 Win32 VK 键码 (MaaXYZ/MaaFramework#1283) * feat(win32): 添加后台托管按键守护,支持后台长按移动 (MaaXYZ/MaaFramework#1231) * fix: resolve compilation errors * chore: update documentation comments --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MistEO <18511905+MistEO@users.noreply.github.com> Co-authored-by: moomiji <35213527+moomiji@users.noreply.github.com>
1 parent 41f49ad commit d9f6f00

46 files changed

Lines changed: 1226 additions & 411 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/articles/overview-of-wrapper-and-api.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
| AdbInputMethods | `MaaAdbInputMethod` |
2727
| Win32ScreencapMethod | `MaaWin32ScreencapMethod` |
2828
| Win32InputMethod | `MaaWin32InputMethod` |
29-
| DbgControllerType | `MaaDbgControllerType` |
29+
| MacOSScreencapMethod | `MaaMacOSScreencapMethod` |
30+
| MacOSInputMethod | `MaaMacOSInputMethod` |
31+
| MacOSPermission | `MaaMacOSPermissionEnum` |
3032
| GamepadType | `MaaGamepadType` |
3133
| GamepadButton | `MaaGamepadButton` |
3234
| GamepadTouch | `MaaGamepadTouch` |
@@ -87,8 +89,12 @@ IMaaDisposable Derived:
8789
| --- | --- |
8890
| MaaAdbController.ctor() | `MaaAdbControllerCreate` <br> `MaaControllerAddSink` |
8991
| MaaWin32Controller.ctor() | `MaaWin32ControllerCreate` <br> `MaaControllerAddSink` |
92+
| MaaMacOSController.ctor() | `MaaMacOSControllerCreate` <br> `MaaControllerAddSink` |
93+
| MaaAndroidNativeController.ctor() | `MaaAndroidNativeControllerCreate` <br> `MaaControllerAddSink` |
9094
| MaaCustomController.ctor() | `MaaCustomControllerCreate` <br> `MaaControllerAddSink` |
9195
| MaaDbgController.ctor() | `MaaDbgControllerCreate` <br> `MaaControllerAddSink` |
96+
| MaaReplayController.ctor() | `MaaReplayControllerCreate` <br> `MaaControllerAddSink` |
97+
| MaaRecordController.ctor() | `MaaRecordControllerCreate` <br> `MaaControllerAddSink` |
9298
| MaaPlayCoverController.ctor() | `MaaPlayCoverControllerCreate` <br> `MaaControllerAddSink` |
9399
| MaaGamepadController.ctor() | `MaaGamepadControllerCreate` <br> `MaaControllerAddSink` |
94100
| MaaWlRootsController.ctor() | `MaaWlRootsControllerCreate` <br> `MaaControllerAddSink` |
@@ -104,6 +110,7 @@ IMaaDisposable Derived:
104110
| IMaaController.TouchDown() | `MaaControllerPostTouchDown` |
105111
| IMaaController.TouchMove() | `MaaControllerPostTouchMove` |
106112
| IMaaController.TouchUp() | `MaaControllerPostTouchUp` |
113+
| IMaaController.RelativeMove() | `MaaControllerPostRelativeMove` |
107114
| IMaaController.Screencap() | `MaaControllerPostScreencap` |
108115
| IMaaController.Scroll() | `MaaControllerPostScroll` |
109116
| IMaaController.Inactive() | `MaaControllerPostInactive` |
@@ -312,6 +319,9 @@ IMaaDisposable Derived:
312319
| MaaToolkit.ctor() <br> IMaaToolkit.Config.InitOption() | `MaaToolkitConfigInitOption` |
313320
| IMaaToolkit.AdbDevice.Find() <br> IMaaToolkit.AdbDevice.FindAsync() | `MaaToolkitAdbDeviceFind` <br> `MaaToolkitAdbDeviceFindSpecified` |
314321
| IMaaToolkit.Desktop.Window.Find() | `MaaToolkitDesktopWindowFindAll` |
322+
| IMaaToolkit.MacOS.CheckPermission() | `MaaToolkitMacOSCheckPermission` |
323+
| IMaaToolkit.MacOS.RequestPermission() | `MaaToolkitMacOSRequestPermission` |
324+
| IMaaToolkit.MacOS.RevealPermissionSettings() | `MaaToolkitMacOSRevealPermissionSettings` |
315325

316326
## Buffers.AdbDeviceListBuffer : Buffers.MaaListBuffer : Buffers.IMaaListBuffer
317327

src/MaaFramework.Binding.Extensions/Notification/NotificationDetail.cs

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,71 @@
33

44
namespace MaaFramework.Binding.Notification;
55

6-
/// <inheritdoc cref="MaaMsg.Resource.Loading.Prefix"/>
6+
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
7+
8+
/// <inheritdoc cref="MaaMsg.Resource.Loading"/>
9+
public enum ResourcePathType
10+
{
11+
Bundle,
12+
OcrModel,
13+
Pipeline,
14+
Image,
15+
16+
Unknown = -1
17+
}
18+
19+
/// <inheritdoc cref="MaaMsg.Resource.Loading"/>
720
public record ResourceLoadingDetail(
8-
[property: JsonPropertyName("res_id")] int ResourceId,
21+
[property: JsonPropertyName("res_id")] long ResourceId,
922
[property: JsonPropertyName("path")] string Path,
1023
[property: JsonPropertyName("type")] string Type,
1124
[property: JsonPropertyName("hash")] string Hash
12-
);
25+
)
26+
{
27+
// 1. .NET 7 没有支持 aot 的 JsonStringEnumConverter<TEnum>
28+
// 2. Unknown 向前兼容,使用 JsonStringEnumConverter 还需要设置 option 并且将 Unknown 设置为默认值 0
29+
[JsonIgnore] public ResourcePathType ParsedType => Enum.TryParse<ResourcePathType>(Type, true, out var result) ? result : ResourcePathType.Unknown;
30+
};
1331

14-
/// <inheritdoc cref="MaaMsg.Controller.Action.Prefix"/>
32+
/// <inheritdoc cref="MaaMsg.Controller.Action"/>
1533
public record ControllerActionDetail(
16-
[property: JsonPropertyName("ctrl_id")] int ControllerId,
34+
[property: JsonPropertyName("ctrl_id")] long ControllerId,
1735
[property: JsonPropertyName("uuid")] string Uuid,
1836
[property: JsonPropertyName("action")] string Action,
1937
[property: JsonPropertyName("param")] JsonElement Param,
2038
[property: JsonPropertyName("info")] JsonElement Info
2139
);
2240

23-
/// <inheritdoc cref="MaaMsg.Tasker.Task.Prefix"/>
41+
/// <inheritdoc cref="MaaMsg.Tasker.Task"/>
2442
public record TaskerTaskDetail(
25-
[property: JsonPropertyName("task_id")] int TaskId,
43+
[property: JsonPropertyName("task_id")] long TaskId,
2644
[property: JsonPropertyName("entry")] string Entry,
2745
[property: JsonPropertyName("uuid")] string Uuid,
2846
[property: JsonPropertyName("hash")] string Hash
2947
);
3048

31-
/// <inheritdoc cref="MaaMsg.Node.PipelineNode.Prefix"/>
49+
/// <inheritdoc cref="MaaMsg.Node.PipelineNode"/>
3250
public record PipelineNodeDetail(
33-
[property: JsonPropertyName("task_id")] int TaskId,
34-
[property: JsonPropertyName("node_id")] int NodeId,
51+
[property: JsonPropertyName("task_id")] long TaskId,
52+
[property: JsonPropertyName("node_id")] long NodeId,
3553
[property: JsonPropertyName("name")] string Name,
36-
[property: JsonPropertyName("focus")] JsonElement? Focus
54+
[property: JsonPropertyName("focus")] JsonElement Focus
3755
);
3856

39-
/// <inheritdoc cref="MaaMsg.Node.RecognitionNode.Prefix"/>
57+
/// <inheritdoc cref="MaaMsg.Node.RecognitionNode"/>
4058
public record RecognitionNodeDetail(
41-
[property: JsonPropertyName("task_id")] int TaskId,
42-
[property: JsonPropertyName("node_id")] int NodeId,
59+
[property: JsonPropertyName("task_id")] long TaskId,
60+
[property: JsonPropertyName("node_id")] long NodeId,
4361
[property: JsonPropertyName("name")] string Name,
44-
[property: JsonPropertyName("focus")] JsonElement? Focus
62+
[property: JsonPropertyName("focus")] JsonElement Focus
4563
);
4664

47-
/// <inheritdoc cref="MaaMsg.Node.ActionNode.Prefix"/>
65+
/// <inheritdoc cref="MaaMsg.Node.ActionNode"/>
4866
public record ActionNodeDetail(
49-
[property: JsonPropertyName("task_id")] int TaskId,
50-
[property: JsonPropertyName("node_id")] int NodeId,
67+
[property: JsonPropertyName("task_id")] long TaskId,
68+
[property: JsonPropertyName("node_id")] long NodeId,
5169
[property: JsonPropertyName("name")] string Name,
52-
[property: JsonPropertyName("focus")] JsonElement? Focus
70+
[property: JsonPropertyName("focus")] JsonElement Focus
5371
);
5472

5573
/// <summary>
@@ -61,26 +79,57 @@ public record NodeAttr(
6179
[property: JsonPropertyName("anchor")] bool Anchor
6280
);
6381

64-
/// <inheritdoc cref="MaaMsg.Node.NextList.Prefix"/>
82+
/// <inheritdoc cref="MaaMsg.Node.NextList"/>
6583
public record NodeNextListDetail(
66-
[property: JsonPropertyName("task_id")] int TaskId,
84+
[property: JsonPropertyName("task_id")] long TaskId,
6785
[property: JsonPropertyName("name")] string Name,
6886
[property: JsonPropertyName("list")] IReadOnlyList<NodeAttr> NextList,
69-
[property: JsonPropertyName("focus")] JsonElement? Focus
87+
[property: JsonPropertyName("focus")] JsonElement Focus
7088
);
7189

72-
/// <inheritdoc cref="MaaMsg.Node.Recognition.Prefix"/>
90+
/// <inheritdoc cref="MaaMsg.Node.Recognition"/>
7391
public record NodeRecognitionDetail(
74-
[property: JsonPropertyName("task_id")] int TaskId,
75-
[property: JsonPropertyName("reco_id")] int RecognitionId,
92+
[property: JsonPropertyName("task_id")] long TaskId,
93+
[property: JsonPropertyName("reco_id")] long RecognitionId,
7694
[property: JsonPropertyName("name")] string Name,
77-
[property: JsonPropertyName("focus")] JsonElement? Focus
95+
[property: JsonPropertyName("focus")] JsonElement Focus,
96+
[property: JsonPropertyName("anchor")] string? Anchor
7897
);
7998

80-
/// <inheritdoc cref="MaaMsg.Node.Action.Prefix"/>
99+
/// <inheritdoc cref="MaaMsg.Node.Action"/>
81100
public record NodeActionDetail(
82-
[property: JsonPropertyName("task_id")] int TaskId,
83-
[property: JsonPropertyName("action_id")] int ActionId,
101+
[property: JsonPropertyName("task_id")] long TaskId,
102+
[property: JsonPropertyName("action_id")] long ActionId,
84103
[property: JsonPropertyName("name")] string Name,
85-
[property: JsonPropertyName("focus")] JsonElement? Focus
104+
[property: JsonPropertyName("focus")] JsonElement Focus
86105
);
106+
107+
public record WaitFreezesParam(
108+
[property: JsonPropertyName("time")] long MillisecondsTime,
109+
[property: JsonPropertyName("threshold")] double Threshold,
110+
[property: JsonPropertyName("method")] int Method,
111+
[property: JsonPropertyName("rate_limit")] long MillisecondsRateLimit,
112+
[property: JsonPropertyName("timeout")] long MillisecondsTimeout
113+
)
114+
{
115+
[JsonIgnore] public TimeSpan Time => TimeSpan.FromMilliseconds(MillisecondsTime);
116+
[JsonIgnore] public TimeSpan RateLimit => TimeSpan.FromMilliseconds(MillisecondsRateLimit);
117+
[JsonIgnore] public TimeSpan Timeout => TimeSpan.FromMilliseconds(MillisecondsTimeout);
118+
}
119+
120+
/// <inheritdoc cref="MaaMsg.Node.WaitFreezes"/>
121+
public record NodeWaitFreezesDetail(
122+
[property: JsonPropertyName("task_id")] long TaskId,
123+
[property: JsonPropertyName("wf_id")] long WaitFreezesId,
124+
[property: JsonPropertyName("name")] string Name,
125+
[property: JsonPropertyName("phase")] string Phase,
126+
[property: JsonPropertyName("roi")] IReadOnlyList<int> Roi,
127+
[property: JsonPropertyName("param")] WaitFreezesParam Param,
128+
[property: JsonPropertyName("reco_ids")] IReadOnlyList<long>? RecognitionIds,
129+
[property: JsonPropertyName("elapsed")] long? MillisecondsElapsed,
130+
[property: JsonPropertyName("focus")] JsonElement Focus
131+
// https://github.com/MaaXYZ/MaaFramework/blob/v5.10.5/source/MaaFramework/Task/Component/ActionHelper.cpp#L46
132+
)
133+
{
134+
[JsonIgnore] public TimeSpan? Elapsed => MillisecondsElapsed.HasValue ? TimeSpan.FromMilliseconds(MillisecondsElapsed.Value) : null;
135+
}

src/MaaFramework.Binding.Extensions/Notification/NotificationDetailContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ namespace MaaFramework.Binding.Notification;
99
[JsonSerializable(typeof(PipelineNodeDetail))]
1010
[JsonSerializable(typeof(RecognitionNodeDetail))]
1111
[JsonSerializable(typeof(ActionNodeDetail))]
12-
[JsonSerializable(typeof(NodeAttr))]
1312
[JsonSerializable(typeof(NodeNextListDetail))]
1413
[JsonSerializable(typeof(NodeRecognitionDetail))]
1514
[JsonSerializable(typeof(NodeActionDetail))]
15+
[JsonSerializable(typeof(NodeWaitFreezesDetail))]
16+
[JsonSerializable(typeof(string))]
1617
public partial class NotificationDetailContext : JsonSerializerContext;

src/MaaFramework.Binding.Extensions/Notification/NotificationHandler.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this Notif
100100
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<TaskerTaskDetail, TContext> notify) where TContext : IMaaTasker
101101
=> notify.ToCallback(MaaMsg.Tasker.Task.Prefix);
102102

103+
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
104+
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<PipelineNodeDetail, TContext> notify) where TContext : IMaaContext
105+
=> notify.ToCallback(MaaMsg.Node.PipelineNode.Prefix);
106+
107+
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
108+
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<RecognitionNodeDetail, TContext> notify) where TContext : IMaaContext
109+
=> notify.ToCallback(MaaMsg.Node.RecognitionNode.Prefix);
110+
111+
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
112+
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<ActionNodeDetail, TContext> notify) where TContext : IMaaContext
113+
=> notify.ToCallback(MaaMsg.Node.ActionNode.Prefix);
114+
103115
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
104116
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<NodeNextListDetail, TContext> notify) where TContext : IMaaContext
105117
=> notify.ToCallback(MaaMsg.Node.NextList.Prefix);
@@ -113,15 +125,7 @@ public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this Notif
113125
=> notify.ToCallback(MaaMsg.Node.Action.Prefix);
114126

115127
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
116-
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<PipelineNodeDetail, TContext> notify) where TContext : IMaaContext
117-
=> notify.ToCallback(MaaMsg.Node.PipelineNode.Prefix);
118-
119-
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
120-
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<RecognitionNodeDetail, TContext> notify) where TContext : IMaaContext
121-
=> notify.ToCallback(MaaMsg.Node.RecognitionNode.Prefix);
122-
123-
/// <inheritdoc cref="ToCallback{TDetail, TContext}"/>
124-
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<ActionNodeDetail, TContext> notify) where TContext : IMaaContext
125-
=> notify.ToCallback(MaaMsg.Node.ActionNode.Prefix);
128+
public static EventHandler<MaaCallbackEventArgs> ToCallback<TContext>(this NotificationHandler<NodeWaitFreezesDetail, TContext> notify) where TContext : IMaaContext
129+
=> notify.ToCallback(MaaMsg.Node.WaitFreezes.Prefix);
126130
}
127131

src/MaaFramework.Binding.Extensions/Notification/NotificationHandlerRegistry.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender,
232232
NotificationDetailContext.Default.NodeActionDetail) ?? throw new InvalidCastException());
233233
}
234234

235+
public WaitFreezesRegistry WaitFreezes { get; } = new();
236+
public sealed class WaitFreezesRegistry
237+
{
238+
public event EventHandler<NodeWaitFreezesDetail>? Starting;
239+
internal void OnStarting(object? sender, string details) => Starting?.Invoke(sender, JsonSerializer.Deserialize(details,
240+
NotificationDetailContext.Default.NodeWaitFreezesDetail) ?? throw new InvalidCastException());
241+
public event EventHandler<NodeWaitFreezesDetail>? Succeeded;
242+
internal void OnSucceeded(object? sender, string details) => Succeeded?.Invoke(sender, JsonSerializer.Deserialize(details,
243+
NotificationDetailContext.Default.NodeWaitFreezesDetail) ?? throw new InvalidCastException());
244+
public event EventHandler<NodeWaitFreezesDetail>? Failed;
245+
internal void OnFailed(object? sender, string details) => Failed?.Invoke(sender, JsonSerializer.Deserialize(details,
246+
NotificationDetailContext.Default.NodeWaitFreezesDetail) ?? throw new InvalidCastException());
247+
}
248+
235249
}
236250

237-
}
251+
}

src/MaaFramework.Binding.Extensions/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ Supported TDetail types:
5656
- ResourceLoadingDetail
5757
- ControllerActionDetail
5858
- TaskerTaskDetail
59+
- PipelineNodeDetail
60+
- RecognitionNodeDetail
61+
- ActionNodeDetail
5962
- NodeNextListDetail
6063
- NodeRecognitionDetail
6164
- NodeActionDetail
65+
- NodeWaitFreezesDetail
6266
- string
6367

6468
Usage example:
@@ -82,4 +86,4 @@ NotificationHandler<ResourceLoadingDetail> OnResourceLoading = (type, detail) =>
8286
}
8387
};
8488
maa.Callback += OnResourceLoading.ToCallback();
85-
```
89+
```

src/MaaFramework.Binding.Extensions/README.zh_cn.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ TDetail 为以下类型:
5656
- ResourceLoadingDetail
5757
- ControllerActionDetail
5858
- TaskerTaskDetail
59+
- PipelineNodeDetail
60+
- RecognitionNodeDetail
61+
- ActionNodeDetail
5962
- NodeNextListDetail
6063
- NodeRecognitionDetail
6164
- NodeActionDetail
65+
- NodeWaitFreezesDetail
6266
- string
6367

6468
使用示例:

0 commit comments

Comments
 (0)