Skip to content

Commit b70fec0

Browse files
committed
Pin modules to ensure they stay loaded on exit
1 parent 0e6baf6 commit b70fec0

File tree

8 files changed

+23
-1
lines changed

8 files changed

+23
-1
lines changed

Common/Utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,12 @@ void CopyReplaceSlash(char* DestStr, size_t Size, LPCSTR SrcStr)
11771177
}
11781178
}
11791179

1180+
void PinModule(HMODULE dll)
1181+
{
1182+
HMODULE dummy = nullptr;
1183+
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCSTR>(dll), &dummy);
1184+
}
1185+
11801186
BOOL GetAppsLightMode()
11811187
{
11821188
HKEY hKey;

Common/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bool GetConfigName(char* ConfigName, rsize_t size, char* ext);
4444
bool GetConfigName(wchar_t* ConfigName, rsize_t size, wchar_t* ext);
4545
bool CheckPathNameMatch(LPCSTR lpFileName1, LPCSTR lpFileName2);
4646
void CopyReplaceSlash(char* DestStr, size_t Size, LPCSTR SrcStr);
47+
void PinModule(HMODULE dll);
4748
BOOL GetAppsLightMode();
4849
void ClearGDISurface(HWND hWnd, COLORREF color);
4950
HMONITOR GetMonitorHandle();

Resources/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 2217
1+
#define BUILD_NUMBER 2218

Wrappers/d3d8/d3d8wrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ HMODULE GetD3d8ScriptDll()
5151
if (script_d3d8_dll)
5252
{
5353
Logging::Log() << "Loaded d3d8.dll from: " << script_path_dll.c_str();
54+
PinModule(script_d3d8_dll);
5455
}
5556

5657
// Load d3d8.dll from 'plugins' folder
@@ -61,6 +62,7 @@ HMODULE GetD3d8ScriptDll()
6162
if (script_d3d8_dll)
6263
{
6364
Logging::Log() << "Loaded d3d8.dll from: " << plugin_path_dll.c_str();
65+
PinModule(script_d3d8_dll);
6466
}
6567
}
6668

@@ -118,6 +120,7 @@ bool GetLocalDirect3DCreate8()
118120
m_pDirect3DCreate8_local = (Direct3DCreate8Proc)GetProcAddress(h_d3d8, "Direct3DCreate8");
119121
if (m_pDirect3DCreate8_local)
120122
{
123+
PinModule(h_d3d8);
121124
return true;
122125
}
123126
}

Wrappers/d3d9/d3d9wrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ HMODULE GetSystemD3d9()
3838
GetSystemDirectoryA(Path, MAX_PATH);
3939
strcat_s(Path, "\\d3d9.dll");
4040
GetModuleHandleExA(NULL, Path, &h_d3d9);
41+
if (h_d3d9)
42+
{
43+
PinModule(h_d3d9);
44+
}
4145
}
4246

4347
return h_d3d9;
@@ -85,6 +89,7 @@ bool GetDirect3DCreate9()
8589
m_pDirect3DCreate9 = (Direct3DCreate9Proc)GetProcAddress(h_d3d9, "Direct3DCreate9");
8690
if (m_pDirect3DCreate9)
8791
{
92+
PinModule(h_d3d9);
8893
return true;
8994
}
9095
}
@@ -113,6 +118,7 @@ bool GetLocalDirect3DCreate9()
113118
m_pDirect3DCreate9_local = (Direct3DCreate9Proc)GetProcAddress(h_d3d9, "Direct3DCreate9");
114119
if (m_pDirect3DCreate9_local)
115120
{
121+
PinModule(h_d3d9);
116122
return true;
117123
}
118124
}

Wrappers/dinput8/dinput8wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool GetLocalDirectInput8Create()
6969
m_pDirectInput8Create_local = (DirectInput8CreateProc)GetProcAddress(h_dinput8, "DirectInput8Create");
7070
if (m_pDirectInput8Create_local)
7171
{
72+
PinModule(h_dinput8);
7273
return true;
7374
}
7475
}

Wrappers/dsound/dsoundwrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ bool GetLocalDirectSoundCreate8()
6666
m_pDirectSoundCreate8_local = (DirectSoundCreate8Proc)GetProcAddress(h_dsound, "DirectSoundCreate8");
6767
if (m_pDirectSoundCreate8_local)
6868
{
69+
PinModule(h_dsound);
6970
return true;
7071
}
7172
}
@@ -93,6 +94,7 @@ bool GetSystem32DirectSoundCreate8()
9394
m_pDirectSoundCreate8_system32 = (DirectSoundCreate8Proc)GetProcAddress(h_dsound, "DirectSoundCreate8");
9495
if (m_pDirectSoundCreate8_system32)
9596
{
97+
PinModule(h_dsound);
9698
return true;
9799
}
98100
}

dllmain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,9 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
903903
{
904904
DelayedStart();
905905
}
906+
907+
// Pin current module
908+
PinModule(m_hModule);
906909
}
907910
break;
908911
case DLL_THREAD_ATTACH:

0 commit comments

Comments
 (0)