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