/[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/10 04:20:04	369
+++ trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/06/10 05:40:24	370
@@ -19,7 +19,7 @@
 
 namespace RomCheater.Docking.UI
 {
-    public partial class UIMemoryViewer : UserControl, 
+    public partial class UIMemoryViewer : UserControl,
         IAcceptsPlugin<IConfigPlugin>,
         IAcceptsProcess<Process>,
         IAcceptsProcessAndConfig,
@@ -27,6 +27,19 @@
         IBrowseMemoryRegion,
         IAcceptPEData
     {
+
+        public delegate void SetTextDelegate(string text);
+        public void SetAsciiData(string text)
+        {
+            if (txtAscii.InvokeRequired)
+            {
+                SetTextDelegate std = new SetTextDelegate(SetAsciiData);
+                txtAscii.Invoke(std, text);
+                return;
+            }
+            txtAscii.Text = text;
+        }
+
         public UIMemoryViewer()
         {
             InitializeComponent();
@@ -34,12 +47,13 @@
             SetStyle(ControlStyles.DoubleBuffer, true);
             SetStyle(ControlStyles.AllPaintingInWmPaint, true);
             SetStyle(ControlStyles.ResizeRedraw, true);
+
             //this.OnPCSX2ProcessCallback = new UIEvents.PCSX2ProcessCallback(this.PCSX2ProcessCallback);
             //if (this.OnPCSX2ProcessCallback != null) { this.OnPCSX2ProcessCallback.Invoke(out procdata); }
             this.UpdateEnabled = false;
             txtData.BytesPerLine = (int)max_address_width;
             txtData.UseFixedBytesPerLine = true;
-            txtData.StringViewVisible = true;
+            //txtData.StringViewVisible = true;
             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;
@@ -70,7 +84,7 @@
                 GotoAddress(addr);
             }
 #else
-            this.GotoImageBase();    
+            this.GotoImageBase();
 #endif
         }
         #region IBrowseMemoryRegion
@@ -82,7 +96,7 @@
                 GotoAddress(MemoryRegion);
                 return true;
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 logger.Error.WriteLine("UIMemoryViewer.BrowseMemoryRegion(int MemoryRegion): Failed to Browse Memory Region: 0x{0:x8}", MemoryRegion);
                 logger.Error.WriteLine(ex.ToString());
@@ -120,9 +134,11 @@
         #endregion
         public void GotoTop() { this.CURRENT_TOP_ADDR = 0; }
         public void GotoBottom() { uint size = (uint)MemoryRangeSize; this.CURRENT_TOP_ADDR = (int)((size - 1) - max_ram_view); }
-        public void GotoAddress(int addr) {
+        public void GotoAddress(int addr)
+        {
             logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoAddress(0x{0:x8})", addr);
-            this.CURRENT_TOP_ADDR = (int)(addr & 0xFFFFFFF0); }
+            this.CURRENT_TOP_ADDR = (int)(addr & 0xFFFFFFF0);
+        }
         private bool _UpdateEnabled;
         public bool UpdateEnabled
         {
@@ -151,7 +167,7 @@
         private byte[] RamData = new byte[] { };
 
         const int max_address_width = 16;
-        static int max_ram_view = max_address_width * 27;
+        static int max_ram_view = max_address_width * 20;
 
         static int small_scroll_change = max_address_width * 1; // scrolls one line (when you clikc the up or down arrows)
         static int medium_scroll_change = max_ram_view / 2; // scrolls half a page
@@ -170,7 +186,7 @@
             Size size = g.MeasureString("00", txtData.Font).ToSize();
             int ByteHeight = size.Height;
             int TotalHeight = txtData.Height;
-            int NumberOfBytes = (int)((TotalHeight / ByteHeight) * max_address_width);
+            int NumberOfBytes = (int)((TotalHeight / ByteHeight) * max_address_width) - max_address_width;
             int byte_width = (max_address_width * 2);
             max_ram_view = NumberOfBytes + (byte_width);
         }
@@ -195,12 +211,12 @@
 
                 if (editor.AsBytes.Length == data.Length)
                 {
-                    
+
                     for (int i = 0; i < data.Length; i++)
                     {
                         if (data[i] != editor.AsBytes[i])
                             changed_byte_count++;
-                    }                    
+                    }
                 }
                 //DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(editor.AsBytes);
                 //txtData.ByteProvider = _DynamicByteProvider;
@@ -224,7 +240,7 @@
         {
             if (AcceptedProcess == null) { return; }
             if (AcceptedPlugin == null) { return; }
-            
+
             if (!this.ShouldUpdateResults()) { return; }// this.Logger.LogDebugMessage(string.Format("ShouldUpdateResults() -> returning false")); return; }
             this.UpdateMaxRamView();
             //if (!force)
@@ -289,11 +305,10 @@
                 if (AcceptedPlugin == null) { return; }
 
                 byte[] data = GetMemory();
+                RamData = data;
+                #region old ascii-code
                 try
                 {
-                    RamData = data;
-
-
                     AddressList = "";
                     AsciiData = "";
                     // write the addreses out
@@ -303,16 +318,53 @@
                     }
                     //// write out the ascii data
                     StringBuilder builder = new StringBuilder();
-                    for (int i = address; i < (address + max_ram_view); i += max_address_width)
+                    int count = 0;
+                    for (int i = 0; i < (0 + max_ram_view); i += max_address_width)
                     {
                         try
                         {
+                            //bool NoAccessRegion = false;
+                            //// preprocess line
+                            //for (int j = 0; j < max_address_width; j++)
+                            //{
+                            //    byte t = data[j];
+                            //    NoAccessRegion = (t == 0);
+                            //}
                             for (int j = 0; j < max_address_width; j++)
                             {
+                                int current_real_address = address + j +i;
                                 int current_addr = i + j;
                                 if (current_addr >= MemoryRangeSize) break;
-                                byte ascii_value_raw = data[j];
-                                char ascii_value = (char)data[j];                             
+
+                                byte ascii_value_raw = data[current_addr];
+                                char ascii_value;
+                                //if (ascii_value_raw == (byte)'?')
+                                //{
+                                //    ascii_value_raw = 0;
+                                //    ascii_value = '?';
+                                //    RamData[count] = 0;
+                                //}
+                                //else
+                                //{
+                                //    ascii_value = (char)data[j];
+                                //}
+
+                                if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
+                                {
+                                    ascii_value = (char)data[current_addr];
+                                }
+                                else
+                                {
+                                    ascii_value = '.';
+                                }
+
+                                GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
+                                gmp.OpenProvider();
+                                byte t;
+                                if (!gmp.ReadMemory(current_real_address, out t)) { ascii_value = '?'; }
+                                gmp.CloseProvider();
+
+
                                 builder.Append(ascii_value.ToString());
                             }
                             builder.AppendLine();
@@ -322,16 +374,16 @@
                             logger.Error.WriteLine("{0}.UpdateMemroyView().BuildingAsciiString:{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
                             return;
                         }
+                        count++;
                     }
                     AsciiData = builder.ToString();
-
-
                 }
                 catch (Exception ex)
                 {
                     logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
                     return;
                 }
+                #endregion
             }
             catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
         }
