core/systems/PluginSys.h
author Borja Ferrer <faluco@alliedmods.net>
Sat Aug 18 17:15:22 2007 +0000 (2007-08-18)
changeset 1348 ad1199b211ac
parent 1330 ab94316bb52b
child 1382 5399d6f24417
permissions -rw-r--r--
added amb374, reload plugin command
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@173
    32
#ifndef _INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
dvander@173
    33
#define _INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_
dvander@173
    34
dvander@211
    35
#include <time.h>
faluco@333
    36
#include <errno.h>
faluco@333
    37
#include <sys/stat.h>
dvander@173
    38
#include <IPluginSys.h>
dvander@220
    39
#include <IHandleSys.h>
ds@611
    40
#include <IForwardSys.h>
dvander@174
    41
#include <sh_list.h>
dvander@174
    42
#include <sh_stack.h>
faluco@389
    43
#include <sh_vector.h>
dvander@601
    44
#include <sh_string.h>
dvander@173
    45
#include "sm_globals.h"
dvander@262
    46
#include "vm/sp_vm_basecontext.h"
dvander@203
    47
#include "PluginInfoDatabase.h"
dvander@211
    48
#include "sm_trie.h"
dvander@220
    49
#include "sourcemod.h"
dvander@309
    50
#include <IRootConsoleMenu.h>
ds@457
    51
#include "convar_sm.h"
dvander@173
    52
dvander@174
    53
using namespace SourceHook;
dvander@174
    54
dvander@209
    55
/**
dvander@209
    56
 * NOTES:
dvander@209
    57
 *
dvander@209
    58
 *  Currently this system needs a lot of work but it's good skeletally.  Plugin creation 
dvander@209
    59
 * is done without actually compiling anything.  This is done by Load functions in the 
dvander@209
    60
 * manager.  This will need a rewrite when we add context switching.
dvander@209
    61
 *
dvander@209
    62
 *  The plugin object itself has a few things to note.  The most important is that it stores
dvander@209
    63
 * a table of function objects.  The manager marshals allocation and freeing of these objects.
dvander@209
    64
 * The plugin object can be in erroneous states, they are:
dvander@209
    65
 *   Plugin_Error   --> Some error occurred any time during or after compilation.
dvander@209
    66
 *						This error can be cleared since the plugin itself is valid.
dvander@209
    67
 *						However, the state itself being set prevents any runtime action.
dvander@209
    68
 *   Plugin_BadLoad	--> The plugin failed to load entirely and nothing can be done to save it.
dvander@209
    69
 *
dvander@209
    70
 *  If a plugin fails to load externally, it is never added to the internal tracker.  However, 
dvander@209
    71
 * plugins that failed to load from the internal loading mechanism are always tracked.  This 
dvander@209
    72
 * allows users to see which automatically loaded plugins failed, and makes the interface a bit
dvander@209
    73
 * more flexible.
dvander@211
    74
 *
dvander@211
    75
 *  Once a plugin is compiled, it sets its own state to Plugin_Created.  This state is still invalid
dvander@211
    76
 * for execution.  SourceMod is a two pass system, and even though the second pass is not implemented
dvander@211
    77
 * yet, it is structured so Plugin_Created must be switched to Plugin_Running in the second pass.  When
dvander@211
    78
 * implemented, a Created plugin will be switched to Error in the second pass if it not loadable.
dvander@211
    79
 *
dvander@211
    80
 *  The two pass loading mechanism is described below.  Modules/natives are not implemented yet.
dvander@211
    81
 * PASS ONE: All loadable plugins are found and have the following steps performed:
dvander@211
    82
 *			 1.  Loading and compilation is attempted.
dvander@211
    83
 *			 2.  If successful, all natives from Core are added.
dvander@211
    84
 *			 3.  OnPluginLoad() is called.
dvander@211
    85
 *			 4.  If failed, any user natives are scrapped and the process halts here.
dvander@211
    86
 *			 5.  If successful, the plugin is ready for Pass 2.
dvander@211
    87
 * INTERMEDIATE:
dvander@211
    88
 *			 1.  All forced modules are loaded.
dvander@211
    89
 * PASS TWO: All loaded plugins are found and have these steps performed:
dvander@211
    90
 *			 1. Any modules referenced in the plugin that are not already loaded, are loaded.
dvander@211
    91
 *			 2. If any module fails to load and the plugin requires it, load fails and jump to step 6.
dvander@211
    92
 *			 3. If any natives are unresolved, check if they are found in the user-natives pool.
dvander@211
    93
 *			 4. If yes, load succeeds.  If not, natives are passed through a native acceptance filter.
dvander@211
    94
 *			 5. If the filter fails, the plugin is marked as failed.
dvander@211
    95
 *			 6. If the plugin has failed to load at this point, any dynamic natives it has added are scrapped.
dvander@211
    96
 *			    Furthermore, any plugin that referenced these natives must now have pass 2 re-ran.
dvander@211
    97
 * PASS THREE (not a real pass):
ds@426
    98
 *			 7. Once all plugins are deemed to be loaded, OnPluginStart() is called
dvander@209
    99
 */
