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 #define SMINTERFACE_EXTENSIONAPI_VERSION 1
75 * @brief The interface an extension must expose.
77 class IExtensionInterface
80 virtual unsigned int GetExtensionVersion()
82 return SMINTERFACE_EXTENSIONAPI_VERSION;
86 * @brief Called when the extension is loaded.
88 * @param me Pointer back to extension.
89 * @param sys Pointer to interface sharing system of SourceMod.
90 * @param error Error buffer to print back to, if any.
91 * @param err_max Maximum size of error buffer.
92 * @param late If this extension was loaded "late" (i.e. manually).
93 * @return True if load should continue, false otherwise.
95 virtual bool OnExtensionLoad(IExtension *me,
102 * @brief Called when the extension is about to be unloaded.
104 virtual void OnExtensionUnload() =0;
107 * @brief Called when all extensions are loaded (loading cycle is done).
108 * If loaded late, this will be called right after OnExtensionLoad().
110 virtual void OnExtensionsAllLoaded() =0;
113 * @brief Called when your pause state is about to change.
115 * @param pause True if pausing, false if unpausing.
117 virtual void OnExtensionPauseChange(bool pause) =0;
120 * @brief Asks the extension whether it's safe to remove an external interface it's using.
121 * If it's not safe, return false, and the extension will be unloaded afterwards.
122 * NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources.
124 * @param pInterface Pointer to interface being dropped.
125 * @return True to continue, false to unload this extension afterwards.
127 virtual bool QueryInterfaceDrop(SMInterface *pInterface)
133 * @brief Notifies the extension that an external interface it uses is being removed.
135 * @param pInterface Pointer to interface being dropped.
137 virtual void NotifyInterfaceDrop(SMInterface *pInterface)
141 virtual bool IsMetamodExtension() =0;
142 virtual const char *GetExtensionName() =0;
143 virtual const char *GetExtensionURL() =0;
144 virtual const char *GetExtensionTag() =0;
145 virtual const char *GetExtensionAuthor() =0;
146 virtual const char *GetExtensionVerString() =0;
147 virtual const char *GetExtensionDescription() =0;
148 virtual const char *GetExtensionDateString() =0;
151 #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
152 #define SMINTERFACE_EXTENSIONMANAGER_VERSION 1
154 enum ExtensionLifetime
156 ExtLifetime_Forever, //Extension will never be unloaded automatically
157 ExtLifetime_Map, //Extension will be unloaded at the end of the map
160 class IExtensionManager : public SMInterface
163 virtual const char *GetInterfaceName()
165 return SMINTERFACE_EXTENSIONMANAGER_NAME;
167 virtual unsigned int GetInterfaceVersion()
169 return SMINTERFACE_EXTENSIONMANAGER_VERSION;
173 * @brief Loads a extension into the extension system.
175 * @param path Path to extension file, relative to the extensions folder.
176 * @param lifetime Lifetime of the extension.
177 * @param error Error buffer.
178 * @param err_max Maximum error buffer length.
179 * @return New IExtension on success, NULL on failure.
181 virtual IExtension *LoadExtension(const char *path,
182 ExtensionLifetime lifetime,
187 * @brief Attempts to unload a module.
189 * @param pExt IExtension pointer.
190 * @return True if successful, false otherwise.
192 virtual bool UnloadExtension(IExtension *pExt) =0;
196 #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_