00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _INCLUDE_ISMM_PLUGIN_H
00029 #define _INCLUDE_ISMM_PLUGIN_H
00030
00037 #include <interface.h>
00038 #include <sourcehook.h>
00039 #include <IPluginManager.h>
00040 #include <ISmmAPI.h>
00041 #include <ISmmPluginExt.h>
00042
00043 namespace SourceMM
00044 {
00045 class ISmmAPI;
00046
00050 class ISmmPlugin
00051 {
00052 public:
00061 virtual int GetApiVersion()
00062 {
00063 return METAMOD_PLAPI_VERSION;
00064 }
00065
00069 virtual ~ISmmPlugin()
00070 {
00071 }
00072
00073 public:
00092 virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late) =0;
00093
00101 virtual void AllPluginsLoaded()
00102 {
00103 }
00104
00126 virtual bool QueryRunning(char *error, size_t maxlen)
00127 {
00128 return true;
00129 }
00130
00139 virtual bool Unload(char *error, size_t maxlen)
00140 {
00141 return true;
00142 }
00143
00151 virtual bool Pause(char *error, size_t maxlen)
00152 {
00153 return true;
00154 }
00155
00163 virtual bool Unpause(char *error, size_t maxlen)
00164 {
00165 return true;
00166 }
00167 public:
00169 virtual const char *GetAuthor() =0;
00170
00172 virtual const char *GetName() =0;
00173
00175 virtual const char *GetDescription() =0;
00176
00178 virtual const char *GetURL() =0;
00179
00181 virtual const char *GetLicense() =0;
00182
00184 virtual const char *GetVersion() =0;
00185
00187 virtual const char *GetDate() =0;
00188
00190 virtual const char *GetLogTag() =0;
00191 };
00192
00196 class IMetamodListener
00197 {
00198 public:
00204 virtual void OnPluginLoad(PluginId id)
00205 {
00206 }
00207
00213 virtual void OnPluginUnload(PluginId id)
00214 {
00215 }
00216
00222 virtual void OnPluginPause(PluginId id)
00223 {
00224 }
00225
00231 virtual void OnPluginUnpause(PluginId id)
00232 {
00233 }
00234
00249 virtual void OnLevelInit(char const *pMapName,
00250 char const *pMapEntities,
00251 char const *pOldLevel,
00252 char const *pLandmarkName,
00253 bool loadGame,
00254 bool background)
00255 {
00256 }
00257
00262 virtual void OnLevelShutdown()
00263 {
00264 }
00265
00278 virtual void *OnEngineQuery(const char *iface, int *ret)
00279 {
00280 if (ret)
00281 {
00282 *ret = IFACE_FAILED;
00283 }
00284
00285 return NULL;
00286 }
00287
00300 virtual void *OnPhysicsQuery(const char *iface, int *ret)
00301 {
00302 if (ret)
00303 {
00304 *ret = IFACE_FAILED;
00305 }
00306
00307 return NULL;
00308 }
00309
00322 virtual void *OnFileSystemQuery(const char *iface, int *ret)
00323 {
00324 if (ret)
00325 {
00326 *ret = IFACE_FAILED;
00327 }
00328
00329 return NULL;
00330 }
00331
00344 virtual void *OnGameDLLQuery(const char *iface, int *ret)
00345 {
00346 if (ret)
00347 {
00348 *ret = IFACE_FAILED;
00349 }
00350
00351 return NULL;
00352 }
00353
00365 virtual void *OnMetamodQuery(const char *iface, int *ret)
00366 {
00367 if (ret)
00368 {
00369 *ret = IFACE_FAILED;
00370 }
00371
00372 return NULL;
00373 }
00374
00398 virtual void OnVSPListening(IServerPluginCallbacks *iface)
00399 {
00400 }
00401
00412 virtual void OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
00413 {
00414 }
00415 };
00416 }
00417
00418 #if !defined METAMOD_NO_AUTO_NAMESPACE
00419 using namespace SourceMM;
00420 #endif
00421
00422 #define PL_EXPOSURE CreateInterface
00423 #define PL_EXPOSURE_C "CreateInterface"
00424
00434 #define PLUGIN_EXPOSE(name, var) \
00435 ISmmAPI *g_SMAPI = NULL; \
00436 ISmmPlugin *g_PLAPI = NULL; \
00437 PluginId g_PLID = (PluginId)0; \
00438 SourceHook::ISourceHook *g_SHPtr = NULL; \
00439 SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
00440 if (name && !strcmp(name, METAMOD_PLAPI_NAME)) { \
00441 return static_cast<void *>(&var); \
00442 } \
00443 return NULL; \
00444 }
00445
00446
00451 #define PLUGIN_GLOBALVARS() \
00452 extern SourceHook::ISourceHook *g_SHPtr; \
00453 extern ISmmAPI *g_SMAPI; \
00454 extern ISmmPlugin *g_PLAPI; \
00455 extern PluginId g_PLID;
00456
00460 #define PLUGIN_SAVEVARS() \
00461 g_SMAPI = ismm; \
00462 g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); \
00463 g_PLAPI = static_cast<ISmmPlugin *>(this); \
00464 g_PLID = id;
00465
00466 #define META_LOG g_SMAPI->LogMsg
00467 #define META_REGCMD(name) g_SMAPI->RegisterConCommandBase(g_PLAPI, name##_command)
00468 #define META_REGCVAR(var) g_SMAPI->RegisterConCommandBase(g_PLAPI, var)
00469 #define META_UNREGCMD(name) g_SMAPI->UnregisterConCommandBase(g_PLAPI, name##_command)
00470 #define META_UNREGCVAR(var) g_SMAPI->UnregisterConCommandBase(g_PLAPI, var)
00471 #define META_CONPRINT g_SMAPI->ConPrint
00472 #define META_CONPRINTF g_SMAPI->ConPrintf
00473
00474
00475 #define CONCMD_VARNAME(name) name##_command
00476
00477 #if !defined SMM_API
00478 #if defined __WIN32__ || defined _WIN32 || defined WIN32
00479 #define SMM_API extern "C" __declspec(dllexport)
00480 #elif defined __GNUC__
00481 #if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)
00482 #define SMM_API extern "C" __attribute__ ((visibility("default")))
00483 #else
00484 #define SMM_API extern "C"
00485 #endif
00486 #endif
00487 #endif
00488
00489
00497 #define GET_V_IFACE_CURRENT(v_factory, v_var, v_type, v_name) \
00498 v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name); \
00499 if (!v_var) \
00500 { \
00501 if (error && maxlen) \
00502 { \
00503 ismm->Format(error, maxlen, "Could not find interface: %s", v_name); \
00504 } \
00505 return false; \
00506 }
00507
00516 #define GET_V_IFACE_ANY(v_factory, v_var, v_type, v_name) \
00517 v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name, 0); \
00518 if (!v_var) \
00519 { \
00520 if (error && maxlen) \
00521 { \
00522 ismm->Format(error, maxlen, "Could not find interface: %s", v_name); \
00523 } \
00524 return false; \
00525 }
00526
00527 #endif //_INCLUDE_ISMM_PLUGIN_H
00528