-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathBaseTextNode.cs
More file actions
102 lines (80 loc) · 2.8 KB
/
BaseTextNode.cs
File metadata and controls
102 lines (80 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Text;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;
namespace ReClassNET.Nodes
{
public abstract class BaseTextNode : BaseNode
{
public int Length { get; set; }
public override int MemorySize => Length * CharacterSize;
/// <summary>The encoding of the string.</summary>
public abstract Encoding Encoding { get; }
/// <summary>Size of one character in bytes.</summary>
private int CharacterSize => Encoding.GuessByteCountPerChar();
public override void CopyFromNode(BaseNode node)
{
Length = node.MemorySize / CharacterSize;
}
protected Size DrawText(DrawContext context, int x, int y, string type)
{
Contract.Requires(context != null);
Contract.Requires(type != null);
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
var length = MemorySize / CharacterSize;
var text = ReadValueFromMemory(context.Memory);
var origX = x;
AddSelection(context, x, y, context.Font.Height);
x = AddIconPadding(context, x);
x = AddIcon(context, x, y, context.IconProvider.Text, HotSpot.NoneId, HotSpotType.None);
x = AddAddressOffset(context, x, y);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, type) + context.Font.Width;
if (!IsWrapped)
{
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name);
}
x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, "[");
x = AddText(context, x, y, context.Settings.IndexColor, 0, length.ToString());
x = AddText(context, x, y, context.Settings.IndexColor, HotSpot.NoneId, "]") + context.Font.Width;
x = AddText(context, x, y, context.Settings.TextColor, HotSpot.NoneId, "= '");
x = AddText(context, x, y, context.Settings.TextColor, 1, text.LimitLength(150));
x = AddText(context, x, y, context.Settings.TextColor, HotSpot.NoneId, "'") + context.Font.Width;
x = AddComment(context, x, y);
DrawInvalidMemoryIndicatorIcon(context, y);
AddContextDropDownIcon(context, y);
AddDeleteIcon(context, y);
return new Size(x - origX, context.Font.Height);
}
public override int CalculateDrawnHeight(DrawContext context)
{
return IsHidden && !IsWrapped ? HiddenHeight : context.Font.Height;
}
public override void Update(HotSpot spot)
{
base.Update(spot);
if (spot.Id == 0)
{
if (int.TryParse(spot.Text, out var val) && val > 0)
{
Length = val;
GetParentContainer()?.ChildHasChanged(this);
}
}
else if (spot.Id == 1)
{
var data = Encoding.GetBytes(spot.Text);
spot.Process.WriteRemoteMemory(spot.Address, data);
}
}
public string ReadValueFromMemory(MemoryBuffer memory)
{
return memory.ReadString(Encoding, Offset, MemorySize);
}
}
}