forked from CasualCoderGuy/FO4-ModSwitchFramework-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSF_Scaleform.h
More file actions
444 lines (391 loc) · 11.6 KB
/
MSF_Scaleform.h
File metadata and controls
444 lines (391 loc) · 11.6 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#pragma once
#include "f4se/ScaleformLoader.h"
#include "f4se/ScaleformValue.h"
#include "f4se/ScaleformCallbacks.h"
#include "f4se/CustomMenu.h"
#include "f4se/PapyrusScaleformAdapter.h"
#include "f4se/PapyrusEvents.h"
#include "f4se/GameInput.h"
#include "f4se/InputMap.h"
#include "MSF_Shared.h"
#include "MSF_Data.h"
#include "MSF_Base.h"
#include "MSF_Addresses.h"
class ItemMenuDataManager;
namespace MSF_Scaleform
{
void ReceiveKeyEvents();
void RegisterMSFCustomMenus();
bool RegisterScaleformCallback(GFxMovieView* view, GFxValue* f4se_root);
bool RegisterScaleformTest(GFxMovieView * view, GFxValue * f4se_root);
void RegisterMSFScaleformFuncs(GFxValue* codeObj, GFxMovieRoot* movieRoot);
bool StartWidgetHideCountdown(UInt32 delayTime);
bool UpdateWidgetData(TESObjectWEAP::InstanceData* instanceData = nullptr);
bool UpdateWidgetSettings();
bool UpdateWidgetQuickkeyMod(KeywordValue ap, TESForm* nameForm, std::string nullModName, bool isAmmo);
bool ClearWidgetQuickkeyMod();
UInt32 GetInterfaceVersion();
bool HandleToggleMenu(ModSelectionMenu* selectMenu, ModData* mods);
bool DisplaySelectionMenu(ModSelectionMenu* selectMenu, ModData* mods, GFxMovieRoot* menuRoot);
bool ToggleGlobalMenu(ModSelectionMenu* selectMenu, std::vector<KeywordValue>* attachPoints);
bool UpdateAmmoMenuCount(TESAmmo* ammo, UInt32 newCount);
bool UpdateAmmoMenuEq(BGSMod::Attachment::Mod* ammoMod);
bool UpdateModMenuReqs(TESObjectMISC* misc, UInt32 newCount);
void RegisterStringW(GFxValue* dst, GFxMovieRoot* root, const char* name, const wchar_t* str);
void RegisterString(GFxValue* dst, GFxMovieRoot* root, const char* name, const char* str);
void RegisterObject(GFxValue* dst, GFxMovieRoot* root, const char* name, void* obj);
void RegisterBool(GFxValue* dst, GFxMovieRoot* root, const char* name, bool value);
void RegisterInt(GFxValue* dst, GFxMovieRoot* root, const char* name, SInt32 value);
}
class PipboyMenu : public IMenu
{
public:
class ScaleformArgs
{
public:
GFxValue* result; // 00
GFxMovieView* movie; // 08
GFxValue* thisObj; // 10
GFxValue* unk18; // 18
GFxValue* args; // 20
UInt32 numArgs; // 28
UInt32 pad2C; // 2C
UInt32 optionID; // 30 pUserData
};
//using FnInvoke = void(__thiscall PipboyMenu::*)(ScaleformArgs*);
//static FnInvoke Invoke_Original;
bool CreateItemDataW(PipboyMenu::ScaleformArgs* args, std::wstring text, std::string value);
bool CreateItemData(PipboyMenu::ScaleformArgs* args, std::string text, std::string value);
};
typedef void(*_PipboyMenuInvoke)(PipboyMenu* menu, PipboyMenu::ScaleformArgs* args);
extern RelocAddr<_PipboyMenuInvoke> PipboyMenuInvoke_HookAddress;
extern RelocAddr<_PipboyMenuInvoke> PipboyMenuInvoke_Original;
extern _PipboyMenuInvoke PipboyMenuInvoke_Copied;
void PipboyMenuInvoke_Hook(PipboyMenu* menu, PipboyMenu::ScaleformArgs* args);
typedef TESForm*(*_GetSelectedForm)(ItemMenuDataManager* mgr, UInt32& handleID);
extern RelocAddr <_GetSelectedForm> GetSelectedForm_Original;
typedef BGSInventoryItem* (*_GetSelectedItem)(ItemMenuDataManager* mgr, UInt32& handleID);
extern RelocAddr <_GetSelectedItem> GetSelectedItem_Original;
extern RelocAddr<uintptr_t> IMenuCreateHook_Start;
typedef void(*_LoadCustomMenu)(IMenu* menu);
extern _LoadCustomMenu LoadCustomMenu_F4SEHook;
void LoadMSFCustomMenu_Hook(IMenu* menu);
class ItemMenuDataManager
{
public:
//DEFINE_MEMBER_FN_1(GetSelectedForm, TESForm*, ID(1453201, 2194011).offset(), UInt32& handleID);
//DEFINE_MEMBER_FN_1(GetSelectedItem, BGSInventoryItem*, ID(1200959, 2194009).offset(), UInt32& handleID);
inline TESForm* GetSelectedForm(UInt32& handleID)
{
return GetSelectedForm_Original(this, handleID);
}
inline BGSInventoryItem* GetSelectedItem(UInt32& handleID)
{
return GetSelectedItem_Original(this, handleID);
}
//BGSInventoryItem
};
extern RelocPtr<ItemMenuDataManager*> g_itemMenuDataMgr;
class PipboyInventoryData
{
};
class PipboyDataManager
{
public:
//4B8
UInt64 unk00[0x4A8 >> 3];
tArray<PipboyObject*> itemData;
};
STATIC_ASSERT(sizeof(PipboyDataManager) == 0x4C0);
extern RelocPtr<PipboyDataManager*> g_pipboyDataMgr;
class PipboyArray : public PipboyValue
{
public:
tArray<PipboyValue*> values;
};
class HUDMenuAmmoDisplay
{
public:
static HUDMenuAmmoDisplay* Init(GFxMovieRoot* root = nullptr)
{
if (!root)
{
IMenu* menu = (*g_ui)->GetMenu(BSFixedString("HUDMenu"));
if (!menu)
return nullptr;
GFxMovieView* movie = menu->movie;
if (!movie)
return nullptr;
root = movie->movieRoot;
if (!root)
return nullptr;
}
HUDMenuAmmoDisplay* tf = new HUDMenuAmmoDisplay(root);
if (tf->IsOK())
return tf;
delete tf;
return nullptr;
}
bool IsOK() { return textfieldOK; }
bool SetDisplayedAmmo(UInt32 newmag, UInt32 newchamber, UInt32 newreserve, bool hasChamber)
{
if (!movieRoot || !textfieldOK)
return false;
mag = newmag;
reserve = newreserve;
if (chamber != newchamber)
{
chamber = newchamber;
if (!hasChamber)
chamber = 0;
}
return true;
}
UInt32 GetDisplayedChamberAmmo()
{
return chamber;
}
private:
HUDMenuAmmoDisplay(GFxMovieRoot* root = nullptr)
{
textfieldOK = false;
movieRoot = root;
formatting = "+%u";
mag = 0; chamber = 0; reserve = 0;
textfieldOK = true;
}
bool textfieldOK;
GFxMovieRoot* movieRoot;
GFxValue ChamberCount_tf;
GFxValue ReserveCount_tf;
GFxValue ClipCount_tf;
GFxValue AmmoType_tf;
GFxValue FiringMode_tf;
GFxValue Muzzle_tf;
GFxValue Scope_tf;
GFxValue TextFormatting;
std::string formatting;
char chamberText[16];
UInt32 mag;
UInt32 chamber;
UInt32 reserve;
bool chamberVisible;
};
class MSFWidgetMenu : public GameMenuBase
{
public:
MSFWidgetMenu() : GameMenuBase()
{
enum
{
//Confirmed
kFlag_PauseGame = 0x01,
kFlag_DoNotDeleteOnClose = 0x02,
kFlag_ShowCursor = 0x04,
kFlag_EnableMenuControl = 0x08, // 1, 2
kFlag_ShaderdWorld = 0x20,
kFlag_Open = 0x40,//set it after open.
kFlag_DoNotPreventGameSave = 0x800,
kFlag_ApplyDropDownFilter = 0x8000, //
kFlag_BlurBackground = 0x400000,
//Unconfirmed
kFlag_Modal = 0x10,
kFlag_PreventGameLoad = 0x80,
kFlag_Unk0100 = 0x100,
kFlag_HideOther = 0x200,
kFlag_DisableInteractive = 0x4000,
kFlag_UpdateCursorOnPlatformChange = 0x400,
kFlag_Unk1000 = 0x1000,
kFlag_ItemMenu = 0x2000,
kFlag_Unk10000 = 0x10000, // mouse cursor
kFlag_Unk800000 = 0x800000
};
flags = kFlag_AllowSaving | kFlag_AlwaysOpen | kFlag_DontHideCursorWhenTopmost;// | kFlag_ApplyDropDownFilter | kFlag_Unk800000;// | 0x40000 | 0x80000 | 0x200000;
depth = 0x6;
if (LoadMovieEx(*g_scaleformManager, this, this->movie, "MSFwidget", "root1", 0, 0.0F))//(CALL_MEMBER_FN((*g_scaleformManager), LoadMovie)(this, this->movie, "MSFwidget", "root1", 0))
{
_MESSAGE("MSF widget loaded.");
CreateBaseShaderTarget(this->filterHolder, this->stage);
//inherit_colors
this->filterHolder->SetFilterColor(false);
(*g_colorUpdateDispatcher)->eventDispatcher.AddEventSink(this->filterHolder);
if (flags & kFlag_ApplyDropDownFilter)
this->shaderFXObjects.Push(this->filterHolder);
}
}
virtual void Invoke(Args * args) final
{
switch (args->optionID)
{
case 0:
break;
default:
break;
}
}
virtual void RegisterFunctions() final
{
_MESSAGE("RegisterFunctions");
}
virtual UInt32 ProcessMessage(UIMessage * msg) final
{
GFxMovieRoot * root = movie->movieRoot;
GFxValue ValueToSet;
//_DEBUG("message proc!!");
return this->GameMenuBase::ProcessMessage(msg);
};
virtual void DrawNextFrame(float unk0, void * unk1) final
{
return this->GameMenuBase::AdvanceMovie(unk0, unk1);
};
static IMenu * CreateMSFMenu()
{
return new MSFWidgetMenu();
}
static void OpenMenu()
{
static BSFixedString menuName("MSFwidget");
CALL_MEMBER_FN((*g_uiMessageManager), SendUIMessage)(menuName, kMessage_Open);
}
static void CloseMenu()
{
static BSFixedString menuName("MSFwidget");
CALL_MEMBER_FN((*g_uiMessageManager), SendUIMessage)(menuName, kMessage_Close);
}
static void RegisterMenu()
{
static BSFixedString menuName("MSFwidget");
if ((*g_ui) != nullptr && !(*g_ui)->IsMenuRegistered(menuName))
{
(*g_ui)->Register("MSFwidget", CreateMSFMenu);
}
_MESSAGE("MSFwidget %s", (*g_ui)->IsMenuRegistered(menuName) ? "registered" : "not registered");
}
};
class MSFMenu : public GameMenuBase
{
public:
MSFMenu() : GameMenuBase()
{
flags = kFlag_AllowSaving | kFlag_AlwaysOpen;// | kFlag_UsesCursor | kFlag_UpdateUsesCursor | kFlag_PausesGame | kFlag_FreezeFrameBackground //| kFlag_ApplyDropDownFilter | kFlag_Unk800000 | kFlag_DisableInteractive;// | 0x40000 | 0x80000 | 0x200000;
//kFlag_UsesMenuContext kFlag_FreezeFramePause kFlag_DontHideCursorWhenTopmost kFlag_UsesBlurredBackground
depth = 0x6;
if (LoadMovieEx(*g_scaleformManager, this, this->movie, "MSFMenu", "root1", 0, 0.0F))//(CALL_MEMBER_FN((*g_scaleformManager), LoadMovie)(this, this->movie, "MSFMenu", "root1", 0))
{
_MESSAGE("MSF Menu loaded.");
CreateBaseShaderTarget(this->filterHolder, this->stage);
//inherit_colors
this->filterHolder->SetFilterColor(false);
(*g_colorUpdateDispatcher)->eventDispatcher.AddEventSink(this->filterHolder);
if (flags & kFlag_CustomRendering)
this->shaderFXObjects.Push(this->filterHolder);
}
}
virtual void Invoke(Args * args) final
{
switch (args->optionID)
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
}
virtual void RegisterFunctions() final
{
_MESSAGE("RegisterFunctions");
}
virtual UInt32 ProcessMessage(UIMessage * msg) final
{
return this->GameMenuBase::ProcessMessage(msg);
};
virtual void DrawNextFrame(float unk0, void * unk1) final
{
//_DMESSAGE("DrawNextFrame");
return this->GameMenuBase::AdvanceMovie(unk0, unk1);
};
static IMenu * CreateMSFMenu()
{
return new MSFMenu();
}
static void OpenMenu()
{
static BSFixedString menuName("MSFMenu");
//_DEBUG("opening menu");
CALL_MEMBER_FN((*g_uiMessageManager), SendUIMessage)(menuName, kMessage_Open);
}
static void CloseMenu()
{
static BSFixedString menuName("MSFMenu");
CALL_MEMBER_FN((*g_uiMessageManager), SendUIMessage)(menuName, kMessage_Close);
}
static void RegisterMenu()
{
static BSFixedString menuName("MSFMenu");
if ((*g_ui) != nullptr && !(*g_ui)->IsMenuRegistered(menuName))
{
(*g_ui)->Register("MSFMenu", CreateMSFMenu);
_MESSAGE("MSFMenu %s", (*g_ui)->IsMenuRegistered(menuName) ? "registered" : "not registered");
}
}
};
class MSFCustomMenuData
{
public:
std::string menuName;
std::string menuPath;
std::string rootPath;
UInt32 menuFlags;
UInt32 movieFlags;
UInt32 extFlags;
UInt32 depth;
bool isValid;
enum ExtendedFlags
{
kExtFlag_InheritColors = 0x01,
kExtFlag_CheckForGamepad = 0x02,
kExtFlag_DontAllowMenuChange = 0x04
};
enum MovieType
{
kNoScale,
kShowAll,
kExactFit,
kNoBorder
};
};
class MSFCustomMenu : CustomMenu
{
public:
static bool RegisterCustomMenu(MSFCustomMenuData* menuData)
{
if (menuData && !(*g_ui)->IsMenuRegistered(BSFixedString(menuData->menuName.c_str())))
{
menuLock.Lock();
customMenuData[menuData->menuName.c_str()] = menuData;
(*g_ui)->Register(menuData->menuName.c_str(), CreateCustomMSFMenu);
menuLock.Release();
return true;
}
return false;
}
static void OpenMenu(BSFixedString menuName)
{
CALL_MEMBER_FN((*g_uiMessageManager), SendUIMessage)(menuName, kMessage_Open);
}
static void CloseMenu(BSFixedString menuName)
{
CALL_MEMBER_FN((*g_uiMessageManager), SendUIMessage)(menuName, kMessage_Close);
}
static IMenu* CreateCustomMSFMenu()
{
return new MSFCustomMenu();
}
static SimpleLock menuLock;
static std::unordered_map<std::string, MSFCustomMenuData*> customMenuData;
static std::vector<MSFCustomMenu*> menuHandles;
};