using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using RomCheater.Docking.MemorySearch; using System.Diagnostics; using RomCheater.Logging; using Sojaner.MemoryScanner.MemoryProviers; using RomCheater.PluginFramework.Interfaces; namespace RomCheater.Docking.MemorySearch { public partial class SearchPatcher : Form, IAcceptsPlugin, IAcceptsProcess, IAcceptsProcessAndConfig { #region IAcceptsProcess Members public Process AcceptedProcess { get; set; } #endregion #region IAcceptsPlugin Members public IConfigPlugin AcceptedPlugin { get; set; } #endregion //PCSX2MemoryProvider provider; SearchDataTypes DataType; bool Unsigned = false; public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address) { InitializeComponent(); this.AcceptedPlugin = pconfig.AcceptedPlugin; this.AcceptedProcess = pconfig.AcceptedProcess; txtAddress.Text = string.Format("0x{0:x8}", Address); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, byte Value) : this(pconfig, Address) { Unsigned = true; DataType = SearchDataTypes._8bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x2}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, sbyte Value) : this(pconfig, Address) { DataType = SearchDataTypes._8bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x2}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, ushort Value) : this(pconfig, Address) { Unsigned = true; DataType = SearchDataTypes._16bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x4}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, short Value) : this(pconfig, Address) { DataType = SearchDataTypes._16bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x4}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, uint Value) : this(pconfig, Address) { Unsigned = true; DataType = SearchDataTypes._32bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x8}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, int Value) : this(pconfig, Address) { DataType = SearchDataTypes._32bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x8}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, ulong Value) : this(pconfig, Address) { Unsigned = true; DataType = SearchDataTypes._64bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x16}", Value); } public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, long Value) : this(pconfig, Address) { DataType = SearchDataTypes._64bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x16}", Value); } private void SearchPatcher_Load(object sender, EventArgs e) { txtAddress.ReadOnly = true; txtValue.ReadOnly = false; } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void btnOK_Click(object sender, EventArgs e) { int Address = txtAddress.ToInt32(); GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); provider.OpenProvider(); switch (DataType) { case SearchDataTypes._8bits: if (Unsigned) { provider.PatchMemory(Address, txtValue.ToByte()); } else { provider.PatchMemory(Address, txtValue.ToSByte()); } break; case SearchDataTypes._16bits: if (Unsigned) { provider.PatchMemory(Address, txtValue.ToUInt16()); } else { provider.PatchMemory(Address, txtValue.ToInt16()); } break; case SearchDataTypes._32bits: if (Unsigned) { provider.PatchMemory(Address, txtValue.ToUInt32()); } else { provider.PatchMemory(Address, txtValue.ToInt32()); } break; case SearchDataTypes._64bits: if (Unsigned) { provider.PatchMemory(Address, txtValue.ToUInt64()); } else { provider.PatchMemory(Address, txtValue.ToInt64()); } break; } provider.CloseProvider(); this.Close(); } private void CopyToClipboard(string data) { Clipboard.SetData(DataFormats.Text, data); } private void btnCopyAddressToClipboard_Click(object sender, EventArgs e) { this.CopyToClipboard(txtAddress.Text); } private void btnCopyvaluetoClipboard_Click(object sender, EventArgs e) { this.CopyToClipboard(txtValue.Text); } private void SearchPatcher_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) btnOK.PerformClick(); } } }