/[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 239 - (show annotations) (download)
Sun Jun 3 12:51:40 2012 UTC (8 years, 10 months ago) by william
File size: 5440 byte(s)
+ implement GenericMemoryProvider : NOTE: config is null

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

  ViewVC Help
Powered by ViewVC 1.1.22