3 * ======================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
28 #ifndef _INCLUDE_CPLUGIN_H
29 #define _INCLUDE_CPLUGIN_H
32 * @brief Implementation of Plugin API and Management routines
36 #include <interface.h>
39 #include <sh_string.h>
40 #include "IPluginManager.h"
41 #include "metamod_oslink.h"
44 * History of plugin versions: (M=min, C=current)
45 * 1: Initial interface
46 * 2: Added GetLogTag()
47 * 3: Moved GetApiVersion() to top (2005-04-16)
48 * 4: Added AllPluginsLoaded() callback (2005-04-18)
49 * 5: Bumped version for SourceHook V4 (2005-05-01)
50 * 6: Added functions for console printing (2005-05-26)
51 * M 7: Changed template libraries (2005-08-11)
52 * New loading structure mechanism
53 * New SourceHook version
54 * 8: New SourceHook version (2005-12-23)
55 * New ISmmAPI additions
56 * 9: New ISmmPluginManager additions
57 * C 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
58 * C 11: New SourceHook version V5 (May, 2007)
61 #define PLAPI_MIN_VERSION 7
67 SourceHook::String alias;
68 SourceHook::String value;
71 * @brief Implements Plugin Manager API
73 class CPluginManager : public ISmmPluginManager
77 * @brief Internal structure for holding plugin data
85 SourceHook::String m_File;
90 SourceHook::List<ConCommandBase *> m_Cvars;
91 SourceHook::List<ConCommandBase *> m_Cmds;
92 SourceHook::List<IMetamodListener *> m_Events;
99 PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
100 bool Unload(PluginId id, bool force, char *error, size_t maxlen);
101 bool Pause(PluginId id, char *error, size_t maxlen);
102 bool Unpause(PluginId id, char *error, size_t maxlen);
104 void SetAlias(const char *alias, const char *value);
106 bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
107 bool QueryRunning(PluginId id, char *error, size_t maxlength);
108 bool QueryHandle(PluginId id, void *&handle);
110 void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
111 void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
112 void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
113 void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
116 * @brief Finds a plugin by Id
118 * @param id Id of plugin
119 * @return CPlugin on success, NULL otherwise
121 CPlugin *FindById(PluginId id);
123 CPlugin *FindByAPI(ISmmPlugin *api);
126 * @brief Attempts to reload a failed plugin
128 * @param id Id of plugin
129 * @param error Error message buffer
130 * @param len Maximum length of buffer
131 * @return True on success, false otherwise
133 bool Retry(PluginId id, char *error, size_t len);
135 int GetPluginCount();
136 const char *GetStatusText(CPlugin *pl);
139 const char *LookupAlias(const char *alias);
140 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
141 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
144 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
145 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
147 //These are identical internal functions for the wrappers above.
148 CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
149 bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
150 bool _Pause(CPlugin *pl, char *error, size_t maxlen);
151 bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
152 void UnregAllConCmds(CPlugin *pl);
155 SourceHook::List<CPlugin *> m_Plugins;
156 SourceHook::List<CNameAlias *> m_Aliases;
161 typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
163 /** @brief Singleton for plugin manager */
164 extern SourceMM::CPluginManager g_PluginMngr;
166 #endif //_INCLUDE_CPLUGIN_H