-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.cpp
132 lines (104 loc) · 3.6 KB
/
main.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
#include "common/IDebugLog.h" // IDebugLog
#include "f4se_common/f4se_version.h" // RUNTIME_VERSION
#include "f4se/PluginAPI.h" // SKSEInterface, PluginInfo
#include "f4sE_common/Relocation.h"
#include "F4SE_common/SafeWrite.h"
#include <chrono>
#include <iomanip>
#include <ShlObj.h> // CSIDL_MYDOCUMENTS
#include "f4se/GameData.h"
#include "Config.h"
#include "version.h"
#include "hook.h"
#include "F4VRBody.h"
#include "SmoothMovementVR.h"
#include "patches.h"
#include "GunReload.h"
#include "VR.h"
void OnBetterScopesMessage(F4SEMessagingInterface::Message* msg) {
if (!msg)
return;
if (msg->type == 15) {
F4VRBody::c_isLookingThroughScope = (bool)msg->data;
}
}
//Listener for F4SE Messages
void OnF4SEMessage(F4SEMessagingInterface::Message* msg) {
if (!msg)
return;
if (msg->type == F4SEMessagingInterface::kMessage_GameLoaded) {
F4VRBody::startUp();
VRHook::InitVRSystem();
SmoothMovementVR::StartFunctions();
SmoothMovementVR::MenuOpenCloseHandler::Register();
_MESSAGE("kMessage_GameLoaded Completed");
}
if (msg->type == F4SEMessagingInterface::kMessage_PostLoad) {
bool gripConfig = !F4VRBody::g_config->staticGripping;
g_messaging->Dispatch(g_pluginHandle, 15, (void*)gripConfig, sizeof(bool), "FO4VRBETTERSCOPES");
g_messaging->RegisterListener(g_pluginHandle, "FO4VRBETTERSCOPES", OnBetterScopesMessage);
_MESSAGE("kMessage_PostLoad Completed");
}
}
extern "C" {
bool F4SEPlugin_Query(const F4SEInterface* a_f4se, PluginInfo* a_info)
{
Sleep(5000);
gLog.OpenRelative(CSIDL_MYDOCUMENTS, R"(\\My Games\\Fallout4VR\\F4SE\\Fallout4VRBody.log)");
gLog.SetPrintLevel(IDebugLog::kLevel_Message);
gLog.SetLogLevel(IDebugLog::kLevel_Message);
_MESSAGE("F4VRBody v%s", F4VRBODY_VERSION_VERSTRING);
a_info->infoVersion = PluginInfo::kInfoVersion;
a_info->name = "F4VRBody";
a_info->version = F4VRBODY_VERSION_MAJOR;
if (a_f4se->isEditor) {
_FATALERROR("[FATAL ERROR] Loaded in editor, marking as incompatible!\n");
return false;
}
a_f4se->runtimeVersion;
if (a_f4se->runtimeVersion < RUNTIME_VR_VERSION_1_2_72)
{
_FATALERROR("Unsupported runtime version %s!\n", a_f4se->runtimeVersion);
return false;
}
return true;
}
bool F4SEPlugin_Load(const F4SEInterface* a_f4se) {
try {
_MESSAGE("F4VRBody Init - %s", F4VRBody::getCurrentTimeString().data());
g_pluginHandle = a_f4se->GetPluginHandle();
if (g_pluginHandle == kPluginHandle_Invalid) {
throw std::exception("Invalid plugin handle");
}
g_messaging = (F4SEMessagingInterface*)a_f4se->QueryInterface(kInterface_Messaging);
g_messaging->RegisterListener(g_pluginHandle, "F4SE", OnF4SEMessage);
if (!g_branchTrampoline.Create(1024 * 128)) {
throw std::exception("couldn't create branch trampoline");
}
auto moduleHandle = reinterpret_cast<void*>(GetModuleHandleA("FRIK.dll"));
if (!g_localTrampoline.Create(1024 * 128, moduleHandle)) {
throw std::exception("couldn't create codegen buffer");
}
_MESSAGE("Init config...");
F4VRBody::initConfig();
_MESSAGE("Register papyrus funcs...");
g_papyrus = (F4SEPapyrusInterface*)a_f4se->QueryInterface(kInterface_Papyrus);
if (!g_papyrus->Register(F4VRBody::RegisterFuncs)) {
throw std::exception("FAILED TO REGISTER PAPYRUS FUNCTIONS!!");
}
_MESSAGE("Run patches...");
patches::patchAll();
_MESSAGE("Init gun reaload system...");
F4VRBody::InitGunReloadSystem();
_MESSAGE("Hook main...");
hookMain();
_MESSAGE("F4VRBody Loaded successfully");
return true;
}
catch (const std::exception& e)
{
_FATALERROR("Fatal error in F4SEPlugin_Load: %s", e.what());
return false;
}
}
};