mirror of
https://github.com/kwsch/NHSE.git
synced 2026-09-29 13:26:51 -05:00
Update to .NET 10 (#683)
This commit is contained in:
@@ -5,150 +5,149 @@
|
||||
using System.Windows.Forms;
|
||||
using NHSE.Core;
|
||||
|
||||
namespace NHSE.WinForms
|
||||
namespace NHSE.WinForms;
|
||||
|
||||
public partial class BatchEditor : Form
|
||||
{
|
||||
public partial class BatchEditor : Form
|
||||
private readonly ItemMutator Mutator;
|
||||
private readonly ItemProcessor Processor;
|
||||
private readonly IReadOnlyList<Item> Items;
|
||||
private readonly Item item;
|
||||
private int currentFormat = -1;
|
||||
|
||||
public BatchEditor(IReadOnlyList<Item> items, Item item)
|
||||
{
|
||||
private readonly ItemMutator Mutator;
|
||||
private readonly ItemProcessor Processor;
|
||||
private readonly IReadOnlyList<Item> Items;
|
||||
private readonly Item item;
|
||||
private int currentFormat = -1;
|
||||
InitializeComponent();
|
||||
Items = items;
|
||||
this.item = item;
|
||||
Mutator = new ItemMutator();
|
||||
Processor = new ItemProcessor(Mutator);
|
||||
|
||||
public BatchEditor(IReadOnlyList<Item> items, Item item)
|
||||
CB_Format.Items.Clear();
|
||||
CB_Format.Items.Add("Any");
|
||||
foreach (Type t in Mutator.Reflect.Types)
|
||||
CB_Format.Items.Add(t.Name.ToLower());
|
||||
CB_Format.Items.Add("All");
|
||||
|
||||
CB_Format.SelectedIndex = CB_Require.SelectedIndex = 0;
|
||||
toolTip1.SetToolTip(CB_Property, "Name");
|
||||
toolTip2.SetToolTip(L_PropType, "Type");
|
||||
toolTip3.SetToolTip(L_PropValue, "Value");
|
||||
}
|
||||
|
||||
private void SysBotRAMEdit_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void B_Go_Click(object sender, EventArgs e)
|
||||
{
|
||||
RunBackgroundWorker();
|
||||
}
|
||||
|
||||
private void B_Add_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CB_Property.SelectedIndex < 0)
|
||||
{ WinFormsUtil.Alert("Invalid Property"); return; }
|
||||
|
||||
var prefix = StringInstruction.Prefixes;
|
||||
string s = prefix[CB_Require.SelectedIndex] + CB_Property.Items[CB_Property.SelectedIndex]!.ToString() + StringInstruction.SplitInstruction;
|
||||
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines[^1].Length > 0)
|
||||
s = Environment.NewLine + s;
|
||||
|
||||
RTB_Instructions.AppendText(s);
|
||||
}
|
||||
|
||||
private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (currentFormat == CB_Format.SelectedIndex)
|
||||
return;
|
||||
|
||||
int format = CB_Format.SelectedIndex;
|
||||
CB_Property.Items.Clear();
|
||||
CB_Property.Items.AddRange(Mutator.Reflect.Properties[format]);
|
||||
CB_Property.SelectedIndex = 0;
|
||||
currentFormat = format;
|
||||
}
|
||||
|
||||
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
L_PropType.Text = Mutator.GetPropertyType(CB_Property.Text, CB_Format.SelectedIndex);
|
||||
if (Mutator.TryGetHasProperty(item, CB_Property.Text, out var pi))
|
||||
{
|
||||
InitializeComponent();
|
||||
Items = items;
|
||||
this.item = item;
|
||||
Mutator = new ItemMutator();
|
||||
Processor = new ItemProcessor(Mutator);
|
||||
|
||||
CB_Format.Items.Clear();
|
||||
CB_Format.Items.Add("Any");
|
||||
foreach (Type t in Mutator.Reflect.Types)
|
||||
CB_Format.Items.Add(t.Name.ToLower());
|
||||
CB_Format.Items.Add("All");
|
||||
|
||||
CB_Format.SelectedIndex = CB_Require.SelectedIndex = 0;
|
||||
toolTip1.SetToolTip(CB_Property, "Name");
|
||||
toolTip2.SetToolTip(L_PropType, "Type");
|
||||
toolTip3.SetToolTip(L_PropValue, "Value");
|
||||
L_PropValue.Text = pi.GetValue(item)?.ToString();
|
||||
L_PropType.ForeColor = L_PropValue.ForeColor; // reset color
|
||||
}
|
||||
|
||||
private void SysBotRAMEdit_FormClosing(object sender, FormClosingEventArgs e)
|
||||
else // no property, flag
|
||||
{
|
||||
}
|
||||
|
||||
private void B_Go_Click(object sender, EventArgs e)
|
||||
{
|
||||
RunBackgroundWorker();
|
||||
}
|
||||
|
||||
private void B_Add_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CB_Property.SelectedIndex < 0)
|
||||
{ WinFormsUtil.Alert("Invalid Property"); return; }
|
||||
|
||||
var prefix = StringInstruction.Prefixes;
|
||||
string s = prefix[CB_Require.SelectedIndex] + CB_Property.Items[CB_Property.SelectedIndex]!.ToString() + StringInstruction.SplitInstruction;
|
||||
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines.Last().Length > 0)
|
||||
s = Environment.NewLine + s;
|
||||
|
||||
RTB_Instructions.AppendText(s);
|
||||
}
|
||||
|
||||
private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (currentFormat == CB_Format.SelectedIndex)
|
||||
return;
|
||||
|
||||
int format = CB_Format.SelectedIndex;
|
||||
CB_Property.Items.Clear();
|
||||
CB_Property.Items.AddRange(Mutator.Reflect.Properties[format]);
|
||||
CB_Property.SelectedIndex = 0;
|
||||
currentFormat = format;
|
||||
}
|
||||
|
||||
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
L_PropType.Text = Mutator.GetPropertyType(CB_Property.Text, CB_Format.SelectedIndex);
|
||||
if (Mutator.TryGetHasProperty(item, CB_Property.Text, out var pi))
|
||||
{
|
||||
L_PropValue.Text = pi.GetValue(item)?.ToString();
|
||||
L_PropType.ForeColor = L_PropValue.ForeColor; // reset color
|
||||
}
|
||||
else // no property, flag
|
||||
{
|
||||
L_PropValue.Text = string.Empty;
|
||||
L_PropType.ForeColor = Color.Red;
|
||||
}
|
||||
}
|
||||
|
||||
private void RunBackgroundWorker()
|
||||
{
|
||||
if (RTB_Instructions.Lines.Any(line => line.Length == 0))
|
||||
{ WinFormsUtil.Error("Invalid instruction detected."); return; }
|
||||
|
||||
var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray();
|
||||
if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))))
|
||||
{ WinFormsUtil.Error("Filter empty."); return; }
|
||||
|
||||
if (sets.Any(z => z.Instructions.Count == 0))
|
||||
{ WinFormsUtil.Error("No instructions."); return; }
|
||||
|
||||
var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray();
|
||||
if (emptyVal.Length > 0)
|
||||
{
|
||||
string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
|
||||
string invalid = "Property empty." + Environment.NewLine + props;
|
||||
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, "Continue?"))
|
||||
return;
|
||||
}
|
||||
|
||||
RTB_Instructions.Enabled = B_Go.Enabled = false;
|
||||
RunBatchEdit(sets);
|
||||
}
|
||||
|
||||
private void RunBatchEdit(StringInstructionSet[] sets)
|
||||
{
|
||||
bool finished = false, displayed = false; // hack cuz DoWork event isn't cleared after completion
|
||||
b.DoWork += (sender, e) =>
|
||||
{
|
||||
if (finished)
|
||||
return;
|
||||
// don't bother reporting progress...
|
||||
Processor.Process(sets, Items);
|
||||
finished = true;
|
||||
};
|
||||
|
||||
b.ProgressChanged += (sender, e) => SetProgressBar(e.ProgressPercentage);
|
||||
b.RunWorkerCompleted += (sender, e) =>
|
||||
{
|
||||
string result = Processor.GetEditorResults(sets);
|
||||
if (!displayed) WinFormsUtil.Alert(result);
|
||||
displayed = true;
|
||||
RTB_Instructions.Enabled = B_Go.Enabled = true;
|
||||
SetupProgressBar(0);
|
||||
};
|
||||
b.RunWorkerAsync();
|
||||
}
|
||||
|
||||
// Progress Bar
|
||||
private void SetupProgressBar(int count)
|
||||
{
|
||||
MethodInvoker mi = () => { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; };
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke(mi);
|
||||
else
|
||||
mi.Invoke();
|
||||
}
|
||||
|
||||
private void SetProgressBar(int i)
|
||||
{
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = i));
|
||||
else
|
||||
PB_Show.Value = i;
|
||||
L_PropValue.Text = string.Empty;
|
||||
L_PropType.ForeColor = Color.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RunBackgroundWorker()
|
||||
{
|
||||
if (RTB_Instructions.Lines.Any(line => line.Length == 0))
|
||||
{ WinFormsUtil.Error("Invalid instruction detected."); return; }
|
||||
|
||||
var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray();
|
||||
if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))))
|
||||
{ WinFormsUtil.Error("Filter empty."); return; }
|
||||
|
||||
if (sets.Any(z => z.Instructions.Count == 0))
|
||||
{ WinFormsUtil.Error("No instructions."); return; }
|
||||
|
||||
var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray();
|
||||
if (emptyVal.Length > 0)
|
||||
{
|
||||
string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
|
||||
string invalid = "Property empty." + Environment.NewLine + props;
|
||||
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, "Continue?"))
|
||||
return;
|
||||
}
|
||||
|
||||
RTB_Instructions.Enabled = B_Go.Enabled = false;
|
||||
RunBatchEdit(sets);
|
||||
}
|
||||
|
||||
private void RunBatchEdit(StringInstructionSet[] sets)
|
||||
{
|
||||
bool finished = false, displayed = false; // hack cuz DoWork event isn't cleared after completion
|
||||
b.DoWork += (sender, e) =>
|
||||
{
|
||||
if (finished)
|
||||
return;
|
||||
// don't bother reporting progress...
|
||||
Processor.Process(sets, Items);
|
||||
finished = true;
|
||||
};
|
||||
|
||||
b.ProgressChanged += (sender, e) => SetProgressBar(e.ProgressPercentage);
|
||||
b.RunWorkerCompleted += (sender, e) =>
|
||||
{
|
||||
string result = Processor.GetEditorResults(sets);
|
||||
if (!displayed) WinFormsUtil.Alert(result);
|
||||
displayed = true;
|
||||
RTB_Instructions.Enabled = B_Go.Enabled = true;
|
||||
SetupProgressBar(0);
|
||||
};
|
||||
b.RunWorkerAsync();
|
||||
}
|
||||
|
||||
// Progress Bar
|
||||
private void SetupProgressBar(int count)
|
||||
{
|
||||
MethodInvoker mi = () => { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; };
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke(mi);
|
||||
else
|
||||
mi.Invoke();
|
||||
}
|
||||
|
||||
private void SetProgressBar(int i)
|
||||
{
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = i));
|
||||
else
|
||||
PB_Show.Value = i;
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,25 @@
|
||||
using NHSE.Core;
|
||||
using NHSE.Injection;
|
||||
|
||||
namespace NHSE.WinForms
|
||||
namespace NHSE.WinForms;
|
||||
|
||||
public partial class SimpleHexEditor : Form
|
||||
{
|
||||
public partial class SimpleHexEditor : Form
|
||||
public byte[] Bytes;
|
||||
|
||||
public SimpleHexEditor(byte[] originalBytes)
|
||||
{
|
||||
public byte[] Bytes;
|
||||
|
||||
public SimpleHexEditor(byte[] originalBytes)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
RTB_RAM.Text = string.Join(" ", originalBytes.Select(z => $"{z:X2}"));
|
||||
Bytes = originalBytes;
|
||||
}
|
||||
|
||||
private void Update_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
var bytestring = RTB_RAM.Text.Replace("\t", "").Replace(" ", "").Trim();
|
||||
Bytes = Decoder.StringToByteArray(bytestring);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
RTB_RAM.Text = string.Join(" ", originalBytes.Select(z => $"{z:X2}"));
|
||||
Bytes = originalBytes;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
var bytestring = RTB_RAM.Text.Replace("\t", "").Replace(" ", "").Trim();
|
||||
Bytes = Decoder.StringToByteArray(bytestring);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -3,109 +3,108 @@
|
||||
using NHSE.Injection;
|
||||
using NHSE.WinForms.Properties;
|
||||
|
||||
namespace NHSE.WinForms
|
||||
namespace NHSE.WinForms;
|
||||
|
||||
public class SysBotController
|
||||
{
|
||||
public class SysBotController
|
||||
public SysBotController(InjectionType type) => Type = type;
|
||||
|
||||
private readonly InjectionType Type;
|
||||
public readonly SysBot Bot = new();
|
||||
private readonly Settings Settings = Settings.Default;
|
||||
|
||||
public string IP => Settings.SysBotIP;
|
||||
public string Port => Settings.SysBotPort.ToString();
|
||||
|
||||
public bool Connect(string ip, string port)
|
||||
{
|
||||
public SysBotController(InjectionType type) => Type = type;
|
||||
if (!int.TryParse(port, out var p))
|
||||
p = 6000;
|
||||
|
||||
private readonly InjectionType Type;
|
||||
public readonly SysBot Bot = new();
|
||||
private readonly Settings Settings = Settings.Default;
|
||||
|
||||
public string IP => Settings.SysBotIP;
|
||||
public string Port => Settings.SysBotPort.ToString();
|
||||
|
||||
public bool Connect(string ip, string port)
|
||||
try
|
||||
{
|
||||
if (!int.TryParse(port, out var p))
|
||||
p = 6000;
|
||||
|
||||
try
|
||||
{
|
||||
Bot.Connect(ip, p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
var settings = Settings;
|
||||
settings.SysBotIP = ip;
|
||||
settings.SysBotPort = p;
|
||||
settings.Save();
|
||||
|
||||
return true;
|
||||
Bot.Connect(ip, p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
public uint GetDefaultOffset()
|
||||
{
|
||||
var settings = Settings;
|
||||
return Type switch
|
||||
{
|
||||
InjectionType.Generic => settings.SysBotGenericOffset,
|
||||
InjectionType.Pouch => settings.SysBotPouchOffset,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
var settings = Settings;
|
||||
settings.SysBotIP = ip;
|
||||
settings.SysBotPort = p;
|
||||
settings.Save();
|
||||
|
||||
public void SetOffset(uint value)
|
||||
{
|
||||
var settings = Settings;
|
||||
switch (Type)
|
||||
{
|
||||
case InjectionType.Generic: settings.SysBotGenericOffset = value; break;
|
||||
case InjectionType.Pouch: settings.SysBotPouchOffset = value; break;
|
||||
default: return;
|
||||
}
|
||||
settings.Save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void HexEdit(uint offset, int length)
|
||||
public uint GetDefaultOffset()
|
||||
{
|
||||
var settings = Settings;
|
||||
return Type switch
|
||||
{
|
||||
var read = ReadBytes(offset, length);
|
||||
using var ram = new SimpleHexEditor(read);
|
||||
if (ram.ShowDialog() != DialogResult.OK)
|
||||
InjectionType.Generic => settings.SysBotGenericOffset,
|
||||
InjectionType.Pouch => settings.SysBotPouchOffset,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
public void SetOffset(uint value)
|
||||
{
|
||||
var settings = Settings;
|
||||
switch (Type)
|
||||
{
|
||||
case InjectionType.Generic: settings.SysBotGenericOffset = value; break;
|
||||
case InjectionType.Pouch: settings.SysBotPouchOffset = value; break;
|
||||
default: return;
|
||||
}
|
||||
settings.Save();
|
||||
}
|
||||
|
||||
public void HexEdit(uint offset, int length)
|
||||
{
|
||||
var read = ReadBytes(offset, length);
|
||||
using var ram = new SimpleHexEditor(read);
|
||||
if (ram.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
var write = ram.Bytes;
|
||||
if (read.Length != write.Length)
|
||||
{
|
||||
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.OKCancel,
|
||||
string.Format(MessageStrings.MsgDataSizeMismatchRAM, read.Length, write.Length),
|
||||
MessageStrings.MsgAskWriteAnyway);
|
||||
|
||||
if (prompt != DialogResult.OK)
|
||||
return;
|
||||
|
||||
var write = ram.Bytes;
|
||||
if (read.Length != write.Length)
|
||||
{
|
||||
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.OKCancel,
|
||||
string.Format(MessageStrings.MsgDataSizeMismatchRAM, read.Length, write.Length),
|
||||
MessageStrings.MsgAskWriteAnyway);
|
||||
|
||||
if (prompt != DialogResult.OK)
|
||||
return;
|
||||
}
|
||||
|
||||
WriteBytes(ram.Bytes, offset);
|
||||
SetOffset(offset);
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
public void PopPrompt()
|
||||
{
|
||||
if (Settings.SysBotPrompted)
|
||||
return;
|
||||
WriteBytes(ram.Bytes, offset);
|
||||
SetOffset(offset);
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
WinFormsUtil.Alert(MessageStrings.MsgSysBotInfo, MessageStrings.MsgSysBotRequired);
|
||||
Settings.SysBotPrompted = true;
|
||||
Settings.Save();
|
||||
}
|
||||
public void PopPrompt()
|
||||
{
|
||||
if (Settings.SysBotPrompted)
|
||||
return;
|
||||
|
||||
public void WriteBytes(byte[] data, uint offset)
|
||||
{
|
||||
Bot.WriteBytes(data, offset);
|
||||
SetOffset(offset);
|
||||
}
|
||||
WinFormsUtil.Alert(MessageStrings.MsgSysBotInfo, MessageStrings.MsgSysBotRequired);
|
||||
Settings.SysBotPrompted = true;
|
||||
Settings.Save();
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(uint offset, int length)
|
||||
{
|
||||
var result = Bot.ReadBytes(offset, length);
|
||||
SetOffset(offset);
|
||||
return result;
|
||||
}
|
||||
public void WriteBytes(byte[] data, uint offset)
|
||||
{
|
||||
Bot.WriteBytes(data, offset);
|
||||
SetOffset(offset);
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(uint offset, int length)
|
||||
{
|
||||
var result = Bot.ReadBytes(offset, length);
|
||||
SetOffset(offset);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -3,57 +3,56 @@
|
||||
using NHSE.Core;
|
||||
using NHSE.Injection;
|
||||
|
||||
namespace NHSE.WinForms
|
||||
namespace NHSE.WinForms;
|
||||
|
||||
public partial class SysBotRAMEdit : Form
|
||||
{
|
||||
public partial class SysBotRAMEdit : Form
|
||||
private readonly SysBotController Bot;
|
||||
|
||||
public SysBotRAMEdit(InjectionType type)
|
||||
{
|
||||
private readonly SysBotController Bot;
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
Bot = new SysBotController(type);
|
||||
RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");
|
||||
|
||||
public SysBotRAMEdit(InjectionType type)
|
||||
TB_IP.Text = Bot.IP;
|
||||
TB_Port.Text = Bot.Port;
|
||||
Bot.PopPrompt();
|
||||
}
|
||||
|
||||
private void B_Connect_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Bot.Connect(TB_IP.Text, TB_Port.Text))
|
||||
return;
|
||||
GB_Inject.Enabled = true;
|
||||
}
|
||||
|
||||
private void SysBotRAMEdit_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (!Bot.Bot.Connected)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
Bot = new SysBotController(type);
|
||||
RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");
|
||||
|
||||
TB_IP.Text = Bot.IP;
|
||||
TB_Port.Text = Bot.Port;
|
||||
Bot.PopPrompt();
|
||||
Bot.Bot.Disconnect();
|
||||
}
|
||||
|
||||
private void B_Connect_Click(object sender, EventArgs e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!Bot.Connect(TB_IP.Text, TB_Port.Text))
|
||||
return;
|
||||
GB_Inject.Enabled = true;
|
||||
}
|
||||
|
||||
private void SysBotRAMEdit_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (!Bot.Bot.Connected)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Bot.Bot.Disconnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void B_Edit_Click(object sender, EventArgs e)
|
||||
{
|
||||
var offset = StringUtil.GetHexValue(RamOffset.Text);
|
||||
if (offset == 0)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
|
||||
return;
|
||||
}
|
||||
|
||||
var length = (int)NUD_Offset.Value;
|
||||
Bot.HexEdit(offset, length);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void B_Edit_Click(object sender, EventArgs e)
|
||||
{
|
||||
var offset = StringUtil.GetHexValue(RamOffset.Text);
|
||||
if (offset == 0)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
|
||||
return;
|
||||
}
|
||||
|
||||
var length = (int)NUD_Offset.Value;
|
||||
Bot.HexEdit(offset, length);
|
||||
}
|
||||
}
|
||||
@@ -3,207 +3,206 @@
|
||||
using NHSE.Core;
|
||||
using NHSE.Injection;
|
||||
|
||||
namespace NHSE.WinForms
|
||||
namespace NHSE.WinForms;
|
||||
|
||||
public partial class SysBotUI : Form
|
||||
{
|
||||
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, AutoInjector injectorUSB, USBBotController b)
|
||||
{
|
||||
private readonly AutoInjector Injector;
|
||||
private readonly SysBotController Bot;
|
||||
private readonly AutoInjector InjectorUSB;
|
||||
private readonly USBBotController BotUSB;
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
Bot = c;
|
||||
Injector = injector;
|
||||
BotUSB = b;
|
||||
InjectorUSB = injectorUSB;
|
||||
|
||||
public SysBotUI(AutoInjector injector, SysBotController c, AutoInjector injectorUSB, USBBotController b)
|
||||
var offset = Bot.GetDefaultOffset();
|
||||
Injector.SetWriteOffset(offset);
|
||||
RamOffset.Text = offset.ToString("X8");
|
||||
RamOffsetUSB.Text = offset.ToString("X8");
|
||||
|
||||
TB_IP.Text = Bot.IP;
|
||||
TB_Port.Text = Bot.Port;
|
||||
|
||||
Bot.PopPrompt();
|
||||
|
||||
TIM_Interval.Tick += (s, e) => injector.Read();
|
||||
}
|
||||
|
||||
private void B_Connect_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Bot.Connect(TB_IP.Text, TB_Port.Text))
|
||||
return;
|
||||
GB_Inject.Enabled = true;
|
||||
}
|
||||
|
||||
private void SysBotUI_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
TurnOffAuto();
|
||||
if (!Bot.Bot.Connected)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
InitializeComponent();
|
||||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
Bot = c;
|
||||
Injector = injector;
|
||||
BotUSB = b;
|
||||
InjectorUSB = injectorUSB;
|
||||
|
||||
var offset = Bot.GetDefaultOffset();
|
||||
Injector.SetWriteOffset(offset);
|
||||
RamOffset.Text = offset.ToString("X8");
|
||||
RamOffsetUSB.Text = offset.ToString("X8");
|
||||
|
||||
TB_IP.Text = Bot.IP;
|
||||
TB_Port.Text = Bot.Port;
|
||||
|
||||
Bot.PopPrompt();
|
||||
|
||||
TIM_Interval.Tick += (s, e) => injector.Read();
|
||||
Bot.Bot.Disconnect();
|
||||
}
|
||||
|
||||
private void B_Connect_Click(object sender, EventArgs e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!Bot.Connect(TB_IP.Text, TB_Port.Text))
|
||||
return;
|
||||
GB_Inject.Enabled = true;
|
||||
}
|
||||
|
||||
private void SysBotUI_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
TurnOffAuto();
|
||||
if (!Bot.Bot.Connected)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Bot.Bot.Disconnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void B_WriteCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
var offset = StringUtil.GetHexValue(RamOffset.Text);
|
||||
if (offset == 0)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
|
||||
return;
|
||||
}
|
||||
|
||||
Injector.SetWriteOffset(offset);
|
||||
|
||||
try
|
||||
{
|
||||
InjectionResult result;
|
||||
if (Injector.Injector is PocketInjector p)
|
||||
{
|
||||
p.SpoofInventoryWrite = ModifierKeys == Keys.Control;
|
||||
result = Injector.Write(true);
|
||||
p.SpoofInventoryWrite = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Injector.Write(true);
|
||||
}
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
}
|
||||
TurnOffAuto();
|
||||
}
|
||||
|
||||
private void B_ReadCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Injector.Read(true);
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
}
|
||||
TurnOffAuto();
|
||||
}
|
||||
|
||||
private void TurnOffAuto()
|
||||
{
|
||||
if (CHK_AutoRead.Checked)
|
||||
CHK_AutoRead.Checked = false;
|
||||
if (CHK_AutoWrite.Checked)
|
||||
CHK_AutoWrite.Checked = false;
|
||||
}
|
||||
|
||||
private void CHK_AutoWrite_CheckedChanged(object sender, EventArgs e) => Injector.AutoInjectEnabled = CHK_AutoWrite.Checked;
|
||||
private void CHK_AutoRead_CheckedChanged(object sender, EventArgs e) => TIM_Interval.Enabled = CHK_AutoRead.Checked;
|
||||
private void CHK_Validate_CheckedChanged(object sender, EventArgs e) => Injector.ValidateEnabled = CHK_Validate.Checked;
|
||||
|
||||
private void RamOffset_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
var offset = StringUtil.GetHexValue(RamOffset.Text);
|
||||
if (offset == 0)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
|
||||
return;
|
||||
}
|
||||
|
||||
Injector.SetWriteOffset(offset);
|
||||
Bot.SetOffset(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);
|
||||
Bot.SetOffset(offset);
|
||||
|
||||
try
|
||||
{
|
||||
var result = InjectorUSB.Read(true);
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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);
|
||||
Bot.SetOffset(offset);
|
||||
|
||||
try
|
||||
{
|
||||
var result = InjectorUSB.Write(true);
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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);
|
||||
Bot.SetOffset(offset);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void B_WriteCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
var offset = StringUtil.GetHexValue(RamOffset.Text);
|
||||
if (offset == 0)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
|
||||
return;
|
||||
}
|
||||
|
||||
Injector.SetWriteOffset(offset);
|
||||
|
||||
try
|
||||
{
|
||||
InjectionResult result;
|
||||
if (Injector.Injector is PocketInjector p)
|
||||
{
|
||||
p.SpoofInventoryWrite = ModifierKeys == Keys.Control;
|
||||
result = Injector.Write(true);
|
||||
p.SpoofInventoryWrite = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Injector.Write(true);
|
||||
}
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
}
|
||||
TurnOffAuto();
|
||||
}
|
||||
|
||||
private void B_ReadCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Injector.Read(true);
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
}
|
||||
TurnOffAuto();
|
||||
}
|
||||
|
||||
private void TurnOffAuto()
|
||||
{
|
||||
if (CHK_AutoRead.Checked)
|
||||
CHK_AutoRead.Checked = false;
|
||||
if (CHK_AutoWrite.Checked)
|
||||
CHK_AutoWrite.Checked = false;
|
||||
}
|
||||
|
||||
private void CHK_AutoWrite_CheckedChanged(object sender, EventArgs e) => Injector.AutoInjectEnabled = CHK_AutoWrite.Checked;
|
||||
private void CHK_AutoRead_CheckedChanged(object sender, EventArgs e) => TIM_Interval.Enabled = CHK_AutoRead.Checked;
|
||||
private void CHK_Validate_CheckedChanged(object sender, EventArgs e) => Injector.ValidateEnabled = CHK_Validate.Checked;
|
||||
|
||||
private void RamOffset_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
var offset = StringUtil.GetHexValue(RamOffset.Text);
|
||||
if (offset == 0)
|
||||
{
|
||||
WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
|
||||
return;
|
||||
}
|
||||
|
||||
Injector.SetWriteOffset(offset);
|
||||
Bot.SetOffset(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);
|
||||
Bot.SetOffset(offset);
|
||||
|
||||
try
|
||||
{
|
||||
var result = InjectorUSB.Read(true);
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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);
|
||||
Bot.SetOffset(offset);
|
||||
|
||||
try
|
||||
{
|
||||
var result = InjectorUSB.Write(true);
|
||||
if (result == InjectionResult.Success)
|
||||
return;
|
||||
WinFormsUtil.Alert(result.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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);
|
||||
Bot.SetOffset(offset);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,50 @@
|
||||
using System;
|
||||
using NHSE.Injection;
|
||||
|
||||
namespace NHSE.WinForms
|
||||
namespace NHSE.WinForms;
|
||||
|
||||
public class USBBotController
|
||||
{
|
||||
public class USBBotController
|
||||
public readonly USBBot Bot = new();
|
||||
|
||||
public bool Connect()
|
||||
{
|
||||
public readonly USBBot Bot = new();
|
||||
|
||||
public bool Connect()
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
return Bot.Connect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
return false;
|
||||
}
|
||||
return Bot.Connect();
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
catch (Exception ex)
|
||||
{
|
||||
Bot.Disconnect();
|
||||
}
|
||||
|
||||
//todo: this
|
||||
//public uint GetDefaultOffset()
|
||||
//{
|
||||
// return Settings.Default.SysBotPouchOffset;
|
||||
//}
|
||||
|
||||
//public void PopPrompt()
|
||||
//{
|
||||
//}
|
||||
|
||||
public void WriteBytes(byte[] data, uint offset)
|
||||
{
|
||||
Bot.WriteBytes(data, offset);
|
||||
//SetOffset(offset);
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(uint offset, int length)
|
||||
{
|
||||
var result = Bot.ReadBytes(offset, length);
|
||||
//SetOffset(offset);
|
||||
return result;
|
||||
WinFormsUtil.Error(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
Bot.Disconnect();
|
||||
}
|
||||
|
||||
//todo: this
|
||||
//public uint GetDefaultOffset()
|
||||
//{
|
||||
// return Settings.Default.SysBotPouchOffset;
|
||||
//}
|
||||
|
||||
//public void PopPrompt()
|
||||
//{
|
||||
//}
|
||||
|
||||
public void WriteBytes(byte[] data, uint offset)
|
||||
{
|
||||
Bot.WriteBytes(data, offset);
|
||||
//SetOffset(offset);
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(uint offset, int length)
|
||||
{
|
||||
var result = Bot.ReadBytes(offset, length);
|
||||
//SetOffset(offset);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user