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