Add logic for preventing recursive SDK initialization

This allows for loading the game with the client.dll without loading the main worker/sdk dll. gamesdk.dll is imported by the game executable, so we cannot circumvent its loading without some hacks, so instead, we just check if -noworkerdll is passed and not perform any init if its present.
This commit is contained in:
Kawe Mazidjatari 2022-10-09 12:41:22 +02:00
parent 1e23ddbf35
commit bc3b580525
3 changed files with 23 additions and 4 deletions

View File

@ -18,7 +18,7 @@
void SDK_Init()
{
CheckCPU(); // Check CPU as early as possible, SpdLog also uses SIMD intrinsics.
CheckCPU(); // Check CPU as early as possible, SpdLog also uses SSE intrinsics.
MathLib_Init(); // Initialize Mathlib.
WinSock_Init(); // Initialize Winsock.
@ -90,17 +90,31 @@ void SDK_Shutdown()
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
#if !defined (DEDICATED) && !defined (CLIENT_DLL)
// This dll is imported by the game executable, we cannot circumvent it.
// To solve the recursive init problem, we check if -noworkerdll is passed.
// If this is passed, the worker dll will not be initialized, which allows
// us to load the client dll (or any other dll) instead, or load the game
// without the SDK.
s_bNoWorkerDll = !!strstr(GetCommandLineA(), "-noworkerdll");
#endif // !DEDICATED && CLIENT_DLL
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
SDK_Init();
if (!s_bNoWorkerDll)
{
SDK_Init();
}
break;
}
case DLL_PROCESS_DETACH:
{
SDK_Shutdown();
if (!s_bNoWorkerDll)
{
SDK_Shutdown();
}
break;
}
}

View File

@ -9,7 +9,7 @@ __declspec(dllexport) void DummyExport()
// Required for detours.
}
const std::string R5R_EMBLEM[] =
const static std::string R5R_EMBLEM[] =
{
R"(+-------------------------------------------------------------+)",
R"(| ___ ___ ___ _ _ _ ___ ___ |)",
@ -19,3 +19,5 @@ const std::string R5R_EMBLEM[] =
R"(| |)",
R"(+-------------------------------------------------------------+)"
};
static bool s_bNoWorkerDll = false;

View File

@ -949,6 +949,9 @@ eLaunchMode CUIBaseSurface::BuildParameter(string& svParameters)
}
case eMode::CLIENT:
{
svParameters.append("-noworkerdll\n"); // This prevents init of worker dll
//(this dll is always imported, but we want client.dll to do the work instead).
// GAME ###############################################################
if (this->m_DeveloperToggle->Checked())
{