Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/game/client/client_mapbase.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ $Project
$File "$SRCDIR\game\shared\mapbase\mapbase_usermessages.cpp"
$File "$SRCDIR\game\shared\mapbase\mapbase_rpc.cpp"
$File "$SRCDIR\game\shared\mapbase\mapbase_game_log.cpp"
$File "$SRCDIR\game\shared\mapbase\mapbase_mp_saverestore.cpp" [$HL2MP||$TF]
$File "$SRCDIR\game\shared\mapbase\mapbase_mp_saverestore.h" [$HL2MP||$TF]
$File "$SRCDIR\game\shared\mapbase\MapEdit.cpp"
$File "$SRCDIR\game\shared\mapbase\MapEdit.h"
$File "$SRCDIR\game\shared\mapbase\matchers.cpp"
Expand Down
31 changes: 31 additions & 0 deletions src/game/server/NextBot/Player/NextBotPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class NextBotPlayer : public PlayerType, public INextBot, public INextBotPlayerI
virtual ~NextBotPlayer();

virtual void Spawn( void );
virtual void OnRestore( void );

virtual void SetSpawnPoint( CBaseEntity *spawnPoint ); // define place in environment where bot will (re)spawn
virtual CBaseEntity *EntSelectSpawnPoint( void );
Expand Down Expand Up @@ -553,6 +554,36 @@ inline void NextBotPlayer< PlayerType >::Spawn( void )
}


//-----------------------------------------------------------------------------------------------------
template < typename PlayerType >
inline void NextBotPlayer< PlayerType >::OnRestore( void )
{
engine->SetFakeClientConVarValue( this->edict(), "cl_autohelp", "0" );

m_prevInputButtons = m_inputButtons = 0;
m_fireButtonTimer.Invalidate();
m_meleeButtonTimer.Invalidate();
m_specialFireButtonTimer.Invalidate();
m_useButtonTimer.Invalidate();
m_reloadButtonTimer.Invalidate();
m_forwardButtonTimer.Invalidate();
m_backwardButtonTimer.Invalidate();
m_leftButtonTimer.Invalidate();
m_rightButtonTimer.Invalidate();
m_jumpButtonTimer.Invalidate();
m_crouchButtonTimer.Invalidate();
m_walkButtonTimer.Invalidate();
m_buttonScaleTimer.Invalidate();
m_forwardScale = m_rightScale = 0.04;
m_burningTimer.Invalidate();

// reset first, because Spawn() may access various interfaces
INextBot::Reset();

BaseClass::OnRestore();
}



//-----------------------------------------------------------------------------------------------------
inline void _NextBot_BuildUserCommand( CUserCmd *cmd, const QAngle &viewangles, float forwardmove, float sidemove, float upmove, int buttons, byte impulse )
Expand Down
19 changes: 19 additions & 0 deletions src/game/server/baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
#include "mapbase/matchers.h"
#include "mapbase/datadesc_mod.h"
#endif
#ifdef MAPBASE_MP
#include "mapbase/mapbase_mp_saverestore.h"
#endif
#ifdef NEW_RESPONSE_SYSTEM
#include "ai_speech.h"
#endif
Expand Down Expand Up @@ -4263,6 +4266,22 @@ int CBaseEntity::Restore( IRestore &restore )
Vector parentSpaceOffset = pGameInfo->modelSpaceOffset;
if ( !GetParent() )
{
#ifdef MAPBASE_MP
if (g_MPSaveRestore.IsTransitioning() || g_MPSaveRestore.IsRestoringPlayer())
{
// HACKHACK: m_vecOrigin isn't saved as a FIELD_POSITION_VECTOR because it's ambiguous whether it's local to the world
// or local to a parent. The existing code here is meant to fix that up, but our implementation of save/restore is having
// m_vecOrigin transition with its old map's direct origin when this code expects a relative origin.
// I have not found any code which converts m_vecOrigin to be relative to the landmark, so I'm not sure why this isn't
// already a problem in stock save/restore, although it could be related to running the game in multiplayer, or the MP
// branch in general.
// Regardless, since the local and absolute origins are meant to be the same when there's no parent anyway, we just assign
// the absolute origin to the local origin and ignore the landmark (since it was already calculated) to get around this issue.
m_vecOrigin = m_vecAbsOrigin;
}
else
#endif

// parent is the world, so parent space is worldspace
// so update with the worldspace leveltransition transform
parentSpaceOffset += pGameInfo->GetLandmark();
Expand Down
73 changes: 73 additions & 0 deletions src/game/server/gameinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
#include "world.h"
#endif

#ifdef MAPBASE_MP
#include "mapbase/mapbase_mp_saverestore.h"
#endif

#include "vscript/ivscript.h"
#include "vscript_server.h"

Expand Down Expand Up @@ -705,6 +709,9 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetEventQueueSaveRestoreBlockHandler() );
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetAchievementSaveRestoreBlockHandler() );
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetVScriptSaveRestoreBlockHandler() );
#ifdef MAPBASE_MP
g_pGameSaveRestoreBlockSet->AddBlockHandler( GetMPPlayerSaveRestoreBlockHandler() );
#endif

