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"
|
2023-05-10 00:05:38 +02:00
|
|
|
|
#include "core/logger.h"
|
2023-06-01 23:44:55 +02:00
|
|
|
|
#include "tier0/basetypes.h"
|
2023-01-31 22:13:40 +01:00
|
|
|
|
#include "tier0/crashhandler.h"
|
2023-07-01 01:20:47 +02:00
|
|
|
|
#include "tier0/commandline.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"
|
2024-03-16 01:27:57 +01:00
|
|
|
|
#include "protobuf/stubs/common.h"
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
2023-06-01 23:44:55 +02:00
|
|
|
|
#ifndef DEDICATED
|
2023-07-13 23:15:10 +02:00
|
|
|
|
#define SDK_DEFAULT_CFG "cfg/system/startup_default.cfg"
|
2023-06-01 23:44:55 +02:00
|
|
|
|
#else
|
2023-07-13 23:15:10 +02:00
|
|
|
|
#define SDK_DEFAULT_CFG "cfg/system/startup_dedi_default.cfg"
|
2023-06-01 23:44:55 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
bool g_bSdkInitialized = false;
|
2024-04-03 01:34:25 +02:00
|
|
|
|
HMODULE s_hModuleHandle = NULL;
|
2023-07-01 01:20:47 +02:00
|
|
|
|
|
2021-06-28 15:51:32 -07:00
|
|
|
|
//#############################################################################
|
2023-07-01 01:20:47 +02:00
|
|
|
|
// UTILITY
|
2021-06-28 15:51:32 -07:00
|
|
|
|
//#############################################################################
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
2023-05-10 00:05:38 +02:00
|
|
|
|
void Crash_Callback()
|
|
|
|
|
{
|
|
|
|
|
// Shutdown SpdLog to flush all buffers.
|
|
|
|
|
SpdLog_Shutdown();
|
|
|
|
|
|
|
|
|
|
// TODO[ AMOS ]: This is where we want to call backtrace from.
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
void Show_Emblem()
|
|
|
|
|
{
|
|
|
|
|
// Logged as 'SYSTEM_ERROR' for its red color.
|
|
|
|
|
for (size_t i = 0; i < SDK_ARRAYSIZE(R5R_EMBLEM); i++)
|
|
|
|
|
{
|
2023-08-21 19:12:29 +02:00
|
|
|
|
Msg(eDLL_T::SYSTEM_ERROR, "%s\n", R5R_EMBLEM[i]);
|
2023-07-01 01:20:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log the SDK's 'build_id' under the emblem.
|
2023-08-21 19:12:29 +02:00
|
|
|
|
Msg(eDLL_T::SYSTEM_ERROR,
|
2023-07-01 21:27:37 +02:00
|
|
|
|
"+------------------------------------------------[%s%010d%s]-+\n",
|
|
|
|
|
g_svYellowF, g_SDKDll.GetNTHeaders()->FileHeader.TimeDateStamp, g_svRedF);
|
2023-08-21 19:12:29 +02:00
|
|
|
|
Msg(eDLL_T::SYSTEM_ERROR, "\n");
|
2023-07-01 01:20:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#############################################################################
|
|
|
|
|
// INITIALIZATION
|
|
|
|
|
//#############################################################################
|
|
|
|
|
|
2023-05-10 00:05:38 +02:00
|
|
|
|
void Tier0_Init()
|
|
|
|
|
{
|
|
|
|
|
#if !defined (DEDICATED)
|
2023-07-10 13:54:00 +02:00
|
|
|
|
g_RadVideoToolsDll.InitFromName("bink2w64.dll");
|
|
|
|
|
g_RadAudioDecoderDll.InitFromName("binkawin64.dll");
|
|
|
|
|
g_RadAudioSystemDll.InitFromName("mileswin64.dll");
|
2023-05-10 00:05:38 +02:00
|
|
|
|
#endif // !DEDICATED
|
2023-07-01 01:20:47 +02:00
|
|
|
|
g_CoreMsgVCallback = &EngineLoggerSink; // Setup logger callback sink.
|
2023-05-10 00:05:38 +02:00
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
g_pCmdLine->CreateCmdLine(GetCommandLineA());
|
2024-02-04 00:55:07 +01:00
|
|
|
|
g_CrashHandler.SetCrashCallback(&Crash_Callback);
|
2023-07-01 02:11:39 +02:00
|
|
|
|
|
|
|
|
|
// This prevents the game from recreating it,
|
|
|
|
|
// see 'CCommandLine::StaticCreateCmdLine' for
|
|
|
|
|
// more information.
|
|
|
|
|
g_bCommandLineCreated = true;
|
2023-05-10 00:05:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 14:31:05 +02:00
|
|
|
|
void SDK_Init()
|
2021-04-13 04:45:22 -07:00
|
|
|
|
{
|
2024-04-03 01:34:25 +02:00
|
|
|
|
CheckCPU(); // Check CPU as early as possible; error out if CPU isn't supported.
|
|
|
|
|
MathLib_Init(); // Initialize Mathlib.
|
|
|
|
|
|
|
|
|
|
PEB64* pEnv = CModule::GetProcessEnvironmentBlock();
|
|
|
|
|
|
|
|
|
|
g_GameDll.InitFromBase(pEnv->ImageBaseAddress);
|
|
|
|
|
g_SDKDll.InitFromBase((QWORD)s_hModuleHandle);
|
|
|
|
|
|
2023-06-25 11:37:52 +02:00
|
|
|
|
Tier0_Init();
|
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
if (!CommandLine()->CheckParm("-launcher"))
|
2022-04-16 00:30:46 +02:00
|
|
|
|
{
|
2023-07-01 01:20:47 +02:00
|
|
|
|
CommandLine()->AppendParametersFromFile(SDK_DEFAULT_CFG);
|
2022-04-16 00:30:46 +02:00
|
|
|
|
}
|
2023-04-09 23:38:55 +02:00
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
const bool bAnsiColor = CommandLine()->CheckParm("-ansicolor") ? true : false;
|
2023-01-31 17:09:56 +01:00
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
#ifndef DEDICATED
|
|
|
|
|
if (CommandLine()->CheckParm("-wconsole"))
|
|
|
|
|
#endif // !DEDICATED
|
2022-04-14 19:18:59 +02:00
|
|
|
|
{
|
2023-07-01 01:20:47 +02:00
|
|
|
|
Console_Init(bAnsiColor);
|
2022-04-14 19:18:59 +02:00
|
|
|
|
}
|
2023-06-19 10:58:12 +02:00
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
SpdLog_Init(bAnsiColor);
|
|
|
|
|
Show_Emblem();
|
2022-04-14 19:18:59 +02:00
|
|
|
|
|
2024-03-31 15:15:30 +02:00
|
|
|
|
Winsock_Startup(); // Initialize Winsock.
|
2024-04-03 01:34:25 +02:00
|
|
|
|
DirtySDK_Startup();
|
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
|
Systems_Init();
|
2023-01-30 21:44:28 +01:00
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
WinSys_Init();
|
2023-01-30 21:44:28 +01:00
|
|
|
|
#ifndef DEDICATED
|
|
|
|
|
Input_Init();
|
|
|
|
|
#endif // !DEDICATED
|
2023-06-18 01:16:58 +02:00
|
|
|
|
|
2024-03-16 01:27:57 +01:00
|
|
|
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
2023-06-28 10:03:10 +02:00
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
2023-06-18 01:16:58 +02:00
|
|
|
|
lzham_enable_fail_exceptions(true);
|
2023-07-01 01:20:47 +02:00
|
|
|
|
|
|
|
|
|
g_bSdkInitialized = true;
|
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
|
|
|
|
{
|
2023-07-01 11:20:44 +02:00
|
|
|
|
assert(g_bSdkInitialized);
|
2023-07-01 01:20:47 +02:00
|
|
|
|
|
2023-07-01 11:20:44 +02:00
|
|
|
|
if (!g_bSdkInitialized)
|
2022-02-18 14:00:58 +01:00
|
|
|
|
{
|
|
|
|
|
spdlog::error("Recursive shutdown!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-01 01:20:47 +02:00
|
|
|
|
|
2023-07-01 11:20:44 +02:00
|
|
|
|
g_bSdkInitialized = false;
|
2023-08-21 19:12:29 +02:00
|
|
|
|
Msg(eDLL_T::NONE, "GameSDK shutdown initiated\n");
|
2022-02-18 14:00:58 +01:00
|
|
|
|
|
2023-01-26 19:58:21 +01:00
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
|
#ifndef DEDICATED
|
|
|
|
|
Input_Shutdown();
|
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
|
2023-07-01 01:20:47 +02:00
|
|
|
|
WinSys_Shutdown();
|
|
|
|
|
Systems_Shutdown();
|
2024-04-03 01:34:25 +02:00
|
|
|
|
|
|
|
|
|
DirtySDK_Shutdown();
|
2023-07-01 01:20:47 +02:00
|
|
|
|
Winsock_Shutdown();
|
|
|
|
|
|
2023-03-18 14:10:29 +01:00
|
|
|
|
SpdLog_Shutdown();
|
2023-07-01 01:20:47 +02:00
|
|
|
|
Console_Shutdown();
|
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
|
|
|
|
|
2023-04-02 17:02:04 +02:00
|
|
|
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
|
2021-04-13 04:45:22 -07:00
|
|
|
|
{
|
2023-04-02 17:02:04 +02:00
|
|
|
|
NOTE_UNUSED(lpReserved);
|
|
|
|
|
|
2021-04-13 04:45:22 -07:00
|
|
|
|
switch (dwReason)
|
|
|
|
|
{
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2021-04-17 04:51:04 -07:00
|
|
|
|
{
|
2024-04-03 01:34:25 +02:00
|
|
|
|
s_hModuleHandle = hModule;
|
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
|
|
|
|
{
|
2024-04-03 01:34:25 +02:00
|
|
|
|
s_hModuleHandle = NULL;
|
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
|
|
|
|
}
|