@@ -14,6 +14,7 @@ using namespace spdlog;
14
14
15
15
namespace fs = std::filesystem;
16
16
17
+ static HMODULE modengine_instance;
17
18
static fs::path modengine_path;
18
19
static fs::path game_path;
19
20
@@ -25,6 +26,29 @@ HookSet entry_hook_set;
25
26
26
27
int WINAPI modengine_entrypoint (void )
27
28
{
29
+ wchar_t dll_filename[MAX_PATH + 1 ];
30
+
31
+ // Grab the path to the modengine2.dll file, so we can locate the global
32
+ // configuration from here if it exists.
33
+ if (!GetModuleFileNameW (modengine_instance, dll_filename, MAX_PATH)) {
34
+ return false ;
35
+ }
36
+
37
+ modengine_path = fs::path (dll_filename).parent_path ();
38
+ if (modengine_path.filename () == " bin" ) {
39
+ modengine_path = modengine_path.parent_path ();
40
+ }
41
+
42
+ wchar_t game_filename[MAX_PATH + 1 ];
43
+
44
+ // Also get the path to the game executable, to support legacy use-cases of putting
45
+ // mods in the game folder.
46
+ if (!GetModuleFileNameW (nullptr , game_filename, MAX_PATH)) {
47
+ return false ;
48
+ }
49
+
50
+ game_path = fs::path (game_filename).parent_path ();
51
+
28
52
start_crash_handler (modengine_path, game_path);
29
53
30
54
auto is_debugger_enabled = std::getenv (" MODENGINE_DEBUG_GAME" ) != nullptr ;
@@ -90,29 +114,8 @@ int WINAPI modengine_entrypoint(void)
90
114
91
115
static bool attach (HMODULE module)
92
116
{
93
- wchar_t dll_filename[MAX_PATH];
94
-
95
- // Grab the path to the modengine2.dll file, so we can locate the global
96
- // configuration from here if it exists.
97
- if (!GetModuleFileNameW (module, dll_filename, MAX_PATH)) {
98
- return false ;
99
- }
100
-
101
- modengine_path = fs::path (dll_filename).parent_path ();
102
- if (modengine_path.filename () == " bin" ) {
103
- modengine_path = modengine_path.parent_path ();
104
- }
105
-
106
- wchar_t game_filename[MAX_PATH];
107
-
108
- // Also get the path to the game executable, to support legacy use-cases of putting
109
- // mods in the game folder.
110
- if (!GetModuleFileNameW (nullptr , game_filename, MAX_PATH)) {
111
- return false ;
112
- }
113
-
114
- game_path = fs::path (game_filename).parent_path ();
115
-
117
+ modengine_instance = module;
118
+
116
119
hooked_entrypoint.original = reinterpret_cast <fnEntry>(DetourGetEntryPoint (nullptr ));
117
120
hooked_entrypoint.replacement = modengine_entrypoint;
118
121
entry_hook_set.install (reinterpret_cast <Hook<modengine::GenericFunctionPointer>*>(&hooked_entrypoint));
@@ -144,4 +147,4 @@ BOOL APIENTRY DllMain(HMODULE module, DWORD dwReason, LPVOID)
144
147
return detach ();
145
148
}
146
149
return TRUE ;
147
- }
150
+ }
0 commit comments