Skip to content

Commit f97fe47

Browse files
committed
Added changable class.
1 parent ca6b399 commit f97fe47

File tree

5 files changed

+97
-30
lines changed

5 files changed

+97
-30
lines changed

Nodes/BaseFunctionPtrNode.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ReClassNET.Nodes
1010
public abstract class BaseFunctionPtrNode : BaseNode
1111
{
1212
private IntPtr address = IntPtr.Zero;
13-
private readonly List<string> disassembledCode = new List<string>();
13+
private readonly List<string> instructions = new List<string>();
1414

1515
/// <summary>Size of the node in bytes.</summary>
1616
public override int MemorySize => IntPtr.Size;
@@ -21,7 +21,7 @@ public override string GetToolTipText(HotSpot spot, MemoryBuffer memory)
2121

2222
DisassembleRemoteCode(memory, ptr);
2323

24-
return string.Join("\n", disassembledCode);
24+
return string.Join("\n", instructions);
2525
}
2626

2727
protected int Draw(ViewInfo view, int x, int y, string type, string name)
@@ -42,10 +42,11 @@ protected int Draw(ViewInfo view, int x, int y, string type, string name)
4242
x += TextPadding;
4343

4444
x = AddIcon(view, x, y, Icons.Function, -1, HotSpotType.None);
45-
x = AddAddressOffset(view, x, y);
4645

4746
var tx = x;
4847

48+
x = AddAddressOffset(view, x, y);
49+
4950
x = AddText(view, x, y, Program.Settings.TypeColor, HotSpot.NoneId, type) + view.Font.Width;
5051
x = AddText(view, x, y, Program.Settings.NameColor, HotSpot.NameId, name) + view.Font.Width;
5152

@@ -78,7 +79,7 @@ protected int Draw(ViewInfo view, int x, int y, string type, string name)
7879

7980
DisassembleRemoteCode(view.Memory, ptr);
8081

81-
foreach (var line in disassembledCode)
82+
foreach (var line in instructions)
8283
{
8384
y += view.Font.Height;
8485

@@ -99,7 +100,7 @@ public override int CalculateHeight(ViewInfo view)
99100
var h = view.Font.Height;
100101
if (levelsOpen[view.Level])
101102
{
102-
h += disassembledCode.Count * view.Font.Height;
103+
h += instructions.Count * view.Font.Height;
103104
}
104105
return h;
105106
}
@@ -110,7 +111,7 @@ private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
110111

111112
if (this.address != address)
112113
{
113-
disassembledCode.Clear();
114+
instructions.Clear();
114115

115116
this.address = address;
116117

@@ -121,9 +122,9 @@ private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
121122
address,
122123
200,
123124
#if WIN64
124-
(a, l, i) => disassembledCode.Add($"{a.ToString("X08")} {i}")
125+
(a, l, i) => instructions.Add($"{a.ToString("X08")} {i}")
125126
#else
126-
(a, l, i) => disassembledCode.Add($"{a.ToString("X04")} {i}")
127+
(a, l, i) => instructions.Add($"{a.ToString("X04")} {i}")
127128
#endif
128129
);
129130
}

