2022-01-16 01:18:36 +01:00
|
|
|
|
#include "core/stdafx.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
|
#include "core/r5dev.h"
|
|
|
|
|
#include "core/init.h"
|
2022-01-14 20:45:36 +01:00
|
|
|
|
#include "core/logdef.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
#ifndef DEDICATED
|
|
|
|
|
#include "windows/id3dx.h"
|
|
|
|
|
#include "windows/input.h"
|
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
#include "windows/console.h"
|
2021-12-30 17:20:41 +01:00
|
|
|
|
#include "windows/system.h"
|
2022-09-14 02:23:06 +02:00
|
|
|
|
#include "mathlib/mathlib.h"
|
2022-04-16 00:30:46 +02:00
|
|
|
|
#include "launcher/launcher.h"
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
|
//#############################################################################
|
|
|
|
|
// INITIALIZATION
|
|
|
|
|
//#############################################################################
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
2022-08-29 14:31:05 +02:00
|
|
|
|
void SDK_Init()
|
2021-04-13 04:45:22 -07:00
|
|
|
|
{
|
2022-10-09 12:41:22 +02:00
|
|
|
|
CheckCPU(); // Check CPU as early as possible, SpdLog also uses SSE intrinsics.
|
2022-09-14 01:35:05 +02:00
|
|
|
|
|
2022-09-14 02:23:06 +02:00
|
|
|
|
MathLib_Init(); // Initialize Mathlib.
|
|
|
|
|
WinSock_Init(); // Initialize Winsock.
|
|
|
|
|
|
2023-01-26 19:58:21 +01:00
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
|
2022-04-16 00:30:46 +02:00
|
|
|
|
if (strstr(GetCommandLineA(), "-launcher"))
|
|
|
|
|
{
|
|
|
|
|
g_svCmdLine = GetCommandLineA();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_svCmdLine = LoadConfigFile(SDK_DEFAULT_CFG);
|
|
|
|
|
}
|
2022-01-14 20:45:36 +01:00
|
|
|
|
#ifndef DEDICATED
|
2022-08-11 11:07:45 +02:00
|
|
|
|
if (g_svCmdLine.find("-wconsole") != std::string::npos)
|
2022-04-16 00:30:46 +02:00
|
|
|
|
{
|
|
|
|
|
Console_Init();
|
|
|
|
|
}
|
2022-01-14 20:45:36 +01:00
|
|
|
|
#else
|
2021-12-25 22:36:38 +01:00
|
|
|
|
Console_Init();
|
2022-01-14 20:45:36 +01:00
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
SpdLog_Init();
|
2022-07-03 19:18:23 +02:00
|
|
|
|
for (size_t i = 0; i < SDK_ARRAYSIZE(R5R_EMBLEM); i++)
|
2022-04-14 19:18:59 +02:00
|
|
|
|
{
|
|
|
|
|
std::string svEscaped = StringEscape(R5R_EMBLEM[i]);
|
2022-08-11 11:07:45 +02:00
|
|
|
|
spdlog::info("{:s}{:s}{:s}\n", g_svRedF, svEscaped, g_svReset);
|
2022-04-14 19:18:59 +02:00
|
|
|
|
}
|
|
|
|
|
spdlog::info("\n");
|
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
|
Systems_Init();
|
2021-12-30 17:20:41 +01:00
|
|
|
|
WinSys_Attach();
|
2023-01-30 21:44:28 +01:00
|
|
|
|
|
|
|
|
|
#ifndef DEDICATED
|
|
|
|
|
Input_Init();
|
|
|
|
|
#endif // !DEDICATED
|
2021-04-13 04:45:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 20:45:36 +01:00
|
|
|
|
//#############################################################################
|
|
|
|
|
// SHUTDOWN
|
|
|
|
|
//#############################################################################
|
|
|
|
|
|
2022-08-29 14:31:05 +02:00
|
|
|
|
void SDK_Shutdown()
|
2021-04-13 04:45:22 -07:00
|
|
|
|
{
|
2022-02-18 14:00:58 +01:00
|
|
|
|
static bool bShutDown = false;
|
2022-10-11 01:21:26 +02:00
|
|
|
|
assert(!bShutDown);
|
2022-02-18 14:00:58 +01:00
|
|
|
|
if (bShutDown)
|
|
|
|
|
{
|
|
|
|
|
spdlog::error("Recursive shutdown!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bShutDown = true;
|
2022-02-19 14:02:46 +01:00
|
|
|
|
spdlog::info("Shutdown GameSDK\n");
|
2022-02-18 14:00:58 +01:00
|
|
|
|
|
2023-01-26 19:58:21 +01:00
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
|
2022-09-14 02:23:06 +02:00
|
|
|
|
WinSock_Shutdown();
|
2021-12-25 22:36:38 +01:00
|
|
|
|
Systems_Shutdown();
|
2021-12-30 17:20:41 +01:00
|
|
|
|
WinSys_Detach();
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
|
|
#ifndef DEDICATED
|
|
|
|
|
Input_Shutdown();
|
|
|
|
|
DirectX_Shutdown();
|
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
|
2021-06-19 11:21:31 -07:00
|
|
|
|
FreeConsole();
|
2021-04-13 04:45:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
|
//#############################################################################
|
|
|
|
|
// ENTRYPOINT
|
|
|
|
|
//#############################################################################
|
2021-06-08 10:54:49 -07:00
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
|
2021-04-13 04:45:22 -07:00
|
|
|
|
{
|
2022-10-09 12:41:22 +02:00
|
|
|
|
#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
|
2021-04-13 04:45:22 -07:00
|
|
|
|
switch (dwReason)
|
|
|
|
|
{
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2021-04-17 04:51:04 -07:00
|
|
|
|
{
|
2022-10-09 12:41:22 +02:00
|
|
|
|
if (!s_bNoWorkerDll)
|
|
|
|
|
{
|
|
|
|
|
SDK_Init();
|
|
|
|
|
}
|
2021-04-13 04:45:22 -07:00
|
|
|
|
break;
|
2021-04-17 04:51:04 -07:00
|
|
|
|
}
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2021-04-17 04:51:04 -07:00
|
|
|
|
{
|
2022-10-09 12:41:22 +02:00
|
|
|
|
if (!s_bNoWorkerDll)
|
|
|
|
|
{
|
|
|
|
|
SDK_Shutdown();
|
|
|
|
|
}
|
2021-04-13 04:45:22 -07:00
|
|
|
|
break;
|
2021-04-17 04:51:04 -07:00
|
|
|
|
}
|
2021-04-13 04:45:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2021-06-08 10:54:49 -07:00
|
|
|
|
}
|