-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathMemoryRecordList.cs
More file actions
195 lines (163 loc) · 4.85 KB
/
MemoryRecordList.cs
File metadata and controls
195 lines (163 loc) · 4.85 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.MemoryScanner;
using ReClassNET.UI;
namespace ReClassNET.Controls
{
public delegate void MemorySearchResultControlResultDoubleClickEventHandler(object sender, MemoryRecord record);
public partial class MemoryRecordList : UserControl
{
public bool ShowDescriptionColumn
{
get => descriptionColumn.Visible;
set => descriptionColumn.Visible = value;
}
public bool ShowAddressColumn
{
get => addressColumn.Visible;
set => addressColumn.Visible = value;
}
public bool ShowValueTypeColumn
{
get => valueTypeColumn.Visible;
set => valueTypeColumn.Visible = value;
}
public bool ShowValueColumn
{
get => valueColumn.Visible;
set => valueColumn.Visible = value;
}
public bool ShowPreviousValueColumn
{
get => previousValueColumn.Visible;
set => previousValueColumn.Visible = value;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IList<MemoryRecord> Records => bindings;
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public MemoryRecord SelectedRecord => GetSelectedRecords().FirstOrDefault();
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IList<MemoryRecord> SelectedRecords => GetSelectedRecords().ToList();
public override ContextMenuStrip ContextMenuStrip
{
get;
set;
}
public event MemorySearchResultControlResultDoubleClickEventHandler RecordDoubleClick;
private readonly BindingList<MemoryRecord> bindings;
public MemoryRecordList()
{
InitializeComponent();
if (Program.DesignMode)
{
return;
}
bindings = new BindingList<MemoryRecord>
{
AllowNew = true,
AllowEdit = true,
RaiseListChangedEvents = true
};
resultDataGridView.AutoGenerateColumns = false;
resultDataGridView.DefaultCellStyle.Font = new Font(
Program.MonoSpaceFont.Font.FontFamily,
DpiUtil.ScaleIntX(11),
GraphicsUnit.Pixel
);
resultDataGridView.DataSource = bindings;
}
#region Event Handler
private void resultDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
OnRecordDoubleClick((MemoryRecord)resultDataGridView.Rows[e.RowIndex].DataBoundItem);
}
private void resultDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1) // Address
{
var record = (MemoryRecord)resultDataGridView.Rows[e.RowIndex].DataBoundItem;
if (record.IsRelativeAddress)
{
e.CellStyle.ForeColor = Color.ForestGreen;
e.FormattingApplied = true;
}
}
else if (e.ColumnIndex == 3) // Value
{
var record = (MemoryRecord)resultDataGridView.Rows[e.RowIndex].DataBoundItem;
e.CellStyle.ForeColor = record.HasChangedValue ? Color.Red : Color.Black;
e.FormattingApplied = true;
}
}
private void resultDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex != -1)
{
var row = resultDataGridView.Rows[e.RowIndex];
if (!row.Selected && !(ModifierKeys == Keys.Shift || ModifierKeys == Keys.Control))
{
resultDataGridView.ClearSelection();
}
row.Selected = true;
}
}
}
private void resultDataGridView_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e)
{
e.ContextMenuStrip = ContextMenuStrip;
}
#endregion
private IEnumerable<MemoryRecord> GetSelectedRecords() => resultDataGridView.SelectedRows.Cast<DataGridViewRow>().Select(r => (MemoryRecord)r.DataBoundItem);
/// <summary>
/// Sets the records to display.
/// </summary>
/// <param name="records">The records.</param>
public void SetRecords(IEnumerable<MemoryRecord> records)
{
Contract.Requires(records != null);
bindings.Clear();
bindings.RaiseListChangedEvents = false;
foreach (var record in records)
{
bindings.Add(record);
}
bindings.RaiseListChangedEvents = true;
bindings.ResetBindings();
}
/// <summary>
/// Removes all records.
/// </summary>
public void Clear()
{
bindings.Clear();
}
/// <summary>
/// Refreshes the data of all displayed records.
/// </summary>
/// <param name="process">The process.</param>
public void RefreshValues(RemoteProcess process)
{
Contract.Requires(process != null);
foreach (var record in resultDataGridView.GetVisibleRows().Select(r => (MemoryRecord)r.DataBoundItem))
{
record.RefreshValue(process);
}
}
private void OnRecordDoubleClick(MemoryRecord record)
{
var evt = RecordDoubleClick;
evt?.Invoke(this, record);
}
}
}