-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathBaseHexNode.cs
More file actions
129 lines (101 loc) · 3.4 KB
/
BaseHexNode.cs
File metadata and controls
129 lines (101 loc) · 3.4 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Globalization;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;
using ReClassNET.Util;
namespace ReClassNET.Nodes
{
public abstract class BaseHexNode : BaseNode
{
private static readonly Random highlightRandom = new Random();
private static readonly Color[] highlightColors = {
Color.Aqua, Color.Aquamarine, Color.Blue, Color.BlueViolet, Color.Chartreuse, Color.Crimson, Color.LawnGreen, Color.Magenta
};
private static Color GetRandomHighlightColor() => highlightColors[highlightRandom.Next(highlightColors.Length)];
private static readonly TimeSpan hightlightDuration = TimeSpan.FromSeconds(1);
private static readonly Dictionary<IntPtr, ValueTypeWrapper<DateTime>> highlightTimer = new Dictionary<IntPtr, ValueTypeWrapper<DateTime>>();
private readonly byte[] buffer;
protected BaseHexNode()
{
Contract.Ensures(buffer != null);
buffer = new byte[MemorySize];
}
protected Size Draw(DrawContext context, int x, int y, string text, int length)
{
Contract.Requires(context != null);
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
var origX = x;
AddSelection(context, x, y, context.Font.Height);
x = AddIconPadding(context, x);
x = AddIconPadding(context, x);
x = AddAddressOffset(context, x, y);
if (!string.IsNullOrEmpty(text))
{
x = AddText(context, x, y, context.Settings.TextColor, HotSpot.NoneId, text);
}
context.Memory.ReadBytes(Offset, buffer);
var color = context.Settings.HexColor;
if (context.Settings.HighlightChangedValues)
{
var address = context.Address + Offset;
highlightTimer.RemoveWhere(kv => kv.Value.Value < context.CurrentTime);
if (highlightTimer.TryGetValue(address, out var until))
{
if (until.Value >= context.CurrentTime)
{
color = GetRandomHighlightColor();
if (context.Memory.HasChanged(Offset, MemorySize))
{
until.Value = context.CurrentTime.Add(hightlightDuration);
}
}
}
else if (context.Memory.HasChanged(Offset, MemorySize))
{
highlightTimer.Add(address, context.CurrentTime.Add(hightlightDuration));
color = GetRandomHighlightColor();
}
}
for (var i = 0; i < length; ++i)
{
x = AddText(context, x, y, color, i, $"{buffer[i]:X02}") + 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;
}
/// <summary>Updates the node from the given spot. Sets the value of the selected byte.</summary>
/// <param name="spot">The spot.</param>
/// <param name="maxId">The highest spot id.</param>
public void Update(HotSpot spot, int maxId)
{
Contract.Requires(spot != null);
base.Update(spot);
if (spot.Id >= 0 && spot.Id < maxId)
{
if (byte.TryParse(spot.Text, NumberStyles.HexNumber, null, out var val))
{
spot.Process.WriteRemoteMemory(spot.Address + spot.Id, val);
}
}
}
public byte[] ReadValueFromMemory(MemoryBuffer memory)
{
return memory.ReadBytes(Offset, MemorySize);
}
}
}