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

Annotation of /trunk/RomCheater/Docking/MemorySearch/SearchRangePatcher.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 245 - (hide annotations) (download)
Sun Jun 3 14:50:09 2012 UTC (8 years, 10 months ago) by william
File size: 4358 byte(s)
+ add exception logic to ensure provider is open

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 william 240 using Sojaner.MemoryScanner.MemoryProviers;
11 william 243 using RomCheater.PluginFramework.Interfaces;
12 william 230
13    
14     namespace RomCheater.Docking.MemorySearch
15     {
16 william 243 public partial class SearchRangePatcher : Form,
17     IAcceptsPlugin<IConfigPlugin>,
18     IAcceptsProcess<Process>,
19     IAcceptsProcessAndConfig
20 william 230 {
21 william 243 #region IAcceptsProcess<Process> Members
22     public Process AcceptedProcess { get; set; }
23     #endregion
24     #region IAcceptsPlugin<IConfigPlugin> Members
25     public IConfigPlugin AcceptedPlugin { get; set; }
26     #endregion
27 william 230 //PCSX2MemoryProvider provider;
28 william 243 //SearchDataTypes DataType;
29 william 230 //bool Unsigned = false;
30     private List<ResultDataType> PatchList;
31 william 243 public SearchRangePatcher(IAcceptsProcessAndConfig pconfig ,List<ResultDataType> patchList)
32 william 230 {
33     InitializeComponent();
34 william 243 this.AcceptedPlugin = pconfig.AcceptedPlugin;
35     this.AcceptedProcess = pconfig.AcceptedProcess;
36 william 230 PatchList = patchList;
37     int CurrentBitSize = 0;
38     // get the larget datatype
39     foreach (ResultDataType patch in PatchList)
40     {
41     if ((int)patch.ValueType > CurrentBitSize)
42     {
43     CurrentBitSize = (int)patch.ValueType;
44     }
45     }
46     switch (CurrentBitSize)
47     {
48     case (int)SearchDataTypes._8bits: txtValue.CreateTypeSize<byte>(); break;
49     case (int)SearchDataTypes._16bits: txtValue.CreateTypeSize<ushort>(); break;
50     case (int)SearchDataTypes._32bits: txtValue.CreateTypeSize<uint>(); break;
51     case (int)SearchDataTypes._64bits: txtValue.CreateTypeSize<ulong>(); break;
52     }
53    
54     }
55    
56     private void SearchPatcher_Load(object sender, EventArgs e)
57     {
58     txtValue.ReadOnly = false;
59     }
60     private void btnCancel_Click(object sender, EventArgs e)
61     {
62     this.Close();
63     }
64     private void btnOK_Click(object sender, EventArgs e)
65     {
66 william 243 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
67 william 245 provider.OpenProvider();
68 william 230 foreach(ResultDataType patch in PatchList)
69     {
70     switch (patch.ValueType)
71     {
72     case SearchDataTypes._8bits:
73 william 240 if (patch.IsUnsigned) { provider.PatchMemory(patch.Address, (byte)txtValue.Value); }
74     else { provider.PatchMemory(patch.Address, (sbyte)txtValue.Value); }
75 william 230 break;
76     case SearchDataTypes._16bits:
77 william 240 if (patch.IsUnsigned) { provider.PatchMemory(patch.Address, (ushort)txtValue.Value); }
78     else { provider.PatchMemory(patch.Address, (short)txtValue.Value); }
79 william 230 break;
80     case SearchDataTypes._32bits:
81 william 240 if (patch.IsUnsigned) { provider.PatchMemory(patch.Address, (uint)txtValue.Value); }
82     else { provider.PatchMemory(patch.Address, (int)txtValue.Value); }
83 william 230 break;
84     case SearchDataTypes._64bits:
85 william 240 if (patch.IsUnsigned) { provider.PatchMemory(patch.Address, (ulong)txtValue.Value); }
86     else { provider.PatchMemory(patch.Address, (long)txtValue.Value); }
87 william 230 break;
88     }
89     }
90 william 245 provider.CloseProvider();
91 william 230 this.Close();
92     }
93    
94     private void CopyToClipboard(string data)
95     {
96     Clipboard.SetData(DataFormats.Text, data);
97     }
98    
99     private void btnCopyvaluetoClipboard_Click(object sender, EventArgs e)
100     {
101     this.CopyToClipboard(txtValue.Text);
102     }
103    
104     private void SearchPatcher_KeyDown(object sender, KeyEventArgs e)
105     {
106     if (e.KeyCode == Keys.Enter) btnOK.PerformClick();
107     }
108     }
109     }

  ViewVC Help
Powered by ViewVC 1.1.22