12 |
using System.Diagnostics; |
using System.Diagnostics; |
13 |
using RomCheater.Docking.MemorySearch; |
using RomCheater.Docking.MemorySearch; |
14 |
using libWin32.Win32.Threading; |
using libWin32.Win32.Threading; |
15 |
|
using System.Threading; |
16 |
|
using RomCheater.Logging; |
17 |
|
using System.IO; |
18 |
|
using Sojaner.MemoryScanner.MemoryProviers; |
19 |
|
|
20 |
namespace RomCheater.Docking |
namespace RomCheater.Docking |
21 |
{ |
{ |
22 |
public partial class FloatingMemorySearcher : DockContent, |
public partial class FloatingMemorySearcher : DockContent, |
23 |
IProcessConfig, |
IAcceptsPlugin<IConfigPlugin>, |
24 |
IAcceptsPlugin<IConfigPlugin>, |
IAcceptsProcess<Process>, |
25 |
|
IAcceptsProcessAndConfig, |
26 |
ISearchInProgress |
ISearchInProgress |
27 |
{ |
{ |
28 |
private bool DefaultUnsignedState = true; // set unsigned to true |
private bool DefaultUnsignedState = true; // set unsigned to true |
30 |
public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; } |
public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; } |
31 |
public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; } |
public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; } |
32 |
|
|
33 |
#region IProcessConfig Members |
#region IAcceptsProcess<Process> Members |
34 |
public Process AcceptedProcess { get; set; } |
private Process _AcceptedProcess; |
35 |
|
public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcessAndConfig(AcceptedPlugin, value); } } |
36 |
#endregion |
#endregion |
37 |
#region IAcceptsPlugin<IConfigPlugin> Members |
#region IAcceptsPlugin<IConfigPlugin> Members |
38 |
public IConfigPlugin AcceptedPlugin { get; set; } |
private IConfigPlugin _AcceptedPlugin; |
39 |
|
public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedProcessAndConfig(value, AcceptedProcess); } } |
40 |
#endregion |
#endregion |
41 |
|
private void UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process) |
42 |
|
{ |
43 |
|
this.lstResults.AcceptedPlugin = config; |
44 |
|
this.lstResults.AcceptedProcess = process; |
45 |
|
this.lstPatchList.AcceptedPlugin = config; |
46 |
|
this.lstPatchList.AcceptedProcess = process; |
47 |
|
} |
48 |
#region ISearchInProgress members |
#region ISearchInProgress members |
49 |
public bool SearchInProgess { get; private set; } |
public bool SearchInProgess { get; private set; } |
50 |
#endregion |
#endregion |
56 |
radio_8bits.Checked = true; |
radio_8bits.Checked = true; |
57 |
radiocompare_equal.Checked = true; |
radiocompare_equal.Checked = true; |
58 |
radio_oldvalue.Checked = true; |
radio_oldvalue.Checked = true; |
59 |
|
chkRefreshResults.Checked = true; |
60 |
|
} |
61 |
|
public enum eListViewResults |
62 |
|
{ |
63 |
|
SEARCH_RESULTS_LIST = 0x3000, |
64 |
|
PATCH_RESULTS_LIST = 0x3001, |
65 |
|
UKNOWN_RESULTS_LIST = 0x3001 |
66 |
|
} |
67 |
|
static int col_Found_Address = 0; |
68 |
|
static int col_Found_Value = 1; |
69 |
|
static int col_Found_Frozen = 2; |
70 |
|
static int col_Added_Address = 0; |
71 |
|
static int col_Added_Value = 1; |
72 |
|
static int col_Added_Frozen = 2; |
73 |
|
List<ListViewItem> ResultItems = new List<ListViewItem>(); |
74 |
|
List<ListViewItem> AddedItems = new List<ListViewItem>(); |
75 |
|
private bool _PatchedValue_NeedsUpdate; |
76 |
|
bool PatchedValue_NeedsUpdate |
77 |
|
{ |
78 |
|
get { if (_PatchedValue_NeedsUpdate) this.ThawResultsUpdate(); return _PatchedValue_NeedsUpdate; } |
79 |
|
set { _PatchedValue_NeedsUpdate = value; if (value) this.ThawResultsUpdate(); } |
80 |
|
} |
81 |
|
private delegate ListViewItem ThreadSafe_GetResultItem(int index, int lv_type); |
82 |
|
private ListViewItem GetResultItem(int index, int lv_type) |
83 |
|
{ |
84 |
|
try |
85 |
|
{ |
86 |
|
AddressValuePairList lv = null; |
87 |
|
switch (lv_type) |
88 |
|
{ |
89 |
|
case (int)eListViewResults.SEARCH_RESULTS_LIST: lv = lstResults; break; |
90 |
|
case (int)eListViewResults.PATCH_RESULTS_LIST: lv = lstPatchList; break; |
91 |
|
default: throw new IndexOutOfRangeException("Detected: " + Enum.GetName(typeof(eListViewResults), eListViewResults.UKNOWN_RESULTS_LIST) + " with value: " + lv_type.ToString("x4")); |
92 |
|
} |
93 |
|
ListViewItem item = new ListViewItem(); |
94 |
|
item = (ListViewItem)lv.Items[index].Clone(); |
95 |
|
return item; |
96 |
|
} |
97 |
|
catch (Exception) |
98 |
|
{ |
99 |
|
return null; |
100 |
|
} |
101 |
} |
} |
|
|
|
102 |
private void radiocompare_equal_CheckedChanged(object sender, EventArgs e) |
private void radiocompare_equal_CheckedChanged(object sender, EventArgs e) |
103 |
{ |
{ |
104 |
//if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked) |
//if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked) |
272 |
ResultsUpdateWorkerThread.RunWorkerAsync(); |
ResultsUpdateWorkerThread.RunWorkerAsync(); |
273 |
} |
} |
274 |
} |
} |
275 |
|
private bool ShouldUpdateResults() |
276 |
|
{ |
277 |
|
if (this.AcceptedProcess == null) return false; |
278 |
|
if (SearchWorkerThread.IsBusy) return false; |
279 |
|
//if (JokerSearchWorker.IsBusy) return false; |
280 |
|
if (this.IsResultsUpdateFrozen) return false; |
281 |
|
if (mnuAddedResults.Visible) return false; |
282 |
|
if (mnuResults.Visible) return false; |
283 |
|
if (Process.GetProcessById(this.AcceptedProcess.Id) == null) return false; |
284 |
|
if (lstResults.Items.Count > 0) return true; |
285 |
|
if (lstPatchList.Items.Count > 0) return true; |
286 |
|
return false; |
287 |
|
} |
288 |
private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e) |
private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e) |
289 |
{ |
{ |
290 |
|
Thread.Sleep(250); // keep thread from blocking |
291 |
|
if (!this.ShouldUpdateResults()) return; |
292 |
|
////if (SearchArgs == null) return; |
293 |
|
////if (this.IsResultsUpdateFrozen) return; |
294 |
|
////// put thread to sleep for 500ms |
295 |
|
////System.Threading.Thread.Sleep(500); |
296 |
|
//PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog); |
297 |
|
//byte[] buffered_mem = provider.GetMemory(); |
298 |
|
//MemoryStream ms = new MemoryStream(buffered_mem); |
299 |
|
//BinaryReader r_ms = new BinaryReader(ms); |
300 |
|
|
301 |
|
#region Update Results List |
302 |
|
ResultItems = new List<ListViewItem>(); |
303 |
|
//r_ms.BaseStream.Seek(0, SeekOrigin.Begin); |
304 |
|
for (int i = 0; i < lstResults.Items.Count; i++) |
305 |
|
{ |
306 |
|
if (this.lstResults.InvokeRequired) |
307 |
|
{ |
308 |
|
ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem); |
309 |
|
object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.SEARCH_RESULTS_LIST }); |
310 |
|
if (item != null) |
311 |
|
ResultItems.Add((ListViewItem)item); |
312 |
|
} |
313 |
|
else |
314 |
|
{ |
315 |
|
ResultItems.Add(lstResults.Items[i]); |
316 |
|
} |
317 |
|
|
318 |
|
} |
319 |
|
for (int i = 0; i < ResultItems.Count; i++) |
320 |
|
{ |
321 |
|
if (ResultsUpdateWorkerThread.CancellationPending == true) |
322 |
|
{ |
323 |
|
e.Cancel = true; |
324 |
|
return; |
325 |
|
} |
326 |
|
uint Address = 0; |
327 |
|
ResultDataType _result = (ResultDataType)ResultItems[i].Tag; |
328 |
|
|
329 |
|
Address = Convert.ToUInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16); |
330 |
|
//r_ms.BaseStream.Seek(Address, SeekOrigin.Begin); |
331 |
|
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
332 |
|
int bytesReadSize; |
333 |
|
byte[] data; |
334 |
|
uint bytesToRead = 0; |
335 |
|
switch (_result.ValueType) |
336 |
|
{ |
337 |
|
case SearchDataTypes._8bits: |
338 |
|
bytesToRead = 1; |
339 |
|
break; |
340 |
|
case SearchDataTypes._16bits: |
341 |
|
bytesToRead = 2; |
342 |
|
break; |
343 |
|
case SearchDataTypes._32bits: |
344 |
|
bytesToRead = 4; |
345 |
|
break; |
346 |
|
case SearchDataTypes._64bits: |
347 |
|
bytesToRead = 8; |
348 |
|
break; |
349 |
|
} |
350 |
|
provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
351 |
|
MemoryStream ms = new MemoryStream(data); |
352 |
|
BinaryReader r_ms = new BinaryReader(ms); |
353 |
|
switch (_result.ValueType) |
354 |
|
{ |
355 |
|
case SearchDataTypes._8bits: |
356 |
|
if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); } |
357 |
|
else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); } |
358 |
|
break; |
359 |
|
case SearchDataTypes._16bits: |
360 |
|
if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); } |
361 |
|
else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); } |
362 |
|
break; |
363 |
|
case SearchDataTypes._32bits: |
364 |
|
if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); } |
365 |
|
else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); } |
366 |
|
break; |
367 |
|
case SearchDataTypes._64bits: |
368 |
|
if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); } |
369 |
|
else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); } |
370 |
|
break; |
371 |
|
} |
372 |
|
r_ms.Close(); |
373 |
|
Application.DoEvents(); |
374 |
|
} |
375 |
|
#endregion |
376 |
|
|
377 |
|
#region Update Added Results List |
378 |
|
AddedItems = new List<ListViewItem>(); |
379 |
|
//r_ms.BaseStream.Seek(0, SeekOrigin.Begin); |
380 |
|
for (int i = 0; i < lstPatchList.Items.Count; i++) |
381 |
|
{ |
382 |
|
if (this.lstResults.InvokeRequired) |
383 |
|
{ |
384 |
|
ThreadSafe_GetResultItem _get_item = new ThreadSafe_GetResultItem(GetResultItem); |
385 |
|
object item = this.lstResults.Invoke(_get_item, new object[] { i, (int)eListViewResults.PATCH_RESULTS_LIST }); |
386 |
|
if (item != null) |
387 |
|
AddedItems.Add((ListViewItem)item); |
388 |
|
} |
389 |
|
else |
390 |
|
{ |
391 |
|
AddedItems.Add(lstPatchList.Items[i]); |
392 |
|
} |
393 |
|
|
394 |
|
} |
395 |
|
for (int i = 0; i < AddedItems.Count; i++) |
396 |
|
{ |
397 |
|
if (ResultsUpdateWorkerThread.CancellationPending == true) |
398 |
|
{ |
399 |
|
e.Cancel = true; |
400 |
|
return; |
401 |
|
} |
402 |
|
uint Address = 0; |
403 |
|
ResultDataType _result = (ResultDataType)AddedItems[i].Tag; |
404 |
|
Address = Convert.ToUInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16); |
405 |
|
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
406 |
|
int bytesReadSize; |
407 |
|
byte[] data; |
408 |
|
uint bytesToRead = 0; |
409 |
|
switch (_result.ValueType) |
410 |
|
{ |
411 |
|
case SearchDataTypes._8bits: |
412 |
|
bytesToRead = 1; |
413 |
|
break; |
414 |
|
case SearchDataTypes._16bits: |
415 |
|
bytesToRead = 2; |
416 |
|
break; |
417 |
|
case SearchDataTypes._32bits: |
418 |
|
bytesToRead = 4; |
419 |
|
break; |
420 |
|
case SearchDataTypes._64bits: |
421 |
|
bytesToRead = 8; |
422 |
|
break; |
423 |
|
} |
424 |
|
provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
425 |
|
MemoryStream ms = new MemoryStream(data); |
426 |
|
BinaryReader r_ms = new BinaryReader(ms); |
427 |
|
switch (_result.ValueType) |
428 |
|
{ |
429 |
|
case SearchDataTypes._8bits: |
430 |
|
if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); } |
431 |
|
else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); } |
432 |
|
break; |
433 |
|
case SearchDataTypes._16bits: |
434 |
|
if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); } |
435 |
|
else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); } |
436 |
|
break; |
437 |
|
case SearchDataTypes._32bits: |
438 |
|
if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); } |
439 |
|
else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); } |
440 |
|
break; |
441 |
|
case SearchDataTypes._64bits: |
442 |
|
if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); } |
443 |
|
else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); } |
444 |
|
break; |
445 |
|
} |
446 |
|
r_ms.Close(); |
447 |
|
Application.DoEvents(); |
448 |
|
} |
449 |
|
#endregion |
450 |
|
|
451 |
|
|
452 |
} |
} |
453 |
|
|
454 |
private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
455 |
{ |
{ |
456 |
|
try |
457 |
|
{ |
458 |
|
//if ((lstResults.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate ) return; |
459 |
|
//if ((lstPatchList.SelectedItems.Count > 0) && !PatchedValue_NeedsUpdate) return; |
460 |
|
if (!this.ShouldUpdateResults()) return; |
461 |
|
if (ResultItems.Count > 0) |
462 |
|
{ |
463 |
|
//lstResults.Items.Clear(); |
464 |
|
//lstResults.Items.AddRange(ResultItems.ToArray()); |
465 |
|
|
466 |
|
for (int i = 0; i < ResultItems.Count; i++) |
467 |
|
{ |
468 |
|
lstResults.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text = |
469 |
|
ResultItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text; |
470 |
|
} |
471 |
|
|
472 |
|
} |
473 |
|
if (AddedItems.Count > 0) |
474 |
|
{ |
475 |
|
//lstPatchList.Items.Clear(); |
476 |
|
//lstPatchList.Items.AddRange(AddedItems.ToArray()); |
477 |
|
|
478 |
|
for (int i = 0; i < AddedItems.Count; i++) |
479 |
|
{ |
480 |
|
lstPatchList.Items[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text = |
481 |
|
AddedItems[i].SubItems[new AVPColumnText(AVPColumnType.VALUE).ColumnIndex].Text; |
482 |
|
} |
483 |
|
|
484 |
|
} |
485 |
|
PatchedValue_NeedsUpdate = false; |
486 |
|
} |
487 |
|
catch { } |
488 |
} |
} |
489 |
|
|
490 |
private void btnImportFile_Click(object sender, EventArgs e) |
private void btnImportFile_Click(object sender, EventArgs e) |
648 |
ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned); |
ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned); |
649 |
this.AddToPatchList(item); |
this.AddToPatchList(item); |
650 |
} |
} |
651 |
|
|
652 |
|
private void mnuItemAddToPatchList_Click(object sender, EventArgs e) |
653 |
|
{ |
654 |
|
if (!(lstResults.SelectedItems.Count > 0)) return; |
655 |
|
//if (SearchArgs == null) return; |
656 |
|
|
657 |
|
try |
658 |
|
{ |
659 |
|
for (int i = 0; i < lstResults.SelectedIndices.Count; i++) |
660 |
|
{ |
661 |
|
//ResultDataType result = (ResultDataType)lstResults.Items[selected_index].Tag; |
662 |
|
ListViewItem item = lstResults.Items[lstResults.SelectedIndices[i]]; |
663 |
|
this.AddToPatchList(item); |
664 |
|
} |
665 |
|
} |
666 |
|
catch (Exception ex) |
667 |
|
{ |
668 |
|
logger.Error.WriteLine(ex.ToString()); |
669 |
|
} |
670 |
|
} |
671 |
|
|
672 |
|
private void mnuItemRemoveResult_Click(object sender, EventArgs e) |
673 |
|
{ |
674 |
|
if (!(lstPatchList.SelectedItems.Count > 0)) return; |
675 |
|
//if (SearchArgs == null) return; |
676 |
|
try |
677 |
|
{ |
678 |
|
this.FreezeResultsUpdate(); |
679 |
|
for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++) |
680 |
|
{ |
681 |
|
//lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]); |
682 |
|
lstPatchList.Items[lstPatchList.SelectedIndices[i]].Remove(); |
683 |
|
} |
684 |
|
this.ThawResultsUpdate(); |
685 |
|
} |
686 |
|
catch (Exception ex) |
687 |
|
{ |
688 |
|
Debug.WriteLine(ex.ToString()); |
689 |
|
} |
690 |
|
} |
691 |
|
private void PatchRange(bool SingleEntry) |
692 |
|
{ |
693 |
|
//if (SearchArgs == null) return; |
694 |
|
#region Patch Selected Address |
695 |
|
// stop ResultsUpdate Thread |
696 |
|
ResultsUpdateWorkerThread.CancelAsync(); |
697 |
|
|
698 |
|
List<ResultDataType> patch_list = new List<ResultDataType>(); |
699 |
|
List<int> SelectedIndexes = new List<int>(); |
700 |
|
|
701 |
|
if (SingleEntry) |
702 |
|
{ |
703 |
|
SelectedIndexes.Add(lstPatchList.SelectedIndices[0]); |
704 |
|
} |
705 |
|
else |
706 |
|
{ |
707 |
|
foreach (int index in lstPatchList.SelectedIndices) |
708 |
|
{ |
709 |
|
SelectedIndexes.Add(index); |
710 |
|
} |
711 |
|
} |
712 |
|
//PCSX2MemoryProvider provider = new PCSX2MemoryProvider(this.SearchPCSX2ProcessPID, resultslog); |
713 |
|
foreach (int index in SelectedIndexes) |
714 |
|
{ |
715 |
|
if (SingleEntry) |
716 |
|
{ |
717 |
|
SearchPatcher patcher = null; |
718 |
|
uint Address = 0; |
719 |
|
ListViewItem item = lstPatchList.Items[index]; |
720 |
|
ResultDataType _result = (ResultDataType)item.Tag; |
721 |
|
Address = Convert.ToUInt32(item.SubItems[col_Found_Address].Text, 16); |
722 |
|
switch (_result.ValueType) |
723 |
|
{ |
724 |
|
case SearchDataTypes._8bits: |
725 |
|
if (_result.IsUnsigned) |
726 |
|
{ |
727 |
|
byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16); |
728 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
729 |
|
timer_update_results.Enabled = false; |
730 |
|
patcher.ShowDialog(); |
731 |
|
timer_update_results.Enabled = true; |
732 |
|
PatchedValue_NeedsUpdate = true; |
733 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
734 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
735 |
|
} |
736 |
|
else |
737 |
|
{ |
738 |
|
sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16); |
739 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
740 |
|
timer_update_results.Enabled = false; |
741 |
|
patcher.ShowDialog(); |
742 |
|
timer_update_results.Enabled = true; |
743 |
|
PatchedValue_NeedsUpdate = true; |
744 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
745 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
746 |
|
} |
747 |
|
break; |
748 |
|
case SearchDataTypes._16bits: |
749 |
|
if (_result.IsUnsigned) |
750 |
|
{ |
751 |
|
ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16); |
752 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
753 |
|
timer_update_results.Enabled = false; |
754 |
|
patcher.ShowDialog(); |
755 |
|
timer_update_results.Enabled = true; |
756 |
|
PatchedValue_NeedsUpdate = true; |
757 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
758 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
759 |
|
} |
760 |
|
else |
761 |
|
{ |
762 |
|
short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16); |
763 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
764 |
|
timer_update_results.Enabled = false; |
765 |
|
patcher.ShowDialog(); |
766 |
|
timer_update_results.Enabled = true; |
767 |
|
PatchedValue_NeedsUpdate = true; |
768 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
769 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
770 |
|
} |
771 |
|
break; |
772 |
|
case SearchDataTypes._32bits: |
773 |
|
if (_result.IsUnsigned) |
774 |
|
{ |
775 |
|
uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16); |
776 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
777 |
|
timer_update_results.Enabled = false; |
778 |
|
patcher.ShowDialog(); |
779 |
|
timer_update_results.Enabled = true; |
780 |
|
PatchedValue_NeedsUpdate = true; |
781 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
782 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
783 |
|
} |
784 |
|
else |
785 |
|
{ |
786 |
|
int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16); |
787 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
788 |
|
timer_update_results.Enabled = false; |
789 |
|
patcher.ShowDialog(); |
790 |
|
timer_update_results.Enabled = true; |
791 |
|
PatchedValue_NeedsUpdate = true; |
792 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
793 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
794 |
|
} |
795 |
|
break; |
796 |
|
case SearchDataTypes._64bits: |
797 |
|
if (_result.IsUnsigned) |
798 |
|
{ |
799 |
|
ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16); |
800 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
801 |
|
timer_update_results.Enabled = false; |
802 |
|
patcher.ShowDialog(); |
803 |
|
timer_update_results.Enabled = true; |
804 |
|
PatchedValue_NeedsUpdate = true; |
805 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
806 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
807 |
|
} |
808 |
|
else |
809 |
|
{ |
810 |
|
long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16); |
811 |
|
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
812 |
|
timer_update_results.Enabled = false; |
813 |
|
patcher.ShowDialog(); |
814 |
|
timer_update_results.Enabled = true; |
815 |
|
PatchedValue_NeedsUpdate = true; |
816 |
|
if (!chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy) |
817 |
|
ResultsUpdateWorkerThread.RunWorkerAsync(); |
818 |
|
} |
819 |
|
break; |
820 |
|
} |
821 |
|
} |
822 |
|
else |
823 |
|
{ |
824 |
|
|
825 |
|
ListViewItem item = lstPatchList.Items[index]; |
826 |
|
ResultDataType _result = (ResultDataType)item.Tag; |
827 |
|
patch_list.Add(_result); |
828 |
|
} |
829 |
|
} |
830 |
|
|
831 |
|
if (patch_list.Count > 0) |
832 |
|
{ |
833 |
|
SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list); |
834 |
|
rangePatcher.ShowDialog(); |
835 |
|
} |
836 |
|
|
837 |
|
#endregion |
838 |
|
} |
839 |
|
private void mnuItemPatchSelectedEntry_Click(object sender, EventArgs e) |
840 |
|
{ |
841 |
|
if (!(lstPatchList.SelectedItems.Count == 1)) return; |
842 |
|
PatchRange(true); |
843 |
|
} |
844 |
|
|
845 |
|
private void mnuItemPatchSelectedRange_Click(object sender, EventArgs e) |
846 |
|
{ |
847 |
|
if (!(lstPatchList.SelectedItems.Count >= 1)) return; |
848 |
|
PatchRange(false); |
849 |
|
} |
850 |
|
|
851 |
|
private void mnuItemFreezeSelectedPatches_Click(object sender, EventArgs e) |
852 |
|
{ |
853 |
|
if (!(lstPatchList.SelectedItems.Count > 0)) return; |
854 |
|
//if (SearchArgs == null) return; |
855 |
|
try |
856 |
|
{ |
857 |
|
lstPatchList.ProcessID = this.AcceptedProcess.Id; |
858 |
|
this.FreezeResultsUpdate(); |
859 |
|
for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++) |
860 |
|
{ |
861 |
|
lstPatchList.FreezeItem(lstPatchList.SelectedIndices[i]); |
862 |
|
} |
863 |
|
// force thaw and update |
864 |
|
this.ThawResultsUpdate(); |
865 |
|
this.Update(); |
866 |
|
} |
867 |
|
catch (Exception ex) |
868 |
|
{ |
869 |
|
Debug.WriteLine(ex.ToString()); |
870 |
|
} |
871 |
|
} |
872 |
|
|
873 |
|
private void mnuItemThawSelectedPatches_Click(object sender, EventArgs e) |
874 |
|
{ |
875 |
|
if (!(lstPatchList.SelectedItems.Count > 0)) return; |
876 |
|
//if (SearchArgs == null) return; |
877 |
|
try |
878 |
|
{ |
879 |
|
lstPatchList.ProcessID = this.AcceptedProcess.Id; |
880 |
|
this.FreezeResultsUpdate(); |
881 |
|
for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++) |
882 |
|
{ |
883 |
|
lstPatchList.ThawItem(lstPatchList.SelectedIndices[i]); |
884 |
|
} |
885 |
|
// force thaw and update |
886 |
|
this.ThawResultsUpdate(); |
887 |
|
this.Update(); |
888 |
|
} |
889 |
|
catch (Exception ex) |
890 |
|
{ |
891 |
|
Debug.WriteLine(ex.ToString()); |
892 |
|
} |
893 |
|
} |
894 |
|
|
895 |
|
private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e) |
896 |
|
{ |
897 |
|
|
898 |
|
} |
899 |
|
|
900 |
|
private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e) |
901 |
|
{ |
902 |
|
|
903 |
|
} |
904 |
|
|
905 |
|
private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
906 |
|
{ |
907 |
|
|
908 |
|
} |
909 |
|
|
910 |
|
private void search_progress_updater_Tick(object sender, EventArgs e) |
911 |
|
{ |
912 |
|
if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null) |
913 |
|
{ |
914 |
|
SearchWorkerThread.CancelAsync(); |
915 |
|
//JokerSearchWorker.CancelAsync(); |
916 |
|
ResultsUpdateWorkerThread.CancelAsync(); |
917 |
|
} |
918 |
|
} |
919 |
|
|
920 |
|
private void btnSearch_Click(object sender, EventArgs e) |
921 |
|
{ |
922 |
|
this.FreezeResultsUpdate(); |
923 |
|
} |
924 |
} |
} |
925 |
} |
} |