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

Release

Nuget (with prereleases)

dotnet add package Maa.Framework --prerelease

Nightly Build

Download nupkgs.zip from CI Action and extract files to .\nupkgs\.

  • shell
dotnet add package Maa.Framework --prerelease -s .\nupkgs\
  • or .csproj
  <PropertyGroup>
    <RestoreSources>$(RestoreSources);$(FullPath of .\nupkgs\)</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, 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).Device.Find();
if (devices.Length < 1)
    throw new InvalidOperationException();

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

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

maa.AppendTask("EmptyTask")
   .Wait()
   .ThrowIfNot(MaaJobStatus.Success);

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.Register(new MyRec());
maa.Register(new MyAct());
maa.AppendTask(taskName, param)
    .Wait()
    .ThrowIfNot(MaaJobStatus.Success);

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

    public bool Analyze(in IMaaSyncContext syncContext, IMaaImageBuffer image, string taskName, string customRecognitionParam, in IMaaRectBuffer outBox, in IMaaStringBuffer outDetail)
    {
        outBox.SetValues(0, 0, 100, 100);
        outDetail.SetValue("Hello World!");
        return true;
    }
}

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

    public void Abort() { }

    public bool Run(in IMaaSyncContext syncContext, string taskName, string customActionParam, IMaaRectBuffer curBox, string curRecDetail)
    {
        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