From eaa398d4f5f404205c372c5f46177f0f00876e47 Mon Sep 17 00:00:00 2001 From: jhh8 Date: Sun, 23 Feb 2025 20:37:23 +0200 Subject: [PATCH 1/3] fix vindinade particles and sound disappearing with packet loss --- .../client/swarm/c_asw_grenade_vindicator.cpp | 57 +++++++++++++ .../client/swarm/c_asw_grenade_vindicator.h | 26 ++++++ src/game/client/swarm_sdk_client.vcxproj | 2 + src/game/server/EntityFlame.cpp | 3 + .../server/swarm/asw_grenade_vindicator.cpp | 85 +++++++------------ .../server/swarm/asw_grenade_vindicator.h | 5 +- 6 files changed, 124 insertions(+), 54 deletions(-) create mode 100644 src/game/client/swarm/c_asw_grenade_vindicator.cpp create mode 100644 src/game/client/swarm/c_asw_grenade_vindicator.h diff --git a/src/game/client/swarm/c_asw_grenade_vindicator.cpp b/src/game/client/swarm/c_asw_grenade_vindicator.cpp new file mode 100644 index 000000000..7bcf89daf --- /dev/null +++ b/src/game/client/swarm/c_asw_grenade_vindicator.cpp @@ -0,0 +1,57 @@ +#include "cbase.h" +#include "c_asw_grenade_vindicator.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Grenade_Vindicator, DT_ASW_Grenade_Vindicator ) + +BEGIN_NETWORK_TABLE( C_ASW_Grenade_Vindicator, DT_ASW_Grenade_Vindicator ) + RecvPropVector( RECVINFO( m_vecDetonateOrigin ) ), +END_NETWORK_TABLE() + + +C_ASW_Grenade_Vindicator::C_ASW_Grenade_Vindicator() +{ + m_bDetonated = false; + m_pSmokeTrail = NULL; + m_vecDetonateOrigin = Vector( 0.0, 0.0, 0.0 ); + + EmitSound( "ASWGrenade.Alarm" ); +} + +void C_ASW_Grenade_Vindicator::OnDataChanged(DataUpdateType_t updateType) +{ + if ( updateType == DATA_UPDATE_CREATED ) + CreateSmokeTrail(); + + if ( updateType == DATA_UPDATE_DATATABLE_CHANGED ) + { + if ( !m_bDetonated && m_vecDetonateOrigin != Vector( 0.0, 0.0, 0.0 ) ) + { + Detonate(); + m_bDetonated = true; + } + } +} + +void C_ASW_Grenade_Vindicator::CreateSmokeTrail() +{ + if ( m_pSmokeTrail ) + return; + + m_pSmokeTrail = ParticleProp()->Create( "rocket_trail_small", PATTACH_ABSORIGIN_FOLLOW, -1, Vector( 0, 0, 0 ) ); +} + +void C_ASW_Grenade_Vindicator::Detonate() +{ + if ( m_pSmokeTrail ) + { + m_pSmokeTrail->StopEmission(); + m_pSmokeTrail = NULL; + } + + StopSound( "ASWGrenade.Alarm" ); + EmitSound( "ASWGrenade.Incendiary" ); + DispatchParticleEffect( "vindicator_grenade", m_vecDetonateOrigin, GetLocalAngles() ); +} diff --git a/src/game/client/swarm/c_asw_grenade_vindicator.h b/src/game/client/swarm/c_asw_grenade_vindicator.h new file mode 100644 index 000000000..08a120d1d --- /dev/null +++ b/src/game/client/swarm/c_asw_grenade_vindicator.h @@ -0,0 +1,26 @@ +#ifndef _INCLUDED_C_ASW_GRENADE_VINDICATOR_H +#define _INCLUDED_C_ASW_GRENADE_VINDICATOR_H + +#pragma once + +#include "c_asw_rifle_grenade.h" + +class C_ASW_Grenade_Vindicator : public C_ASW_Rifle_Grenade +{ + DECLARE_CLASS( C_ASW_Grenade_Vindicator, C_ASW_Rifle_Grenade ); + DECLARE_CLIENTCLASS(); + +public: + C_ASW_Grenade_Vindicator(); + virtual void OnDataChanged(DataUpdateType_t updateType); + virtual void Detonate(); + void CreateSmokeTrail(); + + bool m_bDetonated; + + CNetworkVector( m_vecDetonateOrigin ); + + CUtlReference m_pSmokeTrail; +}; + +#endif // _INCLUDED_C_ASW_GRENADE_VINDICATOR_H diff --git a/src/game/client/swarm_sdk_client.vcxproj b/src/game/client/swarm_sdk_client.vcxproj index b0d660543..bdae3ac07 100644 --- a/src/game/client/swarm_sdk_client.vcxproj +++ b/src/game/client/swarm_sdk_client.vcxproj @@ -1295,6 +1295,7 @@ if exist ..\..\devtools\bin\postbuild.cmd ..\..\devtools\bin\postbuild.cmd clien + @@ -3166,6 +3167,7 @@ if exist ..\..\devtools\bin\postbuild.cmd ..\..\devtools\bin\postbuild.cmd clien + diff --git a/src/game/server/EntityFlame.cpp b/src/game/server/EntityFlame.cpp index 1d6e9dd08..c083e48c8 100644 --- a/src/game/server/EntityFlame.cpp +++ b/src/game/server/EntityFlame.cpp @@ -189,6 +189,9 @@ void CEntityFlame::AttachToEntity( CBaseEntity *pTarget ) // For networking to the client. m_hEntAttached = pTarget; + if ( !m_hEntAttached ) + return; + if( pTarget->IsNPC() ) { EmitSound( "General.BurningFlesh" ); diff --git a/src/game/server/swarm/asw_grenade_vindicator.cpp b/src/game/server/swarm/asw_grenade_vindicator.cpp index edb4e12c8..089001acd 100644 --- a/src/game/server/swarm/asw_grenade_vindicator.cpp +++ b/src/game/server/swarm/asw_grenade_vindicator.cpp @@ -9,6 +9,7 @@ #include "asw_marine_resource.h" #include "te_effect_dispatch.h" #include "particle_parse.h" +#include "EntityFlame.h" #include "asw_player.h" #include "asw_achievements.h" #include "asw_boomer_blob.h" @@ -51,6 +52,12 @@ BEGIN_DATADESC( CASW_Grenade_Vindicator ) DEFINE_OUTPUT(m_OnDamaged, "OnDamaged"), END_DATADESC() +IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Grenade_Vindicator, DT_ASW_Grenade_Vindicator ) + +BEGIN_NETWORK_TABLE( CASW_Grenade_Vindicator, DT_ASW_Grenade_Vindicator ) + SendPropVector( SENDINFO( m_vecDetonateOrigin ) ), +END_NETWORK_TABLE() + extern int g_sModelIndexFireball; // (in combatweapon.cpp) holds the index for the smoke cloud CASW_Grenade_Vindicator::CASW_Grenade_Vindicator() @@ -76,10 +83,12 @@ void CASW_Grenade_Vindicator::Spawn( void ) m_DmgRadius = 220.0f; m_bDamagedByExplosions = rd_vindicator_grenade_pushed_by_explosions.GetBool(); - Ignite(3.0, false, 0, false); + Ignite( 3.0, false, 0, false ); m_takedamage = DAMAGE_YES; + m_vecDetonateOrigin = Vector( 0.0, 0.0, 0.0 ); + SetSize( -Vector(4,4,4), Vector(4,4,4) ); SetSolid( SOLID_BBOX ); SetGravity( asw_vindicator_grenade_gravity.GetFloat() ); @@ -100,10 +109,6 @@ void CASW_Grenade_Vindicator::Spawn( void ) QAngle vecAngVelocity( random->RandomFloat ( -100, -500 ), 0, 0 ); SetLocalAngularVelocity( vecAngVelocity ); - if ( !m_bSilent ) - { - EmitSound( "ASWGrenade.Alarm" ); // 3 second warning sound - } SetFuseLength(asw_vindicator_grenade_fuse.GetFloat()); m_fEarliestTouchDetonationTime = GetEarliestTouchDetonationTime(); @@ -231,7 +236,8 @@ void CASW_Grenade_Vindicator::Detonate() { m_takedamage = DAMAGE_NO; - StopSound( "ASWGrenade.Alarm" ); + m_vecDetonateOrigin = GetAbsOrigin(); + CPASFilter filter( GetAbsOrigin() ); /* @@ -245,15 +251,6 @@ void CASW_Grenade_Vindicator::Detonate() m_flDamage ); */ - if ( !m_bSilent ) - { - EmitSound( "ASWGrenade.Incendiary" ); - } - // throw out some flames - CEffectData data; - data.m_vOrigin = GetAbsOrigin(); - DispatchEffect( "ASWFireBurst", data ); - Vector vecForward = GetAbsVelocity(); VectorNormalize(vecForward); trace_t tr; @@ -345,7 +342,24 @@ void CASW_Grenade_Vindicator::Detonate() m_iClusters--; } - UTIL_Remove( this ); + // hack to remove the burning particles on the grenade itself + // theres probably a better way but this has been bothering me for couple hours now + CEntityFlame* pEntityFlame = dynamic_cast< CEntityFlame* >( GetEffectEntity() ); + if ( pEntityFlame ) + { + pEntityFlame->AttachToEntity( NULL ); + SetEffectEntity( NULL ); + Extinguish(); + } + + SetModelIndex( 0 ); + SetModelName( NULL_STRING ); + SetTouch( NULL ); + SetCollisionGroup( COLLISION_GROUP_DEBRIS ); + + // give time for m_vecDetonateOrigin to be sent to client so it can simulate the explosion effects + SetThink( &CASW_Grenade_Vindicator::SUB_Remove ); + SetNextThink( gpGlobals->curtime + 2.0f ); } void CASW_Grenade_Vindicator::Precache() @@ -360,6 +374,7 @@ void CASW_Grenade_Vindicator::Precache() PrecacheScriptSound("ASWGrenade.Alarm"); PrecacheScriptSound("Grenade.ImpactHard"); PrecacheParticleSystem( "VindGrenade" ); + PrecacheParticleSystem( "vindicator_grenade" ); PrecacheParticleSystem( "grenade_main_trail" ); } @@ -370,44 +385,10 @@ void CASW_Grenade_Vindicator::KillEffects() void CASW_Grenade_Vindicator::CreateEffects() { - // Start up the eye glow - /* - m_pMainGlow = CSprite::SpriteCreate( "sprites/redglow1.vmt", GetLocalOrigin(), false ); - - int nAttachment = LookupAttachment( "fuse" ); - - if ( m_pMainGlow != NULL ) - { - m_pMainGlow->FollowEntity( this ); - m_pMainGlow->SetAttachment( this, nAttachment ); - m_pMainGlow->SetTransparency( kRenderGlow, 255, 255, 255, 200, kRenderFxNoDissipation ); - m_pMainGlow->SetScale( 0.2f ); - m_pMainGlow->SetGlowProxySize( 4.0f ); - } - - // Start up the eye trail - m_pGlowTrail = CSpriteTrail::SpriteTrailCreate( "sprites/bluelaser1.vmt", GetLocalOrigin(), false ); - - if ( m_pGlowTrail != NULL ) - { - m_pGlowTrail->FollowEntity( this ); - m_pGlowTrail->SetAttachment( this, nAttachment ); - m_pGlowTrail->SetTransparency( kRenderTransAdd, 255, 0, 0, 255, kRenderFxNone ); - m_pGlowTrail->SetStartWidth( 8.0f ); - m_pGlowTrail->SetEndWidth( 1.0f ); - m_pGlowTrail->SetLifeTime( 0.5f ); - } - */ - - CEffectData data; - data.m_vOrigin = GetAbsOrigin(); - //data.m_vNormal = dir; - //data.m_flScale = (float)amount; - CPASFilter filter( data.m_vOrigin ); - filter.SetIgnorePredictionCull(true); - DispatchParticleEffect( "rocket_trail_small", PATTACH_ABSORIGIN_FOLLOW, this, "fuse", false, -1, &filter ); + } + int CASW_Grenade_Vindicator::OnTakeDamage_Dying( const CTakeDamageInfo &info ) { return BaseClass::OnTakeDamage_Dying(info); diff --git a/src/game/server/swarm/asw_grenade_vindicator.h b/src/game/server/swarm/asw_grenade_vindicator.h index 1dfd7d17e..2eded828a 100644 --- a/src/game/server/swarm/asw_grenade_vindicator.h +++ b/src/game/server/swarm/asw_grenade_vindicator.h @@ -13,9 +13,8 @@ class CASW_Grenade_Vindicator : public CASW_Rifle_Grenade public: DECLARE_CLASS( CASW_Grenade_Vindicator, CASW_Rifle_Grenade ); -#if !defined( CLIENT_DLL ) + DECLARE_SERVERCLASS(); DECLARE_DATADESC(); -#endif CASW_Grenade_Vindicator(); virtual ~CASW_Grenade_Vindicator( void ); @@ -49,6 +48,8 @@ class CASW_Grenade_Vindicator : public CASW_Rifle_Grenade bool m_bKicked; bool m_bExplodeOnWorldContact; + CNetworkVector( m_vecDetonateOrigin ); + CHandle m_pMainGlow; CHandle m_pGlowTrail; From 22f60455d3bd1949775c64d3cc320371013c3c72 Mon Sep 17 00:00:00 2001 From: jhh8 Date: Sun, 23 Feb 2025 20:43:38 +0200 Subject: [PATCH 2/3] make not solid rather than changing collision group --- src/game/server/swarm/asw_grenade_vindicator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/swarm/asw_grenade_vindicator.cpp b/src/game/server/swarm/asw_grenade_vindicator.cpp index 089001acd..8de806a7a 100644 --- a/src/game/server/swarm/asw_grenade_vindicator.cpp +++ b/src/game/server/swarm/asw_grenade_vindicator.cpp @@ -355,7 +355,7 @@ void CASW_Grenade_Vindicator::Detonate() SetModelIndex( 0 ); SetModelName( NULL_STRING ); SetTouch( NULL ); - SetCollisionGroup( COLLISION_GROUP_DEBRIS ); + SetSolid( SOLID_NONE ); // give time for m_vecDetonateOrigin to be sent to client so it can simulate the explosion effects SetThink( &CASW_Grenade_Vindicator::SUB_Remove ); From d092224d91688dc652b9818eca1bc8dfc4af6a25 Mon Sep 17 00:00:00 2001 From: jhh8 Date: Mon, 24 Mar 2025 00:49:53 +0200 Subject: [PATCH 3/3] move vindinade alarm sound back to server --- src/game/client/swarm/c_asw_grenade_vindicator.cpp | 11 +++++------ src/game/client/swarm/c_asw_grenade_vindicator.h | 1 + src/game/server/swarm/asw_grenade_vindicator.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/game/client/swarm/c_asw_grenade_vindicator.cpp b/src/game/client/swarm/c_asw_grenade_vindicator.cpp index 7bcf89daf..90d25d205 100644 --- a/src/game/client/swarm/c_asw_grenade_vindicator.cpp +++ b/src/game/client/swarm/c_asw_grenade_vindicator.cpp @@ -16,15 +16,15 @@ C_ASW_Grenade_Vindicator::C_ASW_Grenade_Vindicator() m_bDetonated = false; m_pSmokeTrail = NULL; m_vecDetonateOrigin = Vector( 0.0, 0.0, 0.0 ); +} - EmitSound( "ASWGrenade.Alarm" ); +void C_ASW_Grenade_Vindicator::Spawn() +{ + CreateSmokeTrail(); } void C_ASW_Grenade_Vindicator::OnDataChanged(DataUpdateType_t updateType) { - if ( updateType == DATA_UPDATE_CREATED ) - CreateSmokeTrail(); - if ( updateType == DATA_UPDATE_DATATABLE_CHANGED ) { if ( !m_bDetonated && m_vecDetonateOrigin != Vector( 0.0, 0.0, 0.0 ) ) @@ -51,7 +51,6 @@ void C_ASW_Grenade_Vindicator::Detonate() m_pSmokeTrail = NULL; } - StopSound( "ASWGrenade.Alarm" ); EmitSound( "ASWGrenade.Incendiary" ); - DispatchParticleEffect( "vindicator_grenade", m_vecDetonateOrigin, GetLocalAngles() ); + DispatchParticleEffect( "vindicator_grenade", m_vecDetonateOrigin, vec3_angle ); } diff --git a/src/game/client/swarm/c_asw_grenade_vindicator.h b/src/game/client/swarm/c_asw_grenade_vindicator.h index 08a120d1d..c41a80b9a 100644 --- a/src/game/client/swarm/c_asw_grenade_vindicator.h +++ b/src/game/client/swarm/c_asw_grenade_vindicator.h @@ -12,6 +12,7 @@ class C_ASW_Grenade_Vindicator : public C_ASW_Rifle_Grenade public: C_ASW_Grenade_Vindicator(); + virtual void Spawn(); virtual void OnDataChanged(DataUpdateType_t updateType); virtual void Detonate(); void CreateSmokeTrail(); diff --git a/src/game/server/swarm/asw_grenade_vindicator.cpp b/src/game/server/swarm/asw_grenade_vindicator.cpp index 8de806a7a..c92e41560 100644 --- a/src/game/server/swarm/asw_grenade_vindicator.cpp +++ b/src/game/server/swarm/asw_grenade_vindicator.cpp @@ -109,6 +109,10 @@ void CASW_Grenade_Vindicator::Spawn( void ) QAngle vecAngVelocity( random->RandomFloat ( -100, -500 ), 0, 0 ); SetLocalAngularVelocity( vecAngVelocity ); + if ( !m_bSilent ) + { + EmitSound( "ASWGrenade.Alarm" ); // 3 second warning sound + } SetFuseLength(asw_vindicator_grenade_fuse.GetFloat()); m_fEarliestTouchDetonationTime = GetEarliestTouchDetonationTime(); @@ -236,6 +240,8 @@ void CASW_Grenade_Vindicator::Detonate() { m_takedamage = DAMAGE_NO; + StopSound( "ASWGrenade.Alarm" ); + m_vecDetonateOrigin = GetAbsOrigin(); CPASFilter filter( GetAbsOrigin() );