diff --git a/NHSE.WinForms/NHSE.WinForms.csproj b/NHSE.WinForms/NHSE.WinForms.csproj index 267b24e..844170b 100644 --- a/NHSE.WinForms/NHSE.WinForms.csproj +++ b/NHSE.WinForms/NHSE.WinForms.csproj @@ -16,6 +16,7 @@ + diff --git a/NHSE.WinForms/Properties/Settings.Designer.cs b/NHSE.WinForms/Properties/Settings.Designer.cs index 7bbda3b..d516fcd 100644 --- a/NHSE.WinForms/Properties/Settings.Designer.cs +++ b/NHSE.WinForms/Properties/Settings.Designer.cs @@ -34,5 +34,41 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio this["LastFilePath"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("192.168.0.1")] + public string SysBotIP { + get { + return ((string)(this["SysBotIP"])); + } + set { + this["SysBotIP"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("6000")] + public int SysBotPort { + get { + return ((int)(this["SysBotPort"])); + } + set { + this["SysBotPort"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("2889584832")] + public uint SysBotPouchOffset { + get { + return ((uint)(this["SysBotPouchOffset"])); + } + set { + this["SysBotPouchOffset"] = value; + } + } } } diff --git a/NHSE.WinForms/Properties/Settings.settings b/NHSE.WinForms/Properties/Settings.settings index 1aaa44d..12d49a6 100644 --- a/NHSE.WinForms/Properties/Settings.settings +++ b/NHSE.WinForms/Properties/Settings.settings @@ -5,5 +5,14 @@ + + 192.168.0.1 + + + 6000 + + + 2889584832 + \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/SysBotUI.Designer.cs b/NHSE.WinForms/Subforms/SysBotUI.Designer.cs new file mode 100644 index 0000000..f9fa45e --- /dev/null +++ b/NHSE.WinForms/Subforms/SysBotUI.Designer.cs @@ -0,0 +1,181 @@ +namespace NHSE.WinForms +{ + partial class SysBotUI + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.B_Connect = new System.Windows.Forms.Button(); + this.L_Port = new System.Windows.Forms.Label(); + this.TB_Port = new System.Windows.Forms.TextBox(); + this.L_IP = new System.Windows.Forms.Label(); + this.TB_IP = new System.Windows.Forms.TextBox(); + this.GB_Inject = new System.Windows.Forms.GroupBox(); + this.RamOffset = new System.Windows.Forms.TextBox(); + this.L_Offset = new System.Windows.Forms.Label(); + this.B_ReadCurrent = new System.Windows.Forms.Button(); + this.B_WriteCurrent = new System.Windows.Forms.Button(); + this.GB_Inject.SuspendLayout(); + this.SuspendLayout(); + // + // B_Connect + // + this.B_Connect.Location = new System.Drawing.Point(102, 37); + this.B_Connect.Name = "B_Connect"; + this.B_Connect.Size = new System.Drawing.Size(63, 23); + this.B_Connect.TabIndex = 12; + this.B_Connect.Text = "Connect"; + this.B_Connect.UseVisualStyleBackColor = true; + this.B_Connect.Click += new System.EventHandler(this.B_Connect_Click); + // + // L_Port + // + this.L_Port.Location = new System.Drawing.Point(13, 38); + this.L_Port.Name = "L_Port"; + this.L_Port.Size = new System.Drawing.Size(40, 20); + this.L_Port.TabIndex = 11; + this.L_Port.Text = "Port:"; + this.L_Port.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // TB_Port + // + this.TB_Port.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TB_Port.Location = new System.Drawing.Point(54, 38); + this.TB_Port.Name = "TB_Port"; + this.TB_Port.Size = new System.Drawing.Size(42, 20); + this.TB_Port.TabIndex = 10; + this.TB_Port.Text = "6000"; + // + // L_IP + // + this.L_IP.Location = new System.Drawing.Point(13, 12); + this.L_IP.Name = "L_IP"; + this.L_IP.Size = new System.Drawing.Size(40, 20); + this.L_IP.TabIndex = 9; + this.L_IP.Text = "IP:"; + this.L_IP.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // TB_IP + // + this.TB_IP.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TB_IP.Location = new System.Drawing.Point(54, 12); + this.TB_IP.Name = "TB_IP"; + this.TB_IP.Size = new System.Drawing.Size(111, 20); + this.TB_IP.TabIndex = 8; + this.TB_IP.Text = "111.111.111.111"; + // + // GB_Inject + // + this.GB_Inject.Controls.Add(this.RamOffset); + this.GB_Inject.Controls.Add(this.L_Offset); + this.GB_Inject.Controls.Add(this.B_ReadCurrent); + this.GB_Inject.Controls.Add(this.B_WriteCurrent); + this.GB_Inject.Enabled = false; + this.GB_Inject.Location = new System.Drawing.Point(16, 66); + this.GB_Inject.Name = "GB_Inject"; + this.GB_Inject.Size = new System.Drawing.Size(149, 74); + this.GB_Inject.TabIndex = 13; + this.GB_Inject.TabStop = false; + this.GB_Inject.Text = "Injector"; + // + // RamOffset + // + this.RamOffset.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.RamOffset.Location = new System.Drawing.Point(72, 19); + this.RamOffset.MaxLength = 8; + this.RamOffset.Name = "RamOffset"; + this.RamOffset.Size = new System.Drawing.Size(63, 20); + this.RamOffset.TabIndex = 20; + this.RamOffset.Text = "AC3B90C0"; + // + // L_Offset + // + this.L_Offset.Location = new System.Drawing.Point(3, 18); + this.L_Offset.Name = "L_Offset"; + this.L_Offset.Size = new System.Drawing.Size(63, 20); + this.L_Offset.TabIndex = 19; + this.L_Offset.Text = "Offset:"; + this.L_Offset.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // B_ReadCurrent + // + this.B_ReadCurrent.Location = new System.Drawing.Point(18, 41); + this.B_ReadCurrent.Name = "B_ReadCurrent"; + this.B_ReadCurrent.Size = new System.Drawing.Size(56, 23); + this.B_ReadCurrent.TabIndex = 0; + this.B_ReadCurrent.Text = "Read"; + this.B_ReadCurrent.UseVisualStyleBackColor = true; + this.B_ReadCurrent.Click += new System.EventHandler(this.B_ReadCurrent_Click); + // + // B_WriteCurrent + // + this.B_WriteCurrent.Location = new System.Drawing.Point(80, 41); + this.B_WriteCurrent.Name = "B_WriteCurrent"; + this.B_WriteCurrent.Size = new System.Drawing.Size(56, 23); + this.B_WriteCurrent.TabIndex = 1; + this.B_WriteCurrent.Text = "Write"; + this.B_WriteCurrent.UseVisualStyleBackColor = true; + this.B_WriteCurrent.Click += new System.EventHandler(this.B_WriteCurrent_Click); + // + // SysBotUI + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(184, 151); + this.Controls.Add(this.GB_Inject); + this.Controls.Add(this.B_Connect); + this.Controls.Add(this.L_Port); + this.Controls.Add(this.TB_Port); + this.Controls.Add(this.L_IP); + this.Controls.Add(this.TB_IP); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Icon = global::NHSE.WinForms.Properties.Resources.icon; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SysBotUI"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "SysBotUI"; + this.GB_Inject.ResumeLayout(false); + this.GB_Inject.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button B_Connect; + private System.Windows.Forms.Label L_Port; + private System.Windows.Forms.TextBox TB_Port; + private System.Windows.Forms.Label L_IP; + private System.Windows.Forms.TextBox TB_IP; + private System.Windows.Forms.GroupBox GB_Inject; + private System.Windows.Forms.Button B_ReadCurrent; + private System.Windows.Forms.Button B_WriteCurrent; + private System.Windows.Forms.TextBox RamOffset; + private System.Windows.Forms.Label L_Offset; + } +} \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/SysBotUI.cs b/NHSE.WinForms/Subforms/SysBotUI.cs new file mode 100644 index 0000000..79bc0aa --- /dev/null +++ b/NHSE.WinForms/Subforms/SysBotUI.cs @@ -0,0 +1,119 @@ +using System; +using System.Windows.Forms; +using NHSE.Injection; +using NHSE.WinForms.Properties; + +namespace NHSE.WinForms +{ + public partial class SysBotUI : Form + { + private readonly Func ByteFetch; + private readonly Action ByteSet; + private readonly InjectionType Type; + private readonly SysBot Bot = new SysBot(); + private readonly Settings Settings = Settings.Default; + + public SysBotUI(Action read, Func write, InjectionType type) + { + InitializeComponent(); + ByteFetch = write; + ByteSet = read; + Type = type; + RamOffset.Text = GetOffset(type).ToString("X8"); + + TB_IP.Text = Settings.SysBotIP; + TB_Port.Text = Settings.SysBotPort.ToString(); + } + + private uint GetOffset(InjectionType type) + { + var settings = Settings; + return type switch + { + _ => settings.SysBotPouchOffset, + }; + } + + private void SetOffset(InjectionType type, uint value) + { + var settings = Settings; + settings.SysBotPouchOffset = type switch + { + _ => value, + }; + settings.Save(); + } + + private void B_Connect_Click(object sender, EventArgs e) + { + var ip = TB_IP.Text; + var port = TB_Port.Text; + if (!int.TryParse(port, out var p)) + p = 6000; + + try + { + Bot.Connect(ip, p); + } +#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); + return; + } + + var settings = Settings; + settings.SysBotIP = ip; + settings.SysBotPort = p; + settings.Save(); + + GB_Inject.Enabled = true; + } + + private void B_WriteCurrent_Click(object sender, EventArgs e) + { + if (!uint.TryParse(RamOffset.Text, out var offset)) + { + WinFormsUtil.Error("Incorrect hex offset."); + return; + } + + try + { + var data = ByteFetch(); + Bot.WriteBytes(data, offset); + SetOffset(Type, offset); + } +#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); + } + } + + private void B_ReadCurrent_Click(object sender, EventArgs e) + { + if (!uint.TryParse(RamOffset.Text, out var offset)) + { + WinFormsUtil.Error("Incorrect hex offset."); + return; + } + + try + { + var data = ByteFetch(); + var result = Bot.ReadBytes(offset, data.Length); + ByteSet(result); + SetOffset(Type, offset); + } +#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); + } + } + } +} diff --git a/NHSE.WinForms/Subforms/SysBotUI.resx b/NHSE.WinForms/Subforms/SysBotUI.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/NHSE.WinForms/Subforms/SysBotUI.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file