-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
125 lines (105 loc) · 3.47 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
/**
* @file main.cpp
* @author Kassent
* @author Vadfromnu
* @author Andrew Spaulding (Kasplat)
* @brief Main SKSE library configuration.
*
* Cleaned up a little bit by Kasplat.
*/
#include <ShlObj.h>
#include "BranchTrampoline.h"
#include "Utilities.h"
#include "PluginAPI.h"
#include "skse_version.h"
#include "RelocPatch.h"
#include "Settings.h"
#define DLL_EXPORT __declspec(dllexport)
IDebugLog gLog;
HINSTANCE gDllHandle;
UInt32 g_pluginHandle = kPluginHandle_Invalid;
static bool GetDllDirWithSlash(std::string& path)
{
char dllPath[4096]; // with \\?\ prefix path can be longer than MAX_PATH, so just using some magic number
const auto ret = GetModuleFileNameA(gDllHandle, dllPath, sizeof(dllPath));
if (ret == 0) {
_ERROR("GetModuleFileNameA fail:%u", (unsigned)GetLastError());
return false;
}
path.assign(dllPath, ret);
const auto pos = path.find_last_of("/\\");
if (pos == std::string::npos) {
_ERROR("Strange dll path:%s", path.c_str());
return false;
}
path.resize(pos + 1);
return true;
}
static bool SkyrimUncapper_Initialize(const SKSEInterface* skse)
{
static bool isInit = false;
if (isInit) {
_WARNING("Already initialized.");
return true;
}
isInit = true;
gLog.OpenRelative(
CSIDL_MYDOCUMENTS,
"\\My Games\\Skyrim Special Edition\\SKSE\\SkyrimUncapper.log"
);
void *img_base = GetModuleHandle(NULL);
_MESSAGE(
"Compiled skse:0x%08X runtime:0x%08X. "
"Running skse:0x%08X runtime:0x%08X",
(unsigned int) PACKED_SKSE_VERSION,
(unsigned int) CURRENT_RELEASE_RUNTIME,
(unsigned int) skse->skseVersion,
(unsigned int) skse->runtimeVersion
);
_MESSAGE("imagebase = %016I64X", img_base);
std::string path;
if (!GetDllDirWithSlash(path)) {
return false;
}
path += "SkyrimUncapper.ini";
if (!settings.ReadConfig(path)) {
return false;
}
if (ApplyGamePatches(img_base, skse->runtimeVersion) < 0) {
_ERROR("Failed to apply game patches. See log for details.");
return false;
}
_MESSAGE("Init complete");
return true;
}
extern "C" {
DLL_EXPORT SKSEPluginVersionData SKSEPlugin_Version = {
SKSEPluginVersionData::kVersion,
1, // version number of your plugin
"SkyrimUncapperAE",
"Andrew Spaulding (Kasplat)", // name
"andyespaulding@gmail.com", // support@example.com
SKSEPluginVersionData::kVersionIndependentEx_NoStructUse, // We manually check our offsets against the game version
SKSEPluginVersionData::kVersionIndependent_AddressLibraryPostAE,
{0}, // works with any version of the script extender. you probably do not need to put anything here
0 // minimum version of the script extender required, compared against PACKED_SKSE_VERSION
};
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpreserved) {
(void)lpreserved;
switch (dwReason) {
case DLL_PROCESS_ATTACH:
gDllHandle = hinstDLL;
break;
case DLL_PROCESS_DETACH:
break;
};
return TRUE;
}
DLL_EXPORT bool SKSEPlugin_Load(const SKSEInterface* skse) {
if (skse->isEditor) { // ianpatt: yup no more editor. obscript gone (mostly)
return false;
}
g_pluginHandle = skse->GetPluginHandle();
return SkyrimUncapper_Initialize(skse);
}
};