diff --git a/lib/YaeAchievementLib.vcxproj b/lib/YaeAchievementLib.vcxproj
index 19d11eb..06aad96 100644
--- a/lib/YaeAchievementLib.vcxproj
+++ b/lib/YaeAchievementLib.vcxproj
@@ -100,6 +100,7 @@
+
diff --git a/lib/src/dllmain.cpp b/lib/src/dllmain.cpp
index 69e5d0e..e141d80 100644
--- a/lib/src/dllmain.cpp
+++ b/lib/src/dllmain.cpp
@@ -9,6 +9,7 @@
#include "util.h"
#include "il2cpp-init.h"
#include "il2cpp-types.h"
+#include "ntprivate.h"
CRITICAL_SECTION CriticalSection;
void SetBreakpoint(HANDLE thread, uintptr_t address, bool enable, uint8_t index = 0);
@@ -200,6 +201,11 @@ BOOL __stdcall DllMain(HMODULE hInstance, DWORD fdwReason, LPVOID lpReserved)
if (fdwReason == DLL_PROCESS_ATTACH)
{
+ if (hInstance)
+ {
+ LdrAddRefDll(LDR_ADDREF_DLL_PIN, hInstance);
+ }
+
if (const auto hThread = CreateThread(nullptr, 0, ThreadProc, hInstance, 0, nullptr)) {
CloseHandle(hThread);
}
diff --git a/lib/src/ntprivate.h b/lib/src/ntprivate.h
new file mode 100644
index 0000000..be91af9
--- /dev/null
+++ b/lib/src/ntprivate.h
@@ -0,0 +1,9 @@
+#pragma once
+#include
+#include
+
+#pragma comment(lib, "ntdll.lib")
+
+#define LDR_ADDREF_DLL_PIN 0x00000001
+
+EXTERN_C NTSYSAPI NTSTATUS NTAPI LdrAddRefDll(_In_ ULONG Flags, _In_ PVOID DllHandle);
\ No newline at end of file