-
-
Notifications
You must be signed in to change notification settings - Fork 283
/
dllmain.cpp
132 lines (98 loc) · 2.85 KB
/
dllmain.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 <stdafx.h>
#include "CET.h"
#include "Options.h"
#include "RED4ext/Api/EMainReason.hpp"
#include "RED4ext/Api/PluginHandle.hpp"
#include "RED4ext/Api/Runtime.hpp"
#include "RED4ext/Api/Sdk.hpp"
#include "RED4ext/Api/Version.hpp"
#include "scripting/GameHooks.h"
void StartScreenPatch();
void OptionsInitHook();
void DisableIntroMoviesPatch();
void DisableVignettePatch();
void DisableBoundaryTeleportPatch();
static HANDLE s_modInstanceMutex = nullptr;
using namespace std::chrono_literals;
static bool Initialize(RED4ext::PluginHandle aHandle, const RED4ext::Sdk* aSdk)
{
try
{
MH_Initialize();
GameMainThread::Create(aHandle, aSdk);
CET::Initialize(aSdk);
const auto& options = CET::Get().GetOptions();
// single instance check
s_modInstanceMutex = CreateMutex(nullptr, TRUE, TEXT("Cyber Engine Tweaks Module Instance"));
if (s_modInstanceMutex == nullptr)
return false;
// initialize patches
//if (options.Patches.SkipStartMenu)
// StartScreenPatch();
if (options.Patches.DisableIntroMovies)
DisableIntroMoviesPatch();
if (options.Patches.DisableVignette)
DisableVignettePatch();
if (options.Patches.DisableBoundaryTeleport)
DisableBoundaryTeleportPatch();
OptionsInitHook();
MH_EnableHook(nullptr);
}
catch (...)
{
return false;
}
return true;
}
static void Shutdown()
{
bool inGameProcess = false;
if (s_modInstanceMutex)
{
inGameProcess = CET::Get().GetOptions().ExeValid;
MH_DisableHook(nullptr);
MH_Uninitialize();
CET::Shutdown();
ReleaseMutex(s_modInstanceMutex);
}
if (inGameProcess)
{
// flush main log (== default logger)
spdlog::default_logger()->flush();
spdlog::get("scripting")->flush();
}
}
RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::PluginHandle aHandle, RED4ext::EMainReason aReason, const RED4ext::Sdk* aSdk)
{
RED4EXT_UNUSED_PARAMETER(aHandle);
switch (aReason)
{
case RED4ext::EMainReason::Load:
{
return Initialize(aHandle, aSdk);
break;
}
case RED4ext::EMainReason::Unload:
{
Shutdown();
break;
}
}
return true;
}
RED4EXT_C_EXPORT void RED4EXT_CALL Query(RED4ext::PluginInfo* aInfo)
{
aInfo->name = L"Cyber Engine Tweaks";
aInfo->author = L"Yamashi and Friends";
std::istringstream oss(CET_BUILD_COMMIT);
char buffer;
uint32_t major, minor, patch;
oss >> buffer >> major >> buffer >> minor >> buffer >> patch;
aInfo->version = RED4EXT_SEMVER(major, minor, patch);
aInfo->runtime = RED4EXT_RUNTIME_INDEPENDENT;
aInfo->sdk = RED4EXT_SDK_LATEST;
}
RED4EXT_C_EXPORT uint32_t RED4EXT_CALL Supports()
{
return RED4EXT_API_VERSION_LATEST;
}