9494#include " world.h"
9595#endif
9696
97+ #ifdef MAPBASE_MP
98+ #include " mapbase/mapbase_mp_saverestore.h"
99+ #endif
100+
97101#include " vscript/ivscript.h"
98102#include " vscript_server.h"
99103
@@ -705,6 +709,9 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
705709 g_pGameSaveRestoreBlockSet->AddBlockHandler ( GetEventQueueSaveRestoreBlockHandler () );
706710 g_pGameSaveRestoreBlockSet->AddBlockHandler ( GetAchievementSaveRestoreBlockHandler () );
707711 g_pGameSaveRestoreBlockSet->AddBlockHandler ( GetVScriptSaveRestoreBlockHandler () );
712+ #ifdef MAPBASE_MP
713+ g_pGameSaveRestoreBlockSet->AddBlockHandler ( GetMPPlayerSaveRestoreBlockHandler () );
714+ #endif
708715
709716 // The string system must init first + shutdown last
710717 IGameSystem::Add ( GameStringSystem () );
@@ -768,6 +775,15 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
768775 gamestatsuploader->InitConnection ();
769776#endif
770777
778+ #ifdef MAPBASE_MP
779+ // If the last param contains .mpsav, then load it
780+ const char *pszSave = CommandLine ()->GetParm ( CommandLine ()->ParmCount () - 1 );
781+ if ( pszSave && V_strstr ( pszSave, " .mpsav" ) )
782+ {
783+ g_MPSaveRestore.StartLoadingSave ( pszSave );
784+ }
785+ #endif
786+
771787 return true ;
772788}
773789
@@ -1007,6 +1023,21 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
10071023 // Tony; parse custom manifest if exists!
10081024 ParseParticleEffectsMap ( pMapName, false );
10091025
1026+ #ifdef MAPBASE_MP
1027+ if ( g_MPSaveRestore.IsTransitioning () ) // EnabledTransitions
1028+ {
1029+ if ( g_MPSaveRestore.FindTransitionFile ( pMapName, &pOldLevel, &pLandmarkName ) )
1030+ {
1031+ loadGame = true ;
1032+ }
1033+ }
1034+
1035+ if ( !loadGame && g_MPSaveRestore.IsLoadingSave () )
1036+ {
1037+ loadGame = true ;
1038+ }
1039+ #endif
1040+
10101041 // IGameSystem::LevelInitPreEntityAllSystems() is called when the world is precached
10111042 // That happens either in LoadGameState() or in MapEntity_ParseAllEntities()
10121043 if ( loadGame )
@@ -1023,6 +1054,23 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
10231054 BeginRestoreEntities ();
10241055 if ( !engine->LoadGameState ( pMapName, 1 ) )
10251056 {
1057+ #ifdef MAPBASE_MP
1058+ if ( g_MPSaveRestore.IsTransitioning () )
1059+ {
1060+ // If we've been to this level before, transition to it
1061+ CSaveRestoreData *pSaveData = SaveInit ( 0 );
1062+ if ( pSaveData && !g_MPSaveRestore.RestoreNextLevelFile ( pSaveData, pMapName, pOldLevel, pLandmarkName ) && pOldLevel )
1063+ {
1064+ // No existing level data
1065+ MapEntity_ParseAllEntities ( pMapEntities );
1066+ }
1067+ }
1068+ else if ( g_MPSaveRestore.IsLoadingSave () && !pOldLevel )
1069+ {
1070+ // Do nothing and let the system handle it (don't return false)
1071+ }
1072+ else
1073+ #endif
10261074 if ( pOldLevel )
10271075 {
10281076 MapEntity_ParseAllEntities ( pMapEntities );
@@ -1034,6 +1082,28 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
10341082 }
10351083 }
10361084
1085+ #ifdef MAPBASE_MP
1086+ if ( g_MPSaveRestore.IsTransitioning () )
1087+ {
1088+ CSaveRestoreData *pSaveData = SaveInit ( 0 );
1089+ if (pSaveData)
1090+ {
1091+ g_MPSaveRestore.RestoreTransitionFile ( pSaveData, pMapName, pOldLevel, pLandmarkName );
1092+ }
1093+ g_MPSaveRestore.EndTransition ();
1094+ }
1095+ else if ( g_MPSaveRestore.IsLoadingSave () )
1096+ {
1097+ CSaveRestoreData *pSaveData = SaveInit ( 0 );
1098+ if (pSaveData)
1099+ {
1100+ g_MPSaveRestore.LoadFile ( pSaveData );
1101+ }
1102+ g_MPSaveRestore.StopLoadingSave ();
1103+ }
1104+ else
1105+ #endif
1106+
10371107 if ( pOldLevel )
10381108 {
10391109 engine->LoadAdjacentEnts ( pOldLevel, pLandmarkName );
@@ -1042,6 +1112,9 @@ bool CServerGameDLL::LevelInit( const char *pMapName, char const *pMapEntities,
10421112 if ( g_OneWayTransition )
10431113 {
10441114 engine->ClearSaveDirAfterClientLoad ();
1115+ #ifdef MAPBASE_MP
1116+ g_MPSaveRestore.ClearTransitionFiles ();
1117+ #endif
10451118 }
10461119
10471120 if ( pOldLevel && sv_autosave.GetBool () == true )
0 commit comments