Fix passing invalid ent to OnEntity forwards (bug 6119, r=KyleS).
Fix passing invalid ent to OnEntity forwards (
bug 6119, r=KyleS).
1.1 --- a/extensions/sdkhooks/extension.cpp Sat May 10 22:21:42 2014 -0400
1.2 +++ b/extensions/sdkhooks/extension.cpp Sat May 10 22:21:42 2014 -0400
1.3 @@ -814,7 +814,9 @@
1.4 // Call OnEntityCreated forward
1.5 int ref = gamehelpers->EntityToBCompatRef(pEntity);
1.6 int index = gamehelpers->ReferenceToIndex(ref);
1.7 - if (m_EntityExists.IsBitSet(index) || (index > 0 && index <= playerhelpers->GetMaxClients()))
1.8 +
1.9 + // This can be -1 for player ents before any players have connected
1.10 + if (index == INVALID_EHANDLE_INDEX || m_EntityExists.IsBitSet(index) || (index > 0 && index <= playerhelpers->GetMaxClients()))
1.11 {
1.12 return;
1.13 }
1.14 @@ -1587,13 +1589,16 @@
1.15
1.16 void SDKHooks::OnEntityDeleted(CBaseEntity *pEntity)
1.17 {
1.18 - int entity = gamehelpers->EntityToBCompatRef(pEntity);
1.19 - if (entity > 0 && entity <= playerhelpers->GetMaxClients())
1.20 + int ref = gamehelpers->EntityToBCompatRef(pEntity);
1.21 + int index = gamehelpers->ReferenceToIndex(ref);
1.22 +
1.23 + // This can be -1 for player ents before any players have connected
1.24 + if (index == INVALID_EHANDLE_INDEX || (index > 0 && index <= playerhelpers->GetMaxClients()))
1.25 {
1.26 return;
1.27 }
1.28
1.29 - HandleEntityDeleted(pEntity, entity);
1.30 + HandleEntityDeleted(pEntity, ref);
1.31 }
1.32
1.33 void SDKHooks::Hook_VPhysicsUpdate(IPhysicsObject *pPhysics)