Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
moomiji committed Nov 18, 2023
1 parent 48b8476 commit 786c040
Show file tree
Hide file tree
Showing 28 changed files with 468 additions and 224 deletions.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,67 @@

- [MBA](https://github.com/MaaAssistantArknights/MBA) BA 小助手
基于 MAA 全新架构的 BA 小助手。图像技术 + 模拟控制,解放双手,不再点点点!由 MaaFramework 强力驱动!

## Wiki

对应版本 [v1.1.1](https://github.com/MaaAssistantArknights/MaaFramework/blob/v1.1.1)

Binding wrapper 实现 与 Api 一览

### Enums

| Wrapper | MaaDef |
| AdbControllerTypes | MaaAdbControllerTypeEnum |
| ControllerOption | MaaCtrlOptionEnum |
| DebuggingControllerTypes | MaaDebuggingControllerTypeEnum |
| GlobalOption | MaaGlobalOptionEnum |
| InstanceOption | MaaInstOptionEnum |
| MaaJobStatus | MaaStatusEnum |
| ResourceOption | MaaResOptionEnum |

CheckStatusOption
DisposeOptions
LinkOption

### IMaaCommon

| IMaaCommon.Callback | Occurs when MaaFramework calls back. |

### MaaJob

| Wrapper | FFI API |
| IMaaJob.Status | MaaControllerStatus <br> MaaResourceStatus <br> MaaTaskStatus |
| IMaaJob.Wait() | MaaControllerWait <br> MaaResourceWait <br> MaaWaitTask |
| IMaaJob.SetParam() | MaaSetTaskParam |

### MaaController

| Wrapper | FFI API |
| MaaController.MaaController() | MaaAdbControllerCreateV2 |
| MaaCustomController.MaaCustomController() | MaaCustomControllerCreate |
| MaaThriftController.MaaThriftController() | MaaThriftControllerCreate |
| MaaDebuggingController.MaaDebuggingController() | MaaDebuggingControllerCreate |
| IDisposable.Dispose() | MaaControllerDestroy |
| IMaaOption.SetOption() | MaaControllerSetOption |
| IMaaController.LinkStart() | MaaControllerPostConnection |
| IMaaController.Click() | MaaControllerPostClick |
| IMaaController.Swipe() | MaaControllerPostSwipe |
| IMaaController.PressKey() | MaaControllerPostPressKey |
| IMaaController.TouchDown() | MaaControllerPostTouchDown |
| IMaaController.TouchMove() | MaaControllerPostTouchMove |
| IMaaController.TouchUp() | MaaControllerPostTouchUp |
| IMaaController.Screencap() | MaaControllerPostScreencap |
| IMaaPost.SetParam() | Always return false. |
| IMaaPost.GetStatus() | MaaControllerStatus |
| IMaaPost.Wait() | MaaControllerWait |
| IMaaController.LinkStop() | MaaControllerConnected |
| IMaaController.GetImage() | MaaControllerGetImage |
| IMaaController.Uuid | MaaControllerGetUUID |

### MaaInstance

| Wrapper | FFI API |
| MaaInstance.MaaInstance() | MaaCreate |


### Buffers
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
using MaaFramework.Binding.Enums;
using MaaFramework.Binding.Interop.Framework;
using MaaFramework.Binding.Abstractions;
using MaaFramework.Binding.Native.Interop.Framework;
using System.Runtime.InteropServices;

namespace MaaFramework.Binding.Abstractions;
namespace MaaFramework.Binding.Native.Abstractions;

/// <summary>
/// A abstract class providing common members for <see cref="MaaController"/>, <see cref="MaaInstance"/> and <see cref="MaaResource"/>.
/// </summary>
public abstract class MaaCommon<T> : MaaOption<T>, IMaaPost, IDisposable where T : Enum
public abstract class MaaCommon<TEnum> : MaaOption<TEnum>, IMaaCommon, IDisposable where TEnum : Enum
{
/// <inheritdoc/>
~MaaCommon()
{
Dispose(false);
}

/// <inheritdoc/>
public void Dispose()
{
Expand All @@ -25,27 +19,13 @@ public void Dispose()
/// <inheritdoc/>
protected abstract void Dispose(bool disposing);

/// <inheritdoc/>
public abstract bool SetParam(MaaJob job, string param);

/// <inheritdoc/>
public abstract MaaJobStatus GetStatus(MaaJob job);

/// <inheritdoc/>
public abstract MaaJobStatus Wait(MaaJob job);

/// <summary>
/// Maa Callback delegate.
/// </summary>
public delegate void MaaCallback(string msg, string detailsJson, MaaCallbackTransparentArg identifier);

/// <summary>
/// Occurs when MaaFramework calls back.
/// </summary>
public event MaaCallback? Callback;
public event EventHandler<MaaCallbackEventArgs>? Callback;

/// <summary>
/// Raises the Startup event.
/// Raises the Callback event.
/// </summary>
/// <param name="msg"></param>
/// <param name="detail"></param>
Expand All @@ -55,22 +35,22 @@ public void Dispose()
/// </remarks>
protected virtual void OnCallback(MaaStringView msg, MaaStringView detail, MaaCallbackTransparentArg arg)
{
Callback?.Invoke(
Callback?.Invoke(this, new MaaCallbackEventArgs(
Marshal.PtrToStringUTF8(msg) ?? string.Empty,
Marshal.PtrToStringUTF8(detail) ?? "{}",
arg);
arg));
}

/// <summary>
/// A delegate to avoid garbage collection before MaaFramework calls <see cref="OnCallback"/>.
/// </summary>
internal readonly MaaApiCallback MaaApiCallback;
protected readonly MaaApiCallback maaApiCallback;

/// <summary>
/// Initialize <see cref="MaaApiCallback"/>
/// Initialize <see cref="maaApiCallback"/>.
/// </summary>
protected MaaCommon()
{
MaaApiCallback = OnCallback;
maaApiCallback = OnCallback;
}
}
20 changes: 8 additions & 12 deletions src/MaaFramework.Binding.Native/Abstractions/MaaOption.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
using static MaaFramework.Binding.Native.Interop.MaaDefConverter;
using MaaFramework.Binding.Abstractions;
using static MaaFramework.Binding.Native.Interop.MaaDefConverter;

namespace MaaFramework.Binding.Native.Abstractions;

/// <summary>
/// A abstract class providing common overloading members of SetOption method.
/// </summary>
public abstract class MaaOption<T> where T : Enum
public abstract class MaaOption<T> : IMaaOption<T> where T : Enum
{
/// <summary>
/// Sets value to a option.
/// </summary>
/// <param name="option">The option.</param>
/// <param name="value">The value.</param>
/// <returns>true if the option was setted successfully; otherwise, false.</returns>

/// <inheritdoc cref="SetOption(T, int)"/>
internal abstract bool SetOption(T option, MaaOptionValue[] value);

/// <inheritdoc cref="SetOption(T, MaaOptionValue[])"/>
/// <inheritdoc/>
public bool SetOption(T option, int value)
=> SetOption(option, value.ToMaaOptionValues());

/// <inheritdoc cref="SetOption(T, MaaOptionValue[])"/>
/// <inheritdoc/>
public bool SetOption(T option, bool value)
=> SetOption(option, value.ToMaaOptionValues());

/// <inheritdoc cref="SetOption(T, MaaOptionValue[])"/>
/// <exception cref="ArgumentException" />
/// <inheritdoc/>
public bool SetOption(T option, string value)
{
ArgumentException.ThrowIfNullOrEmpty(value);
Expand Down
17 changes: 0 additions & 17 deletions src/MaaFramework.Binding.Native/Interop/Framework/MaaDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@

global using int32_t = System.Int32;

// Consider using SafeHandle
using System.Runtime.InteropServices;

#pragma warning disable S1133 // Deprecated code should be removed
#pragma warning disable S4200 // Native methods should be wrapped
#pragma warning disable CA1401 // P/Invoke method should not be visible
Expand All @@ -80,17 +77,3 @@ public static class MaaDef
}

public delegate void MaaApiCallback(MaaStringView msg, MaaStringView details_json, MaaCallbackTransparentArg callback_arg);

[StructLayout(LayoutKind.Sequential)]
public struct MaaRect : IMaaDefStruct
{
public int32_t X;
public int32_t Y;
public int32_t Width;
public int32_t Height;
}

public interface IMaaDefStruct
{

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.InteropServices.Marshalling;
using System.Runtime.InteropServices;
using MaaFramework.Binding.Abstractions;

namespace MaaFramework.Binding.Native.Interop.Framework;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.InteropServices.Marshalling;
using System.Runtime.InteropServices;
using MaaFramework.Binding.Abstractions;

namespace MaaFramework.Binding.Native.Interop.Framework;

Expand Down
Loading

0 comments on commit 786c040

Please sign in to comment.