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; namespace RomCheater.Docking.MemorySearch { public partial class SearchPatcher : Form { //PCSX2MemoryProvider provider; private int pid = -1; SearchDataTypes DataType; bool Unsigned = false; public SearchPatcher(int pid, uint Address) { InitializeComponent(); this.pid = pid; txtAddress.Text = string.Format("0x{0:x8}", Address); } public SearchPatcher(int pid, uint Address, byte Value) : this(pid, Address) { Unsigned = true; DataType = SearchDataTypes._8bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x2}", Value); } public SearchPatcher(int pid, uint Address, sbyte Value) : this(pid, Address) { DataType = SearchDataTypes._8bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x2}", Value); } public SearchPatcher(int pid, uint Address, ushort Value) : this(pid, Address) { Unsigned = true; DataType = SearchDataTypes._16bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x4}", Value); } public SearchPatcher(int pid, uint Address, short Value) : this(pid, Address) { DataType = SearchDataTypes._16bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x4}", Value); } public SearchPatcher(int pid, uint Address, uint Value) : this(pid, Address) { Unsigned = true; DataType = SearchDataTypes._32bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x8}", Value); } public SearchPatcher(int pid, uint Address, int Value) : this(pid, Address) { DataType = SearchDataTypes._32bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x8}", Value); } public SearchPatcher(int pid, uint Address, ulong Value) : this(pid, Address) { Unsigned = true; DataType = SearchDataTypes._64bits; txtValue.CreateTypeSize(); txtValue.Text = string.Format("0x{0:x16}", Value); } public SearchPatcher(int pid, uint Address, long Value) : this(pid, 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) { uint Address = txtAddress.ToUInt32(); Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); reader.ReadProcess = Process.GetProcessById(pid); if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", pid); return; } switch (DataType) { case SearchDataTypes._8bits: if (Unsigned) { reader.PatchMemory(Address, txtValue.ToByte()); } else { reader.PatchMemory(Address, txtValue.ToSByte()); } break; case SearchDataTypes._16bits: if (Unsigned) { reader.PatchMemory(Address, txtValue.ToUInt16()); } else { reader.PatchMemory(Address, txtValue.ToInt16()); } break; case SearchDataTypes._32bits: if (Unsigned) { reader.PatchMemory(Address, txtValue.ToUInt32()); } else { reader.PatchMemory(Address, txtValue.ToInt32()); } break; case SearchDataTypes._64bits: if (Unsigned) { reader.PatchMemory(Address, txtValue.ToUInt64()); } else { reader.PatchMemory(Address, txtValue.ToInt64()); } break; } 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(); } } }