r5sdk/r5dev/core/dllmain.cpp
Kawe Mazidjatari 88b3336758 Many small code improvements and optimizations
* Use c++ methods as much as possible.
* Use enum types for accessing NavMesh objects from array.
* Use size_t for for loops when testing against size types.
* Don't compute strlen twice of more on the same string.
* Don't use unnecessary c string casts if there is a method with a std::string overload.
* Don't create string objects from string pointers if we could use them directly.
* Don't initialize RCON password twice on each change, and don't set if the new password equals the old.
2022-08-11 11:07:45 +02:00

103 lines
2.3 KiB
C++

#include "core/stdafx.h"
#include "core/r5dev.h"
#include "core/init.h"
#include "core/logdef.h"
/*****************************************************************************/
#ifndef DEDICATED
#include "windows/id3dx.h"
#include "windows/input.h"
#endif // !DEDICATED
#include "windows/console.h"
#include "windows/system.h"
#include "launcher/launcher.h"
//#############################################################################
// INITIALIZATION
//#############################################################################
void R5Dev_Init()
{
if (strstr(GetCommandLineA(), "-launcher"))
{
g_svCmdLine = GetCommandLineA();
}
else
{
g_svCmdLine = LoadConfigFile(SDK_DEFAULT_CFG);
}
#ifndef DEDICATED
if (g_svCmdLine.find("-wconsole") != std::string::npos)
{
Console_Init();
}
#else
Console_Init();
#endif // !DEDICATED
SpdLog_Init();
spdlog::info("\n");
for (size_t i = 0; i < SDK_ARRAYSIZE(R5R_EMBLEM); i++)
{
std::string svEscaped = StringEscape(R5R_EMBLEM[i]);
spdlog::info("{:s}{:s}{:s}\n", g_svRedF, svEscaped, g_svReset);
}
spdlog::info("\n");
Systems_Init();
WinSys_Attach();
#ifndef DEDICATED
Input_Init();
DirectX_Init();
#endif // !DEDICATED
}
//#############################################################################
// SHUTDOWN
//#############################################################################
void R5Dev_Shutdown()
{
static bool bShutDown = false;
if (bShutDown)
{
spdlog::error("Recursive shutdown!\n");
return;
}
bShutDown = true;
spdlog::info("Shutdown GameSDK\n");
Systems_Shutdown();
WinSys_Detach();
#ifndef DEDICATED
Input_Shutdown();
DirectX_Shutdown();
#endif // !DEDICATED
FreeConsole();
}
//#############################################################################
// ENTRYPOINT
//#############################################################################
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
R5Dev_Init();
break;
}
case DLL_PROCESS_DETACH:
{
R5Dev_Shutdown();
break;
}
}
return TRUE;
}