3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
33 #define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
35 #include <IExtensionSys.h>
36 #include <ILibrarySys.h>
38 #include <sh_string.h>
39 #include <sm_trie_tpl.h>
40 #include "sm_globals.h"
43 #include <IPluginSys.h>
44 #include <IRootConsoleMenu.h>
45 #include "PluginSys.h"
46 #include "NativeOwner.h"
50 using namespace SourceMod;
51 using namespace SourceHook;
58 const sp_nativeinfo_t *info;
65 friend class CExtensionManager;
67 virtual ~CExtension();
69 IExtensionInterface *GetAPI();
70 const char *GetFilename();
71 const char *GetPath() const;
72 IdentityToken_t *GetIdentity();
73 ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
74 bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
75 void FreeDependencyIterator(ITERATOR *iter);
76 bool IsRunning(char *error, size_t maxlength);
78 void SetError(const char *error);
79 void AddDependency(const IfaceInfo *pInfo);
80 void AddChildDependent(CExtension *pOther, SMInterface *iface);
81 void AddInterface(SMInterface *pInterface);
82 void AddPlugin(CPlugin *pPlugin);
84 void AddLibrary(const char *library);
86 virtual bool Load(char *error, size_t maxlength);
87 virtual bool IsLoaded() =0;
88 virtual void Unload() =0;
89 virtual bool Reload(char *error, size_t maxlength) =0;
90 virtual bool IsSameFile(const char* file) =0;
92 void Initialize(const char *filename, const char *path);
93 bool PerformAPICheck(char *error, size_t maxlength);
94 void CreateIdentity();
95 void DestroyIdentity();
97 IdentityToken_t *m_pIdentToken;
98 IExtensionInterface *m_pAPI;
103 List<IfaceInfo> m_Deps; /** Dependencies */
104 List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
105 List<SMInterface *> m_Interfaces;
106 List<String> m_Libraries;
107 unsigned int unload_code;
111 class CLocalExtension : public CExtension
114 CLocalExtension(const char *filename);
116 bool Load(char *error, size_t maxlength);
119 bool Reload(char *error, size_t maxlength);
121 bool IsSameFile(const char *file);
127 class CRemoteExtension : public CExtension
130 CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path);
132 bool Load(char *error, size_t maxlength);
135 bool Reload(char *error, size_t maxlength);
137 bool IsSameFile(const char *file);
140 class CExtensionManager :
141 public IExtensionManager,
142 public SMGlobalClass,
143 public IPluginsListener,
144 public IRootConsoleCommand
148 ~CExtensionManager();
149 public: //SMGlobalClass
150 void OnSourceModAllInitialized();
151 void OnSourceModShutdown();
152 public: //IExtensionManager
153 IExtension *LoadExtension(const char *path,
156 bool UnloadExtension(IExtension *pExt);
157 IExtension *FindExtensionByFile(const char *file);
158 IExtension *FindExtensionByName(const char *ext);
159 IExtension *LoadExternal(IExtensionInterface *pInterface,
160 const char *filepath,
161 const char *filename,
164 public: //IPluginsListener
165 void OnPluginDestroyed(IPlugin *plugin);
166 public: //IRootConsoleCommand
167 void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
169 IExtension *LoadAutoExtension(const char *path, bool bErrorOnMissing=true);
170 void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
171 void AddInterface(IExtension *pOwner, SMInterface *pInterface);
172 void BindChildPlugin(IExtension *pParent, CPlugin *pPlugin);
173 void MarkAllLoaded();
174 void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
176 void AddLibrary(IExtension *pSource, const char *library);
177 bool LibraryExists(const char *library);
178 void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
179 void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
181 void ListExtensionsToClient(CPlayer *player, const CCommand &args);
183 CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
185 CNativeOwner *GetNativeOwner(IExtension *pExt)
187 CExtension *p = (CExtension *)pExt;
191 CExtension *FindByOrder(unsigned int num);
193 List<CExtension *> m_Libs;
196 extern CExtensionManager g_Extensions;
198 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_