@@ -356,7 +408,7 @@
                 //{
                 //    int addr = (int)(start_address + i);
                 //    byte data_to_write = data[i];
-                    
+
                 //}
                 provider.CloseProvider();
             }
@@ -370,7 +422,7 @@
             try
             {
                 txtAddresses.Clear(); txtAddresses.Text = AddressList;
-                //txtAscii.Clear(); txtAscii.Text = AsciiData;
+                txtAscii.Clear(); txtAscii.Text = AsciiData;
                 //this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length));
                 DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData);
                 txtData.ByteProvider = _DynamicByteProvider;
@@ -449,7 +501,7 @@
             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 >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
-            
+
             //this.UpdateEnabled = reenable;
         }
 
@@ -461,7 +513,7 @@
 
         private ScrollEventArgs GetMouseWheelScrollChange(int WheelDelta)
         {
-            ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.SmallIncrement,1);
+            ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
             if (WheelDelta < 0)
             {
                 //// negative: scroll down
@@ -495,7 +547,7 @@
 
         void txtAddresses_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
         void txtData_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
-       
+
 
         private void Handle_Scroll(object sender, ScrollEventArgs e)
         {
@@ -553,10 +605,10 @@
             //isScrolling = false;
         }
         private void GotoImageBase()
-        {            
+        {
             if (this.peData == null) return;
             object ImageBase = 0;
-            bool x86 = this.peData.Is32bitAssembly();            
+            bool x86 = this.peData.Is32bitAssembly();
             if (x86)
             {
                 ImageBase = this.peData.NTHeader.OptionalHeader32._ImageBase;
@@ -571,12 +623,12 @@
                 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x16})", ib);
                 txthexGoto.Value = (long)ib;
             }
-            
+
             this.GotoAddress(txthexGoto.ToInt32());
         }
         private void btnGotoImageBase_Click(object sender, EventArgs e)
         {
-            
+
             this.GotoImageBase();
         }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22