00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _INCLUDE_ISMM_PLUGIN_H
00012 #define _INCLUDE_ISMM_PLUGIN_H
00013
00019 #include <interface.h>
00020 #include <sourcehook/sourcehook.h>
00021 #include "ISmmAPI.h"
00022
00023 #define PLAPI_VERSION 10
00024 #define PLAPI_NAME "ISmmPlugin"
00025
00026 class ISmmAPI;
00027
00028 class ISmmPlugin
00029 {
00030 public:
00031 virtual int GetApiVersion() { return PLAPI_VERSION; }
00032 virtual ~ISmmPlugin() { }
00033 public:
00051 virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late) =0;
00052
00070 virtual bool QueryRunning(char *error, size_t maxlen)
00071 {
00072 return true;
00073 }
00074
00083 virtual bool Unload(char *error, size_t maxlen)
00084 {
00085 return true;
00086 }
00087
00094 virtual bool Pause(char *error, size_t maxlen)
00095 {
00096 return true;
00097 }
00098
00105 virtual bool Unpause(char *error, size_t maxlen)
00106 {
00107 return true;
00108 }
00109 public:
00111 virtual const char *GetAuthor() =0;
00112
00114 virtual const char *GetName() =0;
00115
00117 virtual const char *GetDescription() =0;
00118
00120 virtual const char *GetURL() =0;
00121
00123 virtual const char *GetLicense() =0;
00124
00126 virtual const char *GetVersion() =0;
00127
00129 virtual const char *GetDate() =0;
00130
00132 virtual const char *GetLogTag() =0;
00133 public:
00140 virtual void AllPluginsLoaded()
00141 {
00142 }
00143 };
00144
00148 class IMetamodListener
00149 {
00150 public:
00151 virtual ~IMetamodListener() { }
00152 public:
00158 virtual void OnPluginLoad(PluginId id) { }
00159
00165 virtual void OnPluginUnload(PluginId id) { }
00166
00172 virtual void OnPluginPause(PluginId id) { }
00173
00179 virtual void OnPluginUnpause(PluginId id) { }
00180
00193 virtual void OnLevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) { }
00194
00198 virtual void OnLevelShutdown() { }
00199
00210 virtual void *OnEngineQuery(const char *iface, int *ret)
00211 {
00212 if (ret)
00213 {
00214 *ret = IFACE_FAILED;
00215 }
00216
00217 return NULL;
00218 }
00219
00230 virtual void *OnPhysicsQuery(const char *iface, int *ret)
00231 {
00232 if (ret)
00233 {
00234 *ret = IFACE_FAILED;
00235 }
00236
00237 return NULL;
00238 }
00239
00250 virtual void *OnFileSystemQuery(const char *iface, int *ret)
00251 {
00252 if (ret)
00253 {
00254 *ret = IFACE_FAILED;
00255 }
00256
00257 return NULL;
00258 }
00259
00270 virtual void *OnGameDLLQuery(const char *iface, int *ret)
00271 {
00272 if (ret)
00273 {
00274 *ret = IFACE_FAILED;
00275 }
00276
00277 return NULL;
00278 }
00279
00290 virtual void *OnMetamodQuery(const char *iface, int *ret)
00291 {
00292 if (ret)
00293 {
00294 *ret = IFACE_FAILED;
00295 }
00296
00297 return NULL;
00298 }
00299
00316 virtual void OnVSPListening(IServerPluginCallbacks *iface)
00317 {
00318 }
00319 };
00320
00321 #define PL_EXPOSURE CreateInterface
00322 #define PL_EXPOSURE_C "CreateInterface"
00323
00324 #define PLUGIN_EXPOSE(name, var) \
00325 ISmmAPI *g_SMAPI = NULL; \
00326 ISmmPlugin *g_PLAPI = NULL; \
00327 PluginId g_PLID = (PluginId)0; \
00328 SourceHook::ISourceHook *g_SHPtr = NULL; \
00329 SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
00330 if (name && !strcmp(name, PLAPI_NAME)) { \
00331 return static_cast<void *>(&var); \
00332 } \
00333 return NULL; \
00334 }
00335
00336 #define PLUGIN_GLOBALVARS() \
00337 extern SourceHook::ISourceHook *g_SHPtr; \
00338 extern ISmmAPI *g_SMAPI; \
00339 extern ISmmPlugin *g_PLAPI; \
00340 extern PluginId g_PLID;
00341
00342 #define PLUGIN_SAVEVARS() \
00343 g_SMAPI = ismm; \
00344 g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); \
00345 g_PLAPI = static_cast<ISmmPlugin *>(this); \
00346 g_PLID = id;
00347
00348 #define META_LOG g_SMAPI->LogMsg
00349 #define META_REGCMD(name) g_SMAPI->RegisterConCmdBase(g_PLAPI, name##_command)
00350 #define META_REGCVAR(var) g_SMAPI->RegisterConCmdBase(g_PLAPI, var)
00351 #define META_UNREGCMD(name) g_SMAPI->UnregisterConCmdBase(g_PLAPI, name##_command)
00352 #define META_UNREGCVAR(var) g_SMAPI->UnregisterConCmdBase(g_PLAPI, var)
00353 #define META_CONPRINT g_SMAPI->ConPrint
00354 #define META_CONPRINTF g_SMAPI->ConPrintf
00355
00356
00357 #define CONCMD_VARNAME(name) name##_command
00358
00359 #if !defined SMM_API
00360 #if defined __WIN32__ || defined _WIN32 || defined WIN32
00361 #define SMM_API extern "C" __declspec(dllexport)
00362 #elif defined __GNUC__
00363 #if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)
00364 #define SMM_API extern "C" __attribute__ ((visibility("default")))
00365 #else
00366 #define SMM_API extern "C"
00367 #endif
00368 #endif
00369 #endif
00370
00371
00379 #define GET_V_IFACE_CURRENT(v_factory, v_var, v_type, v_name) \
00380 v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name); \
00381 if (!v_var) \
00382 { \
00383 if (error && maxlen) \
00384 { \
00385 snprintf(error, maxlen, "Could not find interface: %s", v_name); \
00386 } \
00387 return false; \
00388 }
00389
00398 #define GET_V_IFACE_ANY(v_factory, v_var, v_type, v_name) \
00399 v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name, 0); \
00400 if (!v_var) \
00401 { \
00402 if (error && maxlen) \
00403 { \
00404 snprintf(error, maxlen, "Could not find interface: %s", v_name); \
00405 } \
00406 return false; \
00407 }
00408
00409 #endif //_INCLUDE_ISMM_PLUGIN_H