// The string system must init first + shutdown last
IGameSystem::Add( GameStringSystem() );
Expand Down Expand Up @@ -768,6 +775,15 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
gamestatsuploader->InitConnection();
#endif

#ifdef MAPBASE_MP
// If the last param contains .mpsav, then load it
const char *pszSave = CommandLine()->GetParm( CommandLine()->ParmCount() - 1 );
if ( pszSave && V_strstr( pszSave, ".mpsav" ) )
{
g_MPSaveRestore.StartLoadingSave( pszSave );
}
#endif

return true;
}

Expand Down Expand Up @@ -1007,6 +1023,21 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
//Tony; parse custom manifest if exists!
ParseParticleEffectsMap( pMapName, false );

#ifdef MAPBASE_MP
if ( g_MPSaveRestore.IsTransitioning() ) // EnabledTransitions
{
if ( g_MPSaveRestore.FindTransitionFile( pMapName, &pOldLevel, &pLandmarkName ) )
{
loadGame = true;
}
}

if ( !loadGame && g_MPSaveRestore.IsLoadingSave() )
{
loadGame = true;
}
#endif

// IGameSystem::LevelInitPreEntityAllSystems() is called when the world is precached
// That happens either in LoadGameState() or in MapEntity_ParseAllEntities()
if ( loadGame )
Expand All @@ -1023,6 +1054,23 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
BeginRestoreEntities();
if ( !engine->LoadGameState( pMapName, 1 ) )
{
#ifdef MAPBASE_MP
if ( g_MPSaveRestore.IsTransitioning() )
{
// If we've been to this level before, transition to it
CSaveRestoreData *pSaveData = SaveInit( 0 );
if ( pSaveData && !g_MPSaveRestore.RestoreNextLevelFile( pSaveData, pMapName, pOldLevel, pLandmarkName ) && pOldLevel )
{
// No existing level data
MapEntity_ParseAllEntities( pMapEntities );
}
}
else if ( g_MPSaveRestore.IsLoadingSave() && !pOldLevel )
{
// Do nothing and let the system handle it (don't return false)
}
else
#endif
if ( pOldLevel )
{
MapEntity_ParseAllEntities( pMapEntities );
Expand All @@ -1034,6 +1082,28 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
}
}

#ifdef MAPBASE_MP
if ( g_MPSaveRestore.IsTransitioning() )
{
CSaveRestoreData *pSaveData = SaveInit( 0 );
if (pSaveData)
{
g_MPSaveRestore.RestoreTransitionFile( pSaveData, pMapName, pOldLevel, pLandmarkName );
}
g_MPSaveRestore.EndTransition();
}
else if ( g_MPSaveRestore.IsLoadingSave() )
{
CSaveRestoreData *pSaveData = SaveInit( 0 );
if (pSaveData)
{
g_MPSaveRestore.LoadFile( pSaveData );
}
g_MPSaveRestore.StopLoadingSave();
}
else
#endif

