Add generic RAM read/write form

accessible once a save is loaded, same as item injecting

untested, but should be fine
This commit is contained in:
Kurt 2020-04-01 16:29:56 -07:00
parent 5578f4898b
commit ebfd2ca87f
18 changed files with 834 additions and 138 deletions

View File

@ -38,5 +38,14 @@ private static byte DecodeTuple(char _0, char _1)
throw new ArgumentOutOfRangeException(nameof(_1));
return result;
}
public static byte[] StringToByteArray(string hex)
{
int NumberChars = hex.Length;
byte[] bytes = new byte[NumberChars / 2];
for (int i = 0; i < NumberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
}
}

View File

@ -78,6 +78,7 @@ public void WriteBytes(byte[] data, uint offset)
public enum InjectionType
{
Generic,
Pouch,
}
}

View File

@ -86,6 +86,7 @@ private void InitializeComponent()
this.Tab_Map = new System.Windows.Forms.TabPage();
this.B_EditBuildings = new System.Windows.Forms.Button();
this.B_RecycleBin = new System.Windows.Forms.Button();
this.Menu_RAMEdit = new System.Windows.Forms.ToolStripMenuItem();
this.Menu_Editor.SuspendLayout();
this.TC_Editors.SuspendLayout();
this.Tab_Players.SuspendLayout();
@ -148,7 +149,8 @@ private void InitializeComponent()
this.Menu_Tools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.Menu_DumpDecrypted,
this.Menu_VerifyHashes,
this.Menu_LoadDecrypted});
this.Menu_LoadDecrypted,
this.Menu_RAMEdit});
this.Menu_Tools.Name = "Menu_Tools";
this.Menu_Tools.Size = new System.Drawing.Size(46, 20);
this.Menu_Tools.Text = "Tools";
@ -729,6 +731,14 @@ private void InitializeComponent()
this.B_RecycleBin.UseVisualStyleBackColor = true;
this.B_RecycleBin.Click += new System.EventHandler(this.B_RecycleBin_Click);
//
// Menu_RAMEdit
//
this.Menu_RAMEdit.Name = "Menu_RAMEdit";
this.Menu_RAMEdit.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.H)));
this.Menu_RAMEdit.Size = new System.Drawing.Size(206, 22);
this.Menu_RAMEdit.Text = "RAM Edit";
this.Menu_RAMEdit.Click += new System.EventHandler(this.Menu_RAMEdit_Click);
//
// Editor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -828,6 +838,7 @@ private void InitializeComponent()
private System.Windows.Forms.PictureBox PB_Palette;
private System.Windows.Forms.Button B_EditBuildings;
private System.Windows.Forms.Button B_EditActivities;
private System.Windows.Forms.ToolStripMenuItem Menu_RAMEdit;
}
}

View File

@ -5,6 +5,7 @@
using System.Linq;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Injection;
using NHSE.Sprites;
namespace NHSE.WinForms
@ -66,6 +67,19 @@ private void Menu_VerifyHashes_Click(object sender, EventArgs e)
Clipboard.SetText(string.Join(Environment.NewLine, lines));
}
private void Menu_RAMEdit_Click(object sender, EventArgs e)
{
var exist = WinFormsUtil.FirstFormOfType<SysBotRAMEdit>();
if (exist != null)
{
exist.Show();
return;
}
var sysbot = new SysBotRAMEdit(InjectionType.Generic);
sysbot.Show();
}
private void LoadAll()
{
LoadPlayers();

View File

@ -52,6 +52,9 @@
<Compile Update="Subforms\ActivityEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Subforms\SysBot\SysBotRAMEdit.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(Configuration)' == 'Release'">

View File

@ -82,5 +82,17 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
this["SysBotPouchOffset"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2889584832")]
public uint SysBotGenericOffset {
get {
return ((uint)(this["SysBotGenericOffset"]));
}
set {
this["SysBotGenericOffset"] = value;
}
}
}
}

View File

