Skip to content

Commit

Permalink
Fix GetDataDescMap not returning a valid ptr on entity deletion (#26)
Browse files Browse the repository at this point in the history
Co-authored-by: Kenzzer <[email protected]>
  • Loading branch information
KitRifty and Kenzzer authored Jul 7, 2022
1 parent 09ea2e4 commit 904a492
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions extension/cbasenpc_behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class CBaseNPCIntention : public IIntention
void InitBehavior();
void DestroyBehavior();


private:
Behavior< INextBot > * m_pBehavior;
};
Expand Down
36 changes: 17 additions & 19 deletions extension/pluginentityfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,24 +467,6 @@ void CPluginEntityFactories::NotifyEntityDestruction( CBaseEntity* pEntity )
}
}

datamap_t* CPluginEntityFactories::Hook_GetDataDescMap()
{
CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
if (!pEntity) RETURN_META_VALUE(MRES_IGNORED, nullptr);

PluginFactoryEntityRecord_t* pEntityRecord = FindRecord(pEntity);
if (!pEntityRecord)
RETURN_META_VALUE(MRES_IGNORED, nullptr);

datamap_t* pDataMap = pEntityRecord->m_pDataMap;
if (pDataMap)
{
RETURN_META_VALUE(MRES_SUPERCEDE, pDataMap);
}

RETURN_META_VALUE(MRES_IGNORED, nullptr);
}

void CPluginEntityFactories::Hook_UpdateOnRemove()
{
CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
Expand Down Expand Up @@ -523,7 +505,7 @@ void PluginFactoryEntityRecord_t::Hook(bool bHookDestructor)
}
m_bHooked = true;

m_pHookIds.push_back( SH_ADD_MANUALHOOK(FactoryEntity_GetDataDescMap, pEntity, SH_MEMBER(g_pPluginEntityFactories, &CPluginEntityFactories::Hook_GetDataDescMap), false) );
m_pHookIds.push_back( SH_ADD_MANUALHOOK(FactoryEntity_GetDataDescMap, pEntity, SH_MEMBER(this, &PluginFactoryEntityRecord_t::Hook_GetDataDescMap), false) );
m_pHookIds.push_back( SH_ADD_MANUALHOOK(FactoryEntity_UpdateOnRemove, pEntity, SH_MEMBER(g_pPluginEntityFactories, &CPluginEntityFactories::Hook_UpdateOnRemove), false) );

if (bHookDestructor)
Expand Down Expand Up @@ -583,6 +565,22 @@ PluginFactoryEntityRecord_t::~PluginFactoryEntityRecord_t()
}
}

datamap_t* PluginFactoryEntityRecord_t::Hook_GetDataDescMap()
{
CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
if (!pEntity)
{
RETURN_META_VALUE(MRES_IGNORED, nullptr);
}

if (m_pDataMap)
{
RETURN_META_VALUE(MRES_SUPERCEDE, m_pDataMap);
}

RETURN_META_VALUE(MRES_IGNORED, nullptr);
}

INextBot* PluginFactoryEntityRecord_t::Hook_MyNextBotPointer()
{
RETURN_META_VALUE(MRES_SUPERCEDE, m_pNextBot);
Expand Down
2 changes: 1 addition & 1 deletion extension/pluginentityfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PluginFactoryEntityRecord_t
PluginFactoryEntityRecord_t( CBaseEntityHack* pEnt ) : pEntity(pEnt) { }
~PluginFactoryEntityRecord_t();

datamap_t* Hook_GetDataDescMap();
INextBot* Hook_MyNextBotPointer();
IIntention* Hook_GetIntentionInterface();

Expand Down Expand Up @@ -87,7 +88,6 @@ class CPluginEntityFactories : public IPluginsListener,

void NotifyEntityDestruction( CBaseEntity* pEntity );

datamap_t* Hook_GetDataDescMap();
void Hook_UpdateOnRemove();
#ifdef __linux__
void Hook_EntityDestructor( void );
Expand Down
2 changes: 1 addition & 1 deletion product.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.0
1.6.1

0 comments on commit 904a492

Please sign in to comment.