/[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	2013/06/03 04:42:38	464
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/03 07:13:44	471
@@ -45,7 +45,7 @@
 {
     public partial class FloatingMemorySearcher : DockContent, 
        IAcceptsPlugin<IConfigPlugin>,
-        IAcceptsProcess<Process>,
+        IAcceptsProcess,
         IAcceptsProcessAndConfig,
         ISearchInProgress,
         IAcceptsBrowseMemoryRegion,
@@ -60,9 +60,9 @@
         const bool USE_OLD_SEARCH_RESULTS_COMPRATOR_CODE = false;
         const bool USE_NONRANGE_SEARCH_RESULT_READER = false;
         private bool DefaultUnsignedState = true; // set unsigned to true
-        public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
+        public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.ProcessPID = 0; SearchInProgess = false; Reload(); }
         public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
-        public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
+        public FloatingMemorySearcher(IConfigPlugin config, int pid) : this() { this.AcceptedPlugin = config; this.ProcessPID = pid; }
 
         //new Action<int, string>(UpdateProgress) to use this as a delegate
         private void UpdateProgress(int value, string message)
@@ -72,8 +72,8 @@
         }
 
         #region IAcceptsProcess<Process> Members
-        private Process _AcceptedProcess;
-        public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcess(value); } }
+        private int _ProcessPID;
+        public int ProcessPID { get { return _ProcessPID; } set { _ProcessPID = value; UpdateProcessPID(value); } }
         #endregion
         #region IAcceptsPlugin<IConfigPlugin> Members
         private IConfigPlugin _AcceptedPlugin;
@@ -93,10 +93,10 @@
                 MemoryRangeSize = AcceptedPlugin.MemoryRangeStart + AcceptedPlugin.MemoryRangeSize;
             }
         }
-        private void UpdateAcceptedProcess(Process process)
-        {            
-            this.lstResults.AcceptedProcess = process;            
-            this.lstPatchList.AcceptedProcess = process;
+        private void UpdateProcessPID(int pid)
+        {
+            this.lstResults.ProcessPID = pid;
+            this.lstPatchList.ProcessPID = pid;
 #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
             logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
             logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
@@ -418,13 +418,13 @@
         }
         private bool ShouldUpdateResults()
         {
-            if (this.AcceptedProcess == null) return false;
+            if (this.ProcessPID == 0) return false;
             if (SearchWorkerThread.IsBusy) return false;
             //if (JokerSearchWorker.IsBusy) return false;
             if (this.IsResultsUpdateFrozen) return false;
             if (mnuAddedResults.Visible) return false;
             if (mnuResults.Visible) return false;
-            if (Process.GetProcessById(this.AcceptedProcess.Id) == null) return false;
+            if (Process.GetProcessById(this.ProcessPID) == null) return false;
             if (lstResults.Items.Count > 0) return true;
             if (lstPatchList.Items.Count > 0) return true;
             return false;
@@ -672,10 +672,10 @@
         private void ThawResultsUpdate()
         {
             this.IsResultsUpdateFrozen = false;
-            if (this.AcceptedProcess != null)
+            if (this.ProcessPID != 0)
             {
 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
-                    ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
+                ThreadControl.ResumeProcess(this.ProcessPID);
 #endif
             }
         }
@@ -684,10 +684,10 @@
         {
             this.IsResultsUpdateFrozen = true;
             //this.IsResultsUpdateFrozen = false;
-            if (this.AcceptedProcess != null)
+            if (this.ProcessPID != 0)
             {
 #if !DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE
-                ThreadControl.SuspendProcess(this.AcceptedProcess.Id);
+                ThreadControl.SuspendProcess(this.ProcessPID);
 #endif
             }
         }
@@ -1014,7 +1014,7 @@
             //if (SearchArgs == null) return;
             try
             {
-                lstPatchList.ProcessID = this.AcceptedProcess.Id;
+                lstPatchList.ProcessID = this.ProcessPID;
                 this.FreezeResultsUpdate();
                 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
                 {
@@ -1036,7 +1036,7 @@
             //if (SearchArgs == null) return;
             try
             {
-                lstPatchList.ProcessID = this.AcceptedProcess.Id;
+                lstPatchList.ProcessID = this.ProcessPID;
                 this.FreezeResultsUpdate();
                 for (int i = 0; i < lstPatchList.SelectedIndices.Count; i++)
                 {
@@ -1460,28 +1460,32 @@
                         {                        
                             byte[] guid = SearchGuid.ToByteArray();
                             guid[guid.Length-1]++; // increment the search guid by 1
-                            Guid new_SearchGuid = new Guid(guid);
-                            provider.OpenProvider();
+                            Guid new_SearchGuid = new Guid(guid);                           
                             //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
                             int count = 0;
                             //int Last_Whole_Percent_Done = 0;
-                            foreach (var item in reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)))
+                            var results = reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
+
+                            using (SearchResultWriter writer = new SearchResultWriter((int)(results.Count()), new_SearchGuid))
                             {
-                                using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
+                                foreach (var item in results)
                                 {
-                                    
-                                    //provider.ReadProcessMemoryAtOnce(item.Address, STEP_SIZE, writer);
-                                    int bytesRead =0;
+                                     provider.OpenProvider();
+                                    int bytesRead = 0;
                                     byte[] data = new byte[STEP_SIZE];
-                                    provider.ReadProcessMemory(item.Address, STEP_SIZE, out bytesRead, out data);                                    
-                                    new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead).Invoke(new OnBytesReadEventArgs(this, writer, data, item.Address, (uint)reader.ResultCount));
-
+                                    provider.ReadProcessMemory(item.Address, STEP_SIZE, out bytesRead, out data);
+                                    BaseEventHandler<OnBytesReadEventArgs> t = new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
+                                    OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, item.Address, (uint)reader.ResultCount);
+                                    t.Invoke(t_args);
+                                    t = null;
+                                    t_args=null;
                                     double percent_done = 100.0 * ((double)count / (double)reader.ResultCount);
-                                    new Action<int, string>(UpdateProgress).Invoke((int)percent_done, string.Format(" -> Reading Address: 0x{0:x8}", item.Address));                                   
+                                    new Action<int, string>(UpdateProgress).Invoke((int)percent_done, string.Format(" -> Reading Address: 0x{0:x8}", item.Address));
+                                    count++;
+                                    data = null;
+                                    provider.CloseProvider();
                                 }
-                                count++;
-                            }
-                            provider.CloseProvider();
+                            }                            
                             SearchGuid = new_SearchGuid;
                         }
                     }
@@ -2154,7 +2158,7 @@
             new Action<int, string>(UpdateProgress).Invoke(0, string.Empty);
             grpDataType.Enabled = false;
             // resume process on reset, incase it was suspended
-            ThreadControl.ResumeProcess(this.AcceptedProcess.Id);
+            ThreadControl.ResumeProcess(this.ProcessPID);
             //Application.DoEvents();
             this.Refresh();
         }
@@ -2176,7 +2180,7 @@
         }
         private void search_progress_updater_Tick(object sender, EventArgs e)
         {
-            if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null)
+            if ((this.ProcessPID == 0) || Process.GetProcessById(this.ProcessPID) == null)
             {
                 SearchWorkerThread.CancelAsync();
                 //JokerSearchWorker.CancelAsync();

 

  ViewVC Help
Powered by ViewVC 1.1.22