public/IGameHelpers.h
author Kyle Sanderson <kyle.leet@gmail.com>
Mon Aug 12 00:54:21 2013 +0100 (2013-08-12)
changeset 3997 59bcfc51eb79
parent 3789 42e367aa4a00
permissions -rw-r--r--
Add support for nested datatables. (bug 5446, r=asherkin)
     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		10
    44 
    45 class CBaseEntity;
    46 class CBaseHandle;
    47 class SendProp;
    48 class ServerClass;
    49 class ICommandLine;
    50 struct edict_t;
    51 struct datamap_t;
    52 struct typedescription_t;
    53 
    54 #define TEXTMSG_DEST_NOTIFY  1
    55 #define TEXTMSG_DEST_CONSOLE 2
    56 #define TEXTMSG_DEST_CHAT    3
    57 #define TEXTMSG_DEST_CENTER  4
    58 
    59 namespace SourceMod
    60 {
    61 	/**
    62 	 * @brief Maps the heirarchy of a SendProp.
    63 	 */
    64 	struct sm_sendprop_info_t
    65 	{
    66 		SendProp *prop;					/**< Property instance. */
    67 		unsigned int actual_offset;		/**< Actual computed offset. */
    68 	};
    69 	
    70 	struct sm_datatable_info_t
    71 	{
    72 		typedescription_t *prop;			/**< Property instance. */
    73 		unsigned int actual_offset;		/**< Actual computed offset. */
    74 	};
    75 
    76 	class IGameHelpers : public SMInterface
    77 	{
    78 	public:
    79 		virtual const char *GetInterfaceName()
    80 		{
    81 			return SMINTERFACE_GAMEHELPERS_NAME;
    82 		}
    83 		virtual unsigned int GetInterfaceVersion()
    84 		{
    85 			return SMINTERFACE_GAMEHELPERS_VERSION;
    86 		}
    87 	public:
    88 		/**
    89 		 * @brief Deprecated; use FindSendPropInfo() instead.
    90 		 *
    91 		 * @param classname		Do not use.
    92 		 * @param offset		Do not use.
    93 		 * @return				Do not use.
    94 		 */
    95 		virtual SendProp *FindInSendTable(const char *classname, const char *offset) =0;
    96 
    97 		/**
    98 		 * @brief Finds a named server class.
    99 		 *
   100 		 * @return				ServerClass pointer on success, NULL on failure.
   101 		 */
   102 		virtual ServerClass *FindServerClass(const char *classname) =0;
   103 
   104 		/**
   105 		 * @brief Finds a datamap_t definition.
   106 		 *
   107 		 * @param pMap			datamap_t pointer.
   108 		 * @param offset		Property name.
   109 		 * @return				typedescription_t pointer on success, NULL 
   110 		 *						on failure.
   111 		 */
   112 		virtual typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset) =0;
   113 
   114 		/**
   115 		 * @brief Retrieves an entity's datamap_t pointer.
   116 		 *
   117 		 * @param pEntity		CBaseEntity entity.
   118 		 * @return				datamap_t pointer, or NULL on failure.
   119 		 */
   120 		virtual datamap_t *GetDataMap(CBaseEntity *pEntity) =0;
   121 
   122 		/**
   123 		 * @brief Marks an edict as state changed for an offset.
   124 		 *
   125 		 * @param pEdict		Edict pointer.
   126 		 * @param offset		Offset index.
   127 		 */
   128 		virtual void SetEdictStateChanged(edict_t *pEdict, unsigned short offset) =0;
   129 
   130 		/**
   131 		 * @brief Sends a text message to a client.
   132 		 *
   133 		 * @param client		Client index.
   134 		 * @param dest			Destination on the HUD (see TEXTMSG_DEST defines above).
   135 		 * @param msg			Message to send.
   136 		 * @return				True on success, false on failure.
   137 		 */
   138 		virtual bool TextMsg(int client, int dest, const char *msg) =0;
   139 		
   140 		/**
   141 		 * @brief Returns whether the server ls a LAN server.
   142 		 * 
   143 		 * @return				True if LAN server, false otherwise.
   144 		 */
   145 		virtual bool IsLANServer() =0;
   146 
   147 		/**
   148 		 * @brief Finds a send property in a named ServerClass.
   149 		 *
   150 		 * This version, unlike FindInSendTable(), correctly deduces the 
   151 		 * offsets of nested tables.
   152 		 *
   153 		 * @param classname		ServerClass name (such as CBasePlayer).
   154 		 * @param offset		Offset name (such as m_iAmmo).
   155 		 * @param info			Buffer to store sm_sendprop_info_t data.
   156 		 * @return				True on success, false on failure.
   157 		 */
   158 		virtual bool FindSendPropInfo(const char *classname,
   159 			const char *offset,
   160 			sm_sendprop_info_t *info) =0;
   161 
   162 		/**
   163 		 * @brief Converts an entity index into an edict pointer.
   164 		 *
   165 		 * @param index			Entity Index.
   166 		 * @return				Edict pointer or NULL on failure.
   167 		 */
   168 		virtual edict_t *EdictOfIndex(int index) =0;
   169 
   170 		/**
   171 		* @brief Converts an edict pointer into an entity index.
   172 		*
   173 		* @param index			Edict Pointer.
   174 		* @return				Entity index or -1 on failure.
   175 		*/
   176 		virtual int IndexOfEdict(edict_t *pEnt) =0;
   177 
   178 		/**
   179 		 * @brief Retrieves the edict pointer from a CBaseHandle object.
   180 		 *
   181 		 * @param hndl			CBaseHandle object.
   182 		 * @return				Edict pointer or NULL on failure.
   183 		 */
   184 		virtual edict_t *GetHandleEntity(CBaseHandle &hndl) =0;
   185 
   186 		/**
   187 		 * @brief Sets the edict pointer in a CBaseHandle object.
   188 		 *
   189 		 * @param hndl			CBaseHandle object.
   190 		 * @param pEnt			Edict pointer.
   191 		 * @noreturn
   192 		 */
   193 		virtual void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt) =0;
   194 
   195 		/**
   196 		 * @brief Returns the current map name.
   197 		 *
   198 		 * @return				Current map name.
   199 		 */
   200 		virtual const char *GetCurrentMap() =0;
   201 
   202 		/**
   203 		 * @brief Wraps IVEngineServer::ServerCommand.
   204 		 *
   205 		 * @param buffer		Command buffer (does not auto \n terminate).
   206 		 */
   207 		virtual void ServerCommand(const char *buffer) =0;
   208 
   209 		/**
   210 		 * @brief Looks up a reference and returns the CBasseEntity* it points to.
   211 		 *
   212 		 * @note Supports 'old style' simple indexes and does a serial confirmation check on references.
   213 		 *
   214 		 * @param entRef		Entity reference.
   215 		 * @return				Entity pointer.
   216 		 */
   217 		virtual CBaseEntity *ReferenceToEntity(cell_t entRef) =0;
   218 
   219 		/**
   220 		 * @brief Returns the entity reference for an entity.
   221 		 *
   222 		 * @param pEntity		Entity pointer.
   223 		 * @return				Entity reference.
   224 		 */
   225 		virtual cell_t EntityToReference(CBaseEntity *pEntity) =0;
   226 
   227 		/**
   228 		 * @brief Returns the entity reference for logical entities, or the index for networked entities.
   229 		 *
   230 		 * @param pEntity		Entity pointer.
   231 		 * @return				Entity reference/index.
   232 		 */
   233 		virtual cell_t EntityToBCompatRef(CBaseEntity *pEntity) =0;
   234 
   235 		/**
   236 		 * @brief Converts an entity index into an entity reference.
   237 		 *
   238 		 * @param entIndex		Entity index.
   239 		 * @return				Entity reference.
   240 		 */
   241 		virtual cell_t IndexToReference(int entIndex) =0;
   242 
   243 		/**
   244 		 * @brief Retrieves the entity index from a reference.
   245 		 *
   246 		 * @param entRef		Entity reference.
   247 		 * @return				Entity index.
   248 		 */
   249 		virtual int ReferenceToIndex(cell_t entRef) =0;
   250 
   251 		/**
   252 		 * @brief Converts a reference into a bcompat version (index for networked entities).
   253 		 *
   254 		 * @param entRef		Entity reference.
   255 		 * @return				Entity reference/index.
   256 		 */
   257 		virtual cell_t ReferenceToBCompatRef(cell_t entRef) =0;
   258 		
   259 		/**
   260 		 * @brief Returns the g_EntList pointer.
   261 		 *
   262 		 * @return				g_EntList pointer.
   263 		 */
   264 		virtual void *GetGlobalEntityList() =0;
   265 		
   266 		/**
   267 		 * @brief Adds a client to the kick queue, where they will be kicked
   268 		 * next game frame.
   269 		 *
   270 		 * The user ID is used to ensure the correct player is kicked.
   271 		 *
   272 		 * @param client		The index of the client to kick.
   273 		 * @param userid		The user ID of the client to kick.
   274 		 * @param msg			The kick message to show to the player.
   275 		 */
   276 		virtual void AddDelayedKick(int client, int userid, const char *msg) =0;
   277 
   278 		/**
   279 		 * @brief Returns the uncomputed offset of a SendProp.
   280 		 *
   281 		 * @param prop          SendProp pointer.
   282 		 * @return              Uncomputed sendprop offset.
   283 		 */
   284 		virtual int GetSendPropOffset(SendProp *prop) =0;
   285 		
   286 		/**
   287 		 * @brief Sends a hint message to a client.
   288 		 *
   289 		 * @param client		Client index.
   290 		 * @param msg			Message to send.
   291 		 * @return				True on success, false on failure.
   292 		 */
   293 		virtual bool HintTextMsg(int client, const char *msg) =0;
   294 
   295 		/**
   296 		 * @brief Retrieves the Valve command line pointer.
   297 		 *
   298 		 * @return				ICommandLine ptr or NULL if not found.
   299 		 */
   300 		virtual ICommandLine *GetValveCommandLine() =0;
   301 
   302 		/**
   303 		 * @brief Gets a Classname from an edict_t pointer.
   304 		 *
   305 		 * @param pEdict		edict_t pointer.
   306 		 * @return				Pointer to the string, or NULL if bad pointer.
   307 		 */
   308 		virtual const char *GetEntityClassname(edict_t *pEdict) =0;
   309 
   310 		/**
   311 		 * @brief Gets a Classname from an CBaseEntity pointer.
   312 		 *
   313 		 * @param pEntity		CBaseEntity pointer.
   314 		 * @return				Pointer to the string, or NULL if bad pointer.
   315 		 */
   316 		virtual const char *GetEntityClassname(CBaseEntity *pEntity) =0;
   317 
   318 		/**
   319 		 * @brief Returns whether or not a map name is valid to use with the
   320 		 * engine's Changelevel functionality. It need not be an exact filename on
   321 		 * some engines. For a check on the exact name, use IVEngineServer::IsMapValid.
   322 		 *
   323 		 * @param map			Map name.
   324 		 * @return				True if valid, otherwise false.
   325 		 */
   326 		virtual bool IsMapValid(const char *map) =0;
   327 		
   328 		/**
   329 		 * @brief Finds a datamap_t definition.
   330 		 *
   331 		 * @param pMap			datamap_t pointer.
   332 		 * @param offset			Property name.
   333 		 * @param pDataTable	Buffer to store sm_datatable_info_t data.
   334 		 * @return				typedescription_t pointer on success, NULL 
   335 		 *						on failure.
   336 		 */
   337 		virtual bool FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable) =0;
   338 	};
   339 }
   340 
   341 #endif //_INCLUDE_SOURCEMOD_GAMEHELPERS_H_