-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathBaseHexNode.cs
More file actions
122 lines (95 loc) · 2.92 KB
/
BaseHexNode.cs
File metadata and controls
122 lines (95 loc) · 2.92 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
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Globalization;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;
using ReClassNET.Util;
namespace ReClassNET.Nodes
{
public abstract class BaseHexNode : BaseNode
{
public static DateTime CurrentHighlightTime;
public 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(ViewInfo view, int x, int y, string text, int length)
{
Contract.Requires(view != null);
if (IsHidden)
{
return DrawHidden(view, x, y);
}
DrawInvalidMemoryIndicator(view, y);
var origX = x;
AddSelection(view, x, y, view.Font.Height);
x += TextPadding + 16;
x = AddAddressOffset(view, x, y);
if (!string.IsNullOrEmpty(text))
{
x = AddText(view, x, y, view.Settings.TextColor, HotSpot.NoneId, text);
}
view.Memory.ReadBytes(Offset, buffer);
var color = view.Settings.HexColor;
if (view.Settings.HighlightChangedValues)
{
var address = view.Address.Add(Offset);
highlightTimer.RemoveWhere(kv => kv.Value.Value < CurrentHighlightTime);
if (highlightTimer.TryGetValue(address, out var until))
{
if (until.Value >= CurrentHighlightTime)
{
color = view.Settings.HighlightColor;
if (view.Memory.HasChanged(Offset, MemorySize))
{
until.Value = CurrentHighlightTime.Add(HightlightDuration);
}
}
}
else if (view.Memory.HasChanged(Offset, MemorySize))
{
highlightTimer.Add(address, CurrentHighlightTime.Add(HightlightDuration));
color = view.Settings.HighlightColor;
}
}
for (var i = 0; i < length; ++i)
{
x = AddText(view, x, y, color, i, $"{buffer[i]:X02}") + view.Font.Width;
}
x = AddComment(view, x, y);
AddTypeDrop(view, y);
AddDelete(view, y);
return new Size(x - origX, view.Font.Height);
}
public override int CalculateDrawnHeight(ViewInfo view)
{
return IsHidden ? HiddenHeight : view.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.Memory.Process.WriteRemoteMemory(spot.Address + spot.Id, val);
}
}
}
public byte[] ReadValueFromMemory(MemoryBuffer memory)
{
return memory.ReadBytes(Offset, MemorySize);
}
}
}