Skip to content

Commit

Permalink
chore: 更新至 Maa.Framework 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dissectum committed Jan 3, 2024
1 parent 5f1c993 commit 24538fb
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 145 deletions.
4 changes: 1 addition & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Maa.AgentBinary" Version="1.0.0" />
<PackageVersion Include="Maa.Framework.Runtimes" Version="0.3.7" />
<PackageVersion Include="Maa.ToolKit.Extensions" Version="1.0.0-beta.2.1" />
<PackageVersion Include="Maa.Framework" Version="1.4.0" />
<PackageVersion Include="Serilog" Version="3.0.1" />
<PackageVersion Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand Down
9 changes: 5 additions & 4 deletions src/MBA.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MBA.Core;
using MBA.Core.Data;
using MBA.Core.Enums;
using MBA.Core.Managers;
Expand Down Expand Up @@ -44,7 +45,7 @@ static int Main(string[] args)
return -1;
}

Core.Main.Current.Start();
Sensei.Agent.Start();

TipNewVersion();
TipPause();
Expand Down Expand Up @@ -305,10 +306,10 @@ static bool CheckAdbAddress(string value, out string result)
var parts = result.Split(':');
if (parts.Length != 2)
{
var count = MaaToolKit.Extensions.MaaTool.FindDevice(Config.Core.Adb);
for (ulong i = 0; i < count; i++)
var devices = Maa.Toolkit.Find(Config.Core.Adb);
foreach (var device in devices)
{
if (MaaToolKit.Extensions.MaaTool.GetDeviceAdbSerial(i) == value)
if (device.AdbSerial == value)
return true;
}
return false;
Expand Down
92 changes: 49 additions & 43 deletions src/MBA.Cli/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,85 +35,91 @@
"Serilog": "2.10.0"
}
},
"Maa.AgentBinary": {
"type": "Transitive",
"resolved": "1.0.0",
"contentHash": "09TsLd4LbaxoK68AZAg4MZFle/kkX8JZTbjRbkJYptyUCPCtdbVr8odukKG1CUzL4Wumbu+Fk7ppNX/OSlRMOA=="
},
"Maa.Framework.Binding": {
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "WODdI8FaiRdrfVtY8iuYuLsWcJ02Nf4AZsU89U4zw/08cdwI3SmlwZCRYtiNcUM/M7h9wSccuokdAxssIGd1mg=="
},
"Maa.Framework.Binding.Native": {
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "v5Fs+L0Aedg3ozD2ZTy61Q1/wOu/Ch2G0LYorygbY0Sz+1U97XcOf3oTF79T5rQKtyMMpqv+GA2LHmYoiWy6Gw==",
"dependencies": {
"Maa.Framework.Binding": "1.4.0",
"Maa.Framework.Runtimes": "1.4.0"
}
},
"Maa.Framework.Runtimes": {
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
},
"mba.core": {
"type": "Project",
"dependencies": {
"Maa.AgentBinary": "[1.0.0, )",
"Maa.ToolKit.Extensions": "[1.0.0-beta.2.1, )",
"Maa.Framework": "[1.4.0, )",
"Serilog": "[3.0.1, )",
"Serilog.Sinks.Console": "[4.1.0, )",
"Serilog.Sinks.Debug": "[2.0.0, )",
"Serilog.Sinks.File": "[5.0.0, )"
}
},
"Maa.AgentBinary": {
"type": "CentralTransitive",
"requested": "[1.0.0, )",
"resolved": "1.0.0",
"contentHash": "09TsLd4LbaxoK68AZAg4MZFle/kkX8JZTbjRbkJYptyUCPCtdbVr8odukKG1CUzL4Wumbu+Fk7ppNX/OSlRMOA=="
},
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
},
"Maa.ToolKit.Extensions": {
"Maa.Framework": {
"type": "CentralTransitive",
"requested": "[1.0.0-beta.2.1, )",
"resolved": "1.0.0-beta.2.1",
"contentHash": "thrl7AxC1syPjp3ls5BLaK3dnECjCcCJyLxAM42bqrMuoHqQ7E8gsrbOmy1w862CJYtSAdAVXY8HSa6PoeIH5w==",
"requested": "[1.4.0, )",
"resolved": "1.4.0",
"contentHash": "lDbbTkU06pjJPLChXaqE3vPeC1nfrU3wPkDvI32YD4HrNYZKpvl3LFNyF+6+vupbX4mRDsRge0KgKCiiEMljOw==",
"dependencies": {
"Maa.Framework.Runtimes": "1.0.0-beta.2"
"Maa.AgentBinary": "1.0.0",
"Maa.Framework.Binding.Native": "1.4.0"
}
}
},
"net7.0/linux-arm64": {
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
}
},
"net7.0/linux-x64": {
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
}
},
"net7.0/osx-arm64": {
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
}
},
"net7.0/osx-x64": {
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
}
},
"net7.0/win-arm64": {
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
}
},
"net7.0/win-x64": {
"Maa.Framework.Runtimes": {
"type": "CentralTransitive",
"requested": "[0.3.7, )",
"resolved": "1.0.0-beta.2",
"contentHash": "QKOddDHKVdSeps/l1qw8AAI4hxhGEisRNIZE8YEHVB1Q9vliM3Lo8C+UEOLdvWS7yZhUlRq9oUo7ju9hhOlk+A=="
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "d3ihdTmR9IejyMb/e7gWfjZ6jRchZaJ5GicK4p0ipC1za2oZ2Ji6zW5bX477Li4c14AfuEvl7CPG72rX5ezO0g=="
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/MBA.Core/Data/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MBA.Core.Enums;
using MaaToolKit.Extensions.Enums;
using MaaFramework.Binding;
using System.Text.Json.Serialization;

namespace MBA.Core.Data;
Expand Down Expand Up @@ -33,11 +33,11 @@ public class CoreConfig
{
public string Adb { get; set; } = "adb";
public string AdbAddress { get; set; } = "127.0.0.1:5555";
public AdbControllerType Touch { get; set; } = AdbControllerType.InputPresetAdb;
public AdbControllerType ScreenCap { get; set; } = AdbControllerType.ScreenCapRawWithGzip;
public AdbControllerTypes Touch { get; set; } = AdbControllerTypes.InputPresetAdb;
public AdbControllerTypes ScreenCap { get; set; } = AdbControllerTypes.ScreencapRawWithGzip;

[JsonIgnore]
public AdbControllerType ControlType => Touch | ScreenCap;
public AdbControllerTypes ControlType => Touch | ScreenCap;
}

public class GameConfig
Expand Down Expand Up @@ -93,8 +93,8 @@ public class ConfigDocument

public string Adb { get; } = "adb.exe 所在路径,相对绝对均可,例如 C:/adb.exe,不要有中文";
public string AdbAddress { get; } = "adb 连接地址,例如 127.0.0.1:5555";
public string Touch { get; } = $"点击方式:{AdbControllerType.InputPresetAdb}, {AdbControllerType.InputPresetMinitouch}, {AdbControllerType.InputPresetMaatouch}";
public string ScreenCap { get; } = $"截图方式:{AdbControllerType.ScreenCapFastestWay}, {AdbControllerType.ScreenCapRawByNetcat}, {AdbControllerType.ScreenCapRawWithGzip}, {AdbControllerType.ScreenCapEncode}, {AdbControllerType.ScreenCapEncodeToFile}, {AdbControllerType.ScreenCapMinicapDirect}, {AdbControllerType.ScreenCapMinicapStream}";
public string Touch { get; } = $"点击方式:{AdbControllerTypes.InputPresetAdb}, {AdbControllerTypes.InputPresetMinitouch}, {AdbControllerTypes.InputPresetMaatouch}";
public string ScreenCap { get; } = $"截图方式:{AdbControllerTypes.ScreencapFastestWay}, {AdbControllerTypes.ScreencapRawByNetcat}, {AdbControllerTypes.ScreencapRawWithGzip}, {AdbControllerTypes.ScreencapEncode}, {AdbControllerTypes.ScreencapEncodeToFile}, {AdbControllerTypes.ScreencapMinicapDirect}, {AdbControllerTypes.ScreencapMinicapStream}";

#endregion

Expand Down
2 changes: 0 additions & 2 deletions src/MBA.Core/Data/GlobalInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ public static class GlobalInfo
internal static readonly string BaseResourceFullPath = Path.GetFullPath(BaseResource);
internal static readonly string AdbConfigFileFullPath = Path.GetFullPath(AdbConfigFile);

internal static readonly int ScreenshotHeight = 720;

public static bool IsCli { get; set; }
}
20 changes: 0 additions & 20 deletions src/MBA.Core/Extensions/MaaJobStatusExtension.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/MBA.Core/MBA.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Maa.AgentBinary" />
<PackageReference Include="Maa.ToolKit.Extensions" />
<PackageReference Include="Maa.Framework" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/MBA.Core/Maa.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MaaFramework.Binding;

namespace MBA.Core;

public class Maa
{
public static MaaToolkit Toolkit { get; } = new();
public static MaaUtility Utility { get; } = new();
}
2 changes: 1 addition & 1 deletion src/MBA.Core/Managers/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ public static void LogConfig()
as JsonObject ?? new();
jsonObject.Remove(nameof(Config.Document));
jsonObject.Remove(nameof(Config.UI));
Log.Verbose("Current Config: {config}", jsonObject.ToString());
Log.Verbose("Native Config: {config}", jsonObject.ToString());
}
}
6 changes: 3 additions & 3 deletions src/MBA.Core/Managers/LogManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MaaToolKit.Extensions;
using MaaFramework.Binding;
using MBA.Core.Data;
using Serilog;
using Serilog.Core;
Expand Down Expand Up @@ -61,8 +61,8 @@ public static void ConfigureLogger(bool enableDebugMode, bool startLog = false)

