-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGeckUtility.cpp
334 lines (279 loc) · 7.74 KB
/
GeckUtility.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include "GECKUtility.h"
#include "GameForms.h"
#include "GameSettings.h"
#include "GameData.h"
void(__cdecl* SaveWindowPositionToINI)(HWND, const char*) = ((void(__cdecl*)(HWND hWnd, const char* Src))(0x43E170));
HWND g_mainWindowToolbar = (HWND)0xECFC14;
void GetCameraViewMatrix(NiMatrix33* out) {
auto current = &RenderData::GetSingleton()->pNode->m_localRotate;
*out = *current;
}
void SetCameraViewMatrix(NiMatrix33* newView) {
auto current = &RenderData::GetSingleton()->pNode->m_localRotate;
*current = *newView;
}
void GetCameraPos(NiPoint3* outPosition) {
NiVector3* currentPos = &RenderData::GetSingleton()->pNode->m_localTranslate;
outPosition->x = currentPos->x;
outPosition->y = currentPos->y;
outPosition->z = currentPos->z;
}
void SetCameraPos(NiPoint3* newPos) {
NiVector3* currentPos = &RenderData::GetSingleton()->pNode->m_localTranslate;
currentPos->x = newPos->x;
currentPos->y = newPos->y;
currentPos->z = newPos->z;
}
void GetCamera(NiPoint3* outPosition, NiMatrix33* outDirection) {
GetCameraPos(outPosition);
GetCameraViewMatrix(outDirection);
}
void SetCamera(NiPoint3* pos, NiMatrix33* direction) {
SetCameraPos(pos);
SetCameraViewMatrix(direction);
}
void SetTimeOfDay(float time) {
if (auto sky = TES::GetSingleton()->sky)
{
ThisCall(0x44CD00, sky, time); // Sky::SetTime
}
}
void ToggleRenderWindowAllowCellLoads(bool toggle) {
/* toggle the third bit */
if (toggle)
{
*(byte*)(0xECFCEC) |= (1 << 2);
}
else
{
*(byte*)(0xECFCEC) &= ~(1 << 2);
}
}
bool GetIsRenderWindowAllowCellLoads() {
return (*(byte*)(0xECFCEC) >> 2) & 1;
}
void SetIsShowWater(bool state) {
(*(byte*)(0xECEED4)) = state;
StdCall(0x4164D0);
}
bool GetIsShowWater() {
return (*(bool*)(0xECEED4));
}
bool GetIsShowPortalsAndRooms() {
return (*(bool*)(0xECEEF8));
}
void SetIsShowPortalsAndRooms(bool state) {
(*(byte*)(0xECEEF8)) = state;
StdCall(0x416590);
}
long GetPreviousRenderWindowSize() {
return (*(long*)(0xED1444));
}
int GetPreviousRenderWindowWidth() {
return (*(int*)(0xED1444));
}
int GetPreviousRenderWindowHeight() {
return (*(int*)(0xED1448));
}
void RefreshLightMarkers() {
StdCall(0x416490);
}
bool GetIsShowLightMarkers() {
return (*(bool*)(0xECEEBC));
}
void SetIsShowLightMarkers(bool state) {
(*(byte*)(0xECEEBC)) = state;
RefreshLightMarkers();
}
void RefreshSoundMarkers() {
StdCall(0x4165B0);
}
bool GetIsShowSoundMarkers() {
return (*(bool*)(0xECEEA4));
}
void SetIsShowSoundMarkers(bool state) {
(*(byte*)(0xECEEA4)) = state;
RefreshSoundMarkers();
}
void SetFlycamMode(int state) {
CdeclCall(0x451EF0, state);
}
int GetFlycamMode() {
return (*(int*)(0xED11BC));
}
ObjectPalette* ObjectPalette::GetSingleton() { return (ObjectPalette*)0xECE248; };
HWND ObjectPalette::GetWindow() { return *(HWND*)0xECE23C; };
HWND RenderWindow::GetWindow() { return *(HWND*)0xECFB40; };
bool RenderWindow::GetMousePos(NiPoint3* aPosOut, NiPoint3* aRotOut) {
POINT point;
if (!GetCursorPos(&point)) {
return false;
}
ScreenToClient(GetWindow(), &point);
NiPoint3 pos;
NiPoint3 rot;
if (!aPosOut)
{
aPosOut = &pos;
}
if (!aRotOut)
{
aRotOut = &rot;
}
return RenderData::GetSingleton()->pCamera->WindowPointToRay(point.x, point.y, aPosOut, aRotOut);
}
TESObjectCELL* RenderWindow::GetCurrentCell() { return *(TESObjectCELL**)0xED1174; };
bool RenderWindow::InLandscapeEditingMode() { return *(bool*)0xED142D; };
RenderWindow::SelectedData* RenderWindow::SelectedData::GetSelected() { return *(SelectedData**)0xECFB8C; }
RenderWindow::SelectedData* RenderWindow::SelectedData::GetClipboard() { return *(SelectedData**)0xECFB90; }
HWND ObjectsView::GetWindow() { return *(HWND*)0xECFB70; };
HWND ObjectsView::GetListView() { return *(HWND*)0xED1114; };
HWND ObjectsView::GetTreeView() { return *(HWND*)0xED1118; };
void ObjectsView::Refresh() { SendMessageA(GetWindow(), 1042, NULL, NULL); };
void ObjectsView::SetColumnWidth(Columns column, short width)
{
if (column >= kCol_COUNT)
{
return;
}
short* widths = (short*)0xE8E5C0;
widths[column] = width;
}
short ObjectsView::GetColumnWidth(Columns column)
{
if (column >= kCol_COUNT)
{
return 0;
}
short* widths = (short*)0xE8E5C0;
return widths[column];
}
void ObjectsView::SetColumnHeading(Columns column, const char* heading)
{
if (column >= kCol_COUNT)
{
return;
}
const char** headings = (const char**)0xE8E6B0;
headings[column] = heading;
}
HWND CellView::GetWindow() { return *(HWND*)0xECFB78; };
HistoryManager* HistoryManager::GetSingleton() { return *(HistoryManager**)0xECFDF4; };
void HistoryManager::ClearHistoryForCurrentElement() { ThisCall(0x467CC0, this); };
void HistoryManager::Undo() { ThisCall(0x4665C0, this, 0); };
void HistoryManager::AddAction(int aiActionType, RenderWindow::SelectedData* apSelectedForms) { ThisCall(0x465D90, this, aiActionType, apSelectedForms); };
RenderData* RenderData::GetSingleton() { return *(RenderData**)0xED116C; };
NavMeshManager* NavMeshManager::GetSingleton() { return (NavMeshManager*)0xECEFF8; }
bool NavMeshManager::IsActive() { return *(bool**)0xED1412; }
void NavMeshManager::Undo() { ThisCall(0x4249F0, this); }
bool NavMeshManager::HasMultipleNavmeshesSelected()
{
NavMesh* UNSET_MESH = (NavMesh*)-1;
NavMesh* navMesh = UNSET_MESH;
for (int i = 0, n = arrayData.vertices.size; i < n; ++i)
{
if (auto vertex = arrayData.vertices.data[i])
{
if (navMesh == UNSET_MESH) navMesh = vertex->navMesh;
else if (navMesh != vertex->navMesh)
{
return true;
}
}
}
return false;
}
tList<HWND>* OpenWindows::GetWindowList() { return (tList<HWND>*)0xED033C; }
void AddFormsToListView(HWND listView, tList<TESForm>* forms, bool(__cdecl* filterFn)(TESForm*, void*), void* filterData)
{
CdeclCall(0x47E410, listView, forms, filterFn, filterData);
}
void GetCellCoords(NiPoint3& pos, TESObjectCELL* cell)
{
if (cell->IsInterior())
{
pos = NiPoint3::ZERO;
}
else
{
pos.x = 2048 + (cell->GetPosX() << 12);
pos.y = 2048 + (cell->GetPosY() << 12);
pos.z = 0;
}
}
void OpenForm(TESForm* form, HWND parentHwnd)
{
if (form)
{
if (form->typeID == kFormType_TESObjectCELL || form->typeID == kFormType_TESObjectLAND)
{
TESObjectCELL* cell = form->typeID == kFormType_TESObjectLAND
? (TESObjectCELL*)(UInt32(form) + 0x34) : (TESObjectCELL*)form;
NiPoint3 pos;
GetCellCoords(pos, cell);
CdeclCall(0x465490, &pos, cell);
if (!cell->IsInterior())
{
cell->GetLandHeight(&pos, &pos.z);
CdeclCall(0x4652D0, &pos);
}
}
else
{
form->OpenDialog(parentHwnd, 0, 1);
}
}
}
void RunCallbackOnCell(TESObjectCELL* cell, void (*callback)(TESObjectREFR*))
{
if (auto iter = cell->objectList.Head())
{
do
{
if (auto ref = iter->data)
{
callback(ref);
}
} while (iter = iter->next);
}
}
void RunCallbackOnAllCellRefs(void (*callback)(TESObjectREFR*))
{
auto tes = TES::GetSingleton();
if (auto cell = tes->currentInterior)
{
RunCallbackOnCell(cell, callback);
}
else
{
Setting* uGridsToLoad = (Setting*)0xED6550;
for (int x = 0, n = uGridsToLoad->data.uint; x < n; ++x)
{
for (int y = 0, n = uGridsToLoad->data.uint; y < n; ++y)
{
if (auto cell = tes->gridCellArray->GetCell(x, y))
{
if (cell->cellState == 6)
{
RunCallbackOnCell(cell, callback);
}
}
}
}
}
}
BOOL __stdcall _CreateProcessA(LPSTR exePath, LPPROCESS_INFORMATION lpProcessInformation)
{
STARTUPINFOA startupInfo;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
return StdCall<BOOL>(*(UInt32*)0xD232D8, NULL, exePath, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, lpProcessInformation);
}
void* Window_GetExtraData(HWND hWnd, int code)
{
return CdeclCall<void*>(0x47AB70, hWnd, code);
}
LRESULT __cdecl TESCSMain__WriteToStatusBar(unsigned int statusBarId, const char* msg)
{
return CdeclCall<LRESULT>(0x4657A0, statusBarId, msg);
}