/[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 838 - (show annotations) (download)
Tue Sep 16 00:57:18 2014 UTC (6 years ago) by william
File size: 6850 byte(s)
+ add an icon resource

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 using Sojaner.MemoryScanner.MemoryProviers;
12
13 using RomCheater.Core;
14
15
16 namespace RomCheater.Docking.MemorySearch
17 {
18 public partial class SearchPatcher : Form,
19 IAcceptsPlugin<IConfigPlugin>,
20 IAcceptsProcess<Process>,
21 IAcceptsProcessAndConfig
22 {
23 #region IAcceptsProcess<Process> Members
24 public Process AcceptedProcess { get; set; }
25 #endregion
26 #region IAcceptsPlugin<IConfigPlugin> Members
27 public IConfigPlugin AcceptedPlugin { get; set; }
28 #endregion
29 //PCSX2MemoryProvider provider;
30 SearchDataTypes DataType;
31 bool Unsigned = false;
32 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address)
33 {
34 InitializeComponent();
35 this.Icon = Core.Properties.Resources.romcheater_icon;
36 this.AcceptedPlugin = pconfig.AcceptedPlugin;
37 this.AcceptedProcess = pconfig.AcceptedProcess;
38 txtValue.CreateTypeSize<uint>();
39 txtAddress.CreateTypeSize<ulong>();
40 txtAddress.Text = string.Format("0x{0:x16}", Address);
41 }
42 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, byte Value)
43 : this(pconfig, Address)
44 {
45 Unsigned = true;
46 DataType = SearchDataTypes._8bits;
47 txtValue.CreateTypeSize<byte>();
48 txtAddress.CreateTypeSize<ulong>();
49 txtValue.Text = string.Format("0x{0:x2}", Value);
50 }
51 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, sbyte Value)
52 : this(pconfig, Address)
53 {
54 DataType = SearchDataTypes._8bits;
55 txtValue.CreateTypeSize<sbyte>();
56 txtAddress.CreateTypeSize<ulong>();
57 txtValue.Text = string.Format("0x{0:x2}", Value);
58 }
59 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, ushort Value)
60 : this(pconfig, Address)
61 {
62 Unsigned = true;
63 DataType = SearchDataTypes._16bits;
64 txtValue.CreateTypeSize<ushort>();
65 txtAddress.CreateTypeSize<ulong>();
66 txtValue.Text = string.Format("0x{0:x4}", Value);
67 }
68 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, short Value)
69 : this(pconfig, Address)
70 {
71 DataType = SearchDataTypes._16bits;
72 txtValue.CreateTypeSize<short>();
73 txtAddress.CreateTypeSize<ulong>();
74 txtValue.Text = string.Format("0x{0:x4}", Value);
75 }
76 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, uint Value)
77 : this(pconfig, Address)
78 {
79 Unsigned = true;
80 DataType = SearchDataTypes._32bits;
81 txtValue.CreateTypeSize<uint>();
82 txtAddress.CreateTypeSize<ulong>();
83 txtValue.Text = string.Format("0x{0:x8}", Value);
84 }
85 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, int Value)
86 : this(pconfig, Address)
87 {
88 DataType = SearchDataTypes._32bits;
89 txtValue.CreateTypeSize<int>();
90 txtAddress.CreateTypeSize<ulong>();
91 txtValue.Text = string.Format("0x{0:x8}", Value);
92 }
93 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, ulong Value)
94 : this(pconfig, Address)
95 {
96 Unsigned = true;
97 DataType = SearchDataTypes._64bits;
98 txtValue.CreateTypeSize<ulong>();
99 txtAddress.CreateTypeSize<ulong>();
100 txtValue.Text = string.Format("0x{0:x16}", Value);
101 }
102 public SearchPatcher(IAcceptsProcessAndConfig pconfig, uint Address, long Value)
103 : this(pconfig, Address)
104 {
105 DataType = SearchDataTypes._64bits;
106 txtValue.CreateTypeSize<long>();
107 txtAddress.CreateTypeSize<ulong>();
108 txtValue.Text = string.Format("0x{0:x16}", Value);
109 }
110 private void SearchPatcher_Load(object sender, EventArgs e)
111 {
112 txtAddress.ReadOnly = true;
113 txtValue.ReadOnly = false;
114 }
115 private void btnCancel_Click(object sender, EventArgs e)
116 {
117 this.Close();
118 }
119 private void btnOK_Click(object sender, EventArgs e)
120 {
121 uint Address = txtAddress.ToUInt32();
122
123 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
124 {
125 provider.OpenProvider();
126 switch (DataType)
127 {
128 case SearchDataTypes._8bits:
129 if (Unsigned) { provider.PatchMemory(Address, txtValue.ToByte()); }
130 else { provider.PatchMemory(Address, txtValue.ToSByte()); }
131 break;
132 case SearchDataTypes._16bits:
133 if (Unsigned) { provider.PatchMemory(Address, txtValue.ToUInt16()); }
134 else { provider.PatchMemory(Address, txtValue.ToInt16()); }
135 break;
136 case SearchDataTypes._32bits:
137 if (Unsigned) { provider.PatchMemory(Address, txtValue.ToUInt32()); }
138 else { provider.PatchMemory(Address, txtValue.ToInt32()); }
139 break;
140 case SearchDataTypes._64bits:
141 if (Unsigned) { provider.PatchMemory(Address, txtValue.ToUInt64()); }
142 else { provider.PatchMemory(Address, txtValue.ToInt64()); }
143 break;
144 }
145 provider.CloseProvider();
146 }
147 this.Close();
148 }
149
150 private void CopyToClipboard(string data)
151 {
152 Clipboard.SetData(DataFormats.Text, data);
153 }
154
155 private void btnCopyAddressToClipboard_Click(object sender, EventArgs e)
156 {
157 this.CopyToClipboard(txtAddress.Text);
158 }
159
160 private void btnCopyvaluetoClipboard_Click(object sender, EventArgs e)
161 {
162 this.CopyToClipboard(txtValue.Text);
163 }
164
165 private void SearchPatcher_KeyDown(object sender, KeyEventArgs e)
166 {
167 if (e.KeyCode == Keys.Enter) btnOK.PerformClick();
168 }
169 }
170 }

  ViewVC Help
Powered by ViewVC 1.1.22