dvander@209
   100
dvander@174
   101
#define SM_CONTEXTVAR_MYSELF	0
dvander@174
   102
dvander@173
   103
struct ContextPair
dvander@173
   104
{
dvander@209
   105
	ContextPair() : base(NULL), ctx(NULL), co(NULL)
dvander@173
   106
	{
dvander@173
   107
	};
dvander@262
   108
	BaseContext *base;
dvander@173
   109
	sp_context_t *ctx;
dvander@209
   110
	ICompilation *co;
dvander@209
   111
	IVirtualMachine *vm;
dvander@173
   112
};
dvander@173
   113
dvander@605
   114
struct FakeNative
dvander@605
   115
{
dvander@605
   116
	IPluginContext *ctx;
dvander@605
   117
	IPluginFunction *call;
dvander@605
   118
	String name;
dvander@605
   119
	SPVM_NATIVE_FUNC func;
dvander@605
   120
};
dvander@605
   121
faluco@383
   122
enum LoadRes
faluco@383
   123
{
faluco@383
   124
	LoadRes_Successful,
faluco@383
   125
	LoadRes_AlreadyLoaded,
faluco@383
   126
	LoadRes_Failure
faluco@383
   127
};
faluco@383
   128
dvander@978
   129
struct AutoConfig
dvander@978
   130
{
dvander@978
   131
	String autocfg;
dvander@978
   132
	String folder;
dvander@978
   133
	bool create;
dvander@978
   134
};
dvander@978
   135
faluco@1112
   136
class CPlugin;
faluco@1112
   137
struct WeakNative
faluco@1112
   138
{
faluco@1112
   139
	WeakNative(CPlugin *plugin, uint32_t index)
faluco@1112
   140
	{
faluco@1112
   141
		pl = plugin;
faluco@1112
   142
		idx = index;
faluco@1112
   143
	}
faluco@1112
   144
	CPlugin *pl;
faluco@1112
   145
	uint32_t idx;
faluco@1112
   146
};
faluco@1112
   147
dvander@173
   148
