Skip to content

Commit 35cb367

Browse files
committed
Added MemoryPreviewToolTip.
1 parent efbc1d7 commit 35cb367

File tree

8 files changed

+166
-15
lines changed

8 files changed

+166
-15
lines changed

Nodes/BaseNode.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ public virtual void Intialize()
9797

9898
}
9999

100+
public virtual bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, out IntPtr address)
101+
{
102+
Contract.Requires(spot != null);
103+
Contract.Requires(memory != null);
104+
105+
address = IntPtr.Zero;
106+
107+
return false;
108+
}
109+
100110
/// <summary>Gets informations about this node to show in a tool tip.</summary>
101111
/// <param name="spot">The spot.</param>
102112
/// <param name="memory">The process memory.</param>

Nodes/Hex32Node.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ReClassNET.Memory;
1+
using System;
2+
using ReClassNET.Memory;
23
using ReClassNET.UI;
34

45
namespace ReClassNET.Nodes
@@ -8,6 +9,15 @@ public class Hex32Node : BaseHexCommentNode
89
/// <summary>Size of the node in bytes.</summary>
910
public override int MemorySize => 4;
1011

12+
public override bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, out IntPtr address)
13+
{
14+
var value = memory.ReadObject<UInt32FloatData>(Offset);
15+
16+
address = value.IntPtr;
17+
18+
return memory.Process.GetNamedAddress(value.IntPtr) != null;
19+
}
20+
1121
/// <summary>Gets informations about this node to show in a tool tip.</summary>
1222
/// <param name="spot">The spot.</param>
1323
/// <param name="memory">The process memory.</param>

Nodes/Hex64Node.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ReClassNET.Memory;
1+
using System;
2+
using ReClassNET.Memory;
23
using ReClassNET.UI;
34

45
namespace ReClassNET.Nodes
@@ -8,6 +9,15 @@ public class Hex64Node : BaseHexCommentNode
89
/// <summary>Size of the node in bytes.</summary>
910
public override int MemorySize => 8;
1011

12+
public override bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, out IntPtr address)
13+
{
14+
var value = memory.ReadObject<UInt64FloatDoubleData>(Offset);
15+
16+
address = value.IntPtr;
17+
18+
return memory.Process.GetSectionToPointer(value.IntPtr) != null;
19+
}
20+
1121
/// <summary>Gets informations about this node to show in a tool tip.</summary>
1222
/// <param name="spot">The spot.</param>
1323
/// <param name="memory">The process memory.</param>

ReClass.NET.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@
218218
<DependentUpon>LogForm.cs</DependentUpon>
219219
</Compile>
220220
<Compile Include="UI\ISettingsBindable.cs" />
221+
<Compile Include="UI\MemoryPreviewToolTip.cs">
222+
<SubType>Component</SubType>
223+
</Compile>
221224
<Compile Include="UI\MemoryViewControl.Designer.cs">
222225
<DependentUpon>MemoryViewControl.cs</DependentUpon>
223226
</Compile>

