public/compat_wrappers.h
author Nicholas Hastings <skamonkey@gmail.com>
Mon Apr 29 21:20:11 2013 -0400 (2013-04-29)
changeset 3903 7d07b4f23cd0
parent 3099 1b7bf8509625
child 3913 a73cf1f26984
permissions -rw-r--r--
Updated TF2 gamedata.
faluco@1541
     1
/**
faluco@1541
     2
 * vim: set ts=4 :
faluco@1541
     3
 * =============================================================================
faluco@1541
     4
 * SourceMod
ds@3099
     5
 * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
faluco@1541
     6
 * =============================================================================
faluco@1541
     7
 *
faluco@1541
     8
 * This program is free software; you can redistribute it and/or modify it under
faluco@1541
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
faluco@1541
    10
 * Free Software Foundation.
faluco@1541
    11
 * 
faluco@1541
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
faluco@1541
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
faluco@1541
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
faluco@1541
    15
 * details.
faluco@1541
    16
 *
faluco@1541
    17
 * You should have received a copy of the GNU General Public License along with
faluco@1541
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
faluco@1541
    19
 *
faluco@1541
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
faluco@1541
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
faluco@1541
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
faluco@1541
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
faluco@1541
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
faluco@1541
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
faluco@1541
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
faluco@1541
    27
 * or <http://www.sourcemod.net/license.php>.
faluco@1541
    28
 *
faluco@1541
    29
 * Version: $Id$
faluco@1541
    30
 */
faluco@1541
    31
faluco@1541
    32
#ifndef _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
faluco@1541
    33
#define _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
faluco@1541
    34
ds@3099
    35
#include <datamap.h>
ds@3099
    36
ds@2400
    37
#if SOURCE_ENGINE >= SE_ORANGEBOX
faluco@1541
    38
	#define CONVAR_REGISTER(object)				ConVar_Register(0, object)
faluco@1541
    39
faluco@1541
    40
	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
faluco@1541
    41
	{
faluco@1541
    42
		return cmd->IsFlagSet(flag);
faluco@1541
    43
	}
faluco@1541
    44
	inline void InsertServerCommand(const char *buf)
faluco@1541
    45
	{
dvander@1731
    46
		engine->InsertServerCommand(buf);
faluco@1541
    47
	}
ds@2400
    48
	inline ConCommandBase *FindCommandBase(const char *name)
ds@2400
    49
	{
ds@2400
    50
		return icvar->FindCommandBase(name);
ds@2400
    51
	}
ds@2400
    52
	inline ConCommand *FindCommand(const char *name)
ds@2400
    53
	{
ds@2400
    54
		return icvar->FindCommand(name);
ds@2400
    55
	}
faluco@1541
    56
#else
faluco@1541
    57
	class CCommand
faluco@1541
    58
	{
faluco@1541
    59
	public:
faluco@1541
    60
		inline const char *ArgS() const
faluco@1541
    61
		{
faluco@1541
    62
			return engine->Cmd_Args();
faluco@1541
    63
		}
faluco@1541
    64
		inline int ArgC() const
faluco@1541
    65
		{
faluco@1541
    66
			return engine->Cmd_Argc();
faluco@1541
    67
		}
faluco@1541
    68
		inline const char *Arg(int index) const
faluco@1541
    69
		{
faluco@1541
    70
			return engine->Cmd_Argv(index);
faluco@1541
    71
		}
faluco@1541
    72
	};
faluco@1541
    73
faluco@1541
    74
	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
faluco@1541
    75
	{
faluco@1541
    76
		return cmd->IsBitSet(flag);
faluco@1541
    77
	}
faluco@1541
    78
	inline void InsertServerCommand(const char *buf)
faluco@1541
    79
	{
faluco@1541
    80
		engine->InsertServerCommand(buf);
faluco@1541
    81
	}
ds@2400
    82
	inline ConCommandBase *FindCommandBase(const char *name)
ds@2400
    83
	{
ds@2400
    84
		ConCommandBase *pBase = icvar->GetCommands();
ds@2400
    85
		while (pBase)
ds@2400
    86
		{
ds@2400
    87
			if (strcmp(pBase->GetName(), name) == 0)
ds@2400
    88
			{
fyrenmoo@2693
    89
				if (!pBase->IsCommand())
ds@2400
    90
				{
ds@2400
    91
					return NULL;
ds@2400
    92
				}
ds@2400
    93
ds@2400
    94
				return pBase;
ds@2400
    95
			}
ds@2400
    96
			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
ds@2400
    97
		}
ds@2400
    98
		return NULL;
ds@2400
    99
	}
ds@2400
   100
	inline ConCommand *FindCommand(const char *name)
ds@2400
   101
	{
ds@2400
   102
		ConCommandBase *pBase = icvar->GetCommands();
ds@2400
   103
		while (pBase)
ds@2400
   104
		{
ds@2400
   105
			if (strcmp(pBase->GetName(), name) == 0)
ds@2400
   106
			{
ds@2400
   107
				if (!pBase->IsCommand())
ds@2400
   108
				{
ds@2400
   109
					return NULL;
ds@2400
   110
				}
ds@2400
   111
ds@2400
   112
				return static_cast<ConCommand *>(pBase);
ds@2400
   113
			}
ds@2400
   114
			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
ds@2400
   115
		}
ds@2400
   116
		return NULL;
ds@2400
   117
	}
faluco@1541
   118
dvander@1545
   119
	#define CVAR_INTERFACE_VERSION				VENGINE_CVAR_INTERFACE_VERSION
dvander@1545
   120
faluco@1541
   121
	#define CONVAR_REGISTER(object)				ConCommandBaseMgr::OneTimeInit(object)
faluco@1541
   122
	typedef FnChangeCallback					FnChangeCallback_t;
ds@2400
   123
#endif //SOURCE_ENGINE >= SE_ORANGEBOX
ds@2400
   124
ds@2400
   125
#if SOURCE_ENGINE >= SE_LEFT4DEAD
ds@2400
   126
	inline int IndexOfEdict(const edict_t *pEdict)
ds@2400
   127
	{
ds@3099
   128
		return (int)(pEdict - gpGlobals->pEdicts);
ds@2400
   129
	}
ds@2400
   130
	inline edict_t *PEntityOfEntIndex(int iEntIndex)
ds@2400
   131
	{
ds@2400
   132
		if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
ds@2400
   133
		{
ds@3099
   134
			return (edict_t *)(gpGlobals->pEdicts + iEntIndex);
ds@2400
   135
		}
ds@2400
   136
		return NULL;
ds@2400
   137
	}
ds@3099
   138
	inline int GetTypeDescOffs(typedescription_t *td)
ds@3099
   139
	{
ds@3099
   140
		return td->fieldOffset;
ds@3099
   141
	}
ds@2400
   142
#else
ds@2400
   143
	inline int IndexOfEdict(const edict_t *pEdict)
ds@2400
   144
	{
ds@2400
   145
		return engine->IndexOfEdict(pEdict);
ds@2400
   146
	}
ds@2400
   147
	inline edict_t *PEntityOfEntIndex(int iEntIndex)
ds@2400
   148
	{
ds@2400
   149
		return engine->PEntityOfEntIndex(iEntIndex);
ds@2400
   150
	}
ds@3099
   151
	inline int GetTypeDescOffs(typedescription_t *td)
ds@3099
   152
	{
ds@3099
   153
		return td->fieldOffset[TD_OFFSET_NORMAL];
ds@3099
   154
	}
ds@2400
   155
#endif //SOURCE_ENGINE >= SE_LEFT4DEAD
faluco@1541
   156
faluco@1541
   157
#endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_