if ( pOldLevel )
{
engine->LoadAdjacentEnts( pOldLevel, pLandmarkName );
Expand All @@ -1042,6 +1112,9 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
if ( g_OneWayTransition )
{
engine->ClearSaveDirAfterClientLoad();
#ifdef MAPBASE_MP
g_MPSaveRestore.ClearTransitionFiles();
#endif
}

if ( pOldLevel && sv_autosave.GetBool() == true )
Expand Down
7 changes: 7 additions & 0 deletions src/game/server/hl2mp/hl2mp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "engine/IEngineSound.h"
#include "team.h"
#include "viewport_panel_names.h"
#ifdef MAPBASE_MP
#include "mapbase/mapbase_mp_saverestore.h"
#endif

#include "tier0/vprof.h"

Expand All @@ -41,6 +44,10 @@ extern bool g_fGameOver;
void FinishClientPutInServer( CHL2MP_Player *pPlayer )
{
pPlayer->InitialSpawn();

#ifdef MAPBASE_MP
if ( !g_MPSaveRestore.RestorePlayer( pPlayer ) )
#endif
pPlayer->Spawn();


Expand Down
47 changes: 47 additions & 0 deletions src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
#include "mapbase/vscript_funcs_shared.h"
#endif

#ifdef MAPBASE_MP
#include "mapbase/mapbase_mp_saverestore.h"
#endif

ConVar autoaim_max_dist( "autoaim_max_dist", "2160" ); // 2160 = 180 feet
ConVar autoaim_max_deflect( "autoaim_max_deflect", "0.99" );

Expand Down Expand Up @@ -401,7 +405,9 @@ BEGIN_DATADESC( CBasePlayer )

DEFINE_FIELD( m_iPlayerLocked, FIELD_INTEGER ),

#ifndef MAPBASE_MP
DEFINE_AUTO_ARRAY( m_hViewModel, FIELD_EHANDLE ),
#endif

DEFINE_FIELD( m_flMaxspeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flWaterJumpTime, FIELD_TIME ),
Expand Down Expand Up @@ -5025,6 +5031,19 @@ void CBasePlayer::PostThink()
PostThinkVPhysics();
VPROF_SCOPE_END();
}
#ifdef MAPBASE_MP
else if (g_MPSaveRestore.IsPlayerWaitingToTransition( this ))
{
// Allow player to cancel transition
if (m_afButtonPressed & IN_JUMP)
{
if (!g_MPSaveRestore.PlayerCanCancelTransition( this ) || !g_MPSaveRestore.RemovePlayerFromTransition( this, true ))
UTIL_HudHintText( this, "#Valve_Hint_ExitTransition_Failure" );
else
UTIL_HudHintText( this, NULL ); // Clear HUD hint
}
}
#endif

#if !defined( NO_ENTITY_PREDICTION )
// Even if dead simulate entities
Expand Down Expand Up @@ -5668,7 +5687,16 @@ int CBasePlayer::Restore( IRestore &restore )

CSaveRestoreData *pSaveData = gpGlobals->pSaveData;
// landmark isn't present.
#ifdef MAPBASE_MP
// This interferes with bots in MP save/restore and appears to serve no purpose.
// When players are created, their physics shadow (which uses abs origin) instantly overwrites this value.
// However, bots issue commands the instant they're created, so the abs origin is overwritten before that can happen.
// Since this code seemingly assumes players always spawn at the start when there's no landmark, I'm assuming it reflects
// an older version of the saving system and isn't used.
if ( !pSaveData->levelInfo.fUseLandmark && !g_MPSaveRestore.IsRestoringPlayer( this ) )
#else
if ( !pSaveData->levelInfo.fUseLandmark )
#endif
{
Msg( "No Landmark:%s\n", pSaveData->levelInfo.szLandmarkName );

Expand Down Expand Up @@ -5708,6 +5736,14 @@ int CBasePlayer::Restore( IRestore &restore )
CPlayerRestoreHelper helper;
InitVCollision( helper.GetAbsOrigin( this ), helper.GetAbsVelocity( this ) );

#ifdef MAPBASE_MP
// We can't save the viewmodels in MP at the moment
CreateViewModel();
#ifdef HL2_DLL
CreateHandModel();
#endif
#endif

// success
return 1;
}
Expand Down Expand Up @@ -5737,6 +5773,17 @@ void CBasePlayer::OnRestore( void )
}
}

#ifdef MAPBASE_MP
//-----------------------------------------------------------------------------
// Purpose: Restores a weapon created by MP save/restore
//-----------------------------------------------------------------------------
void CBasePlayer::RestoreWeapon( CBaseCombatWeapon *pWeapon, int i )
{
pWeapon->Equip( this );
m_hMyWeapons.Set( i, pWeapon );
}
#endif

/* void CBasePlayer::SetTeamName( const char *pTeamName )
{
Q_strncpy( m_szTeamName, pTeamName, TEAM_NAME_LENGTH );
Expand Down
5 changes: 5 additions & 0 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ class CBasePlayer : public CBaseCombatCharacter
virtual bool ShouldSavePhysics();
virtual void OnRestore( void );

#ifdef MAPBASE_MP
// Used by MP save/restore only
virtual void RestoreWeapon( CBaseCombatWeapon *pWeapon, int i );
#endif

virtual void PackDeadPlayerItems( void );
virtual void RemoveAllItems( bool removeSuit );
bool IsDead() const;
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/server_mapbase.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ $Project
$File "$SRCDIR\game\shared\mapbase\mapbase_usermessages.cpp"
$File "$SRCDIR\game\shared\mapbase\mapbase_rpc.cpp"
$File "$SRCDIR\game\shared\mapbase\mapbase_game_log.cpp"
$File "$SRCDIR\game\shared\mapbase\mapbase_mp_saverestore.cpp" [$HL2MP||$TF]
$File "$SRCDIR\game\shared\mapbase\mapbase_mp_saverestore.h" [$HL2MP||$TF]
$File "$SRCDIR\game\shared\mapbase\MapEdit.cpp"
$File "$SRCDIR\game\shared\mapbase\MapEdit.h"
$File "$SRCDIR\game\shared\mapbase\matchers.cpp"
Expand Down
Loading
Loading