/[RomCheater]/trunk/RomCheater/Docking/MemorySearch/SearchPatcher.cs
ViewVC logotype

Contents of /trunk/RomCheater/Docking/MemorySearch/SearchPatcher.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 230 - (show annotations) (download)
Sat Jun 2 19:12:20 2012 UTC (8 years, 10 months ago) by william
File size: 5569 byte(s)
+ commit search wip

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using RomCheater.Docking.MemorySearch;
9 using System.Diagnostics;
10 using RomCheater.Logging;
11
12
13 namespace RomCheater.Docking.MemorySearch
14 {
15 public partial class SearchPatcher : Form
16 {
17 //PCSX2MemoryProvider provider;
18 private int pid = -1;
19 SearchDataTypes DataType;
20 bool Unsigned = false;
21 public SearchPatcher(int pid, uint Address)
22 {
23 InitializeComponent();
24 this.pid = pid;
25 txtAddress.Text = string.Format("0x{0:x8}", Address);
26 }
27 public SearchPatcher(int pid, uint Address, byte Value)
28 : this(pid, Address)
29 {
30 Unsigned = true;
31 DataType = SearchDataTypes._8bits;
32 txtValue.CreateTypeSize<byte>();
33 txtValue.Text = string.Format("0x{0:x2}", Value);
34 }
35 public SearchPatcher(int pid, uint Address, sbyte Value)
36 : this(pid, Address)
37 {
38 DataType = SearchDataTypes._8bits;
39 txtValue.CreateTypeSize<sbyte>();
40 txtValue.Text = string.Format("0x{0:x2}", Value);
41 }
42 public SearchPatcher(int pid, uint Address, ushort Value)
43 : this(pid, Address)
44 {
45 Unsigned = true;
46 DataType = SearchDataTypes._16bits;
47 txtValue.CreateTypeSize<ushort>();
48 txtValue.Text = string.Format("0x{0:x4}", Value);
49 }
50 public SearchPatcher(int pid, uint Address, short Value)
51 : this(pid, Address)
52 {
53 DataType = SearchDataTypes._16bits;
54 txtValue.CreateTypeSize<short>();
55 txtValue.Text = string.Format("0x{0:x4}", Value);
56 }
57 public SearchPatcher(int pid, uint Address, uint Value)
58 : this(pid, Address)
59 {
60 Unsigned = true;
61 DataType = SearchDataTypes._32bits;
62 txtValue.CreateTypeSize<uint>();
63 txtValue.Text = string.Format("0x{0:x8}", Value);
64 }
65 public SearchPatcher(int pid, uint Address, int Value)
66 : this(pid, Address)
67 {
68 DataType = SearchDataTypes._32bits;
69 txtValue.CreateTypeSize<int>();
70 txtValue.Text = string.Format("0x{0:x8}", Value);
71 }
72 public SearchPatcher(int pid, uint Address, ulong Value)
73 : this(pid, Address)
74 {
75 Unsigned = true;
76 DataType = SearchDataTypes._64bits;
77 txtValue.CreateTypeSize<ulong>();
78 txtValue.Text = string.Format("0x{0:x16}", Value);
79 }
80 public SearchPatcher(int pid, uint Address, long Value)
81 : this(pid, Address)
82 {
83 DataType = SearchDataTypes._64bits;
84 txtValue.CreateTypeSize<long>();
85 txtValue.Text = string.Format("0x{0:x16}", Value);
86 }
87 private void SearchPatcher_Load(object sender, EventArgs e)
88 {
89 txtAddress.ReadOnly = true;
90 txtValue.ReadOnly = false;
91 }
92 private void btnCancel_Click(object sender, EventArgs e)
93 {
94 this.Close();
95 }
96 private void btnOK_Click(object sender, EventArgs e)
97 {
98 uint Address = txtAddress.ToUInt32();
99
100 Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader();
101 reader.ReadProcess = Process.GetProcessById(pid);
102 if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", pid); return; }
103 switch (DataType)
104 {
105 case SearchDataTypes._8bits:
106 if (Unsigned) { reader.PatchMemory(Address, txtValue.ToByte()); }
107 else { reader.PatchMemory(Address, txtValue.ToSByte()); }
108 break;
109 case SearchDataTypes._16bits:
110 if (Unsigned) { reader.PatchMemory(Address, txtValue.ToUInt16()); }
111 else { reader.PatchMemory(Address, txtValue.ToInt16()); }
112 break;
113 case SearchDataTypes._32bits:
114 if (Unsigned) { reader.PatchMemory(Address, txtValue.ToUInt32()); }
115 else { reader.PatchMemory(Address, txtValue.ToInt32()); }
116 break;
117 case SearchDataTypes._64bits:
118 if (Unsigned) { reader.PatchMemory(Address, txtValue.ToUInt64()); }
119 else { reader.PatchMemory(Address, txtValue.ToInt64()); }
120 break;
121 }
122 this.Close();
123 }
124
125 private void CopyToClipboard(string data)
126 {
127 Clipboard.SetData(DataFormats.Text, data);
128 }
129
130 private void btnCopyAddressToClipboard_Click(object sender, EventArgs e)
131 {
132 this.CopyToClipboard(txtAddress.Text);
133 }
134
135 private void btnCopyvaluetoClipboard_Click(object sender, EventArgs e)
136 {
137 this.CopyToClipboard(txtValue.Text);
138 }
139
140 private void SearchPatcher_KeyDown(object sender, KeyEventArgs e)
141 {
142 if (e.KeyCode == Keys.Enter) btnOK.PerformClick();
143 }
144 }
145 }

  ViewVC Help
Powered by ViewVC 1.1.22