public/compat_wrappers.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed Aug 14 14:20:57 2013 -0400 (2013-08-14)
changeset 4008 490b01aa0683
parent 3913 a73cf1f26984
child 4212 a1d1392be904
permissions -rw-r--r--
Updated some CS:GO gamedata.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2010 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_COMPAT_WRAPPERS_H_
    33 #define _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
    34 
    35 #include <datamap.h>
    36 
    37 #if SOURCE_ENGINE >= SE_ORANGEBOX
    38 	#define CONVAR_REGISTER(object)				ConVar_Register(0, object)
    39 
    40 	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
    41 	{
    42 		return cmd->IsFlagSet(flag);
    43 	}
    44 	inline void InsertServerCommand(const char *buf)
    45 	{
    46 		engine->InsertServerCommand(buf);
    47 	}
    48 	inline ConCommandBase *FindCommandBase(const char *name)
    49 	{
    50 		return icvar->FindCommandBase(name);
    51 	}
    52 	inline ConCommand *FindCommand(const char *name)
    53 	{
    54 		return icvar->FindCommand(name);
    55 	}
    56 #else
    57 	class CCommand
    58 	{
    59 	public:
    60 		inline const char *ArgS() const
    61 		{
    62 			return engine->Cmd_Args();
    63 		}
    64 		inline int ArgC() const
    65 		{
    66 			return engine->Cmd_Argc();
    67 		}
    68 		inline const char *Arg(int index) const
    69 		{
    70 			return engine->Cmd_Argv(index);
    71 		}
    72 	};
    73 
    74 	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
    75 	{
    76 		return cmd->IsBitSet(flag);
    77 	}
    78 	inline void InsertServerCommand(const char *buf)
    79 	{
    80 		engine->InsertServerCommand(buf);
    81 	}
    82 	inline ConCommandBase *FindCommandBase(const char *name)
    83 	{
    84 		ConCommandBase *pBase = icvar->GetCommands();
    85 		while (pBase)
    86 		{
    87 			if (strcmp(pBase->GetName(), name) == 0)
    88 			{
    89 				if (!pBase->IsCommand())
    90 				{
    91 					return NULL;
    92 				}
    93 
    94 				return pBase;
    95 			}
    96 			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
    97 		}
    98 		return NULL;
    99 	}
   100 	inline ConCommand *FindCommand(const char *name)
   101 	{
   102 		ConCommandBase *pBase = icvar->GetCommands();
   103 		while (pBase)
   104 		{
   105 			if (strcmp(pBase->GetName(), name) == 0)
   106 			{
   107 				if (!pBase->IsCommand())
   108 				{
   109 					return NULL;
   110 				}
   111 
   112 				return static_cast<ConCommand *>(pBase);
   113 			}
   114 			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
   115 		}
   116 		return NULL;
   117 	}
   118 
   119 	#define CVAR_INTERFACE_VERSION				VENGINE_CVAR_INTERFACE_VERSION
   120 
   121 	#define CONVAR_REGISTER(object)				ConCommandBaseMgr::OneTimeInit(object)
   122 	typedef FnChangeCallback					FnChangeCallback_t;
   123 #endif //SOURCE_ENGINE >= SE_ORANGEBOX
   124 
   125 #if SOURCE_ENGINE >= SE_LEFT4DEAD
   126 	inline int IndexOfEdict(const edict_t *pEdict)
   127 	{
   128 		return (int)(pEdict - gpGlobals->pEdicts);
   129 	}
   130 	inline edict_t *PEntityOfEntIndex(int iEntIndex)
   131 	{
   132 		if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
   133 		{
   134 			return (edict_t *)(gpGlobals->pEdicts + iEntIndex);
   135 		}
   136 		return NULL;
   137 	}
   138 	inline int GetTypeDescOffs(typedescription_t *td)
   139 	{
   140 		return td->fieldOffset;
   141 	}
   142 #else
   143 	inline int IndexOfEdict(const edict_t *pEdict)
   144 	{
   145 		return engine->IndexOfEdict(pEdict);
   146 	}
   147 	inline edict_t *PEntityOfEntIndex(int iEntIndex)
   148 	{
   149 		return engine->PEntityOfEntIndex(iEntIndex);
   150 	}
   151 	inline int GetTypeDescOffs(typedescription_t *td)
   152 	{
   153 		return td->fieldOffset[TD_OFFSET_NORMAL];
   154 	}
   155 #endif //SOURCE_ENGINE >= SE_LEFT4DEAD
   156 
   157 #if SOURCE_ENGINE == SE_DOTA
   158 	inline int GetPlayerUserId(edict_t *pEdict)
   159 	{
   160 		return engine->GetPlayerUserId(IndexOfEdict(pEdict) - 1);
   161 	}
   162 
   163 	inline int GetPlayerUserId(int client)
   164 	{
   165 		engine->GetPlayerUserId(client - 1);
   166 	}
   167 #else
   168 	inline int GetPlayerUserId(edict_t *pEdict)
   169 	{
   170 		return engine->GetPlayerUserId(pEdict);
   171 	}
   172 
   173 	inline int GetPlayerUserId(int client)
   174 	{
   175 		return engine->GetPlayerUserId(PEntityOfEntIndex(client));
   176 	}
   177 #endif //SOURCE_ENGINE >= SE_DOTA
   178 
   179 #endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_