class CPlugin : public IPlugin
dvander@173
   149
{
dvander@174
   150
	friend class CPluginManager;
dvander@176
   151
	friend class CFunction;
dvander@173
   152
public:
dvander@209
   153
	CPlugin(const char *file);
dvander@209
   154
	~CPlugin();
dvander@209
   155
public:
faluco@641
   156
	PluginType GetType();
faluco@641
   157
	SourcePawn::IPluginContext *GetBaseContext();
faluco@641
   158
	sp_context_t *GetContext();
faluco@641
   159
	const sm_plugininfo_t *GetPublicInfo();
faluco@641
   160
	const char *GetFilename();
faluco@641
   161
	bool IsDebugging();
faluco@641
   162
	PluginStatus GetStatus();
faluco@641
   163
	bool SetPauseState(bool paused);
faluco@641
   164
	unsigned int GetSerial();
faluco@641
   165
	const sp_plugin_t *GetPluginStructure();
faluco@641
   166
	IdentityToken_t *GetIdentity();
faluco@641
   167
	bool SetProperty(const char *prop, void *ptr);
faluco@641
   168
	bool GetProperty(const char *prop, void **ptr, bool remove=false);
dvander@173
   169
public:
dvander@209
   170
	/**
dvander@209
   171
	 * Creates a plugin object with default values.
dvander@209
   172
	 *   If an error buffer is specified, and an error occurs, the error will be copied to the buffer
dvander@209
   173
	 * and NULL will be returned.
dvander@209
   174
	 *   If an error buffer is not specified, the error will be copied to an internal buffer and 
dvander@209
   175
	 * a valid (but error-stated) CPlugin will be returned.
dvander@209
   176
	 */
dvander@209
   177
	static CPlugin *CreatePlugin(const char *file, char *error, size_t maxlength);
dvander@209
   178
public:
dvander@209
   179
	/**
dvander@209
   180
	 * Starts the initial compilation of a plugin.
dvander@209
   181
	 * Returns false if another compilation exists or there is a current context set.
dvander@209
   182
	 */
dvander@209
   183
	ICompilation *StartMyCompile(IVirtualMachine *vm);
dvander@209
   184
	/** 
dvander@209
   185
	 * Finalizes a compilation.  If error buffer is NULL, the error is saved locally.
dvander@209
   186
	 */
dvander@209
   187
	bool FinishMyCompile(char *error, size_t maxlength);
dvander@209
   188
	void CancelMyCompile();
dvander@229
   189
dvander@209
   190
	/**
dvander@209
   191
	 * Sets an error state on the plugin
dvander@209
   192
	 */
dvander@209
   193
	void SetErrorState(PluginStatus status, const char *error_fmt, ...);
dvander@211
   194
dvander@211
   195
	/**
dvander@229
   196
	 * Initializes the plugin's identity information
dvander@229
   197
	 */
dvander@229
   198
	void InitIdentity();
dvander@229
   199
dvander@229
   200
	/**
dvander@211
   201
	 * Calls the OnPluginLoad function, and sets any failed states if necessary.
dvander@211
   202
	 * NOTE: Valid pre-states are: Plugin_Created
dvander@282
   203
	 * NOTE: If validated, plugin state is changed to Plugin_Loaded
dvander@211
   204
	 *
dvander@211
   205
	 * If the error buffer is NULL, the error message is cached locally.
dvander@211
   206
	 */
dvander@211
   207
	bool Call_AskPluginLoad(char *error, size_t maxlength);
dvander@211
   208
dvander@211
   209
	/**
ds@426
   210
	 * Calls the OnPluginStart function.
dvander@211
   211
	 * NOTE: Valid pre-states are: Plugin_Created
dvander@282
   212
	 * NOTE: Post-state will be Plugin_Running
dvander@211
   213
	 */
ds@426
   214
	void Call_OnPluginStart();
dvander@282
   215
dvander@282
   216
	/**
ds@426
   217
	 * Calls the OnPluginEnd function.
dvander@282
   218
	 */
ds@426
   219
	void Call_OnPluginEnd();
faluco@290
   220
faluco@290
   221
	/**
faluco@1221
   222
	 * Calls the OnAllPluginsLoaded function.
faluco@1221
   223
	 */
faluco@1221
   224
	void Call_OnAllPluginsLoaded();
faluco@1221
   225
faluco@1221
   226
	/**
dvander@315
   227
	 * Toggles debug mode in the plugin
dvander@315
   228
	 */
dvander@309
   229
	bool ToggleDebugMode(bool debug, char *error, size_t maxlength);
faluco@290
   230
faluco@290
   231
	/**
dvander@315
   232
	 * Returns true if a plugin is usable.
dvander@315
   233
	 */
dvander@615
   234
	bool IsRunnable();
faluco@389
   235
faluco@389
   236
	/**
dvander@536
   237
	 * Adds a language file index to the plugin's list.
dvander@536
   238
	 */
faluco@389
   239
	void AddLangFile(unsigned int index);
faluco@389
   240
faluco@389
   241
	/**
dvander@536
   242
	 * Get language file count for this plugin.
dvander@536
   243
	 */
dvander@615
   244
	size_t GetLangFileCount();
faluco@389
   245
faluco@389
   246
	/**
dvander@536
   247
	 * Get language file index based on the vector index.
dvander@536
   248
	 */
dvander@615
   249
	unsigned int GetLangFileByIndex(unsigned int index);
dvander@211
   250
public:
faluco@333
   251
	/**
dvander@536
   252
	 * Returns the modification time during last plugin load.
dvander@536
   253
	 */
dvander@615
   254
	time_t GetTimeStamp();
faluco@333
   255
faluco@333
   256
	/**
dvander@536
   257
	 * Returns the current modification time of the plugin file.
dvander@536
   258
	 */
faluco@333
   259
	time_t GetFileTimeStamp();
dvander@282
   260
dvander@282
   261
	/** 
dvander@282
   262
	 * Returns true if the plugin was running, but is now invalid.
dvander@282
   263
	 */
dvander@282
   264
	bool WasRunning();
dvander@536
   265
dvander@536
   266
	Handle_t GetMyHandle();
dvander@978
   267
dvander@978
   268
	void AddConfig(bool autoCreate, const char *cfg, const char *folder);
dvander@978
   269
	unsigned int GetConfigCount();
dvander@978
   270
	AutoConfig *GetConfig(unsigned int i);
faluco@1112
   271
	inline void AddLibrary(const char *name)
faluco@1089
   272
	{
faluco@1112
   273
		m_Libraries.push_back(name);
faluco@1089
   274
	}
dvander@1124
   275
	void LibraryActions(bool dropping);
dvander@173
   276
protected:
dvander@173
   277
	void UpdateInfo();
faluco@333
   278
	void SetTimeStamp(time_t t);
dvander@605
   279
	void DependencyDropped(CPlugin *pOwner);
dvander@173
   280
private:
dvander@209
   281
	ContextPair m_ctx;
dvander@174
   282
	PluginType m_type;
ds@652
   283
	char m_filename[PLATFORM_MAX_PATH];
dvander@173
   284
	PluginStatus m_status;
dvander@173
   285
	unsigned int m_serial;
dvander@173
   286
	sm_plugininfo_t m_info;
dvander@173
   287
	sp_plugin_t *m_plugin;
dvander@209
   288
	char m_errormsg[256];
dvander@211
   289
	time_t m_LastAccess;
dvander@229
   290
	IdentityToken_t *m_ident;
dvander@220
   291
	Handle_t m_handle;
dvander@282
   292
	bool m_WasRunning;
faluco@389
   293
	CVector<unsigned int> m_PhraseFiles;
dvander@605
   294
	List<CPlugin *> m_dependents;
dvander@605
   295
	List<CPlugin *> m_dependsOn;
dvander@605
   296
	List<FakeNative *> m_fakeNatives;
dvander@1122
   297
	List<WeakNative> m_WeakNatives;
faluco@1112
   298
	List<String> m_RequiredLibs;
faluco@1112
   299
	List<String> m_Libraries;
dvander@486
   300
	Trie *m_pProps;
dvander@605
   301
	bool m_FakeNativesMissing;
faluco@1112
   302
	bool m_LibraryMissing;
dvander@978
   303
	CVector<AutoConfig *> m_configs;
dvander@601
   304
};
dvander@601
   305
