/[RomCheater]/trunk/RomCheater/Docking/FloatingMemorySearcher.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Docking/FloatingMemorySearcher.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 229 - (hide annotations) (download)
Sat Jun 2 18:31:40 2012 UTC (8 years, 4 months ago) by william
File size: 15079 byte(s)

1 william 229 //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
2     using System;
3 william 227 using System.Collections.Generic;
4     using System.ComponentModel;
5     using System.Data;
6     using System.Drawing;
7     using System.Linq;
8     using System.Text;
9     using System.Windows.Forms;
10     using WeifenLuo.WinFormsUI.Docking;
11     using RomCheater.PluginFramework.Interfaces;
12     using System.Diagnostics;
13 william 229 using RomCheater.Docking.MemorySearch;
14     using libWin32.Win32.Threading;
15 william 227
16     namespace RomCheater.Docking
17     {
18 william 228 public partial class FloatingMemorySearcher : DockContent,
19     IProcessConfig,
20     IAcceptsPlugin<IConfigPlugin>,
21     ISearchInProgress
22 william 227 {
23 william 229 private bool DefaultUnsignedState = true; // set unsigned to true
24     public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
25 william 227 public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
26     public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
27    
28     #region IProcessConfig Members
29     public Process AcceptedProcess { get; set; }
30     #endregion
31     #region IAcceptsPlugin<IConfigPlugin> Members
32     public IConfigPlugin AcceptedPlugin { get; set; }
33     #endregion
34 william 228 #region ISearchInProgress members
35     public bool SearchInProgess { get; private set; }
36     #endregion
37 william 229
38    
39     public void Reload()
40     {
41     chkUnsigned.Checked = DefaultUnsignedState;
42     radio_8bits.Checked = true;
43     radiocompare_equal.Checked = true;
44     radio_oldvalue.Checked = true;
45     }
46    
47     private void radiocompare_equal_CheckedChanged(object sender, EventArgs e)
48     {
49     //if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
50     //{
51     if (radio_oldvalue.Checked)
52     {
53     txtStartAddr.ReadOnly = true;
54     txtEndAddr.ReadOnly = true;
55     }
56     if (radio_specificvalue.Checked)
57     {
58     txtStartAddr.ReadOnly = false;
59     txtEndAddr.ReadOnly = true;
60     }
61     //}
62     }
63    
64     private void radiocompare_between_CheckedChanged(object sender, EventArgs e)
65     {
66     if (!radiocompare_equal.Checked &&
67     !radiocompare_greaterthan.Checked &&
68     !radiocompare_greaterthan.Checked &&
69     !radiocompare_lessthan.Checked &&
70     !radiocompare_greaterthan_orequal.Checked &&
71     !radiocompare_lessthan_orequal.Checked &&
72     !radiocompare_notequal.Checked)
73     if (radiocompare_between.Checked)
74     {
75     txtStartAddr.ReadOnly = false;
76     txtEndAddr.ReadOnly = false;
77     return;
78     }
79     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
80     {
81     if (radio_oldvalue.Checked)
82     {
83     txtStartAddr.ReadOnly = true;
84     txtEndAddr.ReadOnly = true;
85     }
86     if (radio_specificvalue.Checked)
87     {
88     txtStartAddr.ReadOnly = false;
89     txtEndAddr.ReadOnly = true;
90     }
91     }
92     }
93    
94     private void radiocompare_notbetween_CheckedChanged(object sender, EventArgs e)
95     {
96     if (!radiocompare_equal.Checked &&
97     !radiocompare_greaterthan.Checked &&
98     !radiocompare_greaterthan.Checked &&
99     !radiocompare_lessthan.Checked &&
100     !radiocompare_greaterthan_orequal.Checked &&
101     !radiocompare_lessthan_orequal.Checked &&
102     !radiocompare_notequal.Checked)
103     if (radiocompare_notbetween.Checked)
104     {
105     txtStartAddr.ReadOnly = false;
106     txtEndAddr.ReadOnly = false;
107     return;
108     }
109     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
110     {
111     if (radio_oldvalue.Checked)
112     {
113     txtStartAddr.ReadOnly = true;
114     txtEndAddr.ReadOnly = true;
115     }
116     if (radio_specificvalue.Checked)
117     {
118     txtStartAddr.ReadOnly = false;
119     txtEndAddr.ReadOnly = true;
120     }
121     }
122     }
123    
124     private void radio_8bits_CheckedChanged(object sender, EventArgs e)
125     {
126     if (chkUnsigned.Checked)
127     {
128     txtStartAddr.CreateTypeSize<byte>();
129     txtEndAddr.CreateTypeSize<byte>();
130     }
131     else
132     {
133     txtStartAddr.CreateTypeSize<sbyte>();
134     txtEndAddr.CreateTypeSize<sbyte>();
135     }
136     }
137    
138     private void radio_16bits_CheckedChanged(object sender, EventArgs e)
139     {
140     if (chkUnsigned.Checked)
141     {
142     txtStartAddr.CreateTypeSize<ushort>();
143     txtEndAddr.CreateTypeSize<ushort>();
144     }
145     else
146     {
147     txtStartAddr.CreateTypeSize<short>();
148     txtEndAddr.CreateTypeSize<short>();
149     }
150     }
151    
152     private void radio_32bits_CheckedChanged(object sender, EventArgs e)
153     {
154    
155     if (chkUnsigned.Checked)
156     {
157     txtStartAddr.CreateTypeSize<uint>();
158     txtEndAddr.CreateTypeSize<uint>();
159     }
160     else
161     {
162     txtStartAddr.CreateTypeSize<int>();
163     txtEndAddr.CreateTypeSize<int>();
164     }
165     }
166    
167     private void radio_64bits_CheckedChanged(object sender, EventArgs e)
168     {
169    
170     if (chkUnsigned.Checked)
171     {
172     txtStartAddr.CreateTypeSize<ulong>();
173     txtEndAddr.CreateTypeSize<ulong>();
174     }
175     else
176     {
177     txtStartAddr.CreateTypeSize<long>();
178     txtEndAddr.CreateTypeSize<long>();
179     }
180     }
181    
182     private void radio_oldvalue_CheckedChanged(object sender, EventArgs e)
183     {
184     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
185     {
186     txtStartAddr.ReadOnly = true;
187     txtEndAddr.ReadOnly = true;
188     }
189     }
190    
191     private void radio_specificvalue_CheckedChanged(object sender, EventArgs e)
192     {
193     if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
194     {
195     txtStartAddr.ReadOnly = false;
196     txtEndAddr.ReadOnly = true;
197     }
198     }
199    
200     private void chkRefreshResults_CheckedChanged(object sender, EventArgs e)
201     {
202     if (chkRefreshResults.Checked)
203     {
204     timer_update_results.Enabled = true;
205     }
206     else
207     {
208     timer_update_results.Enabled = false;
209     ResultsUpdateWorkerThread.CancelAsync();
210     }
211     }
212    
213     private void timer_update_results_Tick(object sender, EventArgs e)
214     {
215     if (chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
216     {
217     ResultsUpdateWorkerThread.RunWorkerAsync();
218     }
219     }
220    
221     private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
222     {
223    
224     }
225    
226     private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
227     {
228    
229     }
230    
231     private void btnImportFile_Click(object sender, EventArgs e)
232     {
233     this.FreezeResultsUpdate();
234     if (!lstPatchList.ImportFromFile())
235     {
236     MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
237     this.ThawResultsUpdate();
238     return;
239     }
240     else
241     {
242     MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
243     this.ThawResultsUpdate();
244     return;
245     }
246     }
247     bool g_isFrozen = false;
248     private bool IsResultsUpdateFrozen
249     {
250     get { return g_isFrozen; }
251     set { g_isFrozen = value; }
252     }
253     private void ThawResultsUpdate()
254     {
255     this.IsResultsUpdateFrozen = false;
256     if (this.AcceptedProcess != null)
257     {
258     #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
259     ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
260     #endif
261     }
262     }
263    
264     private void FreezeResultsUpdate()
265     {
266     this.IsResultsUpdateFrozen = true;
267     this.IsResultsUpdateFrozen = false;
268     if (this.AcceptedProcess != null)
269     {
270     #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
271     ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
272     #endif
273     }
274     }
275    
276     private void btnExportFile_Click(object sender, EventArgs e)
277     {
278     this.FreezeResultsUpdate();
279     if (!lstPatchList.ExportToFile())
280     {
281     MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
282     this.ThawResultsUpdate();
283     return;
284     }
285     else
286     {
287     MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
288     this.ThawResultsUpdate();
289     return;
290     }
291     }
292    
293     private void btnImportClipboard_Click(object sender, EventArgs e)
294     {
295     this.FreezeResultsUpdate();
296     if (!lstPatchList.ImportFromClipboard())
297     {
298     MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
299     this.ThawResultsUpdate();
300     return;
301     }
302     else
303     {
304     MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
305     this.ThawResultsUpdate();
306     }
307     }
308    
309     private void btnExportClipboard_Click(object sender, EventArgs e)
310     {
311     this.FreezeResultsUpdate();
312     if (!lstPatchList.ExportToClipboard())
313     {
314     MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
315     this.ThawResultsUpdate();
316     return;
317     }
318     else
319     {
320     MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
321     this.ThawResultsUpdate();
322     return;
323     }
324     }
325    
326     private void btnAddPatchAddress_Click(object sender, EventArgs e)
327     {
328     PatchAdder adder = new PatchAdder(this.AcceptedProcess.Id);
329     adder.ShowDialog();
330     if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
331     }
332    
333     private void btnAddAddressRange_Click(object sender, EventArgs e)
334     {
335     PatchRangeAdder adder = new PatchRangeAdder(this.AcceptedProcess.Id);
336     adder.ShowDialog();
337     if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
338     }
339     private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
340     private void AddToPatchList(ResultDataType item)
341     {
342     ResultItem item2 = null;
343     switch (item.ValueType)
344     {
345     case SearchDataTypes._8bits:
346     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
347     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
348     break;
349     case SearchDataTypes._16bits:
350     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
351     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
352     break;
353     case SearchDataTypes._32bits:
354     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
355     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
356     break;
357     case SearchDataTypes._64bits:
358     if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
359     else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
360     break;
361     }
362     this.AddToPatchList(item2);
363     }
364     private void AddToPatchList(ListViewItem item)
365     {
366     try
367     {
368     ResultDataType _result = (ResultDataType)item.Tag;
369     this.AddToPatchList(_result);
370     }
371     catch (InvalidCastException ex)
372     {
373     // unable to cast
374     MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
375     }
376     catch (Exception ex)
377     {
378     // other exception
379     MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
380     }
381     }
382     private void AddToPatchList(ResultItem item)
383     {
384     if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
385     }
386     private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
387     {
388     ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, this.AcceptedProcess.Id);
389     ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
390     this.AddToPatchList(item);
391     }
392 william 227 }
393     }

  ViewVC Help
Powered by ViewVC 1.1.22