Fix clients being invalid when passed to OnEntityDestroyed (bug 6119, r=KyleS).
authorNicholas Hastings <skamonkey@gmail.com>
Sat May 10 22:21:38 2014 -0400 (2014-05-10)
changeset 43551f90e7959134
parent 4354 7011587e0021
child 4356 aad66fb7e628
Fix clients being invalid when passed to OnEntityDestroyed (bug 6119, r=KyleS).
extensions/sdkhooks/extension.cpp
extensions/sdkhooks/extension.h
     1.1 --- a/extensions/sdkhooks/extension.cpp	Sat May 10 05:42:33 2014 -0700
     1.2 +++ b/extensions/sdkhooks/extension.cpp	Sat May 10 22:21:38 2014 -0400
     1.3 @@ -422,6 +422,13 @@
     1.4  	m_EntityExists.Set(client);
     1.5  }
     1.6  
     1.7 +void SDKHooks::OnClientDisconnecting(int client)
     1.8 +{
     1.9 +	CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(client);
    1.10 +	
    1.11 +	HandleEntityDeleted(pEntity, client);
    1.12 +}
    1.13 +
    1.14  void SDKHooks::AddEntityListener(ISMEntityListener *listener)
    1.15  {
    1.16  	m_EntListeners.push_back(listener);
    1.17 @@ -1609,24 +1616,13 @@
    1.18  
    1.19  void SDKHooks::OnEntityDeleted(CBaseEntity *pEntity)
    1.20  {
    1.21 -	// Send OnEntityDestroyed to SM listeners
    1.22 -	SourceHook::List<ISMEntityListener *>::iterator iter;
    1.23 -	ISMEntityListener *pListener = NULL;
    1.24 -	for (iter=m_EntListeners.begin(); iter!=m_EntListeners.end(); iter++)
    1.25 +	int entity = gamehelpers->EntityToBCompatRef(pEntity);
    1.26 +	if (entity > 0 && entity <= playerhelpers->GetMaxClients())
    1.27  	{
    1.28 -		pListener = (*iter);
    1.29 -		pListener->OnEntityDestroyed(pEntity);
    1.30 +		return;
    1.31  	}
    1.32  
    1.33 -	int entity = gamehelpers->EntityToBCompatRef(pEntity);
    1.34 -
    1.35 -	// Call OnEntityDestroyed forward
    1.36 -	g_pOnEntityDestroyed->PushCell(entity);
    1.37 -	g_pOnEntityDestroyed->Execute(NULL);
    1.38 -	
    1.39 -	Unhook(pEntity);
    1.40 -
    1.41 -	m_EntityExists.Set(gamehelpers->ReferenceToIndex(entity), false);
    1.42 +	HandleEntityDeleted(pEntity, entity);
    1.43  }
    1.44  
    1.45  void SDKHooks::Hook_VPhysicsUpdate(IPhysicsObject *pPhysics)
    1.46 @@ -1719,3 +1715,23 @@
    1.47  	cell_t result = Call(META_IFACEPTR(CBaseEntity), SDKHook_WeaponSwitchPost, pWeapon);
    1.48  	RETURN_META_VALUE(MRES_IGNORED, true);
    1.49  }
    1.50 +
    1.51 +void SDKHooks::HandleEntityDeleted(CBaseEntity *pEntity, int ref)
    1.52 +{
    1.53 +	// Send OnEntityDestroyed to SM listeners
    1.54 +	SourceHook::List<ISMEntityListener *>::iterator iter;
    1.55 +	ISMEntityListener *pListener = NULL;
    1.56 +	for (iter = m_EntListeners.begin(); iter != m_EntListeners.end(); iter++)
    1.57 +	{
    1.58 +		pListener = (*iter);
    1.59 +		pListener->OnEntityDestroyed(pEntity);
    1.60 +	}
    1.61 +
    1.62 +	// Call OnEntityDestroyed forward
    1.63 +	g_pOnEntityDestroyed->PushCell(ref);
    1.64 +	g_pOnEntityDestroyed->Execute(NULL);
    1.65 +
    1.66 +	Unhook(pEntity);
    1.67 +
    1.68 +	m_EntityExists.Set(gamehelpers->ReferenceToIndex(ref), false);
    1.69 +}
     2.1 --- a/extensions/sdkhooks/extension.h	Sat May 10 05:42:33 2014 -0700
     2.2 +++ b/extensions/sdkhooks/extension.h	Sat May 10 22:21:38 2014 -0400
     2.3 @@ -244,6 +244,7 @@
     2.4  
     2.5  public:  // IClientListener
     2.6  	virtual void OnClientPutInServer(int client);
     2.7 +	virtual void OnClientDisconnecting(int client);
     2.8  
     2.9  public:  // ISDKHooks
    2.10  	virtual void AddEntityListener(ISMEntityListener *listener);
    2.11 @@ -330,6 +331,7 @@
    2.12  	bool Hook_WeaponSwitchPost(CBaseCombatWeapon *pWeapon, int viewmodelindex);
    2.13  	
    2.14  private:
    2.15 +	void HandleEntityDeleted(CBaseEntity *pEntity, int ref);
    2.16  	void Unhook(CBaseEntity *pEntity);
    2.17  	void Unhook(IPluginContext *pContext);
    2.18  };