@ -17,5 +17,8 @@
<Setting Name="SysBotPouchOffset" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2889584832</Value>
</Setting>
<Setting Name="SysBotGenericOffset" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2889584832</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,83 @@
using System.Windows.Forms;
namespace NHSE.WinForms
{
partial class SimpleHexEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.RTB_RAM = new System.Windows.Forms.RichTextBox();
this.B_Update = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// RTB_RAM
//
this.RTB_RAM.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.RTB_RAM.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.RTB_RAM.Location = new System.Drawing.Point(9, 10);
this.RTB_RAM.Name = "RTB_RAM";
this.RTB_RAM.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical;
this.RTB_RAM.Size = new System.Drawing.Size(364, 292);
this.RTB_RAM.TabIndex = 0;
this.RTB_RAM.Text = "";
//
// B_Update
//
this.B_Update.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.B_Update.Location = new System.Drawing.Point(9, 308);
this.B_Update.Name = "B_Update";
this.B_Update.Size = new System.Drawing.Size(363, 26);
this.B_Update.TabIndex = 1;
this.B_Update.Text = "Update";
this.B_Update.UseVisualStyleBackColor = true;
this.B_Update.Click += new System.EventHandler(this.Update_Click);
//
// SimpleHexEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(384, 343);
this.Controls.Add(this.B_Update);
this.Controls.Add(this.RTB_RAM);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SimpleHexEditor";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "RAM Edit";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox RTB_RAM;
private Button B_Update;
}
}

View File

@ -0,0 +1,26 @@
using System.Linq;
using System.Windows.Forms;
using NHSE.Injection;
namespace NHSE.WinForms
{
public partial class SimpleHexEditor : Form
{
public byte[] Bytes;
public SimpleHexEditor(byte[] originalBytes)
{
InitializeComponent();
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();
}
}
}

View File

@ -0,0 +1,105 @@
using System;
using System.Windows.Forms;
using NHSE.Injection;
using NHSE.WinForms.Properties;
namespace NHSE.WinForms
{
public class SysBotController
{
public SysBotController(InjectionType type) => Type = type;
private readonly InjectionType Type;
private readonly SysBot Bot = new SysBot();
private readonly Settings Settings = Settings.Default;
public string IP => Settings.SysBotIP;
public string Port => Settings.SysBotPort.ToString();
public bool Connect(string ip, string port)
{
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 false;
}
var settings = Settings;
settings.SysBotIP = ip;
settings.SysBotPort = p;
settings.Save();
return true;
}
public uint GetDefaultOffset()
{
var settings = Settings;
return Type switch
{
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 data = ReadBytes(offset, length);
using var ram = new SimpleHexEditor(data);
if (ram.ShowDialog() != DialogResult.OK)
return;
WriteBytes(data, offset);
SetOffset(offset);
System.Media.SystemSounds.Asterisk.Play();
}
public void PopPrompt()
{
if (Settings.SysBotPrompted)
return;
const string info = "This SysBot reads and writes RAM directly to your game when called to Read/Write.";
const string reqd = "Using this functionality requires the sys-botbase sysmodule running on the console." +
"Your console must be on the same network as the PC running this program.";
WinFormsUtil.Alert(info, reqd);
Settings.SysBotPrompted = true;
Settings.Save();
}
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;
}
}
}

View File

