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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/02 16:02:01	228
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/02 18:31:40	229
@@ -1,4 +1,5 @@
-´╗┐using System;
+´╗┐//#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
@@ -9,6 +10,8 @@
 using WeifenLuo.WinFormsUI.Docking;
 using RomCheater.PluginFramework.Interfaces;
 using System.Diagnostics;
+using RomCheater.Docking.MemorySearch;
+using libWin32.Win32.Threading;
 
 namespace RomCheater.Docking
 {
@@ -17,7 +20,8 @@
         IAcceptsPlugin<IConfigPlugin>, 
         ISearchInProgress
     {
-        public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; SearchInProgess = false; }
+        private bool DefaultUnsignedState = true; // set unsigned to true
+        public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
         public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
         public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
 
@@ -30,5 +34,360 @@
         #region ISearchInProgress members
         public bool SearchInProgess { get; private set; } 
         #endregion
+
+
+        public void Reload()
+        {
+            chkUnsigned.Checked = DefaultUnsignedState;
+            radio_8bits.Checked = true;
+            radiocompare_equal.Checked = true;
+            radio_oldvalue.Checked = true;
+        }
+
+        private void radiocompare_equal_CheckedChanged(object sender, EventArgs e)
+        {
+            //if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
+            //{
+            if (radio_oldvalue.Checked)
+            {
+                txtStartAddr.ReadOnly = true;
+                txtEndAddr.ReadOnly = true;
+            }
+            if (radio_specificvalue.Checked)
+            {
+                txtStartAddr.ReadOnly = false;
+                txtEndAddr.ReadOnly = true;
+            }
+            //}
+        }
+
+        private void radiocompare_between_CheckedChanged(object sender, EventArgs e)
+        {
+            if (!radiocompare_equal.Checked &&
+                  !radiocompare_greaterthan.Checked &&
+                  !radiocompare_greaterthan.Checked &&
+                  !radiocompare_lessthan.Checked &&
+                  !radiocompare_greaterthan_orequal.Checked &&
+                  !radiocompare_lessthan_orequal.Checked &&
+                  !radiocompare_notequal.Checked)
+                if (radiocompare_between.Checked)
+                {
+                    txtStartAddr.ReadOnly = false;
+                    txtEndAddr.ReadOnly = false;
+                    return;
+                }
+            if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
+            {
+                if (radio_oldvalue.Checked)
+                {
+                    txtStartAddr.ReadOnly = true;
+                    txtEndAddr.ReadOnly = true;
+                }
+                if (radio_specificvalue.Checked)
+                {
+                    txtStartAddr.ReadOnly = false;
+                    txtEndAddr.ReadOnly = true;
+                }
+            }
+        }
+
+        private void radiocompare_notbetween_CheckedChanged(object sender, EventArgs e)
+        {
+            if (!radiocompare_equal.Checked &&
+                !radiocompare_greaterthan.Checked &&
+                !radiocompare_greaterthan.Checked &&
+                !radiocompare_lessthan.Checked &&
+                !radiocompare_greaterthan_orequal.Checked &&
+                !radiocompare_lessthan_orequal.Checked &&
+                !radiocompare_notequal.Checked)
+                if (radiocompare_notbetween.Checked)
+                {
+                    txtStartAddr.ReadOnly = false;
+                    txtEndAddr.ReadOnly = false;
+                    return;
+                }
+            if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
+            {
+                if (radio_oldvalue.Checked)
+                {
+                    txtStartAddr.ReadOnly = true;
+                    txtEndAddr.ReadOnly = true;
+                }
+                if (radio_specificvalue.Checked)
+                {
+                    txtStartAddr.ReadOnly = false;
+                    txtEndAddr.ReadOnly = true;
+                }
+            }
+        }
+
+        private void radio_8bits_CheckedChanged(object sender, EventArgs e)
+        {
+            if (chkUnsigned.Checked)
+            {
+                txtStartAddr.CreateTypeSize<byte>();
+                txtEndAddr.CreateTypeSize<byte>();
+            }
+            else
+            {
+                txtStartAddr.CreateTypeSize<sbyte>();
+                txtEndAddr.CreateTypeSize<sbyte>();
+            }
+        }
+
+        private void radio_16bits_CheckedChanged(object sender, EventArgs e)
+        {
+            if (chkUnsigned.Checked)
+            {
+                txtStartAddr.CreateTypeSize<ushort>();
+                txtEndAddr.CreateTypeSize<ushort>();
+            }
+            else
+            {
+                txtStartAddr.CreateTypeSize<short>();
+                txtEndAddr.CreateTypeSize<short>();
+            }
+        }
+
+        private void radio_32bits_CheckedChanged(object sender, EventArgs e)
+        {
+
+            if (chkUnsigned.Checked)
+            {
+                txtStartAddr.CreateTypeSize<uint>();
+                txtEndAddr.CreateTypeSize<uint>();
+            }
+            else
+            {
+                txtStartAddr.CreateTypeSize<int>();
+                txtEndAddr.CreateTypeSize<int>();
+            }
+        }
+
+        private void radio_64bits_CheckedChanged(object sender, EventArgs e)
+        {
+
+            if (chkUnsigned.Checked)
+            {
+                txtStartAddr.CreateTypeSize<ulong>();
+                txtEndAddr.CreateTypeSize<ulong>();
+            }
+            else
+            {
+                txtStartAddr.CreateTypeSize<long>();
+                txtEndAddr.CreateTypeSize<long>();
+            }
+        }
+
+        private void radio_oldvalue_CheckedChanged(object sender, EventArgs e)
+        {
+            if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
+            {
+                txtStartAddr.ReadOnly = true;
+                txtEndAddr.ReadOnly = true;
+            }
+        }
+
+        private void radio_specificvalue_CheckedChanged(object sender, EventArgs e)
+        {
+            if (!radiocompare_between.Checked && !radiocompare_notbetween.Checked)
+            {
+                txtStartAddr.ReadOnly = false;
+                txtEndAddr.ReadOnly = true;
+            }
+        }
+
+        private void chkRefreshResults_CheckedChanged(object sender, EventArgs e)
+        {
+            if (chkRefreshResults.Checked)
+            {
+                timer_update_results.Enabled = true;
+            }
+            else
+            {
+                timer_update_results.Enabled = false;
+                ResultsUpdateWorkerThread.CancelAsync();
+            }
+        }
+
+        private void timer_update_results_Tick(object sender, EventArgs e)
+        {
+            if (chkRefreshResults.Checked && !ResultsUpdateWorkerThread.IsBusy)
+            {
+                ResultsUpdateWorkerThread.RunWorkerAsync();
+            }
+        }
+
+        private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e)
+        {
+
+        }
+
+        private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+        {
+
+        }
+
+        private void btnImportFile_Click(object sender, EventArgs e)
+        {
+            this.FreezeResultsUpdate();
+            if (!lstPatchList.ImportFromFile())
+            {
+                MessageBox.Show("Failed to Import Patch List from File.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                this.ThawResultsUpdate();
+                return;
+            }
+            else
+            {
+                MessageBox.Show("Succesfully Imported Patch List from File.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                this.ThawResultsUpdate();
+                return;
+            }
+        }
+        bool g_isFrozen = false;
+        private bool IsResultsUpdateFrozen
+        {
+            get { return g_isFrozen; }
+            set { g_isFrozen = value; }
+        }
+        private void ThawResultsUpdate()
+        {
+            this.IsResultsUpdateFrozen = false;
+            if (this.AcceptedProcess != null)
+            {
+#if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
+                    ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
+#endif
+            }
+        }
+
+        private void FreezeResultsUpdate()
+        {
+            this.IsResultsUpdateFrozen = true;
+            this.IsResultsUpdateFrozen = false;
+            if (this.AcceptedProcess != null)
+            {
+#if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
+                ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
+#endif
+            }
+        }
+
+        private void btnExportFile_Click(object sender, EventArgs e)
+        {
+            this.FreezeResultsUpdate();
+            if (!lstPatchList.ExportToFile())
+            {
+                MessageBox.Show("Failed to Export Patch List to File.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                this.ThawResultsUpdate();
+                return;
+            }
+            else
+            {
+                MessageBox.Show("Succesfully Exported Patch List to File.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                this.ThawResultsUpdate();
+                return;
+            }
+        }
+
+        private void btnImportClipboard_Click(object sender, EventArgs e)
+        {
+            this.FreezeResultsUpdate();
+            if (!lstPatchList.ImportFromClipboard())
+            {
+                MessageBox.Show("Failed to Import Patch List from Clipboard.", "Import Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                this.ThawResultsUpdate();
+                return;
+            }
+            else
+            {
+                MessageBox.Show("Succesfully Import Patch List from Clipboard.", "Import Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                this.ThawResultsUpdate();
+            }
+        }
+
+        private void btnExportClipboard_Click(object sender, EventArgs e)
+        {
+            this.FreezeResultsUpdate();
+            if (!lstPatchList.ExportToClipboard())
+            {
+                MessageBox.Show("Failed to Export Patch List to Clipboard.", "Export Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                this.ThawResultsUpdate();
+                return;
+            }
+            else
+            {
+                MessageBox.Show("Succesfully Exported Patch List to Clipboard.", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                this.ThawResultsUpdate();
+                return;
+            }
+        }
+
+        private void btnAddPatchAddress_Click(object sender, EventArgs e)
+        {
+            PatchAdder adder = new PatchAdder(this.AcceptedProcess.Id);
+            adder.ShowDialog();
+            if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
+        }
+
+        private void btnAddAddressRange_Click(object sender, EventArgs e)
+        {
+            PatchRangeAdder adder = new PatchRangeAdder(this.AcceptedProcess.Id);
+            adder.ShowDialog();
+            if (adder.WasAPatchAdded) AddToPatchList(adder.AddedPatchValue);
+        }
+        private void AddToPatchList(List<ResultDataType> item) { foreach (ResultDataType data in item) { AddToPatchList(data); } }
+        private void AddToPatchList(ResultDataType item)
+        {
+            ResultItem item2 = null;
+            switch (item.ValueType)
+            {
+                case SearchDataTypes._8bits:
+                    if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToByte(item.Value)); }
+                    else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToSByte(item.Value)); }
+                    break;
+                case SearchDataTypes._16bits:
+                    if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt16(item.Value)); }
+                    else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt16(item.Value)); }
+                    break;
+                case SearchDataTypes._32bits:
+                    if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt32(item.Value)); }
+                    else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt32(item.Value)); }
+                    break;
+                case SearchDataTypes._64bits:
+                    if (item.IsUnsigned) { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToUInt64(item.Value)); }
+                    else { item2 = new ResultItem(item.Address, item.IsFrozen, Convert.ToInt64(item.Value)); }
+                    break;
+            }
+            this.AddToPatchList(item2);
+        }
+        private void AddToPatchList(ListViewItem item)
+        {
+            try
+            {
+                ResultDataType _result = (ResultDataType)item.Tag;
+                this.AddToPatchList(_result);
+            }
+            catch (InvalidCastException ex)
+            {
+                // unable to cast
+                MessageBox.Show(ex.Message, "Invalid Cast Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            catch (Exception ex)
+            {
+                // other exception
+                MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+        }
+        private void AddToPatchList(ResultItem item)
+        {
+            if (!lstPatchList.Items.Contains(item)) lstPatchList.Items.Add(item);
+        }
+        private void AddToPatchList(string address, SearchDataTypes bitsize, bool IsUnsigned)
+        {
+            ResultItemState state = new ResultItemState(address, bitsize, IsUnsigned, this.AcceptedProcess.Id);
+            ResultItem item = new ResultItem(state.Address, state.Value, state.Frozen, state.ValueType, state.IsUnsigned);
+            this.AddToPatchList(item);
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22