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 * 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 * 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
58 * 11: New SourceHook version v4.5 (May, 2007)
60 * MC 13: Breaking of API for next SH version and other API changes
63 #define PLAPI_MIN_VERSION 13
69 SourceHook::String alias;
70 SourceHook::String value;
73 * @brief Implements Plugin Manager API
75 class CPluginManager : public ISmmPluginManager
79 * @brief Internal structure for holding plugin data
87 SourceHook::String m_File;
92 SourceHook::List<ConCommandBase *> m_Cvars;
93 SourceHook::List<ConCommandBase *> m_Cmds;
94 SourceHook::List<IMetamodListener *> m_Events;
101 PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
102 bool Unload(PluginId id, bool force, char *error, size_t maxlen);
103 bool Pause(PluginId id, char *error, size_t maxlen);
104 bool Unpause(PluginId id, char *error, size_t maxlen);
106 void SetAlias(const char *alias, const char *value);
108 bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
109 bool QueryRunning(PluginId id, char *error, size_t maxlength);
110 bool QueryHandle(PluginId id, void *&handle);
112 void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
113 void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
114 void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
115 void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
118 * @brief Finds a plugin by Id
120 * @param id Id of plugin
121 * @return CPlugin on success, NULL otherwise
123 CPlugin *FindById(PluginId id);
125 CPlugin *FindByAPI(ISmmPlugin *api);
128 * @brief Attempts to reload a failed plugin
130 * @param id Id of plugin
131 * @param error Error message buffer
132 * @param len Maximum length of buffer
133 * @return True on success, false otherwise
135 bool Retry(PluginId id, char *error, size_t len);
137 int GetPluginCount();
138 const char *GetStatusText(CPlugin *pl);
141 const char *LookupAlias(const char *alias);
142 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
143 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
146 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
147 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
149 //These are identical internal functions for the wrappers above.
150 CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
151 bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
152 bool _Pause(CPlugin *pl, char *error, size_t maxlen);
153 bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
154 void UnregAllConCmds(CPlugin *pl);
157 SourceHook::List<CPlugin *> m_Plugins;
158 SourceHook::List<CNameAlias *> m_Aliases;
163 typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
165 /** @brief Singleton for plugin manager */
166 extern SourceMM::CPluginManager g_PluginMngr;
168 #endif //_INCLUDE_CPLUGIN_H