From 80f7e3092be36a68742c133a66453163af9addc9 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Mon, 17 Dec 2012 14:33:57 -0500 Subject: [PATCH] Fixed regressions in a988c42d4248: * Fixed crash when prop/data ent is invalid. * Restored GetEntPropEnt/GetEntDataEnt2 functionality when logical ent support is not available. --- core/smn_entities.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/smn_entities.cpp b/core/smn_entities.cpp index fd6eafda..e957ed38 100644 --- a/core/smn_entities.cpp +++ b/core/smn_entities.cpp @@ -620,14 +620,12 @@ static cell_t GetEntDataEnt2(IPluginContext *pContext, const cell_t *params) } CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset); - int index = hndl.GetEntryIndex(); + CBaseEntity *pHandleEntity = g_HL2.ReferenceToEntity(hndl.GetEntryIndex()); - CEntInfo *pInfo = g_HL2.LookupEntity(index); - if (pInfo->m_SerialNumber != hndl.GetSerialNumber()) + if (!pHandleEntity || hndl != reinterpret_cast(pHandleEntity)->GetRefEHandle()) return -1; - int ref = g_HL2.IndexToReference(index); - return g_HL2.ReferenceToBCompatRef(ref); + return g_HL2.EntityToBCompatRef(pHandleEntity); } /* THIS GUY IS DEPRECATED. */ @@ -1498,14 +1496,12 @@ static cell_t GetEntPropEnt(IPluginContext *pContext, const cell_t *params) } CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset); - int index = hndl.GetEntryIndex(); + CBaseEntity *pHandleEntity = g_HL2.ReferenceToEntity(hndl.GetEntryIndex()); - CEntInfo *pInfo = g_HL2.LookupEntity(index); - if (pInfo->m_SerialNumber != hndl.GetSerialNumber()) + if (!pHandleEntity || hndl != reinterpret_cast(pHandleEntity)->GetRefEHandle()) return -1; - int ref = g_HL2.IndexToReference(index); - return g_HL2.ReferenceToBCompatRef(ref); + return g_HL2.EntityToBCompatRef(pHandleEntity); } static cell_t SetEntPropEnt(IPluginContext *pContext, const cell_t *params)