ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/Win32/Sojaner.MemoryScanner/MemoryProviers/BaseMemoryProvider.cs
(Generate patch)

Comparing trunk/Win32/Sojaner.MemoryScanner/MemoryProviers/BaseMemoryProvider.cs (file contents):
Revision 407 by william, Thu Jun 21 12:51:57 2012 UTC vs.
Revision 408 by william, Thu Jun 21 18:10:21 2012 UTC

--- trunk/Win32/Sojaner.MemoryScanner/MemoryProviers/BaseMemoryProvider.cs	2012/06/21 15:59:29	407
+++ trunk/Win32/Sojaner.MemoryScanner/MemoryProviers/BaseMemoryProvider.cs	2012/06/21 18:10:21	408
@@ -6,6 +6,7 @@ using RomCheater.Logging;
 using System.Diagnostics;
 using RomCheater.PluginFramework.Interfaces;
 using System.IO;
+using RomCheater.PluginFramework.Events;
 
 namespace Sojaner.MemoryScanner.MemoryProviers
 {
@@ -18,7 +19,8 @@ namespace Sojaner.MemoryScanner.MemoryPr
         IMemoryReader,
         IMemoryWriter,
         IFileWriter,
-        IDisposable
+        IDisposable,
+        IAcceptsBytesReadEvent
     {
         private ProcessMemoryReader provider;
         public BaseMemoryProvider() { this.AcceptedPlugin = null; this.AcceptedProcess = null; isClosed = true; isOpen = false; }
@@ -27,9 +29,17 @@ namespace Sojaner.MemoryScanner.MemoryPr
         public BaseMemoryProvider(IAcceptsProcessAndConfig pconfig) : this() { this.AcceptedPlugin = pconfig.AcceptedPlugin; this.AcceptedProcess = pconfig.AcceptedProcess; }
 
 
+        public event BaseEventHandler<OnBytesReadEventArgs> OnBytesRead;
+
         private bool isOpen { get; set; }
         private bool isClosed { get; set; }
 
+        private void provider_OnBytesRead(OnBytesReadEventArgs e)
+        {
+            e.Sender = this;
+            if (this.OnBytesRead != null)
+                this.OnBytesRead.Invoke(e);
+        }
         #region Open/Close Provider
         #region public virtual void OpenProvider()
         public virtual void OpenProvider()
@@ -43,6 +53,7 @@ namespace Sojaner.MemoryScanner.MemoryPr
             {
                 provider = new ProcessMemoryReader();
                 provider.ReadProcess = this.AcceptedProcess;
+                provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(provider_OnBytesRead);
                 if (provider.ReadProcess == null) { logger.Error.WriteLine("{0}.OpenProvider() Could not attach to process: {1}", "", this.GetType().Name, this.AcceptedProcess.ToString()); return; }
                 provider.OpenProcess();
                 isOpen = true;
@@ -261,6 +272,12 @@ namespace Sojaner.MemoryScanner.MemoryPr
         }
         #endregion
         #region public virtual void ReadProcessMemoryAtOnce(int MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
+        public virtual void ReadProcessMemoryAtOnce(uint MemoryAddress, uint bytesToRead, object UserState)
+        {
+            if (!EnsureProviderIsOpen()) { return; }
+            try { provider.ReadProcessMemoryAtOnce(MemoryAddress, bytesToRead,UserState); }
+            catch {  }
+        }
         public virtual void ReadProcessMemoryAtOnce(uint MemoryAddress, uint bytesToRead, out int bytesRead, out byte[] data)
         {
             bytesRead = 0x00;