Skip to content

Commit

Permalink
fix crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
wootguy committed Nov 16, 2024
1 parent 8852c21 commit a3b992e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 18 additions & 0 deletions dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -806,6 +808,22 @@ template <class T> 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
Expand Down
6 changes: 0 additions & 6 deletions dlls/enginecallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a3b992e

Please sign in to comment.