engine_wrappers.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef _INCLUDE_SOURCE_ENGINE_WRAPPERS_
  15. #define _INCLUDE_SOURCE_ENGINE_WRAPPERS_
  16. #include <eiface.h>
  17. extern IVEngineServer *engine;
  18. extern CGlobalVars *gpGlobals;
  19. #if SOURCE_ENGINE == SE_EPISODEONE && defined METAMOD_PLAPI_VERSION
  20. #error "Metamod:Source 1.6 API is not supported on the old engine."
  21. #endif
  22. #define ENGINE_CALL(func) SH_CALL(engine, &IVEngineServer::func)
  23. /**
  24. * Wrap some API calls for legacy MM:S.
  25. */
  26. #if !defined METAMOD_PLAPI_VERSION
  27. #define GetEngineFactory engineFactory
  28. #define GetServerFactory serverFactory
  29. #define MM_Format snprintf
  30. #define GetCGlobals pGlobals
  31. #else
  32. #define MM_Format g_SMAPI->Format
  33. #endif
  34. #if SOURCE_ENGINE <= SE_DARKMESSIAH
  35. /**
  36. * Wrap the CCommand class so our code looks the same on all engines.
  37. */
  38. class CCommand
  39. {
  40. public:
  41. const char *ArgS()
  42. {
  43. return engine->Cmd_Args();
  44. }
  45. int ArgC()
  46. {
  47. return engine->Cmd_Argc();
  48. }
  49. const char *Arg(int index)
  50. {
  51. return engine->Cmd_Argv(index);
  52. }
  53. };
  54. #define CVAR_INTERFACE_VERSION VENGINE_CVAR_INTERFACE_VERSION
  55. #endif
  56. /**
  57. * Left 4 Dead engine removed these from IVEngineServer.
  58. */
  59. #if SOURCE_ENGINE >= SE_LEFT4DEAD
  60. inline int IndexOfEdict(const edict_t *pEdict)
  61. {
  62. return (int)(pEdict - gpGlobals->pEdicts);
  63. }
  64. inline edict_t *PEntityOfEntIndex(int iEntIndex)
  65. {
  66. if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
  67. {
  68. return (edict_t *)(gpGlobals->pEdicts + iEntIndex);
  69. }
  70. return NULL;
  71. }
  72. #else
  73. inline int IndexOfEdict(const edict_t *pEdict)
  74. {
  75. return engine->IndexOfEdict(pEdict);
  76. }
  77. inline edict_t *PEntityOfEntIndex(int iEntIndex)
  78. {
  79. return engine->PEntityOfEntIndex(iEntIndex);
  80. }
  81. #endif
  82. #endif //_INCLUDE_SOURCE_ENGINE_WRAPPERS_