Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 适配 maafw v3 #13

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Maa.AgentBinary" Version="1.0.0" />
<PackageVersion Include="Maa.Framework.Runtimes" Version="2.3.1" />
<PackageVersion Include="Maa.Framework.Runtimes" Version="3.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.1" />
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dotnet add package Maa.Framework --prerelease -s https://nuget.pkg.github.com/ma
```

- NuGet.config
Please refer to [this config](../NuGet.config) for example, and [this article](https://maaxyz.github.io/MaaFramework.Binding.CSharp/articles/preview.html) for complete information.
Please refer to [this config](./NuGet.config) for example, and [this article](https://maaxyz.github.io/MaaFramework.Binding.CSharp/articles/preview.html) for complete information.

#### Specifying RIDs

Expand Down Expand Up @@ -115,11 +115,11 @@ using var maa = new MaaTasker
if (!maa.Initialized)
throw new InvalidOperationException();

maa.AppendPipeline("EmptyTask")
maa.AppendTask("EmptyNode")
.Wait()
.ThrowIfNot(MaaJobStatus.Succeeded);

Console.WriteLine("EmptyTask Completed");
Console.WriteLine("EmptyNode Completed");
```

#### Custom
Expand All @@ -128,10 +128,10 @@ Console.WriteLine("EmptyTask Completed");
using MaaFramework.Binding.Buffers;
using MaaFramework.Binding.Custom;

var taskName = "MyCustomTask";
var nodeName = "MyCustomTask";
var param = $$"""
{
"{{taskName}}": {
"{{nodeName}}": {
"recognition": "Custom",
"custom_recognition": "MyRec",
"custom_recognition_param": {
Expand All @@ -148,7 +148,7 @@ var param = $$"""

maa.Resource.Register(new MyRec());
maa.Resource.Register(new MyAct());
maa.AppendPipeline(taskName, param)
maa.AppendTask(nodeName, param)
.Wait()
.ThrowIfNot(MaaJobStatus.Succeeded);

Expand Down Expand Up @@ -177,8 +177,6 @@ internal sealed class MyAct : IMaaCustomAction

## Best Practices

