1 |
william |
230 |
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.Logging; |
9 |
|
|
using System.Diagnostics; |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
namespace RomCheater.Docking.MemorySearch |
13 |
|
|
{ |
14 |
|
|
public partial class SearchRangePatcher : Form |
15 |
|
|
{ |
16 |
|
|
//PCSX2MemoryProvider provider; |
17 |
|
|
private int pid = -1; |
18 |
|
|
SearchDataTypes DataType; |
19 |
|
|
//bool Unsigned = false; |
20 |
|
|
private List<ResultDataType> PatchList; |
21 |
|
|
public SearchRangePatcher(int pid,List<ResultDataType> patchList) |
22 |
|
|
{ |
23 |
|
|
InitializeComponent(); |
24 |
|
|
this.pid = pid; |
25 |
|
|
PatchList = patchList; |
26 |
|
|
int CurrentBitSize = 0; |
27 |
|
|
// get the larget datatype |
28 |
|
|
foreach (ResultDataType patch in PatchList) |
29 |
|
|
{ |
30 |
|
|
if ((int)patch.ValueType > CurrentBitSize) |
31 |
|
|
{ |
32 |
|
|
CurrentBitSize = (int)patch.ValueType; |
33 |
|
|
} |
34 |
|
|
} |
35 |
|
|
switch (CurrentBitSize) |
36 |
|
|
{ |
37 |
|
|
case (int)SearchDataTypes._8bits: txtValue.CreateTypeSize<byte>(); break; |
38 |
|
|
case (int)SearchDataTypes._16bits: txtValue.CreateTypeSize<ushort>(); break; |
39 |
|
|
case (int)SearchDataTypes._32bits: txtValue.CreateTypeSize<uint>(); break; |
40 |
|
|
case (int)SearchDataTypes._64bits: txtValue.CreateTypeSize<ulong>(); break; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
private void SearchPatcher_Load(object sender, EventArgs e) |
46 |
|
|
{ |
47 |
|
|
txtValue.ReadOnly = false; |
48 |
|
|
} |
49 |
|
|
private void btnCancel_Click(object sender, EventArgs e) |
50 |
|
|
{ |
51 |
|
|
this.Close(); |
52 |
|
|
} |
53 |
|
|
private void btnOK_Click(object sender, EventArgs e) |
54 |
|
|
{ |
55 |
|
|
|
56 |
|
|
Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); |
57 |
|
|
reader.ReadProcess = Process.GetProcessById(pid); |
58 |
|
|
if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", pid); return; } |
59 |
|
|
foreach(ResultDataType patch in PatchList) |
60 |
|
|
{ |
61 |
|
|
switch (patch.ValueType) |
62 |
|
|
{ |
63 |
|
|
case SearchDataTypes._8bits: |
64 |
|
|
if (patch.IsUnsigned) { reader.PatchMemory(patch.Address, (byte)txtValue.Value); } |
65 |
|
|
else { reader.PatchMemory(patch.Address, (sbyte)txtValue.Value); } |
66 |
|
|
break; |
67 |
|
|
case SearchDataTypes._16bits: |
68 |
|
|
if (patch.IsUnsigned) { reader.PatchMemory(patch.Address, (ushort)txtValue.Value); } |
69 |
|
|
else { reader.PatchMemory(patch.Address, (short)txtValue.Value); } |
70 |
|
|
break; |
71 |
|
|
case SearchDataTypes._32bits: |
72 |
|
|
if (patch.IsUnsigned) { reader.PatchMemory(patch.Address, (uint)txtValue.Value); } |
73 |
|
|
else { reader.PatchMemory(patch.Address, (int)txtValue.Value); } |
74 |
|
|
break; |
75 |
|
|
case SearchDataTypes._64bits: |
76 |
|
|
if (patch.IsUnsigned) { reader.PatchMemory(patch.Address, (ulong)txtValue.Value); } |
77 |
|
|
else { reader.PatchMemory(patch.Address, (long)txtValue.Value); } |
78 |
|
|
break; |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
this.Close(); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
private void CopyToClipboard(string data) |
85 |
|
|
{ |
86 |
|
|
Clipboard.SetData(DataFormats.Text, data); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
private void btnCopyvaluetoClipboard_Click(object sender, EventArgs e) |
90 |
|
|
{ |
91 |
|
|
this.CopyToClipboard(txtValue.Text); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
private void SearchPatcher_KeyDown(object sender, KeyEventArgs e) |
95 |
|
|
{ |
96 |
|
|
if (e.KeyCode == Keys.Enter) btnOK.PerformClick(); |
97 |
|
|
} |
98 |
|
|
} |
99 |
|
|
} |