Skip to content

MaaFramework 的 C# 通用封装 | A common interoperable API wrapper around the MaaFramework for .NET 7+.

License

Notifications You must be signed in to change notification settings

MaaXYZ/MaaFramework.Binding.CSharp

Repository files navigation

LOGO

MaaFramework.Binding.CSharp

✨ The csharp binding of MaaFramework

💫 A common interoperable API wrapper 💫

license language platform Nuget (with prereleases)

English | 简体中文

Articles

Get Started

System Requirements

Your computer should meet the minimum system requirements before you run and use MaaFramework.Binding.CSharp, which might run on other platforms or versions not listed here.

OS Version Minimum Requirements / Reason
Windows 10+ Restricted from .NET 7.0
macOS 12+ Restricted from MaaFramework
Linux
Ubuntu 23.10+
libc6 2.38+
and more
Android Unknown
  • Architectures: X64, Arm64

Install Dependents

MaaFramework.Binding.CSharp needs the following dependencies installed to run properly.

Platform Package Id Dependent Download
Windows Maa.Framework
Maa.Framework.Runtimes
Maa.Framework.Runtime.win-arm64
Maa.Framework.Runtime.win-x64
Visual C++ Redistributable

Prepare Resources

See MaaFramework document ( English | 简体中文 ) .

Like this SampleResource in MaaFramework.Binding.CSharp.

Add Packages

Package Id Descriptions
Maa.Framework A metapackage with references to Native, Runtimes.
Maa.Framework.Native A metapackage with references to Binding.Native, AgentBinary.
Maa.Framework.Binding The abstractions of binding.
Maa.Framework.Binding.Native The native api wrapper implementation of binding.
Maa.Framework.Runtimes
Maa.Framework.Runtime.win-x64
Maa.Framework.Runtime.win-arm64
Maa.Framework.Runtime.linux-x64
Maa.Framework.Runtime.linux-arm64
Maa.Framework.Runtime.osx-x64
Maa.Framework.Runtime.osx-arm64
Maa.Framework.Runtime.android-x64
Maa.Framework.Runtime.android-arm64
Native binaries of MaaFramework.
No reference to android packages in Runtimes.
Maa.AgentBinary Pre-built agent binaries, including minitouch, maatouch and minicap.

Release

dotnet add package Maa.Framework --prerelease

Nightly Build

Add package
  • shell
dotnet add package Maa.Framework --prerelease -s https://nuget.pkg.github.com/maaxyz/index.json
Add package source
  • .csproj
  <PropertyGroup>
    <RestoreSources>$(RestoreSources);https://api.nuget.org/v3/index.json;https://maaxyz.github.io/pkg/nuget/index.json</RestoreSources>
  </PropertyGroup>

Specifying RIDs

The supported Runtime IDs for MaaFramework can be found here.

To use specific RIDs, such as the supported win platform packages, please manually reference the following packages:

  • Maa.Framework.Native
  • Maa.Framework.Runtime.win-arm64
  • Maa.Framework.Runtime.win-x64

Run Code

Pre-work: adb connect HOST[:PORT]

using MaaFramework.Binding;

var devices = new MaaToolkit(true).AdbDevice.Find();
if (devices.IsEmpty)
    throw new InvalidOperationException();

using var maa = new MaaTasker
{
    Controller = devices[0].ToAdbController(),
    Resource = new MaaResource("./SampleResource"),
    DisposeOptions = DisposeOptions.All,
};

if (!maa.Initialized)
    throw new InvalidOperationException();

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

Console.WriteLine("EmptyTask Completed");

Custom

using MaaFramework.Binding.Buffers;
using MaaFramework.Binding.Custom;

var taskName = "MyCustomTask";
var param = $$"""
{
  "{{taskName}}": {
      "recognition": "Custom",
      "custom_recognition": "MyRec",
      "custom_recognition_param": {
          "my_rec_key": "my_rec_value"
      },
      "action": "Custom",
      "custom_action": "MyAct",
      "custom_action_param": {
          "my_act_key": "my_act_value"
      }
  }
}
""";

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

internal sealed class MyRec : IMaaCustomRecognition
{
    public string Name { get; set; } = nameof(MyRec);

    public bool Analyze(in IMaaContext context, in AnalyzeArgs args, in AnalyzeResults results)
    {
        results.Box.SetValues(0, 0, 100, 100);
        results.Detail.SetValue("Hello World!");
        return true;
    }
}

internal sealed class MyAct : IMaaCustomAction
{
    public string Name { get; set; } = nameof(MyAct);

    public bool Run(in IMaaContext context, in RunArgs args)
    {
        return true;
    }
}

Best Practices

  • MBA BA Assistant A BA Assistant based on MAA's new architecture. Image technology + simulation control, no more clicking! Powered by MaaFramework.

  • MFAWPF MFA Task Manager A Universal GUI based on MAA's new architecture. Powered by MaaFramework.

  • You can also find more examples in the Unit Tests.

Documentation

We have written detailed documentation comments in source code files.

You can also visit API Reference and Unit Tests for more information.

If you still intend to use a API Reference specific to your preferred version of MaaFramework.Binding.CSharp, you may refer to the releases page of the project and download the attached docs.zip file.

Contributing

We welcome contributions to the MaaFramework.Binding.CSharp. If you find a bug or have a feature request, please open an issue on the GitHub repository. If you want to contribute code, feel free to fork the repository and submit a pull request.

License

MaaFramework is open-sourced under the LGPL-3.0 license.

Discussion

  • QQ Group: 595990173

About

MaaFramework 的 C# 通用封装 | A common interoperable API wrapper around the MaaFramework for .NET 7+.

Resources

License

Stars

Watchers

Forks

Languages