/[RomCheater]/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/UI/UIMemoryViewer.cs

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

--- trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/06/05 02:19:13	286
+++ trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/06/05 08:52:07	287
@@ -14,13 +14,16 @@
 using System.Diagnostics;
 using Sojaner.MemoryScanner.MemoryProviers;
 using System.Runtime.InteropServices;
+using RomCheater.PluginFramework.Events;
 
 namespace RomCheater.Docking.UI
 {
     public partial class UIMemoryViewer : UserControl, 
         IAcceptsPlugin<IConfigPlugin>,
         IAcceptsProcess<Process>,
-        IAcceptsProcessAndConfig
+        IAcceptsProcessAndConfig,
+        IAcceptsMemoryRange,
+        IBrowseMemoryRegion
     {
         public UIMemoryViewer()
         {
@@ -35,8 +38,8 @@
             txtData.BytesPerLine = (int)max_address_width;
             txtData.UseFixedBytesPerLine = true;
             txtData.StringViewVisible = true;
-            ramScroll.Minimum = (int)MemoryStart;
-            for (int i = MemoryStart; i < (MemoryStart + max_ram_view); i += max_address_width) { ramScroll.Maximum += (int)max_address_width; }
+            ramScroll.Minimum = (int)MemoryRangeStart;
+            for (int i = MemoryRangeStart; i < (MemoryRangeStart + max_ram_view); i += max_address_width) { ramScroll.Maximum += (int)max_address_width; }
             ramScroll.Value = ramScroll.Minimum;
             this.CanChangeUpdateInterval = false;
 
@@ -60,13 +63,29 @@
                 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
                 provider.OpenProvider();
                 int addr = 0;
-                provider.ReadFirstNonZeroByte(MemoryStart, MemorySize, out addr);
+                provider.ReadFirstNonZeroByte(MemoryRangeStart, MemoryRangeSize, out addr);
                 provider.CloseProvider();
                 GotoAddress(addr);
             }
 #endif
         }
-
+        #region IBrowseMemoryRegion
+        public bool BrowseMemoryRegion(int MemoryRegion)
+        {
+            try
+            {
+                if (!((MemoryRangeStart <= MemoryRegion) && (MemoryRegion <= (MemoryRangeStart + MemoryRangeSize)))) { return false; }
+                GotoAddress(MemoryRegion);
+                return true;
+            }
+            catch(Exception ex)
+            {
+                logger.Error.WriteLine("UIMemoryViewer.BrowseMemoryRegion(int MemoryRegion): Failed to Browse Memory Region: 0x{0:x8}", MemoryRegion);
+                logger.Error.WriteLine(ex.ToString());
+                return false;
+            }
+        }
+        #endregion
         #region  IAcceptsProcess<Process> Members
         private Process _AcceptedProcess;
         public Process AcceptedProcess
@@ -88,11 +107,11 @@
         public IConfigPlugin AcceptedPlugin { get; set; }
         #endregion
         #region IAcceptsMemoryRange members
-        public int MemoryStart { get { return MemorySizeConstants.MinimumAddress; } }
-        public uint MemorySize { get { return MemorySizeConstants.MaximumAddress; } }
+        public int MemoryRangeStart { get { return MemorySizeConstants.MinimumAddress; } set { } }
+        public uint MemoryRangeSize { get { if (MemoryRangeStart > 0) { return (uint)(MemorySizeConstants.MaximumAddress - MemoryRangeStart); } return MemorySizeConstants.MaximumAddress; } set { } }
         #endregion
         public void GotoTop() { this.CURRENT_TOP_ADDR = 0; }
-        public void GotoBottom() { uint size = (uint)MemorySize; this.CURRENT_TOP_ADDR = (int)((size - 1) - max_ram_view); }
+        public void GotoBottom() { uint size = (uint)MemoryRangeSize; this.CURRENT_TOP_ADDR = (int)((size - 1) - max_ram_view); }
         public void GotoAddress(int addr) { this.CURRENT_TOP_ADDR = (int)(addr & 0xFFFFFFF0); }
         private bool _UpdateEnabled;
         public bool UpdateEnabled
@@ -266,7 +285,7 @@
                             for (int j = 0; j < max_address_width; j++)
                             {
                                 int current_addr = i + j;
-                                if (current_addr >= MemorySize) break;
+                                if (current_addr >= MemoryRangeSize) break;
                                 byte ascii_value_raw = data[j];
                                 char ascii_value = (char)data[j];
                                 if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
@@ -364,7 +383,7 @@
                             this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false; 
                             break;
                         case Keys.End:
-                            this.CURRENT_TOP_ADDR = (int)((MemorySize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false;
+                            this.CURRENT_TOP_ADDR = (int)((MemoryRangeSize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false;
                             break;
                         default:
                             //NonHandledKeysAreBeingPressed = true;
@@ -408,9 +427,9 @@
                         break;
                 }
             }
-            if (this.CURRENT_TOP_ADDR < MemoryStart) this.CURRENT_TOP_ADDR = MemoryStart;
+            if (this.CURRENT_TOP_ADDR < MemoryRangeStart) this.CURRENT_TOP_ADDR = MemoryRangeStart;
             //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view;
-            if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (int)(MemorySize - max_ram_view);
+            if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
             
             //this.UpdateEnabled = reenable;
         }
@@ -510,7 +529,7 @@
             if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0;
             //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view;
             //if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
-            if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (int)(MemorySize - max_ram_view);
+            if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
             //this.UpdateEnabled = reenable;
             //isScrolling = false;
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22