--- trunk/RomCheater/Docking/UI/UIMemoryViewer.cs 2012/05/31 08:38:16 202 +++ trunk/RomCheater/Docking/UI/UIMemoryViewer.cs 2012/05/31 09:31:57 206 @@ -43,7 +43,21 @@ txtAddresses.MouseWheel += new MouseEventHandler(txtAddresses_MouseWheel); txtData.MouseWheel += new MouseEventHandler(txtData_MouseWheel); - } + } + + private void GetFirstNonZeroByte() + { + if (!DesignMode) + { + Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); + reader.ReadProcess = this.AcceptedProcess; + reader.OpenProcess(); + uint addr = 0; + reader.ReadFirstNonZeroByte(MemoryStart, MemorySize, out addr); + GotoAddress(addr); + } + } + #region IProcessConfig Members private Process _AcceptedProcess; public Process AcceptedProcess @@ -54,6 +68,8 @@ _AcceptedProcess = value; update_timer.Enabled = (value != null); UpdateEnabled = update_timer.Enabled; + if (value != null) + GetFirstNonZeroByte(); } } #endregion @@ -61,8 +77,8 @@ public IConfigPlugin AcceptedPlugin { get; set; } #endregion #region IAcceptsMemoryRange members - private uint MemoryStart { get { return 0; } } - private uint MemorySize { get { return int.MaxValue; } } + public uint MemoryStart { get { return 0; } } + public uint MemorySize { get { return int.MaxValue; } } #endregion public void GotoTop() { this.CURRENT_TOP_ADDR = 0; } public void GotoBottom() { uint size = MemorySize; this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); } @@ -308,7 +324,7 @@ uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; ////if (e.Type == ScrollEventType.EndScroll) return; - uint size = max_ram_view; + //uint size = max_ram_view; bool haveModifier = false; switch (e.Modifiers) @@ -320,7 +336,7 @@ this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false; break; case Keys.End: - this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false; + this.CURRENT_TOP_ADDR = (uint)((MemorySize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false; break; default: //NonHandledKeysAreBeingPressed = true; @@ -334,13 +350,27 @@ switch (e.KeyCode) { case Keys.Up: - this.CURRENT_TOP_ADDR -= (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; + if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - small_scroll_change > this.CURRENT_TOP_ADDR)) + { + this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; + } + else + { + this.CURRENT_TOP_ADDR -= (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; + } break; case Keys.Down: this.CURRENT_TOP_ADDR += (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; break; case Keys.PageUp: - this.CURRENT_TOP_ADDR -= (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; + if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - large_scroll_change > this.CURRENT_TOP_ADDR)) + { + this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; + } + else + { + this.CURRENT_TOP_ADDR -= (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; + } break; case Keys.PageDown: this.CURRENT_TOP_ADDR += (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; @@ -352,8 +382,8 @@ } if (this.CURRENT_TOP_ADDR < MemoryStart) this.CURRENT_TOP_ADDR = MemoryStart; //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 = (size - 1); - + if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (MemorySize - max_ram_view); + //this.UpdateEnabled = reenable; } @@ -410,7 +440,7 @@ this.UpdateMaxRamView(); uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; - uint size = MemorySize; + //uint size = MemorySize; if (e.Type == ScrollEventType.EndScroll) return; switch (e.Type) @@ -452,7 +482,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 = (size - 1) - max_ram_view; + if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = MemorySize - max_ram_view; //this.UpdateEnabled = reenable; //isScrolling = false; }