From ce011d3d4dfe5603b4cf8e15545686d7edb27f9f Mon Sep 17 00:00:00 2001 From: redsaurus Date: Wed, 1 Jul 2020 22:31:57 +0100 Subject: [PATCH] Events: better fix avoid entity events from recently freed/reused entities. causes issues at large timescales such as during cutscene skipping when the event time is before the entity free time and cent->gent is used. Also remove unnecessary setting of NPC->count on takeoff/landing for boba and rockettrooper. --- code/cgame/cg_event.cpp | 39 ++++++++++++++++++++++++++++++---- code/game/AI_BobaFett.cpp | 5 ----- code/game/AI_RocketTrooper.cpp | 5 ----- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/code/cgame/cg_event.cpp b/code/cgame/cg_event.cpp index 4e7c682d33..423cb9cded 100644 --- a/code/cgame/cg_event.cpp +++ b/code/cgame/cg_event.cpp @@ -263,7 +263,35 @@ static void CG_UseItem( centity_t *cent ) } +/* +============== +CG_UnsafeEventType +Returns qtrue for event types that access cent->gent directly (and don't require it +to be the player / entity 0). +============== +*/ +qboolean CG_UnsafeEventType(int eventType) +{ + switch (eventType) + { + case EV_CHANGE_WEAPON: + case EV_DISRUPTOR_SNIPER_SHOT: + case EV_DISRUPTOR_SNIPER_MISS: + case EV_CONC_ALT_MISS: + case EV_DISINTEGRATION: + case EV_GRENADE_BOUNCE: + case EV_MISSILE_HIT: + case EV_MISSILE_MISS: + case EV_PAIN: + case EV_PLAY_EFFECT: + case EV_TARGET_BEAM_DRAW: + return qtrue; + break; + default: + return qfalse; + } +} /* ============== CG_EntityEvent @@ -297,10 +325,13 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) { return; } - if ( cg_skippingcin.integer ) - { - return; - } + //When skipping a cutscene the timescale is drastically increased, causing entities to be freed + //and possibly reused between the snapshot currentState and the actual state of the gent when accessed. + //We try to avoid this issue by ignoring events on entities that have been freed since the snapshot. + if (cent->gent->freetime > cg.snap->serverTime && CG_UnsafeEventType(event)) + { + return; + } //ci = ¢->gent->client->clientInfo; clientNum = cent->gent->s.number; diff --git a/code/game/AI_BobaFett.cpp b/code/game/AI_BobaFett.cpp index 3f16e01288..41435a5bef 100644 --- a/code/game/AI_BobaFett.cpp +++ b/code/game/AI_BobaFett.cpp @@ -429,10 +429,6 @@ void Boba_FlyStart( gentity_t *self ) G_SoundOnEnt( self, CHAN_ITEM, "sound/chars/boba/bf_blast-off.wav" ); //jet loop sound self->s.loopSound = G_SoundIndex( "sound/chars/boba/bf_jetpack_lp.wav" ); - if ( self->NPC ) - { - self->count = Q3_INFINITE; // SEEKER shot ammo count - } } } @@ -461,7 +457,6 @@ void Boba_FlyStop( gentity_t *self ) self->s.loopSound = 0; if ( self->NPC ) { - self->count = 0; // SEEKER shot ammo count TIMER_Set( self, "jetRecharge", Q_irand( 1000, 5000 ) ); TIMER_Set( self, "jumpChaseDebounce", Q_irand( 500, 2000 ) ); } diff --git a/code/game/AI_RocketTrooper.cpp b/code/game/AI_RocketTrooper.cpp index 69ac2f99bb..cab13a65b8 100644 --- a/code/game/AI_RocketTrooper.cpp +++ b/code/game/AI_RocketTrooper.cpp @@ -389,10 +389,6 @@ void RT_FlyStart( gentity_t *self ) G_SoundOnEnt( self, CHAN_ITEM, "sound/chars/boba/bf_blast-off.wav" ); //jet loop sound self->s.loopSound = G_SoundIndex( "sound/chars/boba/bf_jetpack_lp.wav" ); - if ( self->NPC ) - { - self->count = Q3_INFINITE; // SEEKER shot ammo count - } } } @@ -417,7 +413,6 @@ void RT_FlyStop( gentity_t *self ) if ( self->NPC ) { - self->count = 0; // SEEKER shot ammo count TIMER_Set( self, "jetRecharge", Q_irand( 1000, 5000 ) ); TIMER_Set( self, "jumpChaseDebounce", Q_irand( 500, 2000 ) ); }