|
ds@1952
|
1 |
/** |
|
ds@1952
|
2 |
* vim: set ts=4 : |
|
ds@1952
|
3 |
* ============================================================================= |
|
ds@1952
|
4 |
* SourceMod |
|
ds@1952
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1952
|
6 |
* ============================================================================= |
|
ds@1952
|
7 |
* |
|
ds@1952
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1952
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1952
|
10 |
* Free Software Foundation. |
|
ds@1952
|
11 |
* |
|
ds@1952
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1952
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1952
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1952
|
15 |
* details. |
|
ds@1952
|
16 |
* |
|
ds@1952
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1952
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1952
|
19 |
* |
|
ds@1952
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1952
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1952
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1952
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1952
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1952
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1952
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1952
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1952
|
28 |
* |
|
ds@1952
|
29 |
* Version: $Id$ |
|
ds@1952
|
30 |
*/ |
|
ds@1952
|
31 |
|
|
ds@1952
|
32 |
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_ |
|
ds@1952
|
33 |
#define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_ |
|
ds@1952
|
34 |
|
|
ds@1952
|
35 |
#include <IExtensionSys.h> |
|
ds@1952
|
36 |
#include <ILibrarySys.h> |
|
ds@1952
|
37 |
#include <sh_list.h> |
|
ds@1952
|
38 |
#include <sh_string.h> |
|
ds@1952
|
39 |
#include <sm_trie_tpl.h> |
|
ds@1952
|
40 |
#include "sm_globals.h" |
|
ds@1952
|
41 |
#include "ShareSys.h" |
|
ds@1952
|
42 |
#include <ISmmAPI.h> |
|
ds@1952
|
43 |
#include <IPluginSys.h> |
|
ds@1952
|
44 |
#include <IRootConsoleMenu.h> |
|
ds@1952
|
45 |
#include "PluginSys.h" |
|
dvander@2086
|
46 |
#include "NativeOwner.h" |
|
ds@1952
|
47 |
|
|
ds@1952
|
48 |
using namespace SourceMod; |
|
ds@1952
|
49 |
using namespace SourceHook; |
|
ds@1952
|
50 |
|
|
ds@1952
|
51 |
class CExtension; |
|
ds@1952
|
52 |
|
|
ds@1952
|
53 |
struct sm_extnative_t |
|
ds@1952
|
54 |
{ |
|
ds@1952
|
55 |
CExtension *owner; |
|
ds@1952
|
56 |
const sp_nativeinfo_t *info; |
|
ds@1952
|
57 |
}; |
|
ds@1952
|
58 |
|
|
dvander@2086
|
59 |
class CExtension : |
|
dvander@2086
|
60 |
public IExtension, |
|
dvander@2086
|
61 |
public CNativeOwner |
|
ds@1952
|
62 |
{ |
|
ds@1952
|
63 |
friend class CExtensionManager; |
|
ds@1952
|
64 |
public: |
|
ds@1952
|
65 |
virtual ~CExtension(); |
|
ds@1952
|
66 |
public: //IExtension |
|
ds@1952
|
67 |
IExtensionInterface *GetAPI(); |
|
ds@1952
|
68 |
const char *GetFilename(); |
|
ds@1952
|
69 |
IdentityToken_t *GetIdentity(); |
|
ds@1952
|
70 |
ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface); |
|
ds@1952
|
71 |
bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface); |
|
ds@1952
|
72 |
void FreeDependencyIterator(ITERATOR *iter); |
|
ds@1952
|
73 |
bool IsRunning(char *error, size_t maxlength); |
|
ds@1952
|
74 |
public: |
|
ds@1952
|
75 |
void SetError(const char *error); |
|
ds@1952
|
76 |
void AddDependency(IfaceInfo *pInfo); |
|
ds@1952
|
77 |
void AddChildDependent(CExtension *pOther, SMInterface *iface); |
|
ds@1952
|
78 |
void AddInterface(SMInterface *pInterface); |
|
dvander@2086
|
79 |
void AddPlugin(CPlugin *pPlugin); |
|
ds@1952
|
80 |
void MarkAllLoaded(); |
|
ds@1952
|
81 |
void AddLibrary(const char *library); |
|
ds@1952
|
82 |
public: |
|
ds@1952
|
83 |
virtual bool Load(char *error, size_t maxlength); |
|
ds@1952
|
84 |
virtual bool IsLoaded() =0; |
|
ds@1952
|
85 |
virtual void Unload() =0; |
|
ds@1952
|
86 |
protected: |
|
ds@1952
|
87 |
void Initialize(const char *filename, const char *path); |
|
ds@1952
|
88 |
bool PerformAPICheck(char *error, size_t maxlength); |
|
ds@1952
|
89 |
void CreateIdentity(); |
|
ds@1952
|
90 |
void DestroyIdentity(); |
|
ds@1952
|
91 |
protected: |
|
ds@1952
|
92 |
IdentityToken_t *m_pIdentToken; |
|
ds@1952
|
93 |
IExtensionInterface *m_pAPI; |
|
ds@1952
|
94 |
String m_File; |
|
ds@1952
|
95 |
String m_Path; |
|
ds@1952
|
96 |
String m_Error; |
|
ds@1952
|
97 |
List<IfaceInfo> m_Deps; /** Dependencies */ |
|
ds@1952
|
98 |
List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */ |
|
ds@1952
|
99 |
List<SMInterface *> m_Interfaces; |
|
ds@1952
|
100 |
List<String> m_Libraries; |
|
ds@1952
|
101 |
unsigned int unload_code; |
|
ds@1952
|
102 |
bool m_bFullyLoaded; |
|
ds@1952
|
103 |
}; |
|
ds@1952
|
104 |
|
|
ds@1952
|
105 |
class CLocalExtension : public CExtension |
|
ds@1952
|
106 |
{ |
|
ds@1952
|
107 |
public: |
|
ds@1952
|
108 |
CLocalExtension(const char *filename); |
|
ds@1952
|
109 |
public: |
|
ds@1952
|
110 |
bool Load(char *error, size_t maxlength); |
|
ds@1952
|
111 |
bool IsLoaded(); |
|
ds@1952
|
112 |
void Unload(); |
|
ds@1952
|
113 |
bool IsExternal(); |
|
ds@1952
|
114 |
private: |
|
ds@1952
|
115 |
PluginId m_PlId; |
|
ds@1952
|
116 |
ILibrary *m_pLib; |
|
ds@1952
|
117 |
}; |
|
ds@1952
|
118 |
|
|
ds@1952
|
119 |
class CRemoteExtension : public CExtension |
|
ds@1952
|
120 |
{ |
|
ds@1952
|
121 |
public: |
|
ds@1952
|
122 |
CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path); |
|
ds@1952
|
123 |
public: |
|
ds@1952
|
124 |
bool Load(char *error, size_t maxlength); |
|
ds@1952
|
125 |
bool IsLoaded(); |
|
ds@1952
|
126 |
void Unload(); |
|
ds@1952
|
127 |
bool IsExternal(); |
|
ds@1952
|
128 |
}; |
|
ds@1952
|
129 |
|
|
ds@1952
|
130 |
class CExtensionManager : |
|
ds@1952
|
131 |
public IExtensionManager, |
|
ds@1952
|
132 |
public SMGlobalClass, |
|
ds@1952
|
133 |
public IPluginsListener, |
|
ds@1952
|
134 |
public IRootConsoleCommand |
|
ds@1952
|
135 |
{ |
|
ds@1952
|
136 |
public: |
|
ds@1952
|
137 |
CExtensionManager(); |
|
ds@1952
|
138 |
~CExtensionManager(); |
|
ds@1952
|
139 |
public: //SMGlobalClass |
|
ds@1952
|
140 |
void OnSourceModAllInitialized(); |
|
ds@1952
|
141 |
void OnSourceModShutdown(); |
|
ds@1952
|
142 |
public: //IExtensionManager |
|
ds@1952
|
143 |
IExtension *LoadExtension(const char *path, |
|
ds@1952
|
144 |
char *error, |
|
ds@1952
|
145 |
size_t maxlength); |
|
ds@1952
|
146 |
bool UnloadExtension(IExtension *pExt); |
|
ds@1952
|
147 |
IExtension *FindExtensionByFile(const char *file); |
|
ds@1952
|
148 |
IExtension *FindExtensionByName(const char *ext); |
|
ds@1952
|
149 |
IExtension *LoadExternal(IExtensionInterface *pInterface, |
|
ds@1952
|
150 |
const char *filepath, |
|
ds@1952
|
151 |
const char *filename, |
|
ds@1952
|
152 |
char *error, |
|
ds@1952
|
153 |
size_t maxlength); |
|
ds@1952
|
154 |
public: //IPluginsListener |
|
ds@1952
|
155 |
void OnPluginDestroyed(IPlugin *plugin); |
|
ds@1952
|
156 |
public: //IRootConsoleCommand |
|
ds@1952
|
157 |
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); |
|
ds@1952
|
158 |
public: |
|
ds@1952
|
159 |
IExtension *LoadAutoExtension(const char *path); |
|
ds@1952
|
160 |
void BindDependency(IExtension *pOwner, IfaceInfo *pInfo); |
|
ds@1952
|
161 |
void AddInterface(IExtension *pOwner, SMInterface *pInterface); |
|
dvander@2086
|
162 |
void BindChildPlugin(IExtension *pParent, CPlugin *pPlugin); |
|
ds@1952
|
163 |
void MarkAllLoaded(); |
|
ds@1952
|
164 |
void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload); |
|
ds@1952
|
165 |
void TryAutoload(); |
|
ds@1952
|
166 |
void AddLibrary(IExtension *pSource, const char *library); |
|
ds@1952
|
167 |
bool LibraryExists(const char *library); |
|
faluco@1993
|
168 |
void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax); |
|
ds@1952
|
169 |
public: |
|
ds@1952
|
170 |
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); |
|
ds@1952
|
171 |
void Shutdown(); |
|
dvander@2086
|
172 |
CNativeOwner *GetNativeOwner(IExtension *pExt) |
|
dvander@2086
|
173 |
{ |
|
dvander@2086
|
174 |
CExtension *p = (CExtension *)pExt; |
|
dvander@2086
|
175 |
return p; |
|
dvander@2086
|
176 |
} |
|
ds@1952
|
177 |
private: |
|
ds@1952
|
178 |
CExtension *FindByOrder(unsigned int num); |
|
ds@1952
|
179 |
private: |
|
ds@1952
|
180 |
List<CExtension *> m_Libs; |
|
ds@1952
|
181 |
}; |
|
ds@1952
|
182 |
|
|
ds@1952
|
183 |
extern CExtensionManager g_Extensions; |
|
ds@1952
|
184 |
|
|
ds@1952
|
185 |
#endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_ |