public/compat_wrappers.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 4261 32e36d3570f0
permissions -rw-r--r--
Update CS:GO team score 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 		static int MaxCommandLength() { return 512; }
    74 	};
    75 
    76 	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
    77 	{
    78 		return cmd->IsBitSet(flag);
    79 	}
    80 	inline void InsertServerCommand(const char *buf)
    81 	{
    82 		engine->InsertServerCommand(buf);
    83 	}
    84 	inline ConCommandBase *FindCommandBase(const char *name)
    85 	{
    86 		ConCommandBase *pBase = icvar->GetCommands();
    87 		while (pBase)
    88 		{
    89 			if (strcmp(pBase->GetName(), name) == 0)
    90 			{
    91 				if (!pBase->IsCommand())
    92 				{
    93 					return NULL;
    94 				}
    95 
    96 				return pBase;
    97 			}
    98 			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
    99 		}
   100 		return NULL;
   101 	}
   102 	inline ConCommand *FindCommand(const char *name)
   103 	{
   104 		ConCommandBase *pBase = icvar->GetCommands();
   105 		while (pBase)
   106 		{
   107 			if (strcmp(pBase->GetName(), name) == 0)
   108 			{
   109 				if (!pBase->IsCommand())
   110 				{
   111 					return NULL;
   112 				}
   113 
   114 				return static_cast<ConCommand *>(pBase);
   115 			}
   116 			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
   117 		}
   118 		return NULL;
   119 	}
   120 
   121 	#define CVAR_INTERFACE_VERSION				VENGINE_CVAR_INTERFACE_VERSION
   122 
   123 	#define CONVAR_REGISTER(object)				ConCommandBaseMgr::OneTimeInit(object)
   124 	typedef FnChangeCallback					FnChangeCallback_t;
   125 #endif //SOURCE_ENGINE >= SE_ORANGEBOX
   126 
   127 #if SOURCE_ENGINE >= SE_LEFT4DEAD
   128 	inline int IndexOfEdict(const edict_t *pEdict)
   129 	{
   130 		return (int)(pEdict - gpGlobals->pEdicts);
   131 	}
   132 	inline edict_t *PEntityOfEntIndex(int iEntIndex)
   133 	{
   134 		if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
   135 		{
   136 			return (edict_t *)(gpGlobals->pEdicts + iEntIndex);
   137 		}
   138 		return NULL;
   139 	}
   140 	inline int GetTypeDescOffs(typedescription_t *td)
   141 	{
   142 		return td->fieldOffset;
   143 	}
   144 #else
   145 	inline int IndexOfEdict(const edict_t *pEdict)
   146 	{
   147 		return engine->IndexOfEdict(pEdict);
   148 	}
   149 	inline edict_t *PEntityOfEntIndex(int iEntIndex)
   150 	{
   151 		return engine->PEntityOfEntIndex(iEntIndex);
   152 	}
   153 	inline int GetTypeDescOffs(typedescription_t *td)
   154 	{
   155 		return td->fieldOffset[TD_OFFSET_NORMAL];
   156 	}
   157 #endif //SOURCE_ENGINE >= SE_LEFT4DEAD
   158 
   159 #if SOURCE_ENGINE == SE_DOTA
   160 	inline int GetPlayerUserId(edict_t *pEdict)
   161 	{
   162 		return engine->GetPlayerUserId(IndexOfEdict(pEdict) - 1);
   163 	}
   164 
   165 	inline int GetPlayerUserId(int client)
   166 	{
   167 		return engine->GetPlayerUserId(client - 1);
   168 	}
   169 #else
   170 	inline int GetPlayerUserId(edict_t *pEdict)
   171 	{
   172 		return engine->GetPlayerUserId(pEdict);
   173 	}
   174 
   175 	inline int GetPlayerUserId(int client)
   176 	{
   177 		return engine->GetPlayerUserId(PEntityOfEntIndex(client));
   178 	}
   179 #endif //SOURCE_ENGINE >= SE_DOTA
   180 
   181 #endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_