Skip to content

Commit b2850db

Browse files
committed
properly handle reload with addon trigered client_unload
1 parent b57b58d commit b2850db

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

loader_core/gw2al_api_impl.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#include "stdafx.h"
22

33
FILE* logFile = NULL;
4+
bool firstInit = true;
45

5-
void gw2al_core__init()
6+
bool gw2al_core__init()
67
{
8+
if (!firstInit)
9+
return false;
10+
711
gw2al_core__init_func_registry();
812
gw2al_core__init_addon_registry();
913
gw2al_core__init_events();
1014

1115
logFile = fopen("gw2al_log.txt", "wb");
16+
17+
firstInit = false;
18+
return true;
1219
}
1320

1421
gw2al_hashed_name gw2al_core__hash_name(wchar_t * name)
@@ -37,8 +44,11 @@ void gw2al_core__client_unload()
3744
if (logFile)
3845
{
3946
fflush(logFile);
40-
fclose(logFile);
41-
logFile = NULL;
47+
//megai2: no reliable way to detect client unload
48+
//log will be populated with new data, not created again and closed by OS on dll unload
49+
//so we are kinda fine to keep it opened
50+
//fclose(logFile);
51+
//logFile = NULL;
4252
}
4353
}
4454

loader_core/gw2al_api_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef struct gw2al_event_dsc {
2323
gw2al_event_subscriber* subs;
2424
} gw2al_event_dsc;
2525

26-
void gw2al_core__init();
26+
bool gw2al_core__init();
2727
void gw2al_core__init_func_registry();
2828
void gw2al_core__init_addon_registry();
2929
void gw2al_core__init_events();

loader_core/loader_core.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ IDirect3D9 * loader_core::OnD3DCreate(UINT sdkVer)
9191
{
9292
if (SwitchState(LDR_ADDON_LOAD))
9393
{
94-
gw2al_core__init();
94+
bool isFirstLoad = gw2al_core__init();
9595

96-
LOG_INFO(L"core", L"Addon loader v%u.%u (%S) initialized", LOADER_CORE_VER_MAJOR, LOADER_CORE_VER_MINOR, LOADER_CORE_VER_NAME);
96+
LOG_INFO(L"core", L"Addon loader v%u.%u (%S) %S", LOADER_CORE_VER_MAJOR, LOADER_CORE_VER_MINOR, LOADER_CORE_VER_NAME,
97+
isFirstLoad ? "initialized" : "reinit");
9798
}
9899
else {
99100
LOG_WARNING(L"core", L"D3DCreate called twice without proper unload. Trying to unload addons.");

0 commit comments

Comments
 (0)