-
Notifications
You must be signed in to change notification settings - Fork 5
/
CustomRenderWindowHotkeys.cpp
306 lines (271 loc) · 8.57 KB
/
CustomRenderWindowHotkeys.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
#include "GameForms.h"
#include "GameObjects.h"
#include "GameData.h"
#include "GameSettings.h"
#include "GECKUtility.h"
#include "NavMeshPickPreventer.h"
#include <CommCtrl.h>
namespace CustomRenderWindowHotkeys
{
void PlaceXMarker()
{
NiPoint3 pos, rot;
if (RenderWindow::GetMousePos(&pos, &rot))
{
TESObjectSTAT* xMarker = *(TESObjectSTAT**)0xEDDA54;
if (auto ref = DataHandler::GetSingleton()->CreateReferenceAtLocation(xMarker, &pos, &NiPoint3::ZERO, 0))
{
CdeclCall(0x44F470);
CdeclCall(0x44F260, ref); // RenderWindow::AddRef
HistoryManager::GetSingleton()->AddAction(2, RenderWindow::SelectedData::GetSelected());
if (*(byte*)0xECFB74) // CellView::bLoaded
{
auto pos = &RenderWindow::SelectedData::GetSelected()->pos;
CdeclCall(0x42E3C0, &pos, 1); // CellView::Refresh
}
}
}
}
void ToggleRefVisible(TESObjectREFR* ref)
{
if (auto node = ref->Get3D())
{
if (node = ThisCall<NiNode*>(0x68B370, node, 0xF1FDD4)) // NiRTTI::HasType(&NiNode::ms_RTTI);
{
node->SetAlphaRecurse(1.0F);
node->m_flags &= ~0x200001;
node->UpdatePropertiesUpward();
}
}
}
void SetAllObjectsVisible()
{
RunCallbackOnAllCellRefs(ToggleRefVisible);
}
static bool bAllDisabledRefsHidden = false;
void GetAnyDisabledRefsVisible(TESObjectREFR* ref)
{
if (ref->IsDisabled())
{
if (auto node = ref->Get3D())
{
if (node->IsNiNode())
{
if (node->IsVisible())
{
bAllDisabledRefsHidden = false;
}
}
}
}
}
void SetIsDisabledRefHidden(TESObjectREFR* ref)
{
if (ref->IsDisabled())
{
if (auto node = ref->Get3D())
{
if (node->IsNiNode())
{
node->SetVisible(!bAllDisabledRefsHidden);
}
}
}
}
void ToggleShowDisabledObjects()
{
bAllDisabledRefsHidden = true;
RunCallbackOnAllCellRefs(GetAnyDisabledRefsVisible);
bAllDisabledRefsHidden = !bAllDisabledRefsHidden;
RunCallbackOnAllCellRefs(SetIsDisabledRefHidden);
}
void LinkSelectedRefs()
{
auto selected = RenderWindow::SelectedData::GetSelected();
if (selected->selectedForms && selected->selectedForms->next && selected->numItems == 2)
{
if (auto ref1 = CdeclCall<TESObjectREFR*>(0xC5D114, selected->selectedForms->ref, 0, 0xE8C57C, 0xE8E3E4, 0)) // DYNAMIC_CAST(TESForm, TESObjectREFR)
{
if (auto ref2 = CdeclCall<TESObjectREFR*>(0xC5D114, selected->selectedForms->next->ref, 0, 0xE8C57C, 0xE8E3E4, 0)) // DYNAMIC_CAST(TESForm, TESObjectREFR)
{
if (ref2->CanSetLinkedRef())
{
if (ref1->Unk_43() && ref1->Unk_4E())
{
ref1->MarkAsModified();
ref1->SetLinkedRef(ref2);
ref1->RedrawLinkedRefs();
SendMessageA(RenderWindow::GetWindow(), 0x40Au, 0, 0);
Console_Print("RENDER WINDOW: Linked %s (%08X) to %s (%08X)", ref1->GetEditorID(), ref1->refID, ref2->GetEditorID(), ref2->refID);
return;
}
}
else
{
Console_Print("RENDER WINDOW: %s (%08X) cannot be set as a linked ref", ref2->GetEditorID(), ref2->refID);
}
}
}
}
PlaySound("SystemExclamation", NULL, SND_ASYNC);
}
enum CustomHotkey
{
kHotkey_NONE = 0x47, // max ID of the vanilla IDs
kHotkey_FIRST,
kHotkey_ToggleShowLightMarkers = kHotkey_FIRST,
kHotkey_SetAllObjectsVisible,
kHotkey_PlaceXMarker,
kHotkey_NavMeshIgnoreLastPick,
kHotkey_NavMeshIgnoreSelectedPicks,
kHotkey_ToggleShowDisabledObjects,
kHotkey_LinkRefs,
};
static RenderWindowHotkey CustomHotkeys[] =
{
RenderWindowHotkey("Toggle show light markers", "ToggleShowLightMarkers", 'I', RenderWindowHotkey::kRenderWindowPreferenceFlag_NONE, RenderWindowHotkey::kRenderHotkeyCategory_Visibility),
RenderWindowHotkey("Set all objects visible", "SetAllObjectsVisible", VK_OEM_4, RenderWindowHotkey::kRenderWindowPreferenceFlag_NONE, RenderWindowHotkey::kRenderHotkeyCategory_Visibility),
RenderWindowHotkey("Place xMarker", "PlaceXMarker", 'O'),
RenderWindowHotkey("Navmesh: Ignore last picked form", "NavMeshIgnoreLastPick", 'K', RenderWindowHotkey::kRenderWindowPreferenceFlag_Navmesh, RenderWindowHotkey::kRenderHotkeyCategory_Navmesh),
RenderWindowHotkey("Navmesh: Ignore selected forms", "NavMeshIgnoreSelectedPicks", 'K', RenderWindowHotkey::kRenderWindowPreferenceFlag_Shift, RenderWindowHotkey::kRenderHotkeyCategory_Navmesh),
RenderWindowHotkey("Toggle show disabled objects", "ToggleShowDisabledObjects", 'N', RenderWindowHotkey::kRenderWindowPreferenceFlag_NONE, RenderWindowHotkey::kRenderHotkeyCategory_Visibility),
RenderWindowHotkey("Link selected refs", "LinkRefs", 'J'),
};
void HandleHotkey(UInt32 hotkey)
{
switch (hotkey)
{
case kHotkey_ToggleShowLightMarkers:
SetIsShowLightMarkers(!GetIsShowLightMarkers());
break;
case kHotkey_PlaceXMarker:
PlaceXMarker();
break;
case kHotkey_SetAllObjectsVisible:
SetAllObjectsVisible();
break;
case kHotkey_NavMeshIgnoreLastPick:
NavMeshPickPreventer::OnKeyDown(false);
break;
case kHotkey_NavMeshIgnoreSelectedPicks:
NavMeshPickPreventer::OnKeyDown(true);
break;
case kHotkey_ToggleShowDisabledObjects:
ToggleShowDisabledObjects();
break;
case kHotkey_LinkRefs:
LinkSelectedRefs();
break;
}
}
void __cdecl PopulateList(HWND hDlg)
{
auto listView = GetDlgItem(hDlg, 5142);
for (int i = 0; i < _ARRAYSIZE(CustomHotkeys); ++i)
{
CdeclCall(0x41A020, listView, &CustomHotkeys[i], 0, -1); // ListView::InsertItem
}
}
void AddCustomHotkey(RenderWindowHotkey::KeyCombo combo, unsigned int hotkey)
{
void* hotkeysNiTMap = (void*)0xE8CF3C;
ThisCall(0x50D880, hotkeysNiTMap, combo.data, kHotkey_FIRST + hotkey);
}
void __cdecl AddKeysToMap()
{
for (int i = 0; i < _ARRAYSIZE(CustomHotkeys); ++i)
{
AddCustomHotkey(CustomHotkeys[i].kCombo, i);
}
}
RenderWindowHotkey::eKeys __cdecl GetPressedHotkeyID(char aiKeyCode, bool abShift, bool abControl, bool abAlt, bool abIsZ, bool abIsNavMesh)
{
auto hotkey = CdeclCall<RenderWindowHotkey::eKeys>(0x412F00, aiKeyCode, abShift, abControl, abAlt, abIsZ, abIsNavMesh);
if (hotkey > RenderWindowHotkey::kRenderHotkey_COUNT)
{
// workaround for the landscape edit hotkey being the same as the toggle lights key by default...
if (RenderWindow::InLandscapeEditingMode())
{
UInt8 pressedFlags = 0;
if (abShift) pressedFlags |= RenderWindowHotkey::kRenderWindowPreferenceFlag_Shift;
if (abControl) pressedFlags |= RenderWindowHotkey::kRenderWindowPreferenceFlag_Ctrl;
if (abAlt) pressedFlags |= RenderWindowHotkey::kRenderWindowPreferenceFlag_Alt;
if (abIsZ) pressedFlags |= RenderWindowHotkey::kRenderWindowPreferenceFlag_Z;
if (abIsNavMesh) pressedFlags |= RenderWindowHotkey::kRenderWindowPreferenceFlag_Navmesh;
auto combo = RenderWindowHotkey::KeyCombo(aiKeyCode, pressedFlags);
if (hotkey == kHotkey_ToggleShowLightMarkers && (RenderWindowHotkey::GetArray()[RenderWindowHotkey::kRenderHotkey_OpenTextureUseDialog].kCombo.data & ~0x8000) == combo.data)
{
return RenderWindowHotkey::kRenderHotkey_OpenTextureUseDialog;
}
}
HandleHotkey(hotkey);
}
return hotkey;
}
constexpr const char* INI_SECTION = "Render Window";
char IniPath[MAX_PATH];
void SetupINIPath()
{
GetModuleFileNameA(NULL, IniPath, MAX_PATH);
strcpy((char*)(strrchr(IniPath, '\\') + 1), "Data\\nvse\\plugins\\GeckExtender\\Hotkeys.ini");
}
void ReadINI()
{
for (int i = 0; i < _ARRAYSIZE(CustomHotkeys); ++i)
{
unsigned short combo = GetPrivateProfileIntA(INI_SECTION, CustomHotkeys[i].sInternalName, 0xFFFF, IniPath);
if (combo != 0xFFFF)
{
CustomHotkeys[i].kCombo.data = combo;
}
}
}
void SaveINI()
{
char buffer[0x10];
for (int i = 0; i < _ARRAYSIZE(CustomHotkeys); ++i)
{
_itoa(CustomHotkeys[i].kCombo.data, buffer, 10);
WritePrivateProfileStringA(INI_SECTION, CustomHotkeys[i].sInternalName, buffer, IniPath);
}
}
void RestoreDefaults()
{
for (int i = 0; i < _ARRAYSIZE(CustomHotkeys); ++i)
{
RenderWindowHotkey* hotkey = &CustomHotkeys[i];
hotkey->kCombo = hotkey->kDefaultCombo;
}
}
void __cdecl OnRestoreDefaults()
{
CdeclCall(0x413230);
RestoreDefaults();
}
void __cdecl OnSaveChanges()
{
CdeclCall(0x412CE0);
SaveINI();
}
void __cdecl OnCancelChanges()
{
CdeclCall(0x4130D0);
ReadINI();
}
void InitHooks()
{
// add support for custom render window preferences
WriteRelJump(0x412D8B, UInt32(PopulateList));
WriteRelJump(0x412FF0, UInt32(AddKeysToMap));
WriteRelCall(0x456975, UInt32(GetPressedHotkeyID));
WriteRelCall(0x4134B5, UInt32(OnRestoreDefaults));
WriteRelCall(0x4134A6, UInt32(OnSaveChanges));
WriteRelCall(0x41348A, UInt32(OnCancelChanges));
}
void Init()
{
InitHooks();
SetupINIPath();
ReadINI();
}
}