dvander@220
   306
class CPluginManager : 
dvander@220
   307
	public IPluginManager,
dvander@220
   308
	public SMGlobalClass,
dvander@309
   309
	public IHandleTypeDispatch,
dvander@309
   310
	public IRootConsoleCommand
dvander@174
   311
{
dvander@176
   312
	friend class CPlugin;
dvander@174
   313
public:
dvander@174
   314
	CPluginManager();
dvander@176
   315
	~CPluginManager();
dvander@174
   316
public:
dvander@203
   317
	/* Implements iterator class */
dvander@174
   318
	class CPluginIterator : public IPluginIterator
dvander@174
   319
	{
dvander@174
   320
	public:
dvander@213
   321
		CPluginIterator(List<CPlugin *> *mylist);
dvander@174
   322
		virtual ~CPluginIterator();
dvander@174
   323
		virtual bool MorePlugins();
dvander@174
   324
		virtual IPlugin *GetPlugin();
dvander@174
   325
		virtual void NextPlugin();
dvander@282
   326
		void Release();
dvander@174
   327
	public:
dvander@174
   328
		void Reset();
dvander@174
   329
	private:
dvander@213
   330
		List<CPlugin *> *mylist;
dvander@213
   331
		List<CPlugin *>::iterator current;
dvander@174
   332
	};
dvander@174
   333
	friend class CPluginManager::CPluginIterator;
dvander@203
   334
public: //IPluginManager
dvander@282
   335
	IPlugin *LoadPlugin(const char *path, 
dvander@174
   336
								bool debug,
dvander@174
   337
								PluginType type,
dvander@174
   338
								char error[],
ds@755
   339
								size_t maxlength,
faluco@383
   340
								bool *wasloaded);
dvander@282
   341
	bool UnloadPlugin(IPlugin *plugin);
dvander@282
   342
	IPlugin *FindPluginByContext(const sp_context_t *ctx);
dvander@282
   343
	unsigned int GetPluginCount();
dvander@282
   344
	IPluginIterator *GetPluginIterator();
dvander@282
   345
	void AddPluginsListener(IPluginsListener *listener);
dvander@282
   346
	void RemovePluginsListener(IPluginsListener *listener);
dvander@220
   347
public: //SMGlobalClass
dvander@282
   348
	void OnSourceModAllInitialized();
dvander@282
   349
	void OnSourceModShutdown();
dvander@220
   350
public: //IHandleTypeDispatch
dvander@282
   351
	void OnHandleDestroy(HandleType_t type, void *object);
dvander@309
   352
public: //IRootConsoleCommand
dvander@309
   353
	void OnRootConsoleCommand(const char *command, unsigned int argcount);
dvander@190
   354
public:
dvander@203
   355
	/**
dvander@211
   356
	 * Loads all plugins not yet loaded
dvander@203
   357
	 */
dvander@211
   358
	void LoadAll_FirstPass(const char *config, const char *basedir);
dvander@211
   359
dvander@211
   360
	/**
dvander@211
   361
	 * Runs the second loading pass for all plugins
dvander@211
   362
	 */
dvander@211
   363
	void LoadAll_SecondPass();
dvander@203
   364
dvander@203
   365
	/**
dvander@203
   366
	 * Tests a plugin file mask against a local folder.
dvander@203
   367
	 * The alias is searched backwards from localdir - i.e., given this input:
dvander@203
   368
	 *   csdm/ban        csdm/ban
dvander@203
   369
	 *   ban             csdm/ban
dvander@203
   370
	 *   csdm/ban        optional/csdm/ban
dvander@203
   371
	 * All of these will return true for an alias match.  
dvander@203
   372
	 * Wildcards are allowed in the filename.
dvander@203
   373
	 */
dvander@209
   374
	bool TestAliasMatch(const char *alias, const char *localdir);
dvander@211
   375
dvander@211
   376
	/** 
dvander@211
   377
	 * Returns whether anything loaded will be a late load.
dvander@211
   378
	 */
faluco@290
   379
	bool IsLateLoadTime() const;
dvander@233
   380
dvander@233
   381
	/**
dvander@233
   382
	 * Adds natives from core into the native pool.
dvander@233
   383
	 */
dvander@233
   384
	void RegisterNativesFromCore(sp_nativeinfo_t *natives);
dvander@247
   385
dvander@247
   386
	/**
dvander@247
   387
	 * Converts a Handle to an IPlugin if possible.
dvander@247
   388
	 */
dvander@247
   389
	IPlugin *PluginFromHandle(Handle_t handle, HandleError *err);
faluco@290
   390
faluco@290
   391
	/**
dvander@309
   392
	 * Finds a plugin based on its index. (starts on index 1)
dvander@309
   393
	 */
faluco@290
   394
	CPlugin *GetPluginByOrder(int num);
dvander@309
   395
ds@457
   396
	/** 
ds@457
   397
	 * Internal version of FindPluginByContext()
ds@457
   398
	 */
ds@457
   399
	inline CPlugin *GetPluginByCtx(const sp_context_t *ctx)
ds@457
   400
	{
ds@457
   401
		return reinterpret_cast<CPlugin *>(ctx->user[SM_CONTEXTVAR_MYSELF]);
ds@457
   402
	}
ds@457
   403
dvander@309
   404
	/**
dvander@309
   405
	 * Gets status text for a status code 
dvander@309
   406
	 */
dvander@309
   407
	const char *GetStatusText(PluginStatus status);
dvander@315
   408
faluco@333
   409
	/**
faluco@333
   410
	* Reload or update plugins on level shutdown.
faluco@333
   411
	*/
faluco@333
   412
	void ReloadOrUnloadPlugins();
faluco@333
   413
ds@611
   414
	/**
ds@611
   415
	 * Add public functions from all running or paused
ds@611
   416
	 * plugins to the specified forward if the names match.
ds@611
   417
	 */
ds@611
   418
	void AddFunctionsToForward(const char *name, IChangeableForward *pForward);
ds@611
   419
faluco@1221
   420
	/**
faluco@1221
   421
	 * Iterates through plugins to call OnAllPluginsLoaded.
faluco@1221
   422
	 */
faluco@1221
   423
	void AllPluginsLoaded();
faluco@1221
   424
dvander@900
   425
	CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken);
