-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCryMemoryDissectionChangeValueWindow.cpp
221 lines (208 loc) · 6.85 KB
/
CryMemoryDissectionChangeValueWindow.cpp
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "CryMemoryDissectionChangeValueWindow.h"
#include "ImlProvider.h"
#include "UIUtilities.h"
#include "BackendGlobalDef.h"
// CryMemoryDissectionChangeValueWindow default constructor.
CryMemoryDissectionChangeValueWindow::CryMemoryDissectionChangeValueWindow(SIZE_T address, CCryDataType rowType, int* size) : CryDialogTemplate(CrySearchIml::ChangeRecordIcon())
{
this->address = address;
this->rowType = rowType;
this->size = size;
this->Title("Change Value").SetRect(0, 0, 250, 120);
this->mCancel <<= THISBACK(CancelDialog);
this->mOk <<= THISBACK(DialogOkay);
*this
<< this->mCancel.SetLabel("Cancel").HSizePos(190, 5).BottomPos(5, 25)
<< this->mOk.Ok().SetLabel("OK").HSizePos(130, 60).BottomPos(5, 25)
<< this->mFieldDescription.SetLabel("Value:").HSizePos(5, 100).TopPos(5, 25)
<< this->mFieldValue.HSizePos(110, 5).TopPos(5, 25)
;
if (this->rowType == CRYDATATYPE_BYTE || this->rowType == CRYDATATYPE_2BYTES ||
this->rowType == CRYDATATYPE_4BYTES || this->rowType == CRYDATATYPE_8BYTES)
{
*this << this->mValueIsHex.SetLabel("Hexadecimal").HSizePos(5, 100).TopPos(30, 20);
this->mValueIsHex.WhenAction = THISBACK(ValueModeHexOptionChanged);
}
// Read and format existing value from memory for display inside the input field.
if (this->rowType == CRYDATATYPE_BYTE)
{
Byte value;
mMemoryScanner->Peek(this->address, sizeof(Byte), &value);
this->mFieldValue.SetText(FormatIntSpecial(value));
}
else if (this->rowType == CRYDATATYPE_2BYTES)
{
short value;
mMemoryScanner->Peek(this->address, sizeof(short), &value);
this->mFieldValue.SetText(FormatIntSpecial(value));
}
else if (this->rowType == CRYDATATYPE_4BYTES)
{
int value;
mMemoryScanner->Peek(this->address, sizeof(int), &value);
this->mFieldValue.SetText(FormatIntSpecial(value));
}
else if (this->rowType == CRYDATATYPE_8BYTES)
{
__int64 value;
mMemoryScanner->Peek(this->address, sizeof(__int64), &value);
this->mFieldValue.SetText(FormatIntSpecial64(value));
}
else if (this->rowType == CRYDATATYPE_FLOAT)
{
float value;
mMemoryScanner->Peek(this->address, sizeof(float), &value);
this->mFieldValue.SetText(DblStr(value));
}
else if (this->rowType == CRYDATATYPE_DOUBLE)
{
double value;
mMemoryScanner->Peek(this->address, sizeof(double), &value);
this->mFieldValue.SetText(DblStr(value));
}
else if (this->rowType == CRYDATATYPE_AOB)
{
ArrayOfBytes value;
mMemoryScanner->PeekB(this->address, *this->size, value);
this->mFieldValue.SetText(BytesToString(value.Data, value.Size));
}
else if (this->rowType == CRYDATATYPE_STRING)
{
String value;
mMemoryScanner->PeekA(this->address, *this->size, value);
this->mFieldValue.SetText(value);
}
else if (this->rowType == CRYDATATYPE_WSTRING)
{
WString value;
mMemoryScanner->PeekW(this->address, *this->size, value);
this->mFieldValue.SetText(value.ToString());
}
}
// CryMemoryDissectionChangeValueWindow default destructor.
CryMemoryDissectionChangeValueWindow::~CryMemoryDissectionChangeValueWindow()
{
}
// Executed when the view mode is changed from or to hexadecimal mode.
void CryMemoryDissectionChangeValueWindow::ValueModeHexOptionChanged()
{
if (this->mValueIsHex)
{
if (this->rowType == CRYDATATYPE_8BYTES)
{
__int64 v = ScanInt64(this->mFieldValue.GetText().ToString());
this->mFieldValue.SetText(FormatInt64HexUpper(v));
}
else if (this->rowType == CRYDATATYPE_4BYTES)
{
int v = ScanInt(this->mFieldValue.GetText().ToString());
this->mFieldValue.SetText(FormatHexadecimalIntSpecial(v));
}
else if (this->rowType == CRYDATATYPE_2BYTES)
{
short v = ScanInt(this->mFieldValue.GetText().ToString());
char text[64];
sprintf_s(text, 64, "%hX", v);
this->mFieldValue.SetText(text);
}
else if (this->rowType == CRYDATATYPE_BYTE)
{
Byte v = ScanInt(this->mFieldValue.GetText().ToString());
char text[64];
sprintf_s(text, 64, "%hhX", v);
this->mFieldValue.SetText(text);
}
}
else
{
if (this->rowType == CRYDATATYPE_8BYTES)
{
__int64 v = ScanInt64(this->mFieldValue.GetText().ToString(), NULL, 16);
this->mFieldValue.SetText(Format("%lli", v));
}
else if (this->rowType == CRYDATATYPE_4BYTES)
{
int v = ScanInt(this->mFieldValue.GetText().ToString(), NULL, 16);
this->mFieldValue.SetText(Format("%li", v));
}
else if (this->rowType == CRYDATATYPE_2BYTES)
{
short v = ScanInt(this->mFieldValue.GetText().ToString(), NULL, 16);
char text[64];
sprintf_s(text, 64, "%hi", v);
this->mFieldValue.SetText(text);
}
else if (this->rowType == CRYDATATYPE_BYTE)
{
Byte v = ScanInt(this->mFieldValue.GetText().ToString(), NULL, 16);
char text[64];
sprintf_s(text, 64, "%hhu", v);
this->mFieldValue.SetText(text);
}
}
}
// Closes the dialog without saving anything.
void CryMemoryDissectionChangeValueWindow::CancelDialog()
{
this->Close();
}
// Executed when the user accepts the dialog.
void CryMemoryDissectionChangeValueWindow::DialogOkay()
{
// Check for empty input value.
const String& inputVal = this->mFieldValue.GetText().ToString();
if (inputVal.IsEmpty())
{
Prompt("Input Error", CtrlImg::error(), "Please enter a value.", "OK");
return;
}
// Value is not managed by address table itself, so WPM.
if (this->rowType == CRYDATATYPE_BYTE)
{
const Byte value = this->mValueIsHex ? ScanInt(inputVal, NULL, 16) : ScanInt(inputVal);
mMemoryScanner->Poke(this->address, &value, sizeof(Byte));
}
else if (this->rowType == CRYDATATYPE_2BYTES)
{
const short value = this->mValueIsHex ? ScanInt(inputVal, NULL, 16) : ScanInt(inputVal);
mMemoryScanner->Poke(this->address, &value, sizeof(short));
}
else if (this->rowType == CRYDATATYPE_4BYTES)
{
const int value = this->mValueIsHex ? ScanInt(inputVal, NULL, 16) : ScanInt(inputVal);
mMemoryScanner->Poke(this->address, &value, sizeof(int));
}
else if (this->rowType == CRYDATATYPE_8BYTES)
{
const __int64 value = this->mValueIsHex ? ScanInt64(inputVal, NULL, 16) : ScanInt64(inputVal);
mMemoryScanner->Poke(this->address, &value, sizeof(__int64));
}
else if (this->rowType == CRYDATATYPE_FLOAT)
{
const float value = (float)ScanDouble(inputVal, NULL, true);
mMemoryScanner->Poke(this->address, &value, sizeof(float));
}
else if (this->rowType == CRYDATATYPE_DOUBLE)
{
const double value = ScanDouble(inputVal, NULL, true);
mMemoryScanner->Poke(this->address, &value, sizeof(double));
}
else if (this->rowType == CRYDATATYPE_STRING)
{
mMemoryScanner->PokeA(this->address, inputVal);
*this->size = this->mFieldValue.GetLength();
}
else if (this->rowType == CRYDATATYPE_WSTRING)
{
mMemoryScanner->PokeW(this->address, this->mFieldValue.GetText());
*this->size = this->mFieldValue.GetLength();
}
else if (this->rowType == CRYDATATYPE_AOB)
{
ArrayOfBytes aob = StringToBytes(inputVal);
mMemoryScanner->PokeB(this->address, aob);
*this->size = aob.Size;
}
// Close the form to pass execution back to the main window.
this->Close();
}