private static void SetFrameworkLog(bool enableDebugMode)
{
MaaObject.FrameworkLogDir = GlobalInfo.DebugFullPath;
MaaObject.DebugMode = enableDebugMode;
Maa.Utility.SetOption(GlobalOption.LogDir, GlobalInfo.DebugFullPath);
Maa.Utility.SetOption(GlobalOption.SaveDraw, enableDebugMode);
}

private static bool _logStarted = false;
Expand Down
2 changes: 1 addition & 1 deletion src/MBA.Core/Managers/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void RunTask(
{
try
{
action();
action.Invoke();
}
catch (Exception e)
{
Expand Down
35 changes: 14 additions & 21 deletions src/MBA.Core/Main.cs → src/MBA.Core/Sensei.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
using MaaToolKit.Extensions;
using MaaToolKit.Extensions.Enums;
using MaaFramework.Binding;
using MBA.Core.Data;
using MBA.Core.Enums;
using MBA.Core.Managers;

namespace MBA.Core;

public class Main
public class Sensei
{
private static Serilog.ILogger Log => LogManager.Logger;

public static Main Current { get; } = new();
public static Sensei Agent { get; } = new();

// TODO: 去除静态
private static Config Config { get; } = ConfigManager.Config;

public void Start()
{
var location = $"{nameof(Main)}.{nameof(Start)}";
var location = $"{nameof(Sensei)}.{nameof(Start)}";

TaskManager.RunTask(() =>
{
// remark: lock config
ConfigManager.LogConfig();

// TODO: GetMaa 抛出的错误应该是可选择的
using var maa = GetMaa();
var tasks = GetTasks();
if (!maa.Instance.Initialized)
if (!maa.Initialized)
Log.Error("Failed to init Maa instance, a connection error or resource file corruption occurred, please refer to the log.");

if (TryRunTasks(maa, tasks))
Expand All @@ -38,19 +36,15 @@ public void Start()
location);
}

private MaaObject GetMaa()
private MaaInstance GetMaa()
{
var maa = new MaaObject(
Config.Core.Adb,
Config.Core.AdbAddress,
Config.Core.ControlType,
ConfigManager.AdbConfig,
GlobalInfo.BaseResourceFullPath,
$"{GlobalInfo.ResourceFullPath}/{Config.Game.Language}");
var maa = new MaaInstance
{
Controller = new MaaAdbController(Config.Core.Adb, Config.Core.AdbAddress, Config.Core.ControlType, ConfigManager.AdbConfig, "./MaaAgentBinary"),
Resource = new MaaResource(GlobalInfo.BaseResourceFullPath, $"{GlobalInfo.ResourceFullPath}/{Config.Game.Language}"),
DisposeOptions = DisposeOptions.All,
};

maa.Controller.SetOption(
ControllerOption.ScreenshotTargetShortSide,
GlobalInfo.ScreenshotHeight);
maa.Controller.SetOption(
ControllerOption.DefaultAppPackageEntry,
Config.Game.LanguageServer.GetPackageEntry());
Expand All @@ -66,7 +60,7 @@ private List<TaskType> GetTasks()
return configTasks;
}

private bool TryRunTasks(MaaObject maa, List<TaskType> tasks)
private bool TryRunTasks(MaaInstance maa, List<TaskType> tasks)
{
Log.Information("Task List: {list}.", tasks);
tasks.Replace(Config.Game.Server);
Expand All @@ -88,8 +82,7 @@ private bool TryRunTasks(MaaObject maa, List<TaskType> tasks)
continue;
}

var status = maa.Instance
.AppendTask(task.ToString(), diffTask)
var status = maa.AppendTask(task.ToString(), diffTask)
.Wait();

// TODO: MaaJob 和 MaaJobStatus 包含 任务名 及其参数
Expand Down
Loading

0 comments on commit 24538fb

Please sign in to comment.