Skip to content

Commit 208454e

Browse files
committed
Added a way to name a class after RTTI information associated with the class. This required some hairy work in a lot of places as the context menu wasn't usable on nested classes. It now is
1 parent 4d2f079 commit 208454e

14 files changed

+200
-38
lines changed

ReClass.NET/Controls/MemoryViewControl.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,5 +704,24 @@ public void Reset()
704704

705705
VerticalScroll.Value = VerticalScroll.Minimum;
706706
}
707+
708+
709+
public void AutoNameCurrentClassFromRTTI(ClassNode classNode)
710+
{
711+
var args = new DrawContextRequestEventArgs { Node = classNode };
712+
713+
var requestHandler = DrawContextRequested;
714+
requestHandler?.Invoke(this, args);
715+
var view = new DrawContext
716+
{
717+
Settings = args.Settings,
718+
Process = args.Process,
719+
Memory = args.Memory,
720+
CurrentTime = args.CurrentTime,
721+
Address = args.BaseAddress,
722+
Level = 0,
723+
};
724+
classNode.AutoNameFromRTTI(view);
725+
}
707726
}
708727
}

ReClass.NET/Forms/MainForm.Designer.cs

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

ReClass.NET/Forms/MainForm.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ private void memoryViewControl_SelectionChanged(object sender, EventArgs e)
835835

836836
addBytesToolStripDropDownButton.Enabled = parentContainer != null || isContainerNode;
837837
insertBytesToolStripDropDownButton.Enabled = selectedNodes.Count == 1 && parentContainer != null && !isContainerNode;
838+
autoNameClassToolStripMenuItem.Enabled = nodeIsClass;
838839

839840
var enabled = selectedNodes.Count > 0 && !nodeIsClass;
840841
toolStrip.Items.OfType<TypeToolStripButton>().ForEach(b => b.Enabled = enabled);
@@ -1027,7 +1028,7 @@ private void memoryViewControl_DrawContextRequested(object sender, DrawContextRe
10271028
{
10281029
var process = Program.RemoteProcess;
10291030

1030-
var classNode = CurrentClassNode;
1031+
var classNode = (args.Node as ClassNode) ?? CurrentClassNode;
10311032
if (classNode != null)
10321033
{
10331034
memoryViewBuffer.Size = classNode.MemorySize;
@@ -1051,5 +1052,17 @@ private void memoryViewControl_DrawContextRequested(object sender, DrawContextRe
10511052
args.BaseAddress = address;
10521053
}
10531054
}
1055+
1056+
1057+
private void autoNameClassToolStripMenuItem_Click(object sender, EventArgs e)
1058+
{
1059+
var selectedNodes = memoryViewControl.GetSelectedNodes();
1060+
var node = selectedNodes.FirstOrDefault()?.Node;
1061+
if (node == null || !(node is ClassNode))
1062+
{
1063+
return;
1064+
}
1065+
memoryViewControl.AutoNameCurrentClassFromRTTI(node as ClassNode);
1066+
}
10541067
}
10551068
}

ReClass.NET/Nodes/BaseContainerNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.Contracts;
44

@@ -183,8 +183,8 @@ public void ReplaceChildNode(BaseNode oldNode, BaseNode newNode, ref List<BaseNo
183183
}
184184

185185
newNode.CopyFromNode(oldNode);
186-
187186
newNode.ParentNode = this;
187+
newNode.PerformPostInitWork();
188188

189189
nodes[index] = newNode;
190190

ReClass.NET/Nodes/BaseHexCommentNode.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected int AddComment(DrawContext view, int x, int y, float fvalue, IntPtr iv
4444

4545
if (view.Settings.ShowCommentRtti)
4646
{
47-
var rtti = view.Process.ReadRemoteRuntimeTypeInformation(ivalue);
47+
var rtti = GetAssociatedRemoteRuntimeTypeInformation(view, ivalue);
4848
if (!string.IsNullOrEmpty(rtti))
4949
{
5050
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, rtti) + view.Font.Width;
@@ -110,5 +110,11 @@ protected int AddComment(DrawContext view, int x, int y, float fvalue, IntPtr iv
110110

111111
return x;
112112
}
113+
114+
115+
public string GetAssociatedRemoteRuntimeTypeInformation(DrawContext context, IntPtr ivalue)
116+
{
117+
return context.Process.ReadRemoteRuntimeTypeInformation(ivalue);
118+
}
113119
}
114120
}

ReClass.NET/Nodes/BaseNode.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public abstract class BaseNode
3939
/// <summary>Gets or sets the parent node.</summary>
4040
public BaseNode ParentNode { get; internal set; }
4141

42-
/// <summary>Gets a value indicating whether this node is wrapped into an other node.</summary>
43-
public bool IsWrapped => ParentNode is BaseWrapperNode;
42+
/// <summary>Gets a value indicating whether this node is wrapped into an other node. We see classnodes never as wrapped.</summary>
43+
public bool IsWrapped => (ParentNode is BaseWrapperNode && !(this is ClassNode));
4444

4545
/// <summary>Gets or sets a value indicating whether this node is hidden.</summary>
4646
public bool IsHidden { get; set; }
@@ -236,6 +236,15 @@ public virtual void ClearSelection()
236236
/// <returns>The calculated height.</returns>
237237
public abstract int CalculateDrawnHeight(DrawContext context);
238238

239+
/// <summary>
240+
/// Called when this node has been created, initialized and the parent node has been assigned. For some nodes
241+
/// Additional work has to be performed, this work can be done in a derived method of this method.
242+
/// </summary>
243+
public virtual void PerformPostInitWork()
244+
{
245+
// nop
246+
}
247+
239248
/// <summary>Updates the node from the given <paramref name="spot"/>. Sets the <see cref="Name"/> and <see cref="Comment"/> of the node.</summary>
240249
/// <param name="spot">The spot.</param>
241250
public virtual void Update(HotSpot spot)

0 commit comments

Comments
 (0)