From cf6aa962037962d4151a7b8a72950ab7e9e7d243 Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 8 Nov 2018 09:17:06 +0700 Subject: [PATCH] Always connect save bot, dup ServerActivate checking --- dlls/coop.cpp | 18 ++++++++++++++++-- dlls/gravgunmod.cpp | 38 ++++++++++++++++++++++++++++++++++++++ dlls/gravgunmod.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/dlls/coop.cpp b/dlls/coop.cpp index b4fb1fab..3e31e1db 100644 --- a/dlls/coop.cpp +++ b/dlls/coop.cpp @@ -426,6 +426,9 @@ bool COOP_ProcessTransition( void ) return false; } + memset( &g_CoopState.p.savedPos, 0, sizeof( struct GGMPosition ) ); + g_CoopState.p.fSaved = false; + COOP_MarkTriggers(); g_CoopState.p.savedPos = g_CoopState.landmarkTransition.pos; @@ -484,12 +487,23 @@ void COOP_SetupLandmarkTransition( const char *szNextMap, const char *szNextSpot void COOP_ServerActivate( void ) { - memset( &g_CoopState.p.savedPos, 0, sizeof( struct GGMPosition ) ); - g_CoopState.p.fSaved = false; + static float st_DupCheck; + if( g_CoopState.landmarkTransition.fLoading ) + { + st_DupCheck = gpGlobals->time; + } + + if( st_DupCheck && gpGlobals->time && st_DupCheck == gpGlobals->time) + { + st_DupCheck = 0.0f; + return; + } if( !mp_coop.value ) return; + GGM_ConnectSaveBot(); + if( !COOP_ProcessTransition() ) { ALERT( at_console, "Transition failed, new game started\n"); diff --git a/dlls/gravgunmod.cpp b/dlls/gravgunmod.cpp index f81d9711..21c1ffd0 100644 --- a/dlls/gravgunmod.cpp +++ b/dlls/gravgunmod.cpp @@ -887,6 +887,41 @@ void GGM_LoadPlayers_f( void ) ALERT( at_error, "Failed to load player states from %s\n", CMD_ARGV( 1 ) ); } +void GGM_ConnectSaveBot( void ) +{ + edict_t *client0 = INDEXENT( 1 ); + edict_t *bot = NULL; + char cmd[33] = ""; + float health = client0->v.health; + int deadflag = client0->v.deadflag; + float zombietime_old; + bool fNeedKick = false; + SERVER_EXECUTE(); + + // save even with dead player + if( health <= 0 ) + client0->v.health = 1; + + client0->v.deadflag = 0; + + if( g_engfuncs.pfnGetInfoKeyBuffer( client0 )[0] ) + return; + + snprintf( cmd, 32, "kick #%d\n", GETPLAYERUSERID( client0 ) ); + SERVER_COMMAND(cmd); + SERVER_EXECUTE(); + bot = g_engfuncs.pfnCreateFakeClient("_save_bot"); + if( bot != client0 ) + ALERT( at_warning, "Bot is not player 1\n" ); + bot->v.health = 1; + bot->v.deadflag = 0; + + client0->v.deadflag = deadflag; + client0->v.health = health; + if( zombietime ) + zombietime->value = zombietime_old; +} + // hack to make save work when client 0 not connected void GGM_Save( const char *savename ) { @@ -916,6 +951,9 @@ void GGM_Save( const char *savename ) if( !strcmp( GETPLAYERAUTHID( client0 ), "VALVE_ID_LOOPBACK" ) ) fNeedKick = false; + if( mp_coop.value ) + fNeedKick = false; + // hack to make save work when client 0 not connected if( fNeedKick ) { diff --git a/dlls/gravgunmod.h b/dlls/gravgunmod.h index e285caeb..0047c22d 100644 --- a/dlls/gravgunmod.h +++ b/dlls/gravgunmod.h @@ -200,5 +200,6 @@ void GGM_TempBan( CBaseEntity *pEnt ); int GGM_ChangelevelVote( CBasePlayer *pPlayer, edict_t *pTrigger, const char *pszMapName ); void GGM_ClearVote( void ); void GGM_StartVoteCommand( CBasePlayer *pPlayer, const char *pszCommand, const char *pszMessage ); +void GGM_ConnectSaveBot( void ); #endif // GRAVGUNMOD_H