Added support for USB-botbase (#299)

Only for player item injection at this time; no sync / toggle between modes
This commit is contained in:
berichan
2020-06-06 20:58:13 +01:00
committed by GitHub
parent 48fbca6b96
commit e0e4dd508c
9 changed files with 386 additions and 5 deletions

View File

@@ -9,13 +9,17 @@ public partial class SysBotUI : Form
{
private readonly AutoInjector Injector;
private readonly SysBotController Bot;
private readonly AutoInjector InjectorUSB;
private readonly USBBotController BotUSB;
public SysBotUI(AutoInjector injector, SysBotController c)
public SysBotUI(AutoInjector injector, SysBotController c, AutoInjector injectorUSB, USBBotController b)
{
InitializeComponent();
this.TranslateInterface(GameInfo.CurrentLanguage);
Bot = c;
Injector = injector;
BotUSB = b;
InjectorUSB = injectorUSB;
var offset = Bot.GetDefaultOffset();
Injector.SetWriteOffset(offset);
@@ -122,5 +126,79 @@ private void RamOffset_TextChanged(object sender, EventArgs e)
Injector.SetWriteOffset(offset);
}
private void ReadUSB_Click(object sender, EventArgs e)
{
if (!BotUSB.Connect())
return;
var offset = StringUtil.GetHexValue(RamOffsetUSB.Text);
if (offset == 0)
{
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
return;
}
InjectorUSB.SetWriteOffset(offset);
try
{
var result = InjectorUSB.Read(true);
if (result == InjectionResult.Success)
return;
WinFormsUtil.Alert(result.ToString());
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
WinFormsUtil.Error(ex.Message);
}
BotUSB.Disconnect();
}
private void WriteUSB_Click(object sender, EventArgs e)
{
if (!BotUSB.Connect())
return;
var offset = StringUtil.GetHexValue(RamOffsetUSB.Text);
if (offset == 0)
{
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
return;
}
InjectorUSB.SetWriteOffset(offset);
try
{
var result = InjectorUSB.Write(true);
if (result == InjectionResult.Success)
return;
WinFormsUtil.Alert(result.ToString());
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
WinFormsUtil.Error(ex.Message);
}
BotUSB.Disconnect();
}
private void RamOffsetUSB_TextChanged(object sender, EventArgs e)
{
var offset = StringUtil.GetHexValue(RamOffsetUSB.Text);
if (offset == 0)
{
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
return;
}
Injector.SetWriteOffset(offset);
}
}
}