Skip to content

Commit 244006a

Browse files
committed
Add botbase version check
1 parent 711e617 commit 244006a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

HomeLive.DeviceExecutor/DeviceExecutor.cs

+28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using SysBot.Base;
2+
using System.Globalization;
23
using System.Text;
34

45
namespace HomeLive.DeviceExecutor;
@@ -19,6 +20,7 @@ public class DeviceState : BotState<RoutineType, SwitchConnectionConfig>
1920

2021
public class DeviceExecutor<T>(DeviceState cfg) : SwitchRoutineExecutor<T>(cfg) where T : DeviceState
2122
{
23+
private const decimal BotbaseVersion = 2.4m;
2224
private static ulong BoxStartAddress = 0;
2325

2426
public override string GetSummary()
@@ -37,6 +39,8 @@ public override async Task MainLoop(CancellationToken token)
3739
{
3840
try
3941
{
42+
var botbase = await VerifyBotbaseVersion(token).ConfigureAwait(false);
43+
Log($"Valid botbase version: {botbase}");
4044
(var title, var build) = await IsRunningHome(token).ConfigureAwait(false);
4145
Log($"Valid Title ID ({title})");
4246
Log($"Valid Build ID ({build})");
@@ -95,6 +99,30 @@ private async Task<string> GetBuildID(CancellationToken token)
9599
return str;
96100
}
97101

102+
//Thanks Anubis
103+
//https://github.com/kwsch/SysBot.NET/blob/b26c8c957364efe316573bec4b82e8c5c5a1a60f/SysBot.Pokemon/Actions/PokeRoutineExecutor.cs#L88
104+
//AGPL v3 License
105+
public async Task<string> VerifyBotbaseVersion(CancellationToken token)
106+
{
107+
if (Config.Connection.Protocol is SwitchProtocol.WiFi && !Connection.Connected)
108+
throw new InvalidOperationException("No remote connection");
109+
110+
var data = await SwitchConnection.GetBotbaseVersion(token).ConfigureAwait(false);
111+
var version = decimal.TryParse(data, CultureInfo.InvariantCulture, out var v) ? v : 0;
112+
if (version < BotbaseVersion)
113+
{
114+
var protocol = Config.Connection.Protocol;
115+
var msg = protocol is SwitchProtocol.WiFi ? "sys-botbase" : "usb-botbase";
116+
msg += $" version is not supported. Expected version {BotbaseVersion} or greater, and current version is {version}. Please download the latest version from: ";
117+
if (protocol is SwitchProtocol.WiFi)
118+
msg += "https://github.com/olliz0r/sys-botbase/releases/latest";
119+
else
120+
msg += "https://github.com/Koi-3088/usb-botbase/releases/latest";
121+
throw new Exception(msg);
122+
}
123+
return data;
124+
}
125+
98126
public async Task<ulong> GetBoxStartOffset(CancellationToken token)
99127
{
100128
if (!Connection.Connected)

0 commit comments

Comments
 (0)