ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
Revision: 372
Committed: Sun Jun 10 06:12:21 2012 UTC (11 years, 8 months ago) by william
File size: 28753 byte(s)
Log Message:
+ fix memory view flickering

File Contents

# User Rev Content
1 william 256 //#define DISABLE_GETFIRSTNONZEROBYTE_ONUPDATE_ACCEPTEDPROCESS // when defined will not call GetFirstNonZeroByte() when AcceptedProcess is updated and is not null
2 william 360 #define DISABLE_GETFIRSTNONZERO_BYTE // when defined will make GetFirstNonZeroByte() an empty void method
3 william 246 using System;
4 william 198 using System.Collections.Generic;
5     using System.ComponentModel;
6     using System.Drawing;
7     using System.Data;
8     using System.Linq;
9     using System.Text;
10     using System.Windows.Forms;
11     using Be.Windows.Forms;
12     using RomCheater.Logging;
13     using RomCheater.PluginFramework.Interfaces;
14     using System.Diagnostics;
15 william 238 using Sojaner.MemoryScanner.MemoryProviers;
16 william 285 using System.Runtime.InteropServices;
17 william 287 using RomCheater.PluginFramework.Events;
18 william 323 using Sojaner.MemoryScanner;
19 william 198
20     namespace RomCheater.Docking.UI
21     {
22 william 370 public partial class UIMemoryViewer : UserControl,
23 william 243 IAcceptsPlugin<IConfigPlugin>,
24     IAcceptsProcess<Process>,
25 william 287 IAcceptsProcessAndConfig,
26     IAcceptsMemoryRange,
27 william 323 IBrowseMemoryRegion,
28     IAcceptPEData
29 william 198 {
30 william 370
31 william 372
32 william 370 public delegate void SetTextDelegate(string text);
33     public void SetAsciiData(string text)
34     {
35     if (txtAscii.InvokeRequired)
36     {
37     SetTextDelegate std = new SetTextDelegate(SetAsciiData);
38     txtAscii.Invoke(std, text);
39     return;
40     }
41     txtAscii.Text = text;
42     }
43    
44 william 198 public UIMemoryViewer()
45     {
46     InitializeComponent();
47     SetStyle(ControlStyles.UserPaint, true);
48     SetStyle(ControlStyles.DoubleBuffer, true);
49     SetStyle(ControlStyles.AllPaintingInWmPaint, true);
50     SetStyle(ControlStyles.ResizeRedraw, true);
51 william 370
52 william 198 //this.OnPCSX2ProcessCallback = new UIEvents.PCSX2ProcessCallback(this.PCSX2ProcessCallback);
53     //if (this.OnPCSX2ProcessCallback != null) { this.OnPCSX2ProcessCallback.Invoke(out procdata); }
54     this.UpdateEnabled = false;
55     txtData.BytesPerLine = (int)max_address_width;
56     txtData.UseFixedBytesPerLine = true;
57 william 370 //txtData.StringViewVisible = true;
58 william 287 ramScroll.Minimum = (int)MemoryRangeStart;
59     for (int i = MemoryRangeStart; i < (MemoryRangeStart + max_ram_view); i += max_address_width) { ramScroll.Maximum += (int)max_address_width; }
60 william 198 ramScroll.Value = ramScroll.Minimum;
61     this.CanChangeUpdateInterval = false;
62    
63    
64     lblAddressMarker.Text = "";
65     for (uint i = 0; i < max_address_width; i++)
66     {
67     lblAddressMarker.Text = lblAddressMarker.Text + string.Format("{0:X2} ", i);
68     }
69     this.AcceptedPlugin = null; this.AcceptedProcess = null;
70 william 202
71     txtAddresses.MouseWheel += new MouseEventHandler(txtAddresses_MouseWheel);
72     txtData.MouseWheel += new MouseEventHandler(txtData_MouseWheel);
73 william 203 }
74    
75     private void GetFirstNonZeroByte()
76     {
77 william 246 #if !DISABLE_GETFIRSTNONZERO_BYTE
78 william 203 if (!DesignMode)
79     {
80 william 238 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
81 william 245 provider.OpenProvider();
82 william 256 int addr = 0;
83 william 287 provider.ReadFirstNonZeroByte(MemoryRangeStart, MemoryRangeSize, out addr);
84 william 245 provider.CloseProvider();
85 william 203 GotoAddress(addr);
86     }
87 william 360 #else
88 william 370 this.GotoImageBase();
89 william 246 #endif
90 william 203 }
91 william 287 #region IBrowseMemoryRegion
92     public bool BrowseMemoryRegion(int MemoryRegion)
93     {
94     try
95     {
96     if (!((MemoryRangeStart <= MemoryRegion) && (MemoryRegion <= (MemoryRangeStart + MemoryRangeSize)))) { return false; }
97     GotoAddress(MemoryRegion);
98     return true;
99     }
100 william 370 catch (Exception ex)
101 william 287 {
102     logger.Error.WriteLine("UIMemoryViewer.BrowseMemoryRegion(int MemoryRegion): Failed to Browse Memory Region: 0x{0:x8}", MemoryRegion);
103     logger.Error.WriteLine(ex.ToString());
104     return false;
105     }
106     }
107     #endregion
108 william 238 #region IAcceptsProcess<Process> Members
109 william 199 private Process _AcceptedProcess;
110     public Process AcceptedProcess
111     {
112     get { return _AcceptedProcess; }
113     set
114     {
115     _AcceptedProcess = value;
116     update_timer.Enabled = (value != null);
117     UpdateEnabled = update_timer.Enabled;
118 william 246 #if !DISABLE_GETFIRSTNONZEROBYTE_ONUPDATE_ACCEPTEDPROCESS
119 william 203 if (value != null)
120     GetFirstNonZeroByte();
121 william 246 #endif
122 william 199 }
123     }
124 william 198 #endregion
125     #region IAcceptsPlugin<IConfigPlugin> Members
126     public IConfigPlugin AcceptedPlugin { get; set; }
127     #endregion
128 william 200 #region IAcceptsMemoryRange members
129 william 287 public int MemoryRangeStart { get { return MemorySizeConstants.MinimumAddress; } set { } }
130     public uint MemoryRangeSize { get { if (MemoryRangeStart > 0) { return (uint)(MemorySizeConstants.MaximumAddress - MemoryRangeStart); } return MemorySizeConstants.MaximumAddress; } set { } }
131 william 200 #endregion
132 william 323 #region IAcceptPEData members
133 william 357 private IPEDData peData { get; set; }
134     public void SetPEViewerData(IPEDData peData) { this.peData = peData; }
135 william 323 #endregion
136 william 198 public void GotoTop() { this.CURRENT_TOP_ADDR = 0; }
137 william 287 public void GotoBottom() { uint size = (uint)MemoryRangeSize; this.CURRENT_TOP_ADDR = (int)((size - 1) - max_ram_view); }
138 william 370 public void GotoAddress(int addr)
139     {
140 william 326 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoAddress(0x{0:x8})", addr);
141 william 370 this.CURRENT_TOP_ADDR = (int)(addr & 0xFFFFFFF0);
142     }
143 william 198 private bool _UpdateEnabled;
144     public bool UpdateEnabled
145     {
146     get { return _UpdateEnabled; }
147     set
148     {
149     _UpdateEnabled = value;
150     if (value) { this.update_timer.Enabled = true; }
151     else { this.update_timer.Enabled = false; }
152     }
153     }
154     private bool _CanChangeUpdateInterval;
155     public bool CanChangeUpdateInterval
156     {
157     get { return _CanChangeUpdateInterval; }
158     set { _CanChangeUpdateInterval = value; }
159     }
160    
161     public int UpdateInterval
162     {
163     get { return this.update_timer.Interval; }
164     set { if (CanChangeUpdateInterval) this.update_timer.Interval = value; }
165     }
166     private string AddressList = "";
167     private string AsciiData = "";
168     private byte[] RamData = new byte[] { };
169    
170 william 249 const int max_address_width = 16;
171 william 370 static int max_ram_view = max_address_width * 20;
172 william 198
173 william 249 static int small_scroll_change = max_address_width * 1; // scrolls one line (when you clikc the up or down arrows)
174     static int medium_scroll_change = max_ram_view / 2; // scrolls half a page
175     static int large_scroll_change = max_ram_view; // scrolls a full page
176     private int _CURRENT_TOP_ADDR;
177     int CURRENT_TOP_ADDR
178 william 198 {
179     get { return _CURRENT_TOP_ADDR; }
180 william 216 set { txthexGoto.Value = _CURRENT_TOP_ADDR = value; }
181 william 198 }
182     //uint CURRENT_BOITTOM_ADDR() { return CURRENT_TOP_ADDR + max_ram_view; }
183     private void UpdateMaxRamView()
184     {
185 william 286 if (this.IsDisposed) return;
186 william 198 Graphics g = this.CreateGraphics();
187     Size size = g.MeasureString("00", txtData.Font).ToSize();
188     int ByteHeight = size.Height;
189     int TotalHeight = txtData.Height;
190 william 370 int NumberOfBytes = (int)((TotalHeight / ByteHeight) * max_address_width) - max_address_width;
191 william 249 int byte_width = (max_address_width * 2);
192 william 274 max_ram_view = NumberOfBytes + (byte_width);
193 william 198 }
194     private void btnGotoAddress_Click(object sender, EventArgs e)
195     {
196 william 326 logger.VerboseDebug.WriteLine("UIMemoryViewer::btnGotoAddress_Click(0x{0:x8})", txthexGoto.ToInt32());
197 william 256 this.GotoAddress(txthexGoto.ToInt32());
198 william 198 }
199    
200     private void btnEditBytes_Click(object sender, EventArgs e)
201     {
202 william 326 byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray();
203     logger.Info.WriteLine("UIMemoryViewer :: editing {0} bytes", data.Length);
204 william 198 bool reenable = false;
205     if (this.UpdateEnabled) reenable = true;
206     this.UpdateEnabled = false;
207 william 326 ByteEditor editor = new ByteEditor(data, this.CURRENT_TOP_ADDR);
208 william 198 editor.ShowDialog();
209 william 326 int changed_byte_count = 0;
210 william 198 if (editor.BytesEdited)
211     {
212 william 326
213     if (editor.AsBytes.Length == data.Length)
214     {
215 william 370
216 william 326 for (int i = 0; i < data.Length; i++)
217     {
218     if (data[i] != editor.AsBytes[i])
219     changed_byte_count++;
220 william 370 }
221 william 326 }
222 william 207 //DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(editor.AsBytes);
223     //txtData.ByteProvider = _DynamicByteProvider;
224     //_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed);
225     this.WriteCurrentBytes(this.CURRENT_TOP_ADDR, editor.AsBytes);
226 william 198 }
227 william 326 logger.Info.WriteLine("UIMemoryViewer :: changed {0} bytes", changed_byte_count);
228 william 198 this.UpdateEnabled = reenable;
229     }
230     private bool ForceUpdate = false;
231     private bool ShouldUpdateResults()
232     {
233     //if (ResultsUpdateWorkerThread.IsBusy) { return false; }
234     if (ForceUpdate) return true;
235     //else if (TextIsBeingSelected) return false;
236     //else if (NonHandledKeysAreBeingPressed) return false;
237     else if (this.UpdateEnabled) return true;
238     else { return false; }
239     }
240     private void UpdateGui(bool force)
241     {
242     if (AcceptedProcess == null) { return; }
243     if (AcceptedPlugin == null) { return; }
244 william 370
245 william 198 if (!this.ShouldUpdateResults()) { return; }// this.Logger.LogDebugMessage(string.Format("ShouldUpdateResults() -> returning false")); return; }
246     this.UpdateMaxRamView();
247     //if (!force)
248     //{
249     if (!ResultsUpdateWorkerThread.IsBusy)
250     ResultsUpdateWorkerThread.RunWorkerAsync();
251     //}
252     //else
253     //{
254     // while (!ResultsUpdateWorkerThread.IsBusy) { ResultsUpdateWorkerThread.CancelAsync(); Application.DoEvents(); }
255     // ResultsUpdateWorkerThread.RunWorkerAsync();
256     //}
257     }
258     private void UpdateGui()
259     {
260     this.UpdateGui(false);
261     }
262     private byte[] GetMemory()
263     {
264 william 351 byte[] data = new byte[max_ram_view];
265 william 198 try
266     {
267 william 238 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
268 william 245 provider.OpenProvider();
269 william 198 int bytesReadSize;
270 william 249 provider.ReadProcessMemory(CURRENT_TOP_ADDR, (uint)max_ram_view, out bytesReadSize, out data);
271 william 285 try
272     {
273     provider.CloseProvider();
274     }
275     catch (SEHException ex)
276     {
277     logger.Error.WriteLine("UIMemoryViewer.GetMemory(): SEHException: (0x{0:x8} {1}", ex.ErrorCode, ex.Message);
278     logger.Error.WriteLine(ex.ToString());
279     }
280     catch (Exception ex)
281     {
282     logger.Error.WriteLine("UIMemoryViewer.GetMemory(): Exception: {0}", ex.Message);
283     logger.Error.WriteLine(ex.ToString());
284     }
285 william 198 }
286     catch (Exception ex)
287     {
288     logger.Error.WriteLine("{0}.GetMemory():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
289     }
290 william 245 finally
291     {
292     if (data.Length == 0)
293     {
294     data = new byte[max_ram_view];
295     for (int i = 0; i < data.Length; i++) { data[i] = 0x0; }
296     }
297     }
298     return data;
299 william 198 }
300     private void UpdateMemroyView() { this.UpdateMemroyView(this.CURRENT_TOP_ADDR); }
301 william 249 private void UpdateMemroyView(int address)
302 william 198 {
303     try
304     {
305     if (AcceptedProcess == null) { return; }
306     if (AcceptedPlugin == null) { return; }
307    
308     byte[] data = GetMemory();
309 william 370 RamData = data;
310     #region old ascii-code
311 william 201 try
312     {
313 william 198 AddressList = "";
314     AsciiData = "";
315     // write the addreses out
316 william 249 for (int i = address; i < (address + max_ram_view); i += max_address_width)
317 william 198 {
318     AddressList = AddressList + string.Format("{0:X8}:\n", i);
319     }
320 william 201 //// write out the ascii data
321 william 198 StringBuilder builder = new StringBuilder();
322 william 370 int count = 0;
323     for (int i = 0; i < (0 + max_ram_view); i += max_address_width)
324 william 198 {
325 william 201 try
326 william 198 {
327 william 370 //bool NoAccessRegion = false;
328     //// preprocess line
329     //for (int j = 0; j < max_address_width; j++)
330     //{
331     // byte t = data[j];
332     // NoAccessRegion = (t == 0);
333     //}
334 william 249 for (int j = 0; j < max_address_width; j++)
335 william 198 {
336 william 370 int current_real_address = address + j +i;
337 william 249 int current_addr = i + j;
338 william 287 if (current_addr >= MemoryRangeSize) break;
339 william 370
340     byte ascii_value_raw = data[current_addr];
341     char ascii_value;
342     //if (ascii_value_raw == (byte)'?')
343     //{
344     // ascii_value_raw = 0;
345     // ascii_value = '?';
346     // RamData[count] = 0;
347     //}
348     //else
349     //{
350     // ascii_value = (char)data[j];
351     //}
352    
353     if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
354     {
355     ascii_value = (char)data[current_addr];
356     }
357     else
358     {
359     ascii_value = '.';
360     }
361    
362     GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
363     gmp.OpenProvider();
364     byte t;
365     if (!gmp.ReadMemory(current_real_address, out t)) { ascii_value = '?'; }
366     gmp.CloseProvider();
367    
368    
369 william 369 builder.Append(ascii_value.ToString());
370 william 198 }
371 william 201 builder.AppendLine();
372 william 198 }
373 william 201 catch (Exception ex)
374     {
375     logger.Error.WriteLine("{0}.UpdateMemroyView().BuildingAsciiString:{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
376     return;
377     }
378 william 370 count++;
379 william 198 }
380     AsciiData = builder.ToString();
381     }
382     catch (Exception ex)
383     {
384     logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
385     return;
386     }
387 william 370 #endregion
388 william 198 }
389     catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
390     }
391 william 207 //private void HexResourceViewerBytes_Changed(object sender, System.EventArgs e)
392     //{
393     // this.WriteCurrentBytes();
394     //}
395 william 249 private void WriteCurrentBytes(int start_address, byte[] data)
396 william 198 {
397     try
398     {
399     if (AcceptedProcess == null) { return; }
400     if (AcceptedPlugin == null) { return; }
401     // Byte changed
402 william 207 //byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray();
403 william 238 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
404 william 245 provider.OpenProvider();
405 william 198 int bytesReadSize;
406    
407 william 352 provider.WriteProcessMemory(start_address, data, out bytesReadSize);
408     //for (int i = 0; i < data.Length; i ++)
409     //{
410     // int addr = (int)(start_address + i);
411     // byte data_to_write = data[i];
412 william 370
413 william 352 //}
414 william 245 provider.CloseProvider();
415 william 198 }
416     catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
417     }
418    
419     private void update_timer_Tick(object sender, EventArgs e) { this.UpdateGui(); }
420     private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e) { try { this.UpdateMemroyView(); } catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_DoWork():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } }
421     private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
422     {
423     try
424     {
425 william 372 txtAddresses.Text = AddressList;
426     txtAscii.Text = AsciiData;
427 william 198 //this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length));
428     DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData);
429     txtData.ByteProvider = _DynamicByteProvider;
430 william 207 //_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed);
431 william 198 }
432     catch (ObjectDisposedException) { } // ignore errors aobut disposed objects (usually only happens when the parent closes)
433     catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_RunWorkerCompleted():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
434     }
435     private void Handle_KeyDown(object sender, KeyEventArgs e)
436     {
437     //isScrolling = false;
438     //bool reenable = false;
439     //if (this.UpdateEnabled) reenable = true;
440     //this.UpdateEnabled = false;
441    
442     this.UpdateMaxRamView();
443 william 249 int ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
444 william 198
445     ////if (e.Type == ScrollEventType.EndScroll) return;
446 william 205 //uint size = max_ram_view;
447 william 198
448     bool haveModifier = false;
449     switch (e.Modifiers)
450     {
451     case Keys.Control:
452     switch (e.KeyCode)
453     {
454     case Keys.Home:
455     this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false;
456     break;
457     case Keys.End:
458 william 287 this.CURRENT_TOP_ADDR = (int)((MemoryRangeSize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false;
459 william 198 break;
460     default:
461     //NonHandledKeysAreBeingPressed = true;
462     break;
463     }
464     break;
465     }
466    
467     if (!haveModifier)
468     {
469     switch (e.KeyCode)
470     {
471     case Keys.Up:
472 william 205 if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - small_scroll_change > this.CURRENT_TOP_ADDR))
473     {
474     this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
475     }
476     else
477     {
478 william 249 this.CURRENT_TOP_ADDR -= (int)small_scroll_change; //NonHandledKeysAreBeingPressed = false;
479 william 205 }
480 william 198 break;
481     case Keys.Down:
482 william 249 this.CURRENT_TOP_ADDR += (int)small_scroll_change; //NonHandledKeysAreBeingPressed = false;
483 william 198 break;
484     case Keys.PageUp:
485 william 205 if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - large_scroll_change > this.CURRENT_TOP_ADDR))
486     {
487     this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
488     }
489     else
490     {
491 william 249 this.CURRENT_TOP_ADDR -= (int)(large_scroll_change); //NonHandledKeysAreBeingPressed = false;
492 william 205 }
493 william 198 break;
494     case Keys.PageDown:
495 william 249 this.CURRENT_TOP_ADDR += (int)(large_scroll_change); //NonHandledKeysAreBeingPressed = false;
496 william 198 break;
497     default:
498     //NonHandledKeysAreBeingPressed = true;
499     break;
500     }
501     }
502 william 287 if (this.CURRENT_TOP_ADDR < MemoryRangeStart) this.CURRENT_TOP_ADDR = MemoryRangeStart;
503 william 198 //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view;
504 william 287 if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
505 william 370
506 william 198 //this.UpdateEnabled = reenable;
507     }
508    
509     private void UIMemoryViewer_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
510     private void txtAddresses_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
511     private void txtData_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
512    
513     private void ramScroll_Scroll(object sender, ScrollEventArgs e) { this.Handle_Scroll(sender, e); }
514 william 202
515     private ScrollEventArgs GetMouseWheelScrollChange(int WheelDelta)
516     {
517 william 370 ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
518 william 202 if (WheelDelta < 0)
519     {
520     //// negative: scroll down
521     //// SmallDecrement -or- LargeDecrement
522     //if (WheelDelta <= small_scroll_change)
523     //{
524     // args = new ScrollEventArgs(ScrollEventType.SmallDecrement,(int)small_scroll_change);
525     //}
526     //if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change)
527     //{
528     // args = new ScrollEventArgs(ScrollEventType.LargeDecrement, (int)large_scroll_change);
529     //}
530     args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
531     }
532     else
533     {
534     //// positive: scroll up
535     //// SmallIncrement -or- LargeIncrement
536     //if (WheelDelta <= small_scroll_change)
537     //{
538     // args = new ScrollEventArgs(ScrollEventType.SmallIncrement, (int)small_scroll_change);
539     //}
540     //if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change)
541     //{
542     // args = new ScrollEventArgs(ScrollEventType.LargeIncrement, (int)large_scroll_change);
543     //}
544     args = new ScrollEventArgs(ScrollEventType.SmallDecrement, 1);
545     }
546     return args;
547     }
548    
549     void txtAddresses_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
550     void txtData_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
551    
552 william 370
553 william 198 private void Handle_Scroll(object sender, ScrollEventArgs e)
554     {
555     //isScrolling = true;
556     //bool reenable = false;
557     //if (this.UpdateEnabled) reenable = true;
558     //this.UpdateEnabled = false;
559    
560     this.UpdateMaxRamView();
561 william 249 int ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
562 william 205 //uint size = MemorySize;
563 william 198 if (e.Type == ScrollEventType.EndScroll) return;
564    
565     switch (e.Type)
566     {
567     case ScrollEventType.SmallDecrement:
568 william 202 if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - small_scroll_change) > this.CURRENT_TOP_ADDR))
569     {
570     this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
571     }
572     else
573     {
574     this.CURRENT_TOP_ADDR -= (small_scroll_change);
575     }
576 william 198 break;
577     case ScrollEventType.SmallIncrement:
578     this.CURRENT_TOP_ADDR += (small_scroll_change);
579     break;
580    
581     case ScrollEventType.LargeDecrement:
582 william 202 if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - large_scroll_change) > this.CURRENT_TOP_ADDR))
583     {
584     this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
585     }
586     else
587     {
588     this.CURRENT_TOP_ADDR -= (large_scroll_change);
589     }
590 william 198 break;
591     case ScrollEventType.LargeIncrement:
592     this.CURRENT_TOP_ADDR += (large_scroll_change);
593     break;
594     case ScrollEventType.ThumbPosition:
595     //this.CURRENT_TOP_ADDR = (uint)e.NewValue;
596     //break;
597     default:
598 william 249 this.CURRENT_TOP_ADDR = (int)(e.NewValue & 0xFFFFFFF0);
599 william 198 break;
600     }
601     if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0;
602     //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view;
603     //if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
604 william 287 if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
605 william 198 //this.UpdateEnabled = reenable;
606     //isScrolling = false;
607     }
608 william 360 private void GotoImageBase()
609 william 370 {
610 william 326 if (this.peData == null) return;
611     object ImageBase = 0;
612 william 370 bool x86 = this.peData.Is32bitAssembly();
613 william 326 if (x86)
614     {
615     ImageBase = this.peData.NTHeader.OptionalHeader32._ImageBase;
616     uint ib = Convert.ToUInt32(ImageBase);
617 william 360 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x8})", ib);
618 william 357 txthexGoto.Value = ib;
619 william 326 }
620     else
621     {
622     ImageBase = this.peData.NTHeader.OptionalHeader64._ImageBase;
623 william 357 ulong ib = Convert.ToUInt64(ImageBase);
624 william 360 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x16})", ib);
625 william 326 txthexGoto.Value = (long)ib;
626     }
627 william 370
628 william 360 this.GotoAddress(txthexGoto.ToInt32());
629 william 326 }
630 william 360 private void btnGotoImageBase_Click(object sender, EventArgs e)
631     {
632 william 370
633 william 360 this.GotoImageBase();
634     }
635 william 326
636 william 198 }
637     }