2022-02-06 16:48:52 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
2022-02-14 23:16:24 +01:00
|
|
|
// Purpose: Runs the state machine for the host & server.
|
2022-02-06 16:48:52 +01:00
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.h"
|
2022-01-10 02:47:19 +01:00
|
|
|
#include "tier0/commandline.h"
|
2022-03-25 02:30:36 +01:00
|
|
|
#include "tier0/fasttimer.h"
|
2022-04-09 16:16:40 +02:00
|
|
|
#include "tier1/cmd.h"
|
|
|
|
#include "tier1/cvar.h"
|
2022-02-06 16:48:52 +01:00
|
|
|
#include "tier1/NetAdr2.h"
|
|
|
|
#include "tier2/socketcreator.h"
|
2022-03-26 00:24:13 +01:00
|
|
|
#include "vpc/keyvalues.h"
|
2022-02-08 16:32:00 +01:00
|
|
|
#ifdef DEDICATED
|
2022-02-06 16:48:52 +01:00
|
|
|
#include "engine/sv_rcon.h"
|
2022-02-14 23:16:24 +01:00
|
|
|
#else //
|
|
|
|
#include "engine/cl_rcon.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "engine/cl_main.h"
|
2022-02-08 16:32:00 +01:00
|
|
|
#endif // DEDICATED
|
2022-04-02 02:48:54 +02:00
|
|
|
#include "engine/net.h"
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "engine/gl_screen.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "engine/host.h"
|
|
|
|
#include "engine/host_cmd.h"
|
2022-02-19 02:31:16 +01:00
|
|
|
#include "engine/host_state.h"
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "engine/sys_engine.h"
|
|
|
|
#include "engine/sys_utils.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "engine/modelloader.h"
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "engine/cmodel_bsp.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-03-26 00:24:13 +01:00
|
|
|
#include "engine/baseserver.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "rtech/rtech_game.h"
|
2022-03-28 18:47:11 +02:00
|
|
|
#include "rtech/rtech_utils.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "rtech/stryder/stryder.h"
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
#include "vgui/vgui_baseui_interface.h"
|
|
|
|
#endif // DEDICATED
|
2022-04-02 12:27:35 +02:00
|
|
|
#include "client/vengineclient_impl.h"
|
2022-02-19 02:31:16 +01:00
|
|
|
#include "networksystem/pylon.h"
|
|
|
|
#include "public/include/bansystem.h"
|
2022-03-26 00:24:13 +01:00
|
|
|
#include "public/include/edict.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-02-24 01:51:11 +01:00
|
|
|
#include "game/server/gameinterface.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-01-09 14:35:43 +01:00
|
|
|
|
2022-03-01 02:39:46 +01:00
|
|
|
bool g_bLevelResourceInitialized = false;
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: state machine's main processing loop
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-12 02:48:46 +02:00
|
|
|
FORCEINLINE void CHostState::FrameUpdate(CHostState* rcx, void* rdx, float time)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
static bool bInitialized = false;
|
|
|
|
if (!bInitialized)
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->Setup();
|
2021-12-25 22:36:38 +01:00
|
|
|
bInitialized = true;
|
|
|
|
}
|
2022-02-08 16:32:00 +01:00
|
|
|
#ifdef DEDICATED
|
2022-02-06 16:48:52 +01:00
|
|
|
g_pRConServer->RunFrame();
|
2022-02-14 23:16:24 +01:00
|
|
|
#else //
|
|
|
|
g_pRConClient->RunFrame();
|
2022-02-08 16:32:00 +01:00
|
|
|
#endif // DEDICATED
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
HostStates_t oldState{};
|
2022-04-12 02:48:46 +02:00
|
|
|
if (setjmp(*host_abortserver))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
g_pHostState->Init();
|
2021-12-25 22:36:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-04-12 02:48:46 +02:00
|
|
|
*g_bAbortServerSet = true;
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2021-12-25 22:36:38 +01:00
|
|
|
do
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
Cbuf_Execute();
|
2021-12-25 22:36:38 +01:00
|
|
|
oldState = g_pHostState->m_iCurrentState;
|
2022-01-05 19:23:53 +01:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
switch (g_pHostState->m_iCurrentState)
|
|
|
|
{
|
|
|
|
case HostStates_t::HS_NEW_GAME:
|
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Loading level: '%s'\n", "CHostState::FrameUpdate", g_pHostState->m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->State_NewGame();
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_CHANGE_LEVEL_SP:
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->State_ChangeLevelSP();
|
2022-03-28 00:57:04 +02:00
|
|
|
g_pHostState->UnloadPakFile(); // Unload our loaded rpaks. Calling this before the actual level change happens kills the game.
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_CHANGE_LEVEL_MP:
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->State_ChangeLevelMP();
|
2022-03-28 00:59:39 +02:00
|
|
|
g_pHostState->UnloadPakFile();
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_RUN:
|
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
CHostState_State_Run(&g_pHostState->m_iCurrentState, nullptr, time);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_GAME_SHUTDOWN:
|
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Shutdown host game\n", "CHostState::FrameUpdate");
|
2022-03-01 02:39:46 +01:00
|
|
|
|
|
|
|
g_bLevelResourceInitialized = false;
|
2022-04-14 19:18:59 +02:00
|
|
|
CHostState_State_GameShutDown(g_pHostState);
|
2022-03-28 00:59:39 +02:00
|
|
|
g_pHostState->UnloadPakFile();
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_RESTART:
|
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Restarting state machine\n", "CHostState::FrameUpdate");
|
2022-03-01 02:39:46 +01:00
|
|
|
g_bLevelResourceInitialized = false;
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
CL_EndMovie();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
Stryder_SendOfflineRequest(); // We have hostnames nulled anyway.
|
2022-01-23 18:26:48 +01:00
|
|
|
g_pEngine->SetNextState(EngineState_t::DLL_RESTART);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_SHUTDOWN:
|
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Shutdown state machine\n", "CHostState::FrameUpdate");
|
2022-03-01 02:39:46 +01:00
|
|
|
g_bLevelResourceInitialized = false;
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
CL_EndMovie();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
Stryder_SendOfflineRequest(); // We have hostnames nulled anyway.
|
2022-01-23 18:26:48 +01:00
|
|
|
g_pEngine->SetNextState(EngineState_t::DLL_CLOSE);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-26 00:44:23 +01:00
|
|
|
} while ((oldState != HostStates_t::HS_RUN || g_pHostState->m_iNextState == HostStates_t::HS_LOAD_GAME && single_frame_shutdown_for_reload->GetBool())
|
2021-12-25 22:36:38 +01:00
|
|
|
&& oldState != HostStates_t::HS_SHUTDOWN
|
|
|
|
&& oldState != HostStates_t::HS_RESTART);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-12 02:48:46 +02:00
|
|
|
// Purpose: state machine initialization
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
FORCEINLINE void CHostState::Init(void)
|
|
|
|
{
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN)
|
|
|
|
{
|
|
|
|
if (m_iNextState == HostStates_t::HS_GAME_SHUTDOWN)
|
|
|
|
{
|
2022-04-14 19:18:59 +02:00
|
|
|
CHostState_State_GameShutDown(this);
|
2022-04-12 02:48:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN;
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !single_frame_shutdown_for_reload->GetInt())
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_flShortFrameTime = 1.0;
|
|
|
|
m_levelName[0] = 0;
|
|
|
|
m_landMarkName[0] = 0;
|
|
|
|
m_mapGroupName[0] = 0;
|
|
|
|
m_bSplitScreenConnect = 256;
|
|
|
|
m_vecLocation.Init();
|
|
|
|
m_angLocation.Init();
|
|
|
|
m_iCurrentState = HostStates_t::HS_NEW_GAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: state machine setup
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-24 01:51:11 +01:00
|
|
|
FORCEINLINE void CHostState::Setup(void) const
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
g_pHostState->LoadConfig();
|
2022-04-15 04:02:33 +02:00
|
|
|
g_pConVar->PurgeHostNames();
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifdef DEDICATED
|
|
|
|
g_pRConServer->Init();
|
|
|
|
#else //
|
|
|
|
g_pRConClient->Init();
|
|
|
|
#endif // DEDICATED
|
|
|
|
|
2022-03-28 12:02:11 +02:00
|
|
|
std::thread think(&CHostState::Think, this);
|
|
|
|
think.detach();
|
2022-03-26 18:06:54 +01:00
|
|
|
|
2022-04-14 19:18:59 +02:00
|
|
|
net_usesocketsforloopback->SetValue(1);
|
2022-02-19 02:31:16 +01:00
|
|
|
if (net_userandomkey->GetBool())
|
|
|
|
{
|
2022-04-02 02:48:54 +02:00
|
|
|
NET_GenerateKey();
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
2022-03-26 02:19:07 +01:00
|
|
|
#ifdef DEDICATED
|
|
|
|
const char* szNoMap = "server_idle";
|
|
|
|
#else // DEDICATED
|
|
|
|
const char* szNoMap = "main_menu";
|
|
|
|
#endif
|
|
|
|
snprintf(const_cast<char*>(m_levelName), sizeof(m_levelName), szNoMap);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 19:47:29 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: think
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
FORCEINLINE void CHostState::Think(void) const
|
|
|
|
{
|
2022-03-26 01:19:02 +01:00
|
|
|
static bool bInitialized = false;
|
2022-03-25 02:30:36 +01:00
|
|
|
static CFastTimer banListTimer;
|
|
|
|
static CFastTimer pylonTimer;
|
2022-03-26 00:24:13 +01:00
|
|
|
static CFastTimer statsTimer;
|
2022-03-25 02:30:36 +01:00
|
|
|
|
2022-03-26 18:06:54 +01:00
|
|
|
for (;;) // Loop running at 20-tps.
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-03-26 18:06:54 +01:00
|
|
|
if (!bInitialized) // Initialize clocks.
|
|
|
|
{
|
|
|
|
banListTimer.Start();
|
|
|
|
#ifdef DEDICATED
|
|
|
|
pylonTimer.Start();
|
|
|
|
#endif // DEDICATED
|
|
|
|
statsTimer.Start();
|
|
|
|
bInitialized = true;
|
|
|
|
}
|
2022-03-26 00:24:13 +01:00
|
|
|
|
2022-03-27 11:42:24 +02:00
|
|
|
if (banListTimer.GetDurationInProgress().GetSeconds() > sv_banlistRefreshInterval->GetDouble())
|
2022-03-26 18:06:54 +01:00
|
|
|
{
|
|
|
|
g_pBanSystem->BanListCheck();
|
|
|
|
banListTimer.Start();
|
|
|
|
}
|
|
|
|
#ifdef DEDICATED
|
2022-03-27 11:42:24 +02:00
|
|
|
if (pylonTimer.GetDurationInProgress().GetSeconds() > sv_pylonRefreshInterval->GetDouble())
|
2022-03-26 18:06:54 +01:00
|
|
|
{
|
|
|
|
KeepAliveToPylon();
|
|
|
|
pylonTimer.Start();
|
|
|
|
}
|
|
|
|
#endif // DEDICATED
|
2022-03-27 11:42:24 +02:00
|
|
|
if (statsTimer.GetDurationInProgress().GetSeconds() > sv_statusRefreshInterval->GetDouble())
|
2022-03-26 18:06:54 +01:00
|
|
|
{
|
2022-04-13 01:37:49 +02:00
|
|
|
string svCurrentPlaylist = KeyValues_GetCurrentPlaylist();
|
|
|
|
int32_t nPlayerCount = g_pServer->GetNumHumanPlayers();
|
2022-03-26 18:06:54 +01:00
|
|
|
|
|
|
|
SetConsoleTitleA(fmt::format("{} - {}/{} Players ({} on {})",
|
|
|
|
hostname->GetString(), nPlayerCount, g_ServerGlobalVariables->m_nMaxClients, svCurrentPlaylist.c_str(), m_levelName).c_str());
|
|
|
|
statsTimer.Start();
|
|
|
|
}
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
2022-02-27 19:47:29 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: load and execute configuration files
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-24 01:51:11 +01:00
|
|
|
FORCEINLINE void CHostState::LoadConfig(void) const
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-04-16 00:30:46 +02:00
|
|
|
if (!CommandLine()->CheckParm("-devsdk"))
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-03-28 12:02:11 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-03-28 12:02:11 +02:00
|
|
|
#endif //!CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
else // Development configs.
|
|
|
|
{
|
2022-03-28 12:02:11 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-03-28 12:02:11 +02:00
|
|
|
#endif //!CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
2022-03-25 13:17:57 +01:00
|
|
|
Cbuf_Execute();
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 02:39:46 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: shutdown active game
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
FORCEINLINE void CHostState::GameShutDown(void)
|
|
|
|
{
|
|
|
|
g_bLevelResourceInitialized = false;
|
|
|
|
if (m_bActiveGame)
|
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-03-01 02:39:46 +01:00
|
|
|
g_pServerGameDLL->GameShutdown();
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-03-01 02:39:46 +01:00
|
|
|
m_bActiveGame = 0;
|
2022-03-26 02:19:07 +01:00
|
|
|
#ifdef DEDICATED
|
|
|
|
const char* szNoMap = "server_idle";
|
|
|
|
#else // DEDICATED
|
|
|
|
const char* szNoMap = "main_menu";
|
|
|
|
#endif
|
|
|
|
snprintf(const_cast<char*>(m_levelName), sizeof(m_levelName), szNoMap);
|
2022-03-01 02:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: unloads all pakfiles loaded by the SDK
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-13 01:37:49 +02:00
|
|
|
FORCEINLINE void CHostState::UnloadPakFile(void) const
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-04-18 03:35:08 +02:00
|
|
|
for (auto& it : g_LoadedPakHandle)
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-03-28 18:47:11 +02:00
|
|
|
if (it >= 0)
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-03-28 18:47:11 +02:00
|
|
|
#ifdef GAMEDLL_S3
|
|
|
|
RPakLoadedInfo_t pakInfo = g_pRTech->GetPakLoadedInfo(it);
|
|
|
|
if (pakInfo.m_pszFileName)
|
|
|
|
{
|
2022-03-28 19:34:51 +02:00
|
|
|
DevMsg(eDLL_T::RTECH, "%s - Unloading PakFile '%s'\n", "CHostState::UnloadPakFile", pakInfo.m_pszFileName);
|
2022-03-28 18:47:11 +02:00
|
|
|
}
|
|
|
|
#endif // GAMEDLL_S3
|
2022-04-18 03:35:08 +02:00
|
|
|
CPakFile_UnloadPak(it);
|
2022-03-01 02:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
2022-04-18 03:35:08 +02:00
|
|
|
g_LoadedPakHandle.clear();
|
2022-03-01 02:39:46 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: initialize new game
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-24 01:51:11 +01:00
|
|
|
FORCEINLINE void CHostState::State_NewGame(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
LARGE_INTEGER time{};
|
|
|
|
|
2022-03-01 02:39:46 +01:00
|
|
|
g_bLevelResourceInitialized = false;
|
2022-02-19 02:31:16 +01:00
|
|
|
m_bSplitScreenConnect = false;
|
2022-04-12 02:48:46 +02:00
|
|
|
if (!g_pServerGameClients) // Init Game if it ain't valid.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
SV_InitGameDLL();
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
2022-04-12 02:48:46 +02:00
|
|
|
if (!CModelLoader__Map_IsValid(g_pModelLoader, m_levelName) // Check if map is valid and if we can start a new game.
|
|
|
|
|| !Host_NewGame(m_levelName, nullptr, m_bBackgroundLevel, m_bSplitScreenConnect, time) || !g_pServerGameClients)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
Error(eDLL_T::ENGINE, "%s - Error: Map not valid\n", "CHostState::State_NewGame");
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
SCR_EndLoadingPlaque();
|
|
|
|
#endif // !DEDICATED
|
|
|
|
GameShutDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
|
|
|
|
|
|
|
|
// If our next state isn't a shutdown or its a forced shutdown then set next state to run.
|
2022-04-14 19:18:59 +02:00
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !host_hasIrreversibleShutdown->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: change singleplayer level
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-24 01:51:11 +01:00
|
|
|
FORCEINLINE void CHostState::State_ChangeLevelSP(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Changing singleplayer level to: '%s'\n", "CHostState::State_ChangeLevelSP", m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
m_flShortFrameTime = 1.5; // Set frame time.
|
2022-03-01 02:39:46 +01:00
|
|
|
g_bLevelResourceInitialized = false;
|
2022-02-19 02:31:16 +01:00
|
|
|
|
2022-04-12 02:48:46 +02:00
|
|
|
if (CModelLoader__Map_IsValid(g_pModelLoader, m_levelName)) // Check if map is valid and if we can start a new game.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
Host_ChangeLevel(true, m_levelName, m_mapGroupName); // Call change level as singleplayer level.
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
Error(eDLL_T::ENGINE, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelSP", m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
|
|
|
|
|
|
|
|
// If our next state isn't a shutdown or its a forced shutdown then set next state to run.
|
2022-04-14 19:18:59 +02:00
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !host_hasIrreversibleShutdown->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: change multiplayer level
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-24 01:51:11 +01:00
|
|
|
FORCEINLINE void CHostState::State_ChangeLevelMP(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s - Changing multiplayer level to: '%s'\n", "CHostState::State_ChangeLevelMP", m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
m_flShortFrameTime = 0.5; // Set frame time.
|
2022-03-01 02:39:46 +01:00
|
|
|
g_bLevelResourceInitialized = false;
|
2022-02-19 02:31:16 +01:00
|
|
|
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-02-24 01:51:11 +01:00
|
|
|
g_pServerGameDLL->LevelShutdown();
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-04-12 02:48:46 +02:00
|
|
|
if (CModelLoader__Map_IsValid(g_pModelLoader, m_levelName)) // Check if map is valid and if we can start a new game.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
#ifndef DEDICATED
|
2022-04-18 03:35:08 +02:00
|
|
|
g_pEngineVGui->EnabledProgressBarForNextLoad();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
Host_ChangeLevel(false, m_levelName, m_mapGroupName); // Call change level as multiplayer level.
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-25 13:17:57 +01:00
|
|
|
Error(eDLL_T::ENGINE, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelMP", m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
|
|
|
|
|
|
|
|
// If our next state isn't a shutdown or its a forced shutdown then set next state to run.
|
2022-04-14 19:18:59 +02:00
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !host_hasIrreversibleShutdown->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
void CHostState_Attach()
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
DetourAttach((LPVOID*)&CHostState_FrameUpdate, &CHostState::FrameUpdate);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHostState_Detach()
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
DetourDetach((LPVOID*)&CHostState_FrameUpdate, &CHostState::FrameUpdate);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-04-12 02:48:46 +02:00
|
|
|
CHostState* g_pHostState = nullptr;
|