dvander@900
   426
dvander@1018
   427
	void Shutdown();
dvander@1018
   428
dvander@1124
   429
	void OnLibraryAction(const char *lib, bool drop);
dvander@1124
   430
dvander@1124
   431
	bool LibraryExists(const char *lib);
faluco@1348
   432
faluco@1348
   433
	bool ReloadPlugin(CPlugin *pl);
dvander@209
   434
private:
ds@755
   435
	LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
dvander@298
   436
dvander@298
   437
	void LoadAutoPlugin(const char *plugin);
dvander@298
   438
dvander@209
   439
	/**
dvander@209
   440
	 * Recursively loads all plugins in the given directory.
dvander@209
   441
	 */
dvander@209
   442
	void LoadPluginsFromDir(const char *basedir, const char *localdir);
dvander@209
   443
dvander@209
   444
	/**
dvander@211
   445
	 * Adds a plugin object.  This is wrapped by LoadPlugin functions.
dvander@211
   446
	 */
dvander@211
   447
	void AddPlugin(CPlugin *pPlugin);
dvander@211
   448
dvander@211
   449
	/**
dvander@211
   450
	 * Runs the second loading pass on a plugin.
dvander@209
   451
	 */
dvander@298
   452
	bool RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength);
dvander@211
   453
dvander@211
   454
	/**
dvander@211
   455
	 * Adds any globally registered natives to a plugin
dvander@211
   456
	 */
