Added edict_t and CBaseHandle conversion functions to IGameHelpers (bug 2616, r=dvander)
authorMatt Woodrow <pred@alliedmods.net>
Sun Feb 22 14:38:05 2009 +1300 (2009-02-22)
changeset 25964fb11ed1e6bc
parent 2595 4eed13e139fd
child 2597 4f6b063098cc
Added edict_t and CBaseHandle conversion functions to IGameHelpers (bug 2616, r=dvander)
core/HalfLife2.cpp
core/HalfLife2.h
public/IGameHelpers.h
     1.1 --- a/core/HalfLife2.cpp	Sat Feb 21 11:29:28 2009 +1300
     1.2 +++ b/core/HalfLife2.cpp	Sun Feb 22 14:38:05 2009 +1300
     1.3 @@ -576,3 +576,59 @@
     1.4  		player->Kick(info.buffer);
     1.5  	}
     1.6  }
     1.7 +
     1.8 +edict_t *CHalfLife2::EdictOfIndex(int index)
     1.9 +{
    1.10 +	return ::PEntityOfEntIndex(index);
    1.11 +}
    1.12 +
    1.13 +int CHalfLife2::IndexOfEdict(edict_t *pEnt)
    1.14 +{
    1.15 +	return ::IndexOfEdict(pEnt);
    1.16 +}
    1.17 +
    1.18 +edict_t *CHalfLife2::GetHandleEntity(CBaseHandle &hndl)
    1.19 +{
    1.20 +	if (!hndl.IsValid())
    1.21 +	{
    1.22 +		return NULL;
    1.23 +	}
    1.24 +
    1.25 +	int index = hndl.GetEntryIndex();
    1.26 +
    1.27 +	edict_t *pStoredEdict;
    1.28 +	CBaseEntity *pStoredEntity;
    1.29 +
    1.30 +	pStoredEdict = GetEntity(index, &pStoredEntity);
    1.31 +
    1.32 +	if (pStoredEdict == NULL || pStoredEntity == NULL)
    1.33 +	{
    1.34 +		return NULL;
    1.35 +	}
    1.36 +
    1.37 +	IServerEntity *pSE = pStoredEdict->GetIServerEntity();
    1.38 +
    1.39 +	if (pSE == NULL)
    1.40 +	{
    1.41 +		return NULL;
    1.42 +	}
    1.43 +
    1.44 +	if (pSE->GetRefEHandle() != hndl)
    1.45 +	{
    1.46 +		return NULL;
    1.47 +	}
    1.48 +
    1.49 +	return pStoredEdict;
    1.50 +}
    1.51 +
    1.52 +void CHalfLife2::SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt)
    1.53 +{
    1.54 +	IServerEntity *pEntOther = pEnt->GetIServerEntity();
    1.55 +
    1.56 +	if (pEntOther == NULL)
    1.57 +	{
    1.58 +		return;
    1.59 +	}
    1.60 +
    1.61 +	hndl.Set(pEntOther);
    1.62 +}
     2.1 --- a/core/HalfLife2.h	Sat Feb 21 11:29:28 2009 +1300
     2.2 +++ b/core/HalfLife2.h	Sun Feb 22 14:38:05 2009 +1300
     2.3 @@ -109,6 +109,10 @@
     2.4  	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
     2.5  	bool IsLANServer();
     2.6  	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
     2.7 +	edict_t *EdictOfIndex(int index);
     2.8 +	int IndexOfEdict(edict_t *pEnt);
     2.9 +	edict_t *GetHandleEntity(CBaseHandle &hndl);
    2.10 +	void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
    2.11  public:
    2.12  	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
    2.13  	void ProcessFakeCliCmdQueue();
    2.14 @@ -140,4 +144,6 @@
    2.15  
    2.16  extern CHalfLife2 g_HL2;
    2.17  
    2.18 +inline edict_t *GetEntity(cell_t num, CBaseEntity **pData);
    2.19 +
    2.20  #endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_
     3.1 --- a/public/IGameHelpers.h	Sat Feb 21 11:29:28 2009 +1300
     3.2 +++ b/public/IGameHelpers.h	Sun Feb 22 14:38:05 2009 +1300
     3.3 @@ -40,9 +40,10 @@
     3.4   */
     3.5  
     3.6  #define SMINTERFACE_GAMEHELPERS_NAME		"IGameHelpers"
     3.7 -#define SMINTERFACE_GAMEHELPERS_VERSION		2
     3.8 +#define SMINTERFACE_GAMEHELPERS_VERSION		3
     3.9  
    3.10  class CBaseEntity;
    3.11 +class CBaseHandle;
    3.12  class SendProp;
    3.13  class ServerClass;
    3.14  struct edict_t;
    3.15 @@ -145,6 +146,39 @@
    3.16  		virtual bool FindSendPropInfo(const char *classname,
    3.17  			const char *offset,
    3.18  			sm_sendprop_info_t *info) =0;
    3.19 +
    3.20 +		/**
    3.21 +		 * @brief Converts an entity index into an edict pointer.
    3.22 +		 *
    3.23 +		 * @param index			Entity Index.
    3.24 +		 * @return				Edict pointer or NULL on failure.
    3.25 +		 */
    3.26 +		virtual edict_t *EdictOfIndex(int index) =0;
    3.27 +
    3.28 +		/**
    3.29 +		* @brief Converts an edict pointer into an entity index.
    3.30 +		*
    3.31 +		* @param index			Edict Pointer.
    3.32 +		* @return				Entity index or -1 on failure.
    3.33 +		*/
    3.34 +		virtual int IndexOfEdict(edict_t *pEnt) =0;
    3.35 +
    3.36 +		/**
    3.37 +		 * @brief Retrieves the edict pointer from a CBaseHandle object.
    3.38 +		 *
    3.39 +		 * @param hndl			CBaseHandle object.
    3.40 +		 * @return				Edict pointer or NULL on failure.
    3.41 +		 */
    3.42 +		virtual edict_t *GetHandleEntity(CBaseHandle &hndl) =0;
    3.43 +
    3.44 +		/**
    3.45 +		 * @brief Sets the edict pointer in a CBaseHandle object.
    3.46 +		 *
    3.47 +		 * @param hndl			CBaseHandle object.
    3.48 +		 * @param pEnt			Edict pointer.
    3.49 +		 * @noreturn
    3.50 +		 */
    3.51 +		virtual void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt) =0;
    3.52  	};
    3.53  }
    3.54