- [MBA](https://github.com/MaaXYZ/MBA) BA Assistant
A BA Assistant based on MAA's new architecture. Image technology + simulation control, no more clicking! Powered by MaaFramework.
- [MFAWPF](https://github.com/SweetSmellFox/MFAWPF) MFA Task Manager
A Universal GUI based on MAA's new architecture. Powered by MaaFramework.

Expand Down
14 changes: 6 additions & 8 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dotnet add package Maa.Framework --prerelease -s https://nuget.pkg.github.com/ma
```

- NuGet.config
例子请参考[该配置](../NuGet.config),完整信息请参考[该文章](https://maaxyz.github.io/MaaFramework.Binding.CSharp/articles/preview.html)。
例子请参考[该配置](./NuGet.config),完整信息请参考[该文章](https://maaxyz.github.io/MaaFramework.Binding.CSharp/articles/preview.html)。

#### 指定 RIDs

Expand Down Expand Up @@ -115,11 +115,11 @@ using var maa = new MaaTasker
if (!maa.Initialized)
throw new InvalidOperationException();

maa.AppendPipeline("EmptyTask")
maa.AppendTask("EmptyNode")
.Wait()
.ThrowIfNot(MaaJobStatus.Succeeded);

Console.WriteLine("EmptyTask Completed");
Console.WriteLine("EmptyNode Completed");
```

#### 客制化
Expand All @@ -128,10 +128,10 @@ Console.WriteLine("EmptyTask Completed");
using MaaFramework.Binding.Buffers;
using MaaFramework.Binding.Custom;

var taskName = "MyCustomTask";
var nodeName = "MyCustomTask";
var param = $$"""
{
"{{taskName}}": {
"{{nodeName}}": {
"recognition": "Custom",
"custom_recognition": "MyRec",
"custom_recognition_param": {
Expand All @@ -148,7 +148,7 @@ var param = $$"""

maa.Resource.Register(new MyRec());
maa.Resource.Register(new MyAct());
maa.AppendPipeline(taskName, param)
maa.AppendTask(nodeName, param)
.Wait()
.ThrowIfNot(MaaJobStatus.Succeeded);

Expand Down Expand Up @@ -177,8 +177,6 @@ internal sealed class MyAct : IMaaCustomAction

## 最佳实践

- [MBA](https://github.com/MaaXYZ/MBA) BA 小助手
基于 MAA 全新架构的 BA 小助手。 图像技术 + 模拟控制,解放双手,不再点点点!由 MaaFramework 强力驱动!
- [MFAWPF](https://github.com/SweetSmellFox/MFAWPF) MFA 任务管理器
基于 MAA 全新架构的 通用 GUI。 由 MaaFramework 强力驱动!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ public record TaskerTaskDetail(
[property: JsonPropertyName("hash")] string Hash
);

/// <inheritdoc cref="MaaMsg.Task.NextList.Prefix"/>
public record TaskNextListDetail(
/// <inheritdoc cref="MaaMsg.Node.NextList.Prefix"/>
public record NodeNextListDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("list")] IReadOnlyList<string> NextList
);

/// <inheritdoc cref="MaaMsg.Task.Recognition.Prefix"/>
public record TaskRecognitionDetail(
/// <inheritdoc cref="MaaMsg.Node.Recognition.Prefix"/>
public record NodeRecognitionDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("reco_id")] int RecognitionId,
[property: JsonPropertyName("name")] string Name
);

/// <inheritdoc cref="MaaMsg.Task.Action.Prefix"/>
public record TaskActionDetail(
/// <inheritdoc cref="MaaMsg.Node.Action.Prefix"/>
public record NodeActionDetail(
[property: JsonPropertyName("task_id")] int TaskId,
[property: JsonPropertyName("node_id")] int NodeId,
[property: JsonPropertyName("name")] string Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace MaaFramework.Binding.Notification;
[JsonSerializable(typeof(ResourceLoadingDetail))]
[JsonSerializable(typeof(ControllerActionDetail))]
[JsonSerializable(typeof(TaskerTaskDetail))]
[JsonSerializable(typeof(TaskNextListDetail))]
[JsonSerializable(typeof(TaskRecognitionDetail))]
[JsonSerializable(typeof(TaskActionDetail))]
[JsonSerializable(typeof(NodeNextListDetail))]
[JsonSerializable(typeof(NodeRecognitionDetail))]
[JsonSerializable(typeof(NodeActionDetail))]
public partial class NotificationDetailContext : JsonSerializerContext { }
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ public static class NotificationHandlerExtensions
{
MaaMsg.Resource.Loading.Starting
or MaaMsg.Controller.Action.Starting
or MaaMsg.Task.Action.Starting
or MaaMsg.Task.NextList.Starting
or MaaMsg.Task.Recognition.Starting
or MaaMsg.Node.Action.Starting
or MaaMsg.Node.NextList.Starting
or MaaMsg.Node.Recognition.Starting
or MaaMsg.Tasker.Task.Starting
=> NotificationType.Starting,

MaaMsg.Resource.Loading.Succeeded
or MaaMsg.Controller.Action.Succeeded
or MaaMsg.Task.Action.Succeeded
or MaaMsg.Task.NextList.Succeeded
or MaaMsg.Task.Recognition.Succeeded
or MaaMsg.Node.Action.Succeeded
or MaaMsg.Node.NextList.Succeeded
or MaaMsg.Node.Recognition.Succeeded
or MaaMsg.Tasker.Task.Succeeded
=> NotificationType.Succeeded,

MaaMsg.Resource.Loading.Failed
or MaaMsg.Controller.Action.Failed
or MaaMsg.Task.Action.Failed
or MaaMsg.Task.NextList.Failed
or MaaMsg.Task.Recognition.Failed
or MaaMsg.Node.Action.Failed
or MaaMsg.Node.NextList.Failed
or MaaMsg.Node.Recognition.Failed
or MaaMsg.Tasker.Task.Failed
=> NotificationType.Failed,

Expand Down Expand Up @@ -86,15 +86,15 @@ public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHan
=> notify.ToCallback(MaaMsg.Tasker.Task.Prefix);

/// <inheritdoc cref="ToCallback{TDetail}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<TaskNextListDetail> notify)
=> notify.ToCallback(MaaMsg.Task.NextList.Prefix);
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodeNextListDetail> notify)
=> notify.ToCallback(MaaMsg.Node.NextList.Prefix);

/// <inheritdoc cref="ToCallback{TDetail}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<TaskRecognitionDetail> notify)
=> notify.ToCallback(MaaMsg.Task.Recognition.Prefix);
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodeRecognitionDetail> notify)
=> notify.ToCallback(MaaMsg.Node.Recognition.Prefix);

/// <inheritdoc cref="ToCallback{TDetail}"/>
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<TaskActionDetail> notify)
=> notify.ToCallback(MaaMsg.Task.Action.Prefix);
public static EventHandler<MaaCallbackEventArgs> ToCallback(this NotificationHandler<NodeActionDetail> notify)
=> notify.ToCallback(MaaMsg.Node.Action.Prefix);
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace MaaFramework.Binding.Interop.Native;
public static partial class MaaContext
{
[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
public static partial MaaTaskId MaaContextRunPipeline(MaaContextHandle context, string entry, string pipelineOverride);
public static partial MaaTaskId MaaContextRunTask(MaaContextHandle context, string entry, string pipelineOverride);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
public static partial MaaRecoId MaaContextRunRecognition(MaaContextHandle context, string entry, string pipelineOverride, MaaImageBufferHandle image);
Expand All @@ -32,7 +32,7 @@ public static partial class MaaContext

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool MaaContextOverrideNext(MaaContextHandle context, string name, MaaStringListBufferHandle nextList);
public static partial bool MaaContextOverrideNext(MaaContextHandle context, string nodeName, MaaStringListBufferHandle nextList);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
public static partial MaaTaskId MaaContextGetTaskId(MaaContextHandle context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static partial class MaaResource
public static partial bool MaaResourceClearCustomAction(MaaResourceHandle res);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
public static partial MaaResId MaaResourcePostPath(MaaResourceHandle res, string path);
public static partial MaaResId MaaResourcePostBundle(MaaResourceHandle res, string path);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
Expand All @@ -74,5 +74,5 @@ public static partial class MaaResource

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool MaaResourceGetTaskList(MaaResourceHandle res, MaaStringListBufferHandle buffer);
public static partial bool MaaResourceGetNodeList(MaaResourceHandle res, MaaStringListBufferHandle buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static partial class MaaTasker
public static partial bool MaaTaskerInited(MaaTaskerHandle tasker);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
public static partial MaaTaskId MaaTaskerPostPipeline(MaaTaskerHandle tasker, string entry, string pipelineOverride);
public static partial MaaTaskId MaaTaskerPostTask(MaaTaskerHandle tasker, string entry, string pipelineOverride);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
public static partial MaaStatus MaaTaskerStatus(MaaTaskerHandle tasker, MaaTaskId id);
Expand All @@ -67,17 +67,17 @@ public static partial class MaaTasker

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool MaaTaskerGetRecognitionDetail(MaaTaskerHandle tasker, MaaRecoId recoId, MaaStringBufferHandle name, MaaStringBufferHandle algorithm, [MarshalAs(UnmanagedType.U1)] out bool hit, MaaRectHandle box, MaaStringBufferHandle detailJson, MaaImageBufferHandle raw, MaaImageListBufferHandle draws);
public static partial bool MaaTaskerGetRecognitionDetail(MaaTaskerHandle tasker, MaaRecoId recoId, MaaStringBufferHandle nodeName, MaaStringBufferHandle algorithm, [MarshalAs(UnmanagedType.U1)] out bool hit, MaaRectHandle box, MaaStringBufferHandle detailJson, MaaImageBufferHandle raw, MaaImageListBufferHandle draws);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool MaaTaskerGetNodeDetail(MaaTaskerHandle tasker, MaaNodeId nodeId, MaaStringBufferHandle name, out MaaRecoId recoId, [MarshalAs(UnmanagedType.U1)] out bool completed);
public static partial bool MaaTaskerGetNodeDetail(MaaTaskerHandle tasker, MaaNodeId nodeId, MaaStringBufferHandle nodeName, out MaaRecoId recoId, [MarshalAs(UnmanagedType.U1)] out bool completed);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool MaaTaskerGetTaskDetail(MaaTaskerHandle tasker, MaaTaskId taskId, MaaStringBufferHandle entry, MaaNodeId[] nodeIdList, ref MaaSize nodeIdListSize, out MaaStatus status);

[LibraryImport("MaaFramework", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
public static partial bool MaaTaskerGetLatestNode(MaaTaskerHandle tasker, string taskName, out MaaNodeId latestId);
public static partial bool MaaTaskerGetLatestNode(MaaTaskerHandle tasker, string nodeName, out MaaNodeId latestId);
}
4 changes: 2 additions & 2 deletions src/MaaFramework.Binding.Native/Interop/Framework/MaaDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ namespace MaaFramework.Binding.Interop.Native;

[return: MarshalAs(UnmanagedType.U1)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool MaaCustomRecognitionCallback(MaaContextHandle context, MaaTaskId taskId, [MarshalAs(UnmanagedType.LPUTF8Str)] string currentTaskName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customRecognitionName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customRecognitionParam, MaaImageBufferHandle image, MaaRectHandle roi, nint transArg, MaaRectHandle outBox, MaaStringBufferHandle outDetail);
public delegate bool MaaCustomRecognitionCallback(MaaContextHandle context, MaaTaskId taskId, [MarshalAs(UnmanagedType.LPUTF8Str)] string nodeName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customRecognitionName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customRecognitionParam, MaaImageBufferHandle image, MaaRectHandle roi, nint transArg, MaaRectHandle outBox, MaaStringBufferHandle outDetail);

[return: MarshalAs(UnmanagedType.U1)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool MaaCustomActionCallback(MaaContextHandle context, MaaTaskId taskId, [MarshalAs(UnmanagedType.LPUTF8Str)] string currentTaskName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customActionName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customActionParam, MaaRecoId recoId, MaaRectHandle box, nint transArg);
public delegate bool MaaCustomActionCallback(MaaContextHandle context, MaaTaskId taskId, [MarshalAs(UnmanagedType.LPUTF8Str)] string nodeName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customActionName, [MarshalAs(UnmanagedType.LPUTF8Str)] string customActionParam, MaaRecoId recoId, MaaRectHandle box, nint transArg);

public static partial class MaaDef
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static MaaCustomActionCallback Convert(this IMaaCustomAction resource, ou
(
MaaContextHandle contextHandle,
MaaTaskId taskId,
string currentTaskName,
string nodeName,
string customActionName,
string customActionParam,
MaaRecoId recoId,
Expand All @@ -39,7 +39,7 @@ nint transArg
new RunArgs
(
TaskDetail: taskDetail,
TaskName: currentTaskName,
NodeName: nodeName,
ActionName: customActionName,
ActionParam: customActionParam,
RecognitionDetail: recognitionDetail,
Expand All @@ -63,7 +63,7 @@ public static MaaCustomRecognitionCallback Convert(this IMaaCustomRecognition re
(
MaaContextHandle contextHandle,
MaaTaskId taskId,
string currentTaskName,
string nodeName,
string customRecognitionName,
string customRecognitionParam,
MaaImageBufferHandle imageHandle,
Expand All @@ -82,7 +82,7 @@ MaaStringBufferHandle outDetailHandle
new AnalyzeArgs
(
TaskDetail: taskDetail,
TaskName: currentTaskName,
NodeName: nodeName,
RecognitionName: customRecognitionName,
RecognitionParam: customRecognitionParam,
Image: new MaaImageBuffer(imageHandle),
Expand Down
Loading
Loading