UI/MemoryPreviewToolTip.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Drawing;
5+
using System.Drawing.Drawing2D;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
using ReClassNET.Memory;
11+
using ReClassNET.Nodes;
12+
13+
namespace ReClassNET.UI
14+
{
15+
public class MemoryPreviewToolTip : ToolTip
16+
{
17+
[Browsable(false)]
18+
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
19+
public FontEx Font
20+
{
21+
get { return viewInfo.Font; }
22+
set { viewInfo.Font = value; }
23+
}
24+
25+
[Browsable(false)]
26+
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
27+
public MemoryBuffer Memory
28+
{
29+
get { return viewInfo.Memory; }
30+
set { viewInfo.Memory = value; }
31+
}
32+
33+
private readonly List<BaseHexNode> nodes;
34+
35+
private readonly ViewInfo viewInfo;
36+
37+
private Size size = new Size();
38+
39+
public MemoryPreviewToolTip()
40+
{
41+
OwnerDraw = true;
42+
43+
#if WIN64
44+
nodes = new List<BaseHexNode>(Enumerable.Range(0, 10).Select(i => new Hex64Node { Offset = (IntPtr)(i * 8) }));
45+
#else
46+
nodes = new List<BaseHexNode>(Enumerable.Range(0, 10).Select(i => new Hex32Node { Offset = (IntPtr)(i * 4) }));
47+
#endif
48+
49+
viewInfo = new ViewInfo
50+
{
51+
Memory = new MemoryBuffer { Size = nodes.Select(n => n.MemorySize).Sum() },
52+
53+
HotSpots = new List<HotSpot>(),
54+
Classes = new List<ClassNode>()
55+
};
56+
57+
Popup += new PopupEventHandler(OnPopup);
58+
Draw += new DrawToolTipEventHandler(OnDraw);
59+
}
60+
61+
private void OnPopup(object sender, PopupEventArgs e)
62+
{
63+
size.Width = 604;
64+
size.Height = nodes.Select(n => n.CalculateHeight(viewInfo)).Sum() + 4;
65+
66+
e.ToolTipSize = size;
67+
68+
viewInfo.ClientArea = new Rectangle(2, 2, size.Width - 4, size.Height - 4);
69+
}
70+
71+
private void OnDraw(object sender, DrawToolTipEventArgs e)
72+
{
73+
viewInfo.HotSpots.Clear();
74+
75+
viewInfo.Context = e.Graphics;
76+
77+
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
78+
using (var pen = new Pen(Brushes.Black, 1))
79+
{
80+
e.Graphics.DrawRectangle(pen, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
81+
}
82+
83+
int x = -24;
84+
int y = 2;
85+
foreach (var node in nodes)
86+
{
87+
y = node.Draw(viewInfo, x, y);
88+
}
89+
}
90+
91+
public void UpdateMemory(RemoteProcess process, IntPtr address)
92+
{
93+
viewInfo.Memory.Process = process;
94+
viewInfo.Memory.Update(address);
95+
}
96+
}
97+
}

UI/MemoryViewControl.Designer.cs

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UI/MemoryViewControl.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public MemoryViewControl()
8787
};
8888

8989
editBox.Font = font;
90+
memoryPreviewToolTip.Font = font;
9091
}
9192

9293
protected override void OnLoad(EventArgs e)
@@ -452,18 +453,28 @@ protected override void OnMouseHover(EventArgs e)
452453
if (selectedNodes.Count > 1)
453454
{
454455
var memorySize = selectedNodes.Select(h => h.Node.MemorySize).Sum();
455-
toolTip.Show($"{selectedNodes.Count} Nodes selected, {memorySize} bytes", this, toolTipPosition.OffsetEx(16, 16));
456+
nodeInfoToolTip.Show($"{selectedNodes.Count} Nodes selected, {memorySize} bytes", this, toolTipPosition.OffsetEx(16, 16));
456457
}
457458
else
458459
{
459460
foreach (var spot in hotSpots.Where(h => h.Type == HotSpotType.Select))
460461
{
461462
if (spot.Rect.Contains(toolTipPosition))
462463
{
463-
var text = spot.Node.GetToolTipText(spot, spot.Memory);
464-
if (!string.IsNullOrEmpty(text))
464+
IntPtr previewAddress;
465+
if (spot.Node.UseMemoryPreviewToolTip(spot, spot.Memory, out previewAddress))
465466
{
466-
toolTip.Show(text, this, toolTipPosition.OffsetEx(16, 16));
467+
memoryPreviewToolTip.UpdateMemory(spot.Memory.Process, previewAddress);
468+
469+
memoryPreviewToolTip.Show("<>", this, toolTipPosition.OffsetEx(16, 16));
470+
}
471+
else
472+
{
473+
var text = spot.Node.GetToolTipText(spot, spot.Memory);
474+
if (!string.IsNullOrEmpty(text))
475+
{
476+
nodeInfoToolTip.Show(text, this, toolTipPosition.OffsetEx(16, 16));
477+
}
467478
}
468479

469480
return;
@@ -482,7 +493,8 @@ protected override void OnMouseMove(MouseEventArgs e)
482493
{
483494
toolTipPosition = e.Location;
484495

485-
toolTip.Hide(this);
496+
nodeInfoToolTip.Hide(this);
497+
memoryPreviewToolTip.Hide(this);
486498

487499
ResetMouseEventArgs();
488500
}

UI/MemoryViewControl.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@
123123
<metadata name="repaintTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124124
<value>243, 17</value>
125125
</metadata>
126-
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
126+
<metadata name="nodeInfoToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
127127
<value>364, 17</value>
128128
</metadata>
129+
<metadata name="memoryPreviewToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
130+
<value>506, 17</value>
131+
</metadata>
129132
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
130133
<value>65</value>
131134
</metadata>

0 commit comments

Comments
 (0)