1 #ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
2 #define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
5 #include <ILibrarySys.h>
9 class IExtensionInterface;
10 typedef void * ITERATOR;
13 * @brief Encapsulates an IExtension.
19 * @brief Returns whether or not the extension is properly loaded.
21 virtual bool IsLoaded() =0;
24 * @brief Returns the extension's API interface
26 * @return An IExtensionInterface pointer.
28 virtual IExtensionInterface *GetAPI() =0;
31 * @brief Returns the filename of the extension, relative to the
34 * @return A string containing the extension file name.
36 virtual const char *GetFilename() =0;
39 * @brief Returns the extension's identity token.
41 * @return An IdentityToken_t pointer.
43 virtual IdentityToken_t *GetIdentity() =0;
46 * @brief Retrieves the extension dependency list for this extension.
48 * @param pOwner Optional pointer to store the first interface's owner.
49 * @param pInterface Optional pointer to store the first interface.
50 * @return An ITERATOR pointer for the results, or NULL if no results at all.
52 virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
55 * @brief Finds the next dependency in the dependency list.
57 * @param iter Pointer to iterator from FindFirstDependency.
58 * @param pOwner Optional pointer to store the interface's owner.
59 * @param pInterface Optional pointer to store the interface.
60 * @return True if there are more results after this, false otherwise.
62 virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
65 * @brief Frees an ITERATOR handle from FindFirstDependency.
67 * @param iter Pointer to iterator to free.
69 virtual void FreeDependencyIterator(ITERATOR *iter) =0;
72 * @brief Queries the extension to see its run state.
74 * @param error Error buffer (may be NULL).
75 * @param maxlength Maximum length of buffer.
76 * @return True if extension is okay, false if not okay.
78 virtual bool IsRunning(char *error, size_t maxlength) =0;
81 #define SMINTERFACE_EXTENSIONAPI_VERSION 1
84 * @brief The interface an extension must expose.
86 class IExtensionInterface
89 virtual unsigned int GetExtensionVersion()
91 return SMINTERFACE_EXTENSIONAPI_VERSION;
95 * @brief Called when the extension is loaded.
97 * @param me Pointer back to extension.
98 * @param sys Pointer to interface sharing system of SourceMod.
99 * @param error Error buffer to print back to, if any.
100 * @param err_max Maximum size of error buffer.
101 * @param late If this extension was loaded "late" (i.e. manually).
102 * @return True if load should continue, false otherwise.
104 virtual bool OnExtensionLoad(IExtension *me,
111 * @brief Called when the extension is about to be unloaded.
113 virtual void OnExtensionUnload() =0;
116 * @brief Called when all extensions are loaded (loading cycle is done).
117 * If loaded late, this will be called right after OnExtensionLoad().
119 virtual void OnExtensionsAllLoaded() =0;
122 * @brief Called when your pause state is about to change.
124 * @param pause True if pausing, false if unpausing.
126 virtual void OnExtensionPauseChange(bool pause) =0;
129 * @brief Asks the extension whether it's safe to remove an external interface it's using.
130 * If it's not safe, return false, and the extension will be unloaded afterwards.
131 * NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources.
133 * @param pInterface Pointer to interface being dropped.
134 * @return True to continue, false to unload this extension afterwards.
136 virtual bool QueryInterfaceDrop(SMInterface *pInterface)
142 * @brief Notifies the extension that an external interface it uses is being removed.
144 * @param pInterface Pointer to interface being dropped.
146 virtual void NotifyInterfaceDrop(SMInterface *pInterface)
151 * @brief Return false to tell Core that your extension should be considered unsable.
153 * @param error Error buffer.
154 * @param maxlength Size of error buffer.
155 * @return True on success, false otherwise.
157 virtual bool QueryRunning(char *error, size_t maxlength)
162 virtual bool IsMetamodExtension() =0;
163 virtual const char *GetExtensionName() =0;
164 virtual const char *GetExtensionURL() =0;
165 virtual const char *GetExtensionTag() =0;
166 virtual const char *GetExtensionAuthor() =0;
167 virtual const char *GetExtensionVerString() =0;
168 virtual const char *GetExtensionDescription() =0;
169 virtual const char *GetExtensionDateString() =0;
172 #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
173 #define SMINTERFACE_EXTENSIONMANAGER_VERSION 1
175 enum ExtensionLifetime
177 ExtLifetime_Forever, //Extension will never be unloaded automatically
178 ExtLifetime_Map, //Extension will be unloaded at the end of the map
181 class IExtensionManager : public SMInterface
184 virtual const char *GetInterfaceName()
186 return SMINTERFACE_EXTENSIONMANAGER_NAME;
188 virtual unsigned int GetInterfaceVersion()
190 return SMINTERFACE_EXTENSIONMANAGER_VERSION;
194 * @brief Loads a extension into the extension system.
196 * @param path Path to extension file, relative to the extensions folder.
197 * @param lifetime Lifetime of the extension (currently ignored).
198 * @param error Error buffer.
199 * @param err_max Maximum error buffer length.
200 * @return New IExtension on success, NULL on failure.
202 virtual IExtension *LoadExtension(const char *path,
203 ExtensionLifetime lifetime,
208 * @brief Attempts to unload a module.
210 * @param pExt IExtension pointer.
211 * @return True if successful, false otherwise.
213 virtual bool UnloadExtension(IExtension *pExt) =0;
217 #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_