sample_mm/engine_wrappers.h
author David Anderson <dvander@alliedmods.net>
Sat Dec 19 16:50:07 2009 -0800 (2009-12-19)
changeset 692 0133b1bed407
parent 678 c676a9ce0320
child 726 97c3e79dc80f
permissions -rw-r--r--
Pinned release version strings.
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * ======================================================
     4  * Metamod:Source Sample Plugin
     5  * Written by AlliedModders LLC.
     6  * ======================================================
     7  *
     8  * This software is provided 'as-is', without any express or implied warranty.
     9  * In no event will the authors be held liable for any damages arising from 
    10  * the use of this software.
    11  *
    12  * This sample plugin is public domain.
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCE_ENGINE_WRAPPERS_
    16 #define _INCLUDE_SOURCE_ENGINE_WRAPPERS_
    17 
    18 #include <eiface.h>
    19 
    20 extern IVEngineServer *engine;
    21 extern CGlobalVars *gpGlobals;
    22 
    23 #if SOURCE_ENGINE == SE_EPISODEONE && defined METAMOD_PLAPI_VERSION
    24 #error "Metamod:Source 1.6 API is not supported on the old engine."
    25 #endif
    26 
    27 #define ENGINE_CALL(func) SH_CALL(engine, &IVEngineServer::func)
    28 
    29 /**
    30  * Wrap some API calls for legacy MM:S.
    31  */
    32 #if !defined METAMOD_PLAPI_VERSION
    33 #define GetEngineFactory engineFactory
    34 #define GetServerFactory serverFactory
    35 #define MM_Format snprintf
    36 #define	GetCGlobals	pGlobals
    37 #else
    38 #define MM_Format g_SMAPI->Format
    39 #endif
    40 
    41 #if SOURCE_ENGINE <= SE_DARKMESSIAH
    42 /**
    43  * Wrap the CCommand class so our code looks the same on all engines.
    44  */
    45 class CCommand
    46 {
    47 public:
    48 	const char *ArgS()
    49 	{
    50 		return engine->Cmd_Args();
    51 	}
    52 	int ArgC()
    53 	{
    54 		return engine->Cmd_Argc();
    55 	}
    56 
    57 	const char *Arg(int index)
    58 	{
    59 		return engine->Cmd_Argv(index);
    60 	}
    61 };
    62 
    63 #define CVAR_INTERFACE_VERSION VENGINE_CVAR_INTERFACE_VERSION
    64 #endif
    65 
    66 /**
    67  * Left 4 Dead engine removed these from IVEngineServer.
    68  */
    69 #if SOURCE_ENGINE >= SE_LEFT4DEAD
    70 
    71 inline int IndexOfEdict(const edict_t *pEdict)
    72 {
    73 	return (int)(pEdict - gpGlobals->baseEdict);
    74 }
    75 inline edict_t *PEntityOfEntIndex(int iEntIndex)
    76 {
    77 	if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
    78 	{
    79 		return (edict_t *)(gpGlobals->baseEdict + iEntIndex);
    80 	}
    81 	return NULL;
    82 }
    83 
    84 #else
    85 
    86 inline int IndexOfEdict(const edict_t *pEdict)
    87 {
    88 	return engine->IndexOfEdict(pEdict);
    89 }
    90 inline edict_t *PEntityOfEntIndex(int iEntIndex)
    91 {
    92 	return engine->PEntityOfEntIndex(iEntIndex);
    93 }
    94 
    95 #endif
    96 
    97 #endif //_INCLUDE_SOURCE_ENGINE_WRAPPERS_
    98