diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 53af3dc8..7600917b 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -1099,8 +1099,26 @@ int CHalfLife2::ReferenceToIndex(cell_t entRef) return hndl.GetEntryIndex(); } + else + { + CEntInfo *pInfo = LookupEntity(entRef); + if (!pInfo) + { + return INVALID_EHANDLE_INDEX; + } + IServerUnknown *pUnk = static_cast(pInfo->m_pEntity); + if (!pUnk) + { + return INVALID_EHANDLE_INDEX; + } + CBaseEntity *pEntity = pUnk->GetBaseEntity(); + if (!pEntity) + { + return INVALID_EHANDLE_INDEX; + } - return entRef; + return entRef; + } } cell_t CHalfLife2::EntityToBCompatRef(CBaseEntity *pEntity) diff --git a/plugins/include/halflife.inc b/plugins/include/halflife.inc index ccb5bf90..38626f23 100644 --- a/plugins/include/halflife.inc +++ b/plugins/include/halflife.inc @@ -667,10 +667,11 @@ stock void DisplayAskConnectBox(int client, float time, const char[] ip, const c native int EntIndexToEntRef(int entity); /** - * Retrieves the entity index from a reference. + * Retrieves the entity index from a reference or validates an entity index. + * The input ref is checked that it is still valid and refers to the same entity. * - * @param ref Entity reference. - * @return Entity index or -1 on invalid reference. + * @param ref Entity reference or index. + * @return Entity index or returns INVALID_ENT_REFERENCE if ref is invalid. */ native int EntRefToEntIndex(int ref);