Skip to content

Commit

Permalink
Automatically detect game version
Browse files Browse the repository at this point in the history
  • Loading branch information
LegoFigure11 committed Dec 3, 2022
1 parent ee742f2 commit e1976ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 20 additions & 1 deletion MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SysBot.Base;
using System.Data;
using System.Net.Sockets;
using static RaidCrawler.Structures.Offsets;
using static SysBot.Base.SwitchButton;

namespace RaidCrawler
Expand Down Expand Up @@ -93,6 +94,22 @@ private async void Connect()
SwitchConnection.Connect();
ConnectionStatusText.Text = "Connected!";
IsReading = true;
string id = await GetGameID(CancellationToken.None);
if (id is ScarletID)
{
Game.SelectedIndex = Game.FindString("Scarlet");
}
else if (id is VioletID)
{
Game.SelectedIndex = Game.FindString("Violet");
}
else
{
MessageBox.Show("Unable to detect Pokémon Scarlet or Pokémon Violet running on your switch!");
Disconnect();
IsReading = false;
}

await ReadRaids(CancellationToken.None);
IsReading = false;
ButtonAdvanceDate.Enabled = true;
Expand Down Expand Up @@ -338,6 +355,8 @@ private static async Task PressAndHold(SwitchButton b, int hold, int delay, Canc
await Task.Delay(delay, token).ConfigureAwait(false);
}

private static async Task<string> GetGameID(CancellationToken token) => await SwitchConnection.GetTitleID(token).ConfigureAwait(false);

private async Task AdvanceDate(CancellationToken token)
{
ConnectionStatusText.Text = "Changing date...";
Expand Down Expand Up @@ -413,7 +432,7 @@ private async void ButtonReadRaids_Click(object sender, EventArgs e)
private async Task ReadRaids(CancellationToken token)
{
ConnectionStatusText.Text = "Parsing pointer...";
offset = await OffsetUtil.GetPointerAddress(Offsets.RaidBlockPointer, CancellationToken.None);
offset = await OffsetUtil.GetPointerAddress(RaidBlockPointer, CancellationToken.None);

Raids.Clear();
index = 0;
Expand Down
3 changes: 3 additions & 0 deletions Structures/Offsets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace RaidCrawler.Structures
{
internal class Offsets
{
public const string ScarletID = "0100A3D008C5C000";
public const string VioletID = "01008F6008C5E000";

public const string RaidBlockPointer = "[[main+4384B18]+180]+40";
}

Expand Down

0 comments on commit e1976ac

Please sign in to comment.