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