@@ -92,15 +92,16 @@ static std::string GetLatestVersion()
92
92
return data;
93
93
}
94
94
95
+ static std::once_flag hooking_once_flag;
95
96
static bool checked_hooking = false ;
96
97
HANDLE CreateFileW_S (LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
97
98
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
98
99
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
99
100
{
100
101
if (!checked_hooking && std::wstring (lpFileName).find (L" maindata/file.db" ) != std::string::npos) {
101
102
checked_hooking = true ;
102
- static std::once_flag flag1;
103
- std::call_once (flag1 , []() { events.DoHooking (); });
103
+
104
+ std::call_once (hooking_once_flag , []() { events.DoHooking (); });
104
105
}
105
106
return CreateFileW (lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
106
107
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
@@ -126,7 +127,7 @@ FARPROC GetProcAddress_S(HMODULE hModule, LPCSTR lpProcName)
126
127
// those would have usually been in the import table.
127
128
// This means we are ready to do some hooking
128
129
// But only do hooking once.
129
-
130
+ std::call_once (hooking_once_flag, []() { events. DoHooking (); });
130
131
131
132
if ((uintptr_t )lpProcName > 0x1000 ) {
132
133
if (lpProcName == std::string (" CreateFileW" )) {
@@ -247,6 +248,43 @@ HANDLE GetParentProcess()
247
248
return OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, FALSE , ProcessEntry.th32ParentProcessID );
248
249
}
249
250
251
+ static void CheckVersion ()
252
+ {
253
+ // Version Check
254
+ try {
255
+ auto body = GetLatestVersion ();
256
+ const auto & data = nlohmann::json::parse (body);
257
+ const auto & version_str = data[" version" ].get <std::string>();
258
+
259
+ static int32_t current_version[3 ] = {VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION};
260
+
261
+ int32_t latest_version[3 ] = {0 };
262
+ std::sscanf (version_str.c_str (), " %d.%d.%d" , &latest_version[0 ], &latest_version[1 ],
263
+ &latest_version[2 ]);
264
+
265
+ if (std::lexicographical_compare (current_version, current_version + 3 , latest_version,
266
+ latest_version + 3 )) {
267
+ std::string msg = " Verion " + version_str + " of " + VER_FILE_DESCRIPTION_STR
268
+ + " is available for download.\n\n " ;
269
+ msg.append (" Do you want to go to the release page on GitHub?\n (THIS IS "
270
+ " HIGHLY RECOMMENDED!!!)" );
271
+
272
+ if (MessageBoxA (NULL , msg.c_str (), VER_FILE_DESCRIPTION_STR,
273
+ MB_ICONQUESTION | MB_YESNO | MB_SYSTEMMODAL)
274
+ == IDYES) {
275
+ auto result =
276
+ ShellExecuteA (nullptr , " open" ,
277
+ " https://github.com/xforce/anno1800-mod-loader/releases/latest" ,
278
+ nullptr , nullptr , SW_SHOWNORMAL);
279
+ result = result;
280
+ TerminateProcess (GetCurrentProcess (), 0 );
281
+ }
282
+ }
283
+ } catch (...) {
284
+ // TODO(alexander): Logging
285
+ }
286
+ }
287
+
250
288
BOOL APIENTRY DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
251
289
{
252
290
switch (ul_reason_for_call) {
@@ -302,8 +340,9 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
302
340
}
303
341
}
304
342
305
- // Version Check
306
343
events.DoHooking .connect ([]() {
344
+ CheckVersion ();
345
+
307
346
// Let's start loading the list of files we want to have
308
347
HMODULE module ;
309
348
if (GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
@@ -343,40 +382,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
343
382
return ;
344
383
}
345
384
346
- try {
347
- auto body = GetLatestVersion ();
348
- const auto & data = nlohmann::json::parse (body);
349
- const auto & version_str = data[" version" ].get <std::string>();
350
-
351
- static int32_t current_version[3 ] = {VERSION_MAJOR, VERSION_MINOR,
352
- VERSION_REVISION};
353
-
354
- int32_t latest_version[3 ] = {0 };
355
- std::sscanf (version_str.c_str (), " %d.%d.%d" , &latest_version[0 ],
356
- &latest_version[1 ], &latest_version[2 ]);
357
-
358
- if (std::lexicographical_compare (current_version, current_version + 3 ,
359
- latest_version, latest_version + 3 )) {
360
- std::string msg = " Verion " + version_str + " of "
361
- + VER_FILE_DESCRIPTION_STR
362
- + " is available for download.\n\n " ;
363
- msg.append (" Do you want to go to the release page on GitHub?\n (THIS IS "
364
- " HIGHLY RECOMMENDED!!!)" );
365
-
366
- if (MessageBoxA (NULL , msg.c_str (), VER_FILE_DESCRIPTION_STR,
367
- MB_ICONQUESTION | MB_YESNO | MB_SYSTEMMODAL)
368
- == IDYES) {
369
- auto result = ShellExecuteA (
370
- nullptr , " open" ,
371
- " https://github.com/xforce/anno1800-mod-loader/releases/latest" ,
372
- nullptr , nullptr , SW_SHOWNORMAL);
373
- result = result;
374
- TerminateProcess (GetCurrentProcess (), 0 );
375
- }
376
- }
377
- } catch (...) {
378
- // TODO(alexander): Logging
379
- }
385
+
380
386
});
381
387
382
388
EnableExtenalFileLoading (events);
0 commit comments