2023-05-10 00:05:38 +02:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: IApplication methods
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.h"
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "tier0/frametask.h"
|
|
|
|
#include "tier0/commandline.h"
|
|
|
|
#include "tier1/cvar.h"
|
|
|
|
#include "vpc/interfaces.h"
|
|
|
|
#include "common/engine_launcher_api.h"
|
|
|
|
#include "pluginsystem/pluginsystem.h"
|
|
|
|
#include "pluginsystem/modsystem.h"
|
|
|
|
#include "ebisusdk/EbisuSDK.h"
|
|
|
|
#include "engine/cmodel_bsp.h"
|
|
|
|
#include "engine/sys_engine.h"
|
|
|
|
#include "engine/sys_dll2.h"
|
|
|
|
#include "engine/sdk_dll.h"
|
|
|
|
#include "engine/host_cmd.h"
|
|
|
|
#include "engine/enginetrace.h"
|
|
|
|
#ifndef CLIENT_DLL
|
2024-04-19 12:55:31 +02:00
|
|
|
#include "engine/server/server.h"
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "engine/server/sv_main.h"
|
|
|
|
#include "server/vengineserver_impl.h"
|
|
|
|
#include "game/server/gameinterface.h"
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
#ifndef DEDICATED
|
|
|
|
#include "client/cdll_engine_int.h"
|
|
|
|
#include "game/client/cliententitylist.h"
|
|
|
|
#include "gameui/IConsole.h"
|
|
|
|
#include "windows/id3dx.h"
|
|
|
|
#include "windows/input.h"
|
|
|
|
#endif // !DEDICATED
|
|
|
|
#include "public/idebugoverlay.h"
|
|
|
|
#include "vstdlib/keyvaluessystem.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "engine/sys_dll.h"
|
|
|
|
|
2023-05-10 00:05:38 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CSourceAppSystemGroup::StaticPreInit(CSourceAppSystemGroup* pSourceAppSystemGroup)
|
|
|
|
{
|
|
|
|
return CSourceAppSystemGroup__PreInit(pSourceAppSystemGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CSourceAppSystemGroup::StaticCreate(CSourceAppSystemGroup* pSourceAppSystemGroup)
|
|
|
|
{
|
|
|
|
return CSourceAppSystemGroup__Create(pSourceAppSystemGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int CModAppSystemGroup::StaticMain(CModAppSystemGroup* pModAppSystemGroup)
|
|
|
|
{
|
|
|
|
int nRunResult = RUN_OK;
|
|
|
|
HEbisuSDK_Init(); // Not here in retail. We init EbisuSDK here though.
|
|
|
|
|
|
|
|
g_pEngine->SetQuitting(IEngine::QUIT_NOTQUITTING);
|
|
|
|
if (g_pEngine->Load(pModAppSystemGroup->IsServerOnly(), g_pEngineParms->baseDirectory))
|
|
|
|
{
|
2023-09-09 15:12:58 +02:00
|
|
|
if (CEngineAPI::MainLoop())
|
2023-05-10 00:05:38 +02:00
|
|
|
{
|
|
|
|
nRunResult = RUN_RESTART;
|
|
|
|
}
|
|
|
|
g_pEngine->Unload();
|
|
|
|
|
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
SV_ShutdownGameDLL();
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
}
|
|
|
|
return nRunResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Instantiate all main libraries
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup)
|
|
|
|
{
|
|
|
|
#ifdef DEDICATED
|
|
|
|
pModAppSystemGroup->SetServerOnly();
|
|
|
|
*m_bIsDedicated = true;
|
|
|
|
#endif // DEDICATED
|
2023-08-22 01:11:49 +02:00
|
|
|
|
|
|
|
EXPOSE_INTERFACE_FN((InstantiateInterfaceFn)PluginSystem, CPluginSystem, INTERFACEVERSION_PLUGINSYSTEM);
|
|
|
|
EXPOSE_INTERFACE_FN((InstantiateInterfaceFn)KeyValuesSystem, CKeyValuesSystem, KEYVALUESSYSTEM_INTERFACE_VERSION);
|
2023-05-10 00:05:38 +02:00
|
|
|
|
2023-07-20 22:00:00 +02:00
|
|
|
InitPluginSystem(pModAppSystemGroup);
|
2024-01-21 21:29:23 +01:00
|
|
|
CALL_PLUGIN_CALLBACKS(g_PluginSystem.GetCreateCallbacks(), pModAppSystemGroup);
|
2023-05-10 00:05:38 +02:00
|
|
|
|
2024-01-21 21:29:23 +01:00
|
|
|
ModSystem()->Init();
|
2023-05-10 00:05:38 +02:00
|
|
|
|
2024-01-21 21:29:23 +01:00
|
|
|
g_pDebugOverlay = (CIVDebugOverlay*)g_FactorySystem.GetFactory(VDEBUG_OVERLAY_INTERFACE_VERSION);
|
2023-05-10 00:05:38 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2024-01-21 21:29:23 +01:00
|
|
|
g_pServerGameDLL = (CServerGameDLL*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMEDLL);
|
|
|
|
g_pServerGameClients = (CServerGameClients*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMECLIENTS_NEW);
|
2023-05-10 00:05:38 +02:00
|
|
|
if (!g_pServerGameClients)
|
2024-01-21 21:29:23 +01:00
|
|
|
g_pServerGameClients = (CServerGameClients*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMECLIENTS);
|
|
|
|
g_pServerGameEntities = (CServerGameEnts*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMEENTS);
|
2023-05-10 00:05:38 +02:00
|
|
|
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
#ifndef DEDICATED
|
2024-01-21 21:29:23 +01:00
|
|
|
g_pClientEntityList = (CClientEntityList*)g_FactorySystem.GetFactory(VCLIENTENTITYLIST_INTERFACE_VERSION);
|
|
|
|
g_pEngineTraceClient = (CEngineTraceClient*)g_FactorySystem.GetFactory(INTERFACEVERSION_ENGINETRACE_CLIENT);
|
2023-05-10 00:05:38 +02:00
|
|
|
|
2024-02-29 22:31:43 +01:00
|
|
|
g_ImGuiConfig.Load(); // Load ImGui configs.
|
2023-05-10 00:05:38 +02:00
|
|
|
DirectX_Init();
|
|
|
|
|
|
|
|
#endif // !DEDICATED
|
|
|
|
if (CommandLine()->CheckParm("-devsdk"))
|
|
|
|
{
|
|
|
|
cv->EnableDevCvars();
|
|
|
|
}
|
|
|
|
|
2024-02-28 00:43:57 +01:00
|
|
|
g_TaskQueueList.push_back(&g_TaskQueue);
|
2024-04-19 12:55:31 +02:00
|
|
|
g_bAppSystemInit = true;
|
2024-04-20 01:33:34 +02:00
|
|
|
|
2024-01-02 15:21:36 +01:00
|
|
|
return CModAppSystemGroup__Create(pModAppSystemGroup);
|
2023-05-10 00:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Initialize plugin system
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CModAppSystemGroup::InitPluginSystem(CModAppSystemGroup* pModAppSystemGroup)
|
|
|
|
{
|
2024-01-21 21:29:23 +01:00
|
|
|
g_PluginSystem.Init();
|
2023-09-17 20:33:57 +02:00
|
|
|
|
2024-01-21 21:29:23 +01:00
|
|
|
for (auto& it : g_PluginSystem.GetInstances())
|
2023-05-10 00:05:38 +02:00
|
|
|
{
|
2024-01-21 21:29:23 +01:00
|
|
|
if (g_PluginSystem.LoadInstance(it))
|
2023-08-22 19:32:21 +02:00
|
|
|
Msg(eDLL_T::ENGINE, "Loaded plugin: '%s'\n", it.m_Name.String());
|
2023-05-10 00:05:38 +02:00
|
|
|
else
|
2023-08-22 19:32:21 +02:00
|
|
|
Warning(eDLL_T::ENGINE, "Failed loading plugin: '%s'\n", it.m_Name.String());
|
2023-05-10 00:05:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Sys_Error_Internal
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int HSys_Error_Internal(char* fmt, va_list args)
|
|
|
|
{
|
2023-05-22 23:17:50 +02:00
|
|
|
char buffer[2048];
|
2023-07-22 21:14:04 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "_______________________________________________________________\n");
|
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "] ENGINE ERROR ################################################\n");
|
2023-05-22 23:17:50 +02:00
|
|
|
|
|
|
|
int nLen = vsprintf(buffer, fmt, args);
|
|
|
|
bool shouldNewline = true;
|
|
|
|
|
|
|
|
if (nLen > 0)
|
|
|
|
shouldNewline = buffer[nLen - 1] != '\n';
|
|
|
|
|
2023-07-22 21:14:04 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, shouldNewline ? "%s\n" : "%s", buffer);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
return Sys_Error_Internal(fmt, args);
|
|
|
|
}
|
|
|
|
|
2023-11-26 13:21:20 +01:00
|
|
|
void VSys_Dll::Detour(const bool bAttach) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-11-26 13:21:20 +01:00
|
|
|
DetourSetup(&CSourceAppSystemGroup__PreInit, &CSourceAppSystemGroup::StaticPreInit, bAttach);
|
|
|
|
DetourSetup(&CSourceAppSystemGroup__Create, &CSourceAppSystemGroup::StaticCreate, bAttach);
|
2023-05-10 00:05:38 +02:00
|
|
|
|
2024-01-02 15:21:36 +01:00
|
|
|
DetourSetup(&CModAppSystemGroup__Main, &CModAppSystemGroup::StaticMain, bAttach);
|
|
|
|
DetourSetup(&CModAppSystemGroup__Create, &CModAppSystemGroup::StaticCreate, bAttach);
|
2023-05-10 00:05:38 +02:00
|
|
|
|
2023-11-26 13:21:20 +01:00
|
|
|
DetourSetup(&Sys_Error_Internal, &HSys_Error_Internal, bAttach);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|