1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2007 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * ============================
11 #ifndef _INCLUDE_CPLUGIN_H
12 #define _INCLUDE_CPLUGIN_H
15 * @brief Implementation of Plugin API and Management routines
19 #include <interface.h>
22 #include <sh_string.h>
23 #include "IPluginManager.h"
24 #include "metamod_oslink.h"
27 * History of plugin versions: (M=min, C=current)
28 * 1: Initial interface
29 * 2: Added GetLogTag()
30 * 3: Moved GetApiVersion() to top (2005-04-16)
31 * 4: Added AllPluginsLoaded() callback (2005-04-18)
32 * 5: Bumped version for SourceHook V4 (2005-05-01)
33 * 6: Added functions for console printing (2005-05-26)
34 * M 7: Changed template libraries (2005-08-11)
35 * New loading structure mechanism
36 * New SourceHook version
37 * 8: New SourceHook version (2005-12-23)
38 * New ISmmAPI additions
39 * 9: New ISmmPluginManager additions
40 * C 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
41 * C 11: New SourceHook version V5 (May, 2007)
44 #define PLAPI_MIN_VERSION 7
50 SourceHook::String alias;
51 SourceHook::String value;
54 * @brief Implements Plugin Manager API
56 class CPluginManager : public ISmmPluginManager
60 * @brief Internal structure for holding plugin data
68 SourceHook::String m_File;
73 SourceHook::List<ConCommandBase *> m_Cvars;
74 SourceHook::List<ConCommandBase *> m_Cmds;
75 SourceHook::List<IMetamodListener *> m_Events;
82 PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
83 bool Unload(PluginId id, bool force, char *error, size_t maxlen);
84 bool Pause(PluginId id, char *error, size_t maxlen);
85 bool Unpause(PluginId id, char *error, size_t maxlen);
87 void SetAlias(const char *alias, const char *value);
89 bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
90 bool QueryRunning(PluginId id, char *error, size_t maxlength);
91 bool QueryHandle(PluginId id, void *&handle);
93 void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
94 void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
95 void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
96 void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
99 * @brief Finds a plugin by Id
101 * @param id Id of plugin
102 * @return CPlugin on success, NULL otherwise
104 CPlugin *FindById(PluginId id);
106 CPlugin *FindByAPI(ISmmPlugin *api);
109 * @brief Attempts to reload a failed plugin
111 * @param id Id of plugin
112 * @param error Error message buffer
113 * @param len Maximum length of buffer
114 * @return True on success, false otherwise
116 bool Retry(PluginId id, char *error, size_t len);
118 int GetPluginCount();
119 const char *GetStatusText(CPlugin *pl);
122 const char *LookupAlias(const char *alias);
123 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
124 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
127 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
128 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
130 //These are identical internal functions for the wrappers above.
131 CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
132 bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
133 bool _Pause(CPlugin *pl, char *error, size_t maxlen);
134 bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
135 void UnregAllConCmds(CPlugin *pl);
138 SourceHook::List<CPlugin *> m_Plugins;
139 SourceHook::List<CNameAlias *> m_Aliases;
144 typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
146 /** @brief Singleton for plugin manager */
147 extern SourceMM::CPluginManager g_PluginMngr;
149 #endif //_INCLUDE_CPLUGIN_H