@ -0,0 +1,203 @@
namespace NHSE.WinForms
{
partial class SysBotRAMEdit
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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.NUD_Offset = new System.Windows.Forms.NumericUpDown();
this.L_Length = new System.Windows.Forms.Label();
this.RamOffset = new System.Windows.Forms.TextBox();
this.L_Offset = new System.Windows.Forms.Label();
this.B_Edit = new System.Windows.Forms.Button();
this.GB_Inject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_Offset)).BeginInit();
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.NUD_Offset);
this.GB_Inject.Controls.Add(this.L_Length);
this.GB_Inject.Controls.Add(this.RamOffset);
this.GB_Inject.Controls.Add(this.L_Offset);
this.GB_Inject.Controls.Add(this.B_Edit);
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(210, 67);
this.GB_Inject.TabIndex = 13;
this.GB_Inject.TabStop = false;
this.GB_Inject.Text = "Injector";
//
// numericUpDown1
//
this.NUD_Offset.Location = new System.Drawing.Point(73, 39);
this.NUD_Offset.Maximum = new decimal(new int[] {
8192,
0,
0,
0});
this.NUD_Offset.Name = "NUD_Offset";
this.NUD_Offset.Size = new System.Drawing.Size(63, 20);
this.NUD_Offset.TabIndex = 22;
this.NUD_Offset.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.NUD_Offset.Value = new decimal(new int[] {
1024,
0,
0,
0});
//
// L_Length
//
this.L_Length.Location = new System.Drawing.Point(5, 37);
this.L_Length.Name = "L_Length";
this.L_Length.Size = new System.Drawing.Size(63, 20);
this.L_Length.TabIndex = 21;
this.L_Length.Text = "Length:";
this.L_Length.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// 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(73, 15);
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(4, 14);
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_Edit
//
this.B_Edit.Location = new System.Drawing.Point(142, 15);
this.B_Edit.Name = "B_Edit";
this.B_Edit.Size = new System.Drawing.Size(56, 44);
this.B_Edit.TabIndex = 0;
this.B_Edit.Text = "Edit";
this.B_Edit.UseVisualStyleBackColor = true;
this.B_Edit.Click += new System.EventHandler(this.B_Edit_Click);
//
// SysBotRAMEdit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(234, 140);
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 = "SysBotRAMEdit";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SysBotUI";
this.GB_Inject.ResumeLayout(false);
this.GB_Inject.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.NUD_Offset)).EndInit();
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_Edit;
private System.Windows.Forms.TextBox RamOffset;
private System.Windows.Forms.Label L_Offset;
private System.Windows.Forms.Label L_Length;
private System.Windows.Forms.NumericUpDown NUD_Offset;
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Injection;
namespace NHSE.WinForms
{
public partial class SysBotRAMEdit : Form
{
private readonly SysBotController Bot;
public SysBotRAMEdit(InjectionType type)
{
InitializeComponent();
Bot = new SysBotController(type);
RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");
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 B_Edit_Click(object sender, EventArgs e)
{
var offset = StringUtil.GetHexValue(RamOffset.Text);
if (offset == 0)
{
WinFormsUtil.Error("Incorrect hex offset.");
return;
}
var length = (int)NUD_Offset.Value;
Bot.HexEdit(offset, length);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,80 @@
using System;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Injection;
namespace NHSE.WinForms
{
public partial class SysBotUI : Form
{
private readonly Func<byte[]> ByteFetch;
private readonly Action<byte[]> ByteSet;
private readonly SysBotController Bot;
public SysBotUI(Action<byte[]> read, Func<byte[]> write, InjectionType type)
{
InitializeComponent();
Bot = new SysBotController(type);
ByteFetch = write;
ByteSet = read;
RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");
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 B_WriteCurrent_Click(object sender, EventArgs e)
{
var offset = StringUtil.GetHexValue(RamOffset.Text);
if (offset == 0)
{
WinFormsUtil.Error("Incorrect hex offset.");
return;
}
try
{
var data = ByteFetch();
Bot.WriteBytes(data, 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)
{
var offset = StringUtil.GetHexValue(RamOffset.Text);
if (offset == 0)
{
WinFormsUtil.Error("Incorrect hex offset.");
return;
}
try
{
var data = ByteFetch();
var result = Bot.ReadBytes(offset, data.Length);
ByteSet(result);
}
#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);
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,137 +0,0 @@
using System;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Injection;
using NHSE.WinForms.Properties;
namespace NHSE.WinForms
{
public partial class SysBotUI : Form
{
private readonly Func<byte[]> ByteFetch;
private readonly Action<byte[]> ByteSet;
private readonly InjectionType Type;
private readonly SysBot Bot = new SysBot();
private readonly Settings Settings = Settings.Default;
public SysBotUI(Action<byte[]> read, Func<byte[]> 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();
PopPrompt();
}
private void PopPrompt()
{
if (Settings.SysBotPrompted)
return;
const string info = "This SysBot reads and writes RAM directly to your game when called to Read/Write.";
const string reqd = "Using this functionality requires the sys-botbase sysmodule running on the console." +
"Your console must be on the same network as the PC running this program.";
WinFormsUtil.Alert(info, reqd);
Settings.SysBotPrompted = true;
Settings.Save();
}
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)
{
var offset = StringUtil.GetHexValue(RamOffset.Text);
if (offset == 0)
{
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)
{
var offset = StringUtil.GetHexValue(RamOffset.Text);
if (offset == 0)
{
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);
}
}
}
}