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-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-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"
|
|
|
|
#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-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-02-24 01:51:11 +01:00
|
|
|
FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
static bool bInitialized = false;
|
2022-03-26 00:44:23 +01:00
|
|
|
static ConVar* single_frame_shutdown_for_reload = g_pCVar->FindVar("single_frame_shutdown_for_reload");
|
2021-12-25 22:36:38 +01:00
|
|
|
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{};
|
|
|
|
void* placeHolder = nullptr;
|
|
|
|
if (setjmpFn(*host_abortserver, placeHolder))
|
|
|
|
{
|
|
|
|
CHostState_InitFn(g_pHostState);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2021-12-25 22:36:38 +01:00
|
|
|
*g_ServerAbortServer = 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:
|
|
|
|
{
|
|
|
|
State_RunFn(&g_pHostState->m_iCurrentState, nullptr, time);
|
|
|
|
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;
|
2021-12-25 22:36:38 +01:00
|
|
|
Host_Game_ShutdownFn(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
|
2021-12-25 22:36:38 +01:00
|
|
|
CL_EndMovieFn();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
SendOfflineRequestToStryderFn(); // 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
|
2021-12-25 22:36:38 +01:00
|
|
|
CL_EndMovieFn();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2021-12-25 22:36:38 +01:00
|
|
|
SendOfflineRequestToStryderFn(); // 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-02-19 02:43:20 +01:00
|
|
|
// Purpose: setup state machine
|
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();
|
|
|
|
g_pConVar->ClearHostNames();
|
|
|
|
#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-02 02:48:54 +02:00
|
|
|
*m_bRestrictServerCommands = true; // Restrict commands.
|
2022-03-26 00:24:13 +01:00
|
|
|
ConCommandBase* disconnect = g_pCVar->FindCommandBase("disconnect");
|
2022-02-19 02:31:16 +01:00
|
|
|
disconnect->AddFlags(FCVAR_SERVER_CAN_EXECUTE); // Make sure server is not restricted to this.
|
2022-03-26 00:24:13 +01:00
|
|
|
g_pCVar->FindVar("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-26 00:44:23 +01:00
|
|
|
static ConVar* hostname = g_pCVar->FindVar("hostname");
|
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
|
|
|
{
|
|
|
|
std::string svCurrentPlaylist = KeyValues_GetCurrentPlaylist();
|
|
|
|
std::int64_t nPlayerCount = g_pServer->GetNumHumanPlayers();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!g_pCmdLine->CheckParm("-devsdk"))
|
|
|
|
{
|
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
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
FORCEINLINE void CHostState::UnloadPakFile(void)
|
|
|
|
{
|
2022-03-28 00:57:04 +02:00
|
|
|
for (auto& it : g_nLoadedPakFileId)
|
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-03-28 00:57:04 +02:00
|
|
|
RTech_UnloadPak(it);
|
2022-03-01 02:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-28 00:57:04 +02:00
|
|
|
g_nLoadedPakFileId.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-03-01 02:39:46 +01:00
|
|
|
g_bLevelResourceInitialized = false;
|
2022-02-19 02:31:16 +01:00
|
|
|
m_bSplitScreenConnect = false;
|
|
|
|
if (!g_ServerGameClients) // Init Game if it ain't valid.
|
|
|
|
{
|
|
|
|
SV_InitGameDLLFn();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CModelLoader_Map_IsValidFn(g_CModelLoader, m_levelName) // Check if map is valid and if we can start a new game.
|
|
|
|
|| !Host_NewGameFn(m_levelName, nullptr, m_bBackgroundLevel, m_bSplitScreenConnect, nullptr) || !g_ServerGameClients)
|
|
|
|
{
|
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.
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !g_pCVar->FindVar("host_hasIrreversibleShutdown")->GetBool())
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
if (CModelLoader_Map_IsValidFn(g_CModelLoader, m_levelName)) // Check if map is valid and if we can start a new game.
|
|
|
|
{
|
|
|
|
Host_ChangelevelFn(true, m_levelName, m_mapGroupName); // Call change level as singleplayer level.
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !g_pCVar->FindVar("host_hasIrreversibleShutdown")->GetBool())
|
|
|
|
{
|
|
|
|
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-02-19 02:31:16 +01:00
|
|
|
if (CModelLoader_Map_IsValidFn(g_CModelLoader, m_levelName)) // Check if map is valid and if we can start a new game.
|
|
|
|
{
|
|
|
|
#ifndef DEDICATED
|
|
|
|
using EnabledProgressBarForNextLoadFn = void(*)(void*);
|
2022-02-24 01:51:11 +01:00
|
|
|
(*reinterpret_cast<EnabledProgressBarForNextLoadFn**>(g_pEngineVGui))[31](g_pEngineVGui); // EnabledProgressBarForNextLoad
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
|
|
|
Host_ChangelevelFn(false, m_levelName, m_mapGroupName); // Call change level as multiplayer level.
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !g_pCVar->FindVar("host_hasIrreversibleShutdown")->GetBool())
|
|
|
|
{
|
|
|
|
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-10 19:59:34 +02:00
|
|
|
CHostState* g_pHostState = reinterpret_cast<CHostState*>(p_CHostState_FrameUpdate.FindPatternSelf("48 8D ?? ?? ?? ?? 01", CMemory::Direction::DOWN, 100).ResolveRelativeAddressSelf(0x3, 0x7).GetPtr());
|