public/IGameHelpers.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed May 25 13:31:14 2011 -0400 (2011-05-25)
changeset 3285 065beec73902
parent 3010 8ea042c00c80
child 3300 be9323414243
permissions -rw-r--r--
Backed out changeset: 65eb3df32b1c
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_GAMEHELPERS_H_
    33 #define _INCLUDE_SOURCEMOD_GAMEHELPERS_H_
    34 
    35 #include <IShareSys.h>
    36 
    37 /**
    38  * @file IGameHelpers.h
    39  * @brief Provides Source helper functions.
    40  */
    41 
    42 #define SMINTERFACE_GAMEHELPERS_NAME		"IGameHelpers"
    43 #define SMINTERFACE_GAMEHELPERS_VERSION		6
    44 
    45 class CBaseEntity;
    46 class CBaseHandle;
    47 class SendProp;
    48 class ServerClass;
    49 struct edict_t;
    50 struct datamap_t;
    51 struct typedescription_t;
    52 
    53 namespace SourceMod
    54 {
    55 	/**
    56 	 * @brief Maps the heirarchy of a SendProp.
    57 	 */
    58 	struct sm_sendprop_info_t
    59 	{
    60 		SendProp *prop;					/**< Property instance. */
    61 		unsigned int actual_offset;		/**< Actual computed offset. */
    62 	};
    63 
    64 	class IGameHelpers : public SMInterface
    65 	{
    66 	public:
    67 		virtual const char *GetInterfaceName()
    68 		{
    69 			return SMINTERFACE_GAMEHELPERS_NAME;
    70 		}
    71 		virtual unsigned int GetInterfaceVersion()
    72 		{
    73 			return SMINTERFACE_GAMEHELPERS_VERSION;
    74 		}
    75 	public:
    76 		/**
    77 		 * @brief Deprecated; use FindSendPropInfo() instead.
    78 		 *
    79 		 * @param classname		Do not use.
    80 		 * @param offset		Do not use.
    81 		 * @return				Do not use.
    82 		 */
    83 		virtual SendProp *FindInSendTable(const char *classname, const char *offset) =0;
    84 
    85 		/**
    86 		 * @brief Finds a named server class.
    87 		 *
    88 		 * @return				ServerClass pointer on success, NULL on failure.
    89 		 */
    90 		virtual ServerClass *FindServerClass(const char *classname) =0;
    91 
    92 		/**
    93 		 * @brief Finds a datamap_t definition.
    94 		 *
    95 		 * @param pMap			datamap_t pointer.
    96 		 * @param offset		Property name.
    97 		 * @return				typedescription_t pointer on success, NULL 
    98 		 *						on failure.
    99 		 */
   100 		virtual typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset) =0;
   101 
   102 		/**
   103 		 * @brief Retrieves an entity's datamap_t pointer.
   104 		 *
   105 		 * @param pEntity		CBaseEntity entity.
   106 		 * @return				datamap_t pointer, or NULL on failure.
   107 		 */
   108 		virtual datamap_t *GetDataMap(CBaseEntity *pEntity) =0;
   109 
   110 		/**
   111 		 * @brief Marks an edict as state changed for an offset.
   112 		 *
   113 		 * @param pEdict		Edict pointer.
   114 		 * @param offset		Offset index.
   115 		 */
   116 		virtual void SetEdictStateChanged(edict_t *pEdict, unsigned short offset) =0;
   117 
   118 		/**
   119 		 * @brief Sends a text message to a client.
   120 		 *
   121 		 * @param client		Client index.
   122 		 * @param dest			Destination on the HUD.
   123 		 * @param msg			Message to send.
   124 		 * @return				True on success, false on failure.
   125 		 */
   126 		virtual bool TextMsg(int client, int dest, const char *msg) =0;
   127 		
   128 		/**
   129 		 * @brief Returns whether the server ls a LAN server.
   130 		 * 
   131 		 * @return				True if LAN server, false otherwise.
   132 		 */
   133 		virtual bool IsLANServer() =0;
   134 
   135 		/**
   136 		 * @brief Finds a send property in a named ServerClass.
   137 		 *
   138 		 * This version, unlike FindInSendTable(), correctly deduces the 
   139 		 * offsets of nested tables.
   140 		 *
   141 		 * @param classname		ServerClass name (such as CBasePlayer).
   142 		 * @param offset		Offset name (such as m_iAmmo).
   143 		 * @param info			Buffer to store sm_sendprop_info_t data.
   144 		 * @return				True on success, false on failure.
   145 		 */
   146 		virtual bool FindSendPropInfo(const char *classname,
   147 			const char *offset,
   148 			sm_sendprop_info_t *info) =0;
   149 
   150 		/**
   151 		 * @brief Converts an entity index into an edict pointer.
   152 		 *
   153 		 * @param index			Entity Index.
   154 		 * @return				Edict pointer or NULL on failure.
   155 		 */
   156 		virtual edict_t *EdictOfIndex(int index) =0;
   157 
   158 		/**
   159 		* @brief Converts an edict pointer into an entity index.
   160 		*
   161 		* @param index			Edict Pointer.
   162 		* @return				Entity index or -1 on failure.
   163 		*/
   164 		virtual int IndexOfEdict(edict_t *pEnt) =0;
   165 
   166 		/**
   167 		 * @brief Retrieves the edict pointer from a CBaseHandle object.
   168 		 *
   169 		 * @param hndl			CBaseHandle object.
   170 		 * @return				Edict pointer or NULL on failure.
   171 		 */
   172 		virtual edict_t *GetHandleEntity(CBaseHandle &hndl) =0;
   173 
   174 		/**
   175 		 * @brief Sets the edict pointer in a CBaseHandle object.
   176 		 *
   177 		 * @param hndl			CBaseHandle object.
   178 		 * @param pEnt			Edict pointer.
   179 		 * @noreturn
   180 		 */
   181 		virtual void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt) =0;
   182 
   183 		/**
   184 		 * @brief Returns the current map name.
   185 		 *
   186 		 * @return				Current map name.
   187 		 */
   188 		virtual const char *GetCurrentMap() =0;
   189 
   190 		/**
   191 		 * @brief Wraps IVEngineServer::ServerCommand.
   192 		 *
   193 		 * @param buffer		Command buffer (does not auto \n terminate).
   194 		 */
   195 		virtual void ServerCommand(const char *buffer) =0;
   196 
   197 		/**
   198 		 * @brief Looks up a reference and returns the CBasseEntity* it points to.
   199 		 *
   200 		 * @note Supports 'old style' simple indexes and does a serial confirmation check on references.
   201 		 *
   202 		 * @param entRef		Entity reference.
   203 		 * @return				Entity pointer.
   204 		 */
   205 		virtual CBaseEntity *ReferenceToEntity(cell_t entRef) =0;
   206 
   207 		/**
   208 		 * @brief Returns the entity reference for an entity.
   209 		 *
   210 		 * @param pEntity		Entity pointer.
   211 		 * @return				Entity reference.
   212 		 */
   213 		virtual cell_t EntityToReference(CBaseEntity *pEntity) =0;
   214 
   215 		/**
   216 		 * @brief Returns the entity reference for logical entities, or the index for networked entities.
   217 		 *
   218 		 * @param pEntity		Entity pointer.
   219 		 * @return				Entity reference/index.
   220 		 */
   221 		virtual cell_t EntityToBCompatRef(CBaseEntity *pEntity) =0;
   222 
   223 		/**
   224 		 * @brief Converts an entity index into an entity reference.
   225 		 *
   226 		 * @param entIndex		Entity index.
   227 		 * @return				Entity reference.
   228 		 */
   229 		virtual cell_t IndexToReference(int entIndex) =0;
   230 
   231 		/**
   232 		 * @brief Retrieves the entity index from a reference.
   233 		 *
   234 		 * @param entRef		Entity reference.
   235 		 * @return				Entity index.
   236 		 */
   237 		virtual int ReferenceToIndex(cell_t entRef) =0;
   238 
   239 		/**
   240 		 * @brief Converts a reference into a bcompat version (index for networked entities).
   241 		 *
   242 		 * @param entRef		Entity reference.
   243 		 * @return				Entity reference/index.
   244 		 */
   245 		virtual cell_t ReferenceToBCompatRef(cell_t entRef) =0;
   246 		
   247 		/**
   248 		 * @brief Returns the g_EntList pointer.
   249 		 *
   250 		 * @return				g_EntList pointer.
   251 		 */
   252 		virtual void *GetGlobalEntityList() =0;
   253 		
   254 		/**
   255 		 * @brief Adds a client to the kick queue, where they will be kicked
   256 		 * next game frame.
   257 		 *
   258 		 * The user ID is used to ensure the correct player is kicked.
   259 		 *
   260 		 * @param client		The index of the client to kick.
   261 		 * @param userid		The user ID of the client to kick.
   262 		 * @param msg			The kick message to show to the player.
   263 		 */
   264 		virtual void AddDelayedKick(int client, int userid, const char *msg) =0;
   265 
   266 		/**
   267 		 * @brief Returns the uncomputed offset of a SendProp.
   268 		 *
   269 		 * @param prop          SendProp pointer.
   270 		 * @return              Uncomputed sendprop offset.
   271 		 */
   272 		virtual int GetSendPropOffset(SendProp *prop) =0;
   273 	};
   274 }
   275 
   276 #endif //_INCLUDE_SOURCEMOD_GAMEHELPERS_H_