/[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 19:12:20	230
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/03 13:21:51	243
@@ -15,12 +15,14 @@
 using System.Threading;
 using RomCheater.Logging;
 using System.IO;
+using Sojaner.MemoryScanner.MemoryProviers;
 
 namespace RomCheater.Docking
 {
     public partial class FloatingMemorySearcher : DockContent, 
-        IProcessConfig, 
-        IAcceptsPlugin<IConfigPlugin>, 
+       IAcceptsPlugin<IConfigPlugin>,
+        IAcceptsProcess<Process>,
+        IAcceptsProcessAndConfig,
         ISearchInProgress
     {
         private bool DefaultUnsignedState = true; // set unsigned to true
@@ -28,12 +30,21 @@
         public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
         public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
 
-        #region IProcessConfig Members
-        public Process AcceptedProcess { get; set; }
+        #region IAcceptsProcess<Process> Members
+        private Process _AcceptedProcess;
+        public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcessAndConfig(AcceptedPlugin, value); } }
         #endregion
         #region IAcceptsPlugin<IConfigPlugin> Members
-        public IConfigPlugin AcceptedPlugin { get; set; }
+        private IConfigPlugin _AcceptedPlugin;
+        public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedProcessAndConfig(value, AcceptedProcess); } }
         #endregion
+        private void UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process)
+        {
+            this.lstResults.AcceptedPlugin = config;
+            this.lstResults.AcceptedProcess = process;
+            this.lstPatchList.AcceptedPlugin = config;
+            this.lstPatchList.AcceptedProcess = process;
+        }
         #region ISearchInProgress members
         public bool SearchInProgess { get; private set; } 
         #endregion
@@ -316,13 +327,10 @@
                 ResultDataType _result = (ResultDataType)ResultItems[i].Tag;
                 
                 Address = Convert.ToUInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
-                //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);
-                Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader();
-                reader.ReadProcess = Process.GetProcessById(this.AcceptedProcess.Id);
-                if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", this.AcceptedProcess.Id); return; }
-                reader.OpenProcess();
+                //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);                
+                GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
                 int bytesReadSize;
-                byte[] data;
+                byte[] data;    
                 uint bytesToRead = 0;
                 switch (_result.ValueType)
                 {
@@ -339,7 +347,7 @@
                         bytesToRead = 8;
                         break;
                 }
-                reader.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
+                provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
                 MemoryStream ms = new MemoryStream(data);
                 BinaryReader r_ms = new BinaryReader(ms);
                 switch (_result.ValueType)
@@ -362,7 +370,6 @@
                         break;
                 }
                 r_ms.Close();
-                reader.CloseHandle();
                 Application.DoEvents();
             }
             #endregion
@@ -395,10 +402,7 @@
                 uint Address = 0;
                 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
                 Address = Convert.ToUInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
-                Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader();
-                reader.ReadProcess = Process.GetProcessById(this.AcceptedProcess.Id);
-                if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", this.AcceptedProcess.Id); return; }
-                reader.OpenProcess();
+                GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
                 int bytesReadSize;
                 byte[] data;
                 uint bytesToRead = 0;
@@ -417,7 +421,7 @@
                         bytesToRead = 8;
                         break;
                 }
-                reader.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
+                provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
                 MemoryStream ms = new MemoryStream(data);
                 BinaryReader r_ms = new BinaryReader(ms);
                 switch (_result.ValueType)
@@ -440,7 +444,6 @@
                         break;
                 }
                 r_ms.Close();
-                reader.CloseHandle();
                 Application.DoEvents();
             }
             #endregion
@@ -722,7 +725,7 @@
                             if (_result.IsUnsigned)
                             {
                                 byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -733,7 +736,7 @@
                             else
                             {
                                 sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -746,7 +749,7 @@
                             if (_result.IsUnsigned)
                             {
                                 ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -757,7 +760,7 @@
                             else
                             {
                                 short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -770,7 +773,7 @@
                             if (_result.IsUnsigned)
                             {
                                 uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -781,7 +784,7 @@
                             else
                             {
                                 int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -794,7 +797,7 @@
                             if (_result.IsUnsigned)
                             {
                                 ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -805,7 +808,7 @@
                             else
                             {
                                 long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16);
-                                patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value);
+                                patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value);
                                 timer_update_results.Enabled = false;
                                 patcher.ShowDialog();
                                 timer_update_results.Enabled = true;
@@ -827,7 +830,7 @@
 
             if (patch_list.Count > 0)
             {
-                SearchRangePatcher rangePatcher = new SearchRangePatcher(this.AcceptedProcess.Id, patch_list);
+                SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list);
                 rangePatcher.ShowDialog();
             }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22