Added macro so that ConCommands created with the SDK's CON_COMMAND and CON_COMMAND_F macros can be properly registered and unregisterd
1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2005 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * ============================
11 #ifndef _INCLUDE_ISMM_PLUGIN_H
12 #define _INCLUDE_ISMM_PLUGIN_H
15 * @brief Plugin API interface
19 #include <interface.h>
20 #include <sourcehook/sourcehook.h>
23 #define PLAPI_VERSION 5
24 #define PLAPI_NAME "ISmmPlugin"
28 CreateInterfaceFn engine;
29 CreateInterfaceFn server;
30 CreateInterfaceFn physics;
31 CreateInterfaceFn fileSystem;
40 virtual int GetApiVersion() { return PLAPI_VERSION; }
43 * @brief Called on plugin load.
45 * @param id Internal id of plugin. Saved globally by PLUGIN_SAVEVARS()
46 * @param ismm External API for SourceMM. Saved globally by PLUGIN_SAVEVARS()
47 * @param list Contains a list of factories. Hook a factory call by setting one equal to your own function.
48 * @param error Error message buffer
49 * @param maxlen Size of error message buffer
50 * @return True on success, return false to request no load.
52 virtual bool Load(PluginId id, ISmmAPI *ismm, factories *list, char *error, size_t maxlen) =0;
54 /** @brief Called on plugin unload.
56 * @param error Error message buffer
57 * @param maxlen Size of error message buffer
58 * @return True on success, return false to request no unload.
60 virtual bool Unload(char *error, size_t maxlen) =0;
62 /** @brief Called on plugin pause.
64 * @param error Error message buffer
65 * @param maxlen Size of error message buffer
66 * @return True on success, return false to request no pause.
68 virtual bool Pause(char *error, size_t maxlen) =0;
70 /** @brief Called on plugin unpause.
72 * @param error Error message buffer
73 * @param maxlen Size of error message buffer
74 * @return True on success, return false to request no unpause.
76 virtual bool Unpause(char *error, size_t maxlen) =0;
78 /** @brief Return author as string */
79 virtual const char *GetAuthor() =0;
81 /** @brief Return plugin name as string */
82 virtual const char *GetName() =0;
84 /** @brief Return a description as string */
85 virtual const char *GetDescription() =0;
87 /** @brief Return a URL as string */
88 virtual const char *GetURL() =0;
90 /** @brief Return quick license code as string */
91 virtual const char *GetLicense() =0;
93 /** @brief Return version as string */
94 virtual const char *GetVersion() =0;
96 /** @brief Return author as string */
97 virtual const char *GetDate() =0;
99 /** @brief Return author as string */
100 virtual const char *GetLogTag() =0;
103 * @brief Called when all plugins have been loaded - API version 4
105 * Ths is useful for knowing when it's safe to request things another plugin might have.
107 virtual void AllPluginsLoaded() =0;
110 #define PL_EXPOSURE CreateInterface
111 #define PL_EXPOSURE_C "CreateInterface"
113 #define PLUGIN_EXPOSE(name, var) \
114 ISmmAPI *g_SMAPI = NULL; \
115 ISmmPlugin *g_PLAPI = NULL; \
116 PluginId g_PLID = (PluginId)0; \
117 SourceHook::ISourceHook *g_SHPtr = NULL; \
118 SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
119 if (name && !strcmp(name, PLAPI_NAME)) { \
120 return static_cast<void *>(&var); \
125 #define PLUGIN_GLOBALVARS() \
126 extern SourceHook::ISourceHook *g_SHPtr; \
127 extern ISmmAPI *g_SMAPI; \
128 extern ISmmPlugin *g_PLAPI; \
129 extern PluginId g_PLID;
131 #define PLUGIN_SAVEVARS() \
133 g_SHPtr = ismm->SourceHook(); \
134 g_PLAPI = static_cast<ISmmPlugin *>(this); \
137 #define FACTORY_RETURN(mres, value) \
138 g_SMAPI->SetLastMetaReturn(mres); \
141 #define META_LOG g_SMAPI->LogMsg
143 #define CONCMD_VARNAME(name) name##_command
146 #if defined __WIN32__ || defined _WIN32 || defined WIN32
147 #define SMM_API extern "C" __declspec(dllexport)
148 #elif defined __GNUC__
149 #define SMM_API extern "C"
151 #endif //!defined SMM_API
153 #endif //_INCLUDE_ISMM_PLUGIN_H