From a3b992e91dca446cfc01d852a093aaa6cf7d6e2c Mon Sep 17 00:00:00 2001 From: wootguy Date: Fri, 15 Nov 2024 19:21:08 -0800 Subject: [PATCH] fix crashes --- dlls/cbase.h | 18 ++++++++++++++++++ dlls/enginecallback.h | 6 ------ dlls/util.cpp | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/dlls/cbase.h b/dlls/cbase.h index e56d7632..a404d397 100644 --- a/dlls/cbase.h +++ b/dlls/cbase.h @@ -87,6 +87,8 @@ typedef enum { USE_OFF = 0, USE_ON = 1, USE_SET = 2, USE_TOGGLE = 3 } USE_TYPE; EXPORT extern void FireTargets( const char *targetName, CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); +void* GET_PRIVATE(const edict_t* pent); + typedef void (CBaseEntity::*BASEPTR)(void); typedef void (CBaseEntity::*ENTITYFUNCPTR)(CBaseEntity *pOther ); typedef void (CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); @@ -806,6 +808,22 @@ template T * GetClassPtr( T *a ) return allocate ? (T*)RelocateEntIdx(a) : a; } +inline void* GET_PRIVATE(const edict_t* pent) +{ + if (pent) { + CBaseEntity* bent = (CBaseEntity*)pent->pvPrivateData; + + if (bent && bent->pev != &pent->v) { + // TODO: pev was linked wrong somehow. mem corruption? + ALERT(at_error, "Entity pev not linked to edict %d pev (%s)\n", + ENTINDEX(pent), STRING(pent->v.classname)); + return NULL; + } + + return bent; + } + return NULL; +} /* bit_PUSHBRUSH_DATA | bit_TOGGLE_DATA diff --git a/dlls/enginecallback.h b/dlls/enginecallback.h index 19792680..66c2890a 100644 --- a/dlls/enginecallback.h +++ b/dlls/enginecallback.h @@ -103,12 +103,6 @@ EXPORT void DEBUG_MSG(ALERT_TYPE target, const char* format, ...); #define ENGINE_FPRINTF (*g_engfuncs.pfnEngineFprintf) #define ALLOC_PRIVATE (*g_engfuncs.pfnPvAllocEntPrivateData) -inline void *GET_PRIVATE( const edict_t *pent ) -{ - if ( pent ) - return pent->pvPrivateData; - return NULL; -} #define FREE_PRIVATE (*g_engfuncs.pfnFreeEntPrivateData) //#define STRING (*g_engfuncs.pfnSzFromIndex) diff --git a/dlls/util.cpp b/dlls/util.cpp index 1b00dbcf..ea400ead 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -820,7 +820,7 @@ void WRITE_BYTES(uint8_t* bytes, int count) { // tests if a player would receive a message given a send mode // and the entity which is emitting the message bool TestMsgVis(edict_t* plr, int testEntIdx, int netMsgMode) { - CBaseEntity* ent = CBaseEntity::Instance(ENT(testEntIdx)); + CBaseEntity* ent = CBaseEntity::Instance(INDEXENT(testEntIdx)); if (!ent) { return false;