r5sdk/r5dev/launcher/IApplication.cpp
Kawe Mazidjatari 656b0be3ec Improve threading (work in progress)
* Only run '_DownloadPlaylists_f()' in the main thread, schedule for next frame if we aren't in the main thread. (this should fix crash cases related to disconnecting from the game).

* Locked read/write to CBrowser members (thread for obtaining the server list is detached, but once the 'slow' post operation in this thread is complete, mutex lock is acquired (locking the render thread if the browser is active) to set the string members of CBrowser, this operation is very fast as we only set the string and the color after the http post operation (this never caused a crash, but the behavior without any lock mechanism is technically undefined regardless).

* Obtain the host name dynamically from the ConVar 'pylon_matchmaking_hostname' (atomic operation). Initial approach was deleting the whole master server pointer just to construct a new httpclient object..
2022-08-27 18:57:56 +02:00

114 lines
3.5 KiB
C++

//=============================================================================//
//
// Purpose: IApplication methods
//
//=============================================================================//
#include "core/stdafx.h"
#include "tier0/frametask.h"
#include "tier0/commandline.h"
#include "tier1/cvar.h"
#include "vpc/interfaces.h"
#include "launcher/IApplication.h"
#include "pluginsystem/pluginsystem.h"
#include "ebisusdk/EbisuSDK.h"
#include "engine/cmodel_bsp.h"
#include "engine/sys_engine.h"
#include "engine/sys_dll2.h"
#include "engine/host_cmd.h"
#include "engine/server/sv_main.h"
#include "server/vengineserver_impl.h"
#include "client/cdll_engine_int.h"
#ifndef DEDICATED
#include "gameui/IConsole.h"
#endif // !DEDICATED
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CModAppSystemGroup::Main(CModAppSystemGroup* pModAppSystemGroup)
{
int nRunResult = RUN_OK;
HEbisuSDK_Init(); // Not here in retail. We init EbisuSDK here though.
MOD_GetAllInstalledMaps();
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) // !TODO: rebuild does not work for S1 (CModAppSystemGroup and CEngine member offsets do align with all other builds).
return CModAppSystemGroup_Main(pModAppSystemGroup);
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
g_pEngine->SetQuitting(IEngine::QUIT_NOTQUITTING);
if (g_pEngine->Load(pModAppSystemGroup->IsServerOnly(), g_pEngineParms->baseDirectory))
{
if (CEngineAPI_MainLoop())
{
nRunResult = RUN_RESTART;
}
g_pEngine->Unload();
SV_ShutdownGameDLL();
}
return nRunResult;
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Instantiate all main libraries
//-----------------------------------------------------------------------------
bool CModAppSystemGroup::Create(CModAppSystemGroup* pModAppSystemGroup)
{
#ifdef DEDICATED
pModAppSystemGroup->SetServerOnly();
*g_bDedicated = true;
#endif // DEDICATED
g_pConCommand->Init();
g_pFactory->GetFactoriesFromRegister();
g_pFactory->AddFactory(FACTORY_INTERFACE_VERSION, g_pFactory);
g_pFactory->AddFactory(INTERFACEVERSION_PLUGINSYSTEM, g_pPluginSystem);
// DEBUG CODE FOR PLUGINS
//g_pPluginSystem->PluginSystem_Init();
//for (auto& it : g_pPluginSystem->GetPluginInstances())
//{
// if (g_pPluginSystem->LoadPluginInstance(it))
// spdlog::info("Load PLUGIN SUCCESS\n");
//}
#ifndef DEDICATED
g_pClientEntityList = g_pFactory->GetFactoryPtr("VClientEntityList003", false).RCast<IClientEntityList*>();
for (auto& map : g_pCVar->DumpToMap())
{
g_pConsole->m_vsvCommandBases.push_back(
CSuggest(map.first, map.second->GetFlags()));
}
#endif // !DEDICATED
if (CommandLine()->CheckParm("-devsdk"))
{
cv->EnableDevCvars();
}
if (pModAppSystemGroup->IsServerOnly())
{
memset(gHLClient, '\0', sizeof(void*));
gHLClient = nullptr;
memset(g_pHLClient, '\0', sizeof(void*));
g_pHLClient = nullptr;
}
g_FrameTasks.push_back(std::move(g_TaskScheduler));
g_bAppSystemInit = true;
return CModAppSystemGroup_Create(pModAppSystemGroup);
}
///////////////////////////////////////////////////////////////////////////////
void IApplication_Attach()
{
DetourAttach((LPVOID*)&CModAppSystemGroup_Main, &CModAppSystemGroup::Main);
DetourAttach((LPVOID*)&CModAppSystemGroup_Create, &CModAppSystemGroup::Create);
}
void IApplication_Detach()
{
DetourDetach((LPVOID*)&CModAppSystemGroup_Main, &CModAppSystemGroup::Main);
DetourDetach((LPVOID*)&CModAppSystemGroup_Create, &CModAppSystemGroup::Create);
}