Nodes/FunctionNode.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Collections.Generic;
33
using System.Diagnostics.Contracts;
44
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
75
using ReClassNET.Memory;
86
using ReClassNET.UI;
97
using ReClassNET.Util;
@@ -12,19 +10,22 @@ namespace ReClassNET.Nodes
1210
{
1311
public class FunctionNode : BaseNode
1412
{
15-
private int memorySize = IntPtr.Size;
16-
1713
private IntPtr address = IntPtr.Zero;
18-
private readonly List<string> disassembledCode = new List<string>();
14+
private readonly List<string> instructions = new List<string>();
15+
16+
private string signature = "void function()";
1917

18+
public ClassNode BelongsToClass { get; set; }
19+
20+
private int memorySize = IntPtr.Size;
2021
/// <summary>Size of the node in bytes.</summary>
2122
public override int MemorySize => memorySize;
2223

2324
public override string GetToolTipText(HotSpot spot, MemoryBuffer memory)
2425
{
2526
DisassembleRemoteCode(memory, spot.Address);
2627

27-
return string.Join("\n", disassembledCode);
28+
return string.Join("\n", instructions);
2829
}
2930

3031
public override int Draw(ViewInfo view, int x, int y)
@@ -43,10 +44,11 @@ public override int Draw(ViewInfo view, int x, int y)
4344
x += TextPadding;
4445

4546
x = AddIcon(view, x, y, Icons.Function, -1, HotSpotType.None);
46-
x = AddAddressOffset(view, x, y);
4747

4848
var tx = x;
4949

50+
x = AddAddressOffset(view, x, y);
51+
5052
x = AddText(view, x, y, Program.Settings.TypeColor, HotSpot.NoneId, "Function") + view.Font.Width;
5153
x = AddText(view, x, y, Program.Settings.NameColor, HotSpot.NameId, Name) + view.Font.Width;
5254

@@ -60,7 +62,16 @@ public override int Draw(ViewInfo view, int x, int y)
6062

6163
if (levelsOpen[view.Level])
6264
{
63-
foreach (var line in disassembledCode)
65+
y += view.Font.Height;
66+
x = AddText(view, tx, y, Program.Settings.TypeColor, HotSpot.NoneId, "Signature:") + view.Font.Width;
67+
x = AddText(view, x, y, Program.Settings.ValueColor, 0, signature);
68+
69+
y += view.Font.Height;
70+
x = AddText(view, tx, y, Program.Settings.TextColor, HotSpot.NoneId, "Belongs to: ");
71+
x = AddText(view, x, y, Program.Settings.ValueColor, HotSpot.NoneId, BelongsToClass == null ? "<None>" : $"<{BelongsToClass.Name}>");
72+
x = AddIcon(view, x, y, Icons.Change, 1, HotSpotType.ChangeType);
73+
74+
foreach (var line in instructions)
6475
{
6576
y += view.Font.Height;
6677

@@ -81,18 +92,32 @@ public override int CalculateHeight(ViewInfo view)
8192
var h = view.Font.Height;
8293
if (levelsOpen[view.Level])
8394
{
84-
h += disassembledCode.Count() * view.Font.Height;
95+
h += instructions.Count() * view.Font.Height;
8596
}
8697
return h;
8798
}
8899

100+
public override void Update(HotSpot spot)
101+
{
102+
base.Update(spot);
103+
104+
if (spot.Id == 0) // Signature
105+
{
106+
signature = spot.Text;
107+
}
108+
else if (spot.Id == 1)
109+
{
110+
111+
}
112+
}
113+
89114
private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
90115
{
91116
Contract.Requires(memory != null);
92117

93118
if (this.address != address)
94119
{
95-
disassembledCode.Clear();
120+
instructions.Clear();
96121

97122
this.address = address;
98123

@@ -108,9 +133,9 @@ private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
108133
{
109134
memorySize += l;
110135
#if WIN64
111-
disassembledCode.Add($"{a.ToString("X08")} {i}");
136+
instructions.Add($"{a.ToString("X08")} {i}");
112137
#else
113-
disassembledCode.Add($"{a.ToString("X04")} {i}");
138+
instructions.Add($"{a.ToString("X04")} {i}");
114139
#endif
115140
}
116141
);

Nodes/FunctionPtrNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class FunctionPtrNode : BaseFunctionPtrNode
1111
/// <returns>The height the node occupies.</returns>
1212
public override int Draw(ViewInfo view, int x, int y)
1313
{
14-
return Draw(view, x, y, "Function", Name);
14+
return Draw(view, x, y, "FunctionPtr", Name);
1515
}
1616
}
1717
}

ReClass.NET.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
</Compile>
155155
<Compile Include="Memory\NodeDissector.cs" />
156156
<Compile Include="Memory\UnionDataType.cs" />
157-
<Compile Include="Nodes\BaseFunctionNode.cs" />
158157
<Compile Include="Nodes\BoolNode.cs" />
159158
<Compile Include="Nodes\ClassUtil.cs" />
160159
<Compile Include="Nodes\FunctionNode.cs" />

UI/MemoryViewControl.cs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,50 @@ protected override void OnMouseClick(MouseEventArgs e)
323323
}
324324
else if (hotSpot.Type == HotSpotType.ChangeType)
325325
{
326+
IEnumerable<TypeToolStripMenuItem> items = null;
327+
328+
var functionNode = hitObject as FunctionNode;
329+
if (functionNode != null)
330+
{
331+
var noneClass = new ClassNode(false)
332+
{
333+
Name = "None"
334+
};
335+
336+
EventHandler handler = (sender2, e2) =>
337+
{
338+
var classNode = (sender2 as TypeToolStripMenuItem)?.Tag as ClassNode;
339+
if (classNode == null)
340+
{
341+
return;
342+
}
343+
344+
if (classNode == noneClass)
345+
{
346+
classNode = null;
347+
}
348+
349+
functionNode.BelongsToClass = classNode;
350+
};
351+
352+
items = noneClass.Yield()
353+
.Concat(project.Classes.OrderBy(c => c.Name))
354+
.Select(c =>
355+
{
356+
var b = new TypeToolStripMenuItem
357+
{
358+
Text = c.Name,
359+
Tag = c
360+
};
361+
b.Click += handler;
362+
return b;
363+
});
364+
}
365+
326366
var refNode = hitObject as BaseReferenceNode;
327367
if (refNode != null)
328368
{
329-
EventHandler changeInnerType = (sender2, e2) =>
369+
EventHandler handler = (sender2, e2) =>
330370
{
331371
var classNode = (sender2 as TypeToolStripMenuItem)?.Tag as ClassNode;
332372
if (classNode == null)
@@ -340,9 +380,7 @@ protected override void OnMouseClick(MouseEventArgs e)
340380
}
341381
};
342382

343-
var menu = new ContextMenuStrip();
344-
menu.Items.AddRange(
345-
project.Classes
383+
items = project.Classes
346384
.OrderBy(c => c.Name)
347385
.Select(c =>
348386
{
@@ -351,11 +389,15 @@ protected override void OnMouseClick(MouseEventArgs e)
351389
Text = c.Name,
352390
Tag = c
353391
};
354-
b.Click += changeInnerType;
392+
b.Click += handler;
355393
return b;
356-
})
357-
.ToArray()
358-
);
394+
});
395+
}
396+
397+
if (items != null)
398+
{
399+
var menu = new ContextMenuStrip();
400+
menu.Items.AddRange(items.ToArray());
359401
menu.Show(this, e.Location);
360402
}
361403
}

0 commit comments

Comments
 (0)