dvander@211
   457
	void AddCoreNativesToPlugin(CPlugin *pPlugin);
dvander@315
   458
dvander@315
   459
	/**
dvander@315
   460
	 * Runs an extension pass on a plugin.
dvander@315
   461
	 */
dvander@315
   462
	bool LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength);
faluco@430
   463
faluco@1112
   464
	/**
faluco@1112
   465
	* Manages required natives.
faluco@1112
   466
	*/
faluco@1112
   467
	bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength);
faluco@1112
   468
faluco@430
   469
	void _SetPauseState(CPlugin *pPlugin, bool pause);
dvander@174
   470
protected:
dvander@209
   471
	/**
dvander@209
   472
	 * Caching internal objects
dvander@209
   473
	 */
dvander@174
   474
	void ReleaseIterator(CPluginIterator *iter);
dvander@900
   475
public:
dvander@229
   476
	inline IdentityToken_t *GetIdentity()
dvander@229
   477
	{
dvander@229
   478
		return m_MyIdent;
dvander@229
   479
	}
dvander@601
   480
public:
dvander@601
   481
	bool AddFakeNative(IPluginFunction *pFunction, const char *name, SPVM_FAKENATIVE_FUNC func);
dvander@601
   482
private:
dvander@601
   483
	void AddFakeNativesToPlugin(CPlugin *pPlugin);
faluco@1112
   484
	void TryRefreshDependencies(CPlugin *pOther);
dvander@174
   485
private:
dvander@174
   486
	List<IPluginsListener *> m_listeners;
dvander@213
   487
	List<CPlugin *> m_plugins;
dvander@211
   488
	List<sp_nativeinfo_t *> m_natives;
dvander@174
   489
	CStack<CPluginManager::CPluginIterator *> m_iters;
dvander@203
   490
	CPluginInfoDatabase m_PluginInfo;
dvander@211
   491
	Trie *m_LoadLookup;
dvander@211
   492
	bool m_AllPluginsLoaded;
dvander@229
   493
	IdentityToken_t *m_MyIdent;
dvander@601
   494
dvander@601
   495
	/* Dynamic native stuff */
dvander@601
   496
	List<FakeNative *> m_Natives;
dvander@601
   497
	Trie *m_pNativeLookup;
dvander@601
   498
dvander@174
   499
};
dvander@174
   500
dvander@211
   501
extern CPluginManager g_PluginSys;
dvander@174
   502
dvander@173
   503
#endif //_INCLUDE_SOURCEMOD_PLUGINSYSTEM_H_