4 #include "LibrarySys.h"
6 #include "sourcemm_api.h"
8 #include "CTextParsers.h"
10 #include "ExtensionSys.h"
12 CPluginManager g_PluginSys;
13 HandleType_t g_PluginType = 0;
14 IdentityType_t g_PluginIdent = 0;
16 CPlugin::CPlugin(const char *file)
18 static int MySerial = 0;
20 m_type = PluginType_Private;
21 m_status = Plugin_Uncompiled;
22 m_serial = ++MySerial;
27 m_errormsg[256] = '\0';
28 snprintf(m_filename, sizeof(m_filename), "%s", file);
38 sec.pOwner = g_PluginSys.GetIdentity();
39 sec.pIdentity = sec.pOwner;
41 g_HandleSys.FreeHandle(m_handle, &sec);
42 g_ShareSys.DestroyIdentity(m_ident);
52 m_ctx.vm->FreeContext(m_ctx.ctx);
57 m_ctx.vm->AbortCompilation(m_ctx.co);
63 for (uint32_t i=0; i<m_plugin->info.publics_num; i++)
65 g_PluginSys.ReleaseFunctionToPool(m_pub_funcs[i]);
67 delete [] m_pub_funcs;
73 for (unsigned int i=0; i<m_funcsnum; i++)
75 g_PluginSys.ReleaseFunctionToPool(m_priv_funcs[i]);
77 delete [] m_priv_funcs;
83 g_pSourcePawn->FreeFromMemory(m_plugin);
88 void CPlugin::InitIdentity()
92 m_ident = g_ShareSys.CreateIdentity(g_PluginIdent);
93 m_handle = g_HandleSys.CreateHandle(g_PluginType, this, g_PluginSys.GetIdentity(), g_PluginSys.GetIdentity(), NULL);
94 m_ctx.base->SetIdentity(m_ident);
98 CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
100 char fullpath[PLATFORM_MAX_PATH+1];
101 g_LibSys.PathFormat(fullpath, sizeof(fullpath), "%s/plugins/%s", g_SourceMod.GetSMBaseDir(), file);
102 FILE *fp = fopen(fullpath, "rb");
104 CPlugin *pPlugin = new CPlugin(file);
110 snprintf(error, maxlength, "Unable to open file");
112 pPlugin->m_status = Plugin_BadLoad;
117 sp_plugin_t *pl = g_pSourcePawn->LoadFromFilePointer(fp, &err);
123 snprintf(error, maxlength, "Error %d while parsing plugin", err);
125 pPlugin->m_status = Plugin_BadLoad;
131 pPlugin->m_plugin = pl;
136 ICompilation *CPlugin::StartMyCompile(IVirtualMachine *vm)
143 /* :NOTICE: We will eventually need to change these natives
144 * for swapping in new contexts
146 if (m_ctx.co || m_ctx.ctx)
151 m_status = Plugin_Uncompiled;
154 m_ctx.co = vm->StartCompilation(m_plugin);
159 void CPlugin::CancelMyCompile()
166 m_ctx.vm->AbortCompilation(m_ctx.co);
171 bool CPlugin::FinishMyCompile(char *error, size_t maxlength)
179 m_ctx.ctx = m_ctx.vm->CompileToContext(m_ctx.co, &err);
182 memset(&m_ctx, 0, sizeof(m_ctx));
185 snprintf(error, maxlength, "Failed to compile (error %d)", err);
190 m_ctx.base = new BaseContext(m_ctx.ctx);
191 m_ctx.ctx->user[SM_CONTEXTVAR_MYSELF] = (void *)this;
193 m_funcsnum = m_ctx.vm->FunctionCount(m_ctx.ctx);
196 * Note: Since the m_plugin member will never change,
197 * it is safe to assume the function count will never change
199 if (m_funcsnum && m_priv_funcs == NULL)
201 m_priv_funcs = new CFunction *[m_funcsnum];
202 memset(m_priv_funcs, 0, sizeof(CFunction *) * m_funcsnum);
207 if (m_plugin->info.publics_num && m_pub_funcs == NULL)
209 m_pub_funcs = new CFunction *[m_plugin->info.publics_num];
210 memset(m_pub_funcs, 0, sizeof(CFunction *) * m_plugin->info.publics_num);
215 m_status = Plugin_Created;
223 void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
228 va_start(ap, error_fmt);
229 vsnprintf(m_errormsg, sizeof(m_errormsg), error_fmt, ap);
233 IPluginFunction *CPlugin::GetFunctionById(funcid_t func_id)
235 CFunction *pFunc = NULL;
236 funcid_t save = func_id;
241 if (func_id >= m_plugin->info.publics_num)
245 pFunc = m_pub_funcs[func_id];
248 pFunc = g_PluginSys.GetFunctionFromPool(save, this);
249 m_pub_funcs[func_id] = pFunc;
254 if (!g_pVM->FunctionLookup(m_ctx.ctx, func_id, &index))
258 pFunc = m_priv_funcs[func_id];
261 pFunc = g_PluginSys.GetFunctionFromPool(save, this);
262 m_priv_funcs[func_id] = pFunc;
269 IPluginFunction *CPlugin::GetFunctionByName(const char *public_name)
272 IPluginContext *base = m_ctx.base;
274 if (base->FindPublicByName(public_name, &index) != SP_ERROR_NONE)
279 CFunction *pFunc = m_pub_funcs[index];
282 sp_public_t *pub = NULL;
283 base->GetPublicByIndex(index, &pub);
286 pFunc = g_PluginSys.GetFunctionFromPool(pub->funcid, this);
287 m_pub_funcs[index] = pFunc;
294 void CPlugin::UpdateInfo()
296 /* Now grab the info */
298 IPluginContext *base = GetBaseContext();
299 int err = base->FindPubvarByName("myinfo", &idx);
301 if (err == SP_ERROR_NONE)
303 struct sm_plugininfo_c_t
311 sm_plugininfo_c_t *cinfo;
314 base->GetPubvarAddrs(idx, &local_addr, (cell_t **)&cinfo);
315 base->LocalToString(cinfo->name, (char **)&m_info.name);
316 base->LocalToString(cinfo->description, (char **)&m_info.description);
317 base->LocalToString(cinfo->author, (char **)&m_info.author);
318 base->LocalToString(cinfo->url, (char **)&m_info.url);
319 base->LocalToString(cinfo->version, (char **)&m_info.version);
322 m_info.author = m_info.author ? m_info.author : "";
323 m_info.description = m_info.description ? m_info.description : "";
324 m_info.name = m_info.name ? m_info.name : "";
325 m_info.url = m_info.url ? m_info.url : "";
326 m_info.version = m_info.version ? m_info.version : "";
329 void CPlugin::Call_OnPluginInit()
331 if (m_status != Plugin_Loaded)
336 m_status = Plugin_Running;
339 IPluginFunction *pFunction = GetFunctionByName("OnPluginInit");
345 pFunction->PushCell(m_handle);
346 pFunction->Execute(&result);
349 void CPlugin::Call_OnPluginUnload()
351 if (m_status < Plugin_Paused)
357 IPluginFunction *pFunction = GetFunctionByName("OnPluginUnload");
363 pFunction->Execute(&result);
366 bool CPlugin::Call_AskPluginLoad(char *error, size_t maxlength)
368 if (m_status != Plugin_Created)
373 m_status = Plugin_Loaded;
377 IPluginFunction *pFunction = GetFunctionByName("AskPluginLoad");
384 pFunction->PushCell(m_handle);
385 pFunction->PushCell(g_PluginSys.IsLateLoadTime() ? 1 : 0);
386 pFunction->PushStringEx(error, maxlength, 0, SM_PARAM_COPYBACK);
387 pFunction->PushCell(maxlength);
388 if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE)
390 m_status = Plugin_Failed;
394 if (!result || m_status != Plugin_Loaded)
396 m_status = Plugin_Failed;
403 const sp_plugin_t *CPlugin::GetPluginStructure() const
408 IPluginContext *CPlugin::GetBaseContext() const
413 sp_context_t *CPlugin::GetContext() const
418 const char *CPlugin::GetFilename() const
423 PluginType CPlugin::GetType() const
428 const sm_plugininfo_t *CPlugin::GetPublicInfo() const
433 unsigned int CPlugin::GetSerial() const
438 PluginStatus CPlugin::GetStatus() const
443 bool CPlugin::IsDebugging() const
450 return ((m_ctx.ctx->flags & SP_FLAG_DEBUG) == SP_FLAG_DEBUG);
453 bool CPlugin::SetPauseState(bool paused)
455 if (paused && GetStatus() != Plugin_Paused)
458 } else if (!paused && GetStatus() != Plugin_Running) {
462 m_status = (paused) ? Plugin_Paused : Plugin_Running;
464 IPluginFunction *pFunction = GetFunctionByName("OnPluginPauseChange");
468 pFunction->PushCell(paused ? 1 : 0);
469 pFunction->Execute(&result);
475 IdentityToken_t *CPlugin::GetIdentity() const
480 bool CPlugin::ToggleDebugMode(bool debug)
489 if ((debug && IsDebugging()) || (!debug && !IsDebugging()))
493 ICompilation *co = g_pVM->StartCompilation(m_ctx.ctx->plugin);
494 if (!g_pVM->SetCompilationOption(co, "debug", (debug) ? "1" : "0"))
498 sp_context_t *new_ctx = g_pVM->CompileToContext(co, &err);
500 memcpy(new_ctx->memory, m_ctx.ctx->memory, m_ctx.ctx->mem_size);
501 new_ctx->hp = m_ctx.ctx->hp;
502 new_ctx->sp = m_ctx.ctx->sp;
503 new_ctx->frm = m_ctx.ctx->frm;
504 new_ctx->dbreak = m_ctx.ctx->dbreak;
505 new_ctx->context = m_ctx.ctx->context;
506 memcpy(new_ctx->user, m_ctx.ctx->user, sizeof(m_ctx.ctx->user));
508 g_pVM->FreeContext(m_ctx.ctx);
510 m_ctx.base->SetContext(new_ctx);
517 bool CPlugin::IsRunnable() const
519 return (m_status <= Plugin_Paused) ? true : false;
526 CPluginManager::CPluginIterator::CPluginIterator(List<CPlugin *> *_mylist)
532 IPlugin *CPluginManager::CPluginIterator::GetPlugin()
537 bool CPluginManager::CPluginIterator::MorePlugins()
539 return (current != mylist->end());
542 void CPluginManager::CPluginIterator::NextPlugin()
547 void CPluginManager::CPluginIterator::Release()
549 g_PluginSys.ReleaseIterator(this);
552 CPluginManager::CPluginIterator::~CPluginIterator()
556 void CPluginManager::CPluginIterator::Reset()
558 current = mylist->begin();
565 CPluginManager::CPluginManager()
567 m_LoadLookup = sm_trie_create();
568 m_AllPluginsLoaded = false;
572 CPluginManager::~CPluginManager()
575 * Ignore the fact that there might be plugins in the cache.
576 * This usually means that Core is not being unloaded properly, and everything
577 * will crash anyway. YAY
579 sm_trie_destroy(m_LoadLookup);
583 void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir)
585 /* First read in the database of plugin settings */
587 unsigned int line, col;
588 m_AllPluginsLoaded = false;
589 if ((err=g_TextParser.ParseFile_SMC(config, &m_PluginInfo, &line, &col)) != SMCParse_Okay)
591 g_Logger.LogError("[SOURCEMOD] Encountered fatal error parsing file \"%s\"", config);
592 const char *err_msg = g_TextParser.GetSMCErrorString(err);
595 g_Logger.LogError("[SOURCEMOD] Parse error encountered: \"%s\"", err_msg);
599 LoadPluginsFromDir(basedir, NULL);
602 void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpath)
604 char base_path[PLATFORM_MAX_PATH+1];
606 /* Form the current path to start reading from */
607 if (localpath == NULL)
609 g_LibSys.PathFormat(base_path, sizeof(base_path), "%s", basedir);
611 g_LibSys.PathFormat(base_path, sizeof(base_path), "%s/%s", basedir, localpath);
614 IDirectory *dir = g_LibSys.OpenDirectory(base_path);
619 g_LibSys.GetPlatformError(error, sizeof(error));
620 g_Logger.LogError("[SOURCEMOD] Failure reading from plugins path: %s", localpath);
621 g_Logger.LogError("[SOURCEMOD] Platform returned error: %s", error);
625 while (dir->MoreFiles())
627 if (dir->IsEntryDirectory()
628 && (strcmp(dir->GetEntryName(), ".") != 0)
629 && (strcmp(dir->GetEntryName(), "..") != 0)
630 && (strcmp(dir->GetEntryName(), "disabled") != 0)
631 && (strcmp(dir->GetEntryName(), "optional") != 0))
633 char new_local[PLATFORM_MAX_PATH+1];
634 if (localpath == NULL)
636 /* If no path yet, don't add a former slash */
637 snprintf(new_local, sizeof(new_local), "%s", dir->GetEntryName());
639 g_LibSys.PathFormat(new_local, sizeof(new_local), "%s/%s", localpath, dir->GetEntryName());
641 LoadPluginsFromDir(basedir, new_local);
642 } else if (dir->IsEntryFile()) {
643 const char *name = dir->GetEntryName();
644 size_t len = strlen(name);
646 && strcmp(&name[len-4], ".smx") == 0)
648 /* If the filename matches, load the plugin */
649 char plugin[PLATFORM_MAX_PATH+1];
650 if (localpath == NULL)
652 snprintf(plugin, sizeof(plugin), "%s", name);
654 g_LibSys.PathFormat(plugin, sizeof(plugin), "%s/%s", localpath, name);
656 LoadAutoPlugin(plugin);
661 g_LibSys.CloseDirectory(dir);
664 //well i have discovered that gabe newell is very fat, so i wrote this comment now
665 //:TODO: remove this function, create a better wrapper for LoadPlugin()/LoadAutoPlugin()
666 bool CPluginManager::_LoadPlugin(CPlugin **_plugin, const char *path, bool debug, PluginType type, char error[], size_t err_max)
669 * Does this plugin already exist?
672 if (sm_trie_retrieve(m_LoadLookup, path, (void **)&pPlugin))
674 /* First check the type */
675 PluginType type = pPlugin->GetType();
676 if (type == PluginType_Private
677 || type == PluginType_Global)
681 /* Check to see if we should try reloading it */
682 if (pPlugin->GetStatus() == Plugin_BadLoad
683 || pPlugin->GetStatus() == Plugin_Error
684 || pPlugin->GetStatus() == Plugin_Failed)
686 UnloadPlugin(pPlugin);
690 pPlugin = CPlugin::CreatePlugin(path, error, err_max);
692 assert(pPlugin != NULL);
694 pPlugin->m_type = PluginType_MapUpdated;
696 ICompilation *co = NULL;
698 if (pPlugin->m_status == Plugin_Uncompiled)
700 co = pPlugin->StartMyCompile(g_pVM);
703 PluginSettings *pset;
704 unsigned int setcount = m_PluginInfo.GetSettingsNum();
705 for (unsigned int i=0; i<setcount; i++)
707 if ((pset=m_PluginInfo.GetSettingsIfMatch(i, path)) == NULL)
711 pPlugin->m_type = pset->type_val;
714 for (unsigned int j=0; j<pset->opts_num; j++)
716 const char *key, *val;
717 m_PluginInfo.GetOptionsForPlugin(pset, j, &key, &val);
722 if (!g_pVM->SetCompilationOption(co, key, val))
726 snprintf(error, err_max, "Unable to set JIT option (key \"%s\") (value \"%s\")", key, val);
728 pPlugin->CancelMyCompile();
729 pPlugin->m_status = Plugin_Failed;
737 /* Do the actual compiling */
740 pPlugin->FinishMyCompile(NULL, 0);
745 if (pPlugin->GetStatus() == Plugin_Created)
747 AddCoreNativesToPlugin(pPlugin);
748 pPlugin->InitIdentity();
749 pPlugin->Call_AskPluginLoad(error, err_max);
757 return (pPlugin->GetStatus() == Plugin_Loaded);
760 IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType type, char error[], size_t err_max)
764 if (!_LoadPlugin(&pl, path, debug, type, error, err_max))
775 void CPluginManager::LoadAutoPlugin(const char *plugin)
778 char error[255] = "Unknown error";
780 if (!_LoadPlugin(&pl, plugin, false, PluginType_MapUpdated, error, sizeof(error)))
782 g_Logger.LogError("[SOURCEMOD] Failed to load plugin \"%s\": %s", plugin, error);
783 pl->SetErrorState(Plugin_Failed, "%s", error);
789 void CPluginManager::AddPlugin(CPlugin *pPlugin)
791 List<IPluginsListener *>::iterator iter;
792 IPluginsListener *pListener;
794 for (iter=m_listeners.begin(); iter!=m_listeners.end(); iter++)
797 pListener->OnPluginCreated(pPlugin);
800 m_plugins.push_back(pPlugin);
801 sm_trie_insert(m_LoadLookup, pPlugin->m_filename, pPlugin);
804 void CPluginManager::LoadAll_SecondPass()
806 List<CPlugin *>::iterator iter;
809 for (iter=m_plugins.begin(); iter!=m_plugins.end(); iter++)
812 if (pPlugin->GetStatus() == Plugin_Loaded)
815 RunSecondPass(pPlugin, NULL, 0);
819 m_AllPluginsLoaded = true;
822 bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength)
824 /* Find any extensions this plugin needs */
833 IPluginContext *pBase = pPlugin->GetBaseContext();
834 uint32_t num = pBase->GetPubVarsNum();
837 char path[PLATFORM_MAX_PATH+1];
839 for (uint32_t i=0; i<num; i++)
841 if (pBase->GetPubvarByIndex(i, &pubvar) != SP_ERROR_NONE)
845 if (strncmp(pubvar->name, "__ext_", 6) == 0)
847 ext = (_ext *)pubvar->offs;
848 if (!ext->required && !ext->autoload)
852 if (pBase->LocalToString(ext->file, &file) != SP_ERROR_NONE)
856 if (pBase->LocalToString(ext->name, &name) != SP_ERROR_NONE)
860 snprintf(path, PLATFORM_MAX_PATH, "%s.%s", file, PLATFORM_LIB_EXT);
862 /* Attempt to auto-load if necessary */
865 pExt = g_Extensions.LoadAutoExtension(path);
867 if (ext->required && !pExt)
869 if ((pExt = g_Extensions.FindExtensionByFile(path)) == NULL)
871 pExt = g_Extensions.FindExtensionByName(name);
874 if (ext->required && (!pExt || !pExt->IsLoaded()))
878 snprintf(error, maxlength, "Required extension \"%s\" (file \"%s\") not found", name, file);
880 pPlugin->m_status = Plugin_Failed;
886 /* Finish by telling all listeners */
887 List<IPluginsListener *>::iterator iter;
888 IPluginsListener *pListener;
889 for (iter=m_listeners.begin(); iter!=m_listeners.end(); iter++)
892 pListener->OnPluginLoaded(pPlugin);
895 /* Tell this plugin to finish initializing itself */
896 pPlugin->Call_OnPluginInit();
901 void CPluginManager::AddCoreNativesToPlugin(CPlugin *pPlugin)
903 List<sp_nativeinfo_t *>::iterator iter;
905 for (iter=m_natives.begin(); iter!=m_natives.end(); iter++)
907 sp_nativeinfo_t *natives = (*iter);
908 IPluginContext *ctx = pPlugin->GetBaseContext();
910 /* Attempt to bind every native! */
911 while (natives[i].func != NULL)
913 ctx->BindNative(&natives[i++]);
918 bool CPluginManager::UnloadPlugin(IPlugin *plugin)
920 CPlugin *pPlugin = (CPlugin *)plugin;
922 /* This prevents removal during insertion or anything else weird */
923 if (m_plugins.find(pPlugin) == m_plugins.end())
928 List<IPluginsListener *>::iterator iter;
929 IPluginsListener *pListener;
931 if (pPlugin->GetStatus() >= Plugin_Error)
933 /* Notify listeners of unloading */
934 for (iter=m_listeners.begin(); iter!=m_listeners.end(); iter++)
937 pListener->OnPluginUnloaded(pPlugin);
940 pPlugin->Call_OnPluginUnload();
943 for (iter=m_listeners.begin(); iter!=m_listeners.end(); iter++)
945 /* Notify listeners of destruction */
947 pListener->OnPluginDestroyed(pPlugin);
950 /* Remove us from the lookup table and linked list */
951 m_plugins.remove(pPlugin);
952 sm_trie_delete(m_LoadLookup, pPlugin->m_filename);
954 /* Tell the plugin to delete itself */
960 IPlugin *CPluginManager::FindPluginByContext(const sp_context_t *ctx)
962 IPlugin *pl = (IPlugin *)ctx->user[SM_CONTEXTVAR_MYSELF];
966 unsigned int CPluginManager::GetPluginCount()
968 return m_plugins.size();
971 void CPluginManager::AddPluginsListener(IPluginsListener *listener)
973 m_listeners.push_back(listener);
976 void CPluginManager::RemovePluginsListener(IPluginsListener *listener)
978 m_listeners.remove(listener);
981 IPluginIterator *CPluginManager::GetPluginIterator()
985 return new CPluginIterator(&m_plugins);
987 CPluginIterator *iter = m_iters.front();
994 void CPluginManager::ReleaseIterator(CPluginIterator *iter)
999 void CPluginManager::ReleaseFunctionToPool(CFunction *func)
1006 m_funcpool.push(func);
1009 CFunction *CPluginManager::GetFunctionFromPool(funcid_t f, CPlugin *plugin)
1011 if (m_funcpool.empty())
1013 return new CFunction(f, plugin);
1015 CFunction *func = m_funcpool.front();
1017 func->Set(f, plugin);
1022 bool CPluginManager::TestAliasMatch(const char *alias, const char *localpath)
1024 /* As an optimization, we do not call strlen, but compute the length in the first pass */
1025 size_t alias_len = 0;
1026 size_t local_len = 0;
1028 const char *ptr = alias;
1029 unsigned int alias_explicit_paths = 0;
1030 unsigned int alias_path_end = 0;
1031 while (*ptr != '\0')
1033 if (*ptr == '\\' || *ptr == '/')
1035 alias_explicit_paths++;
1036 alias_path_end = alias_len;
1042 if (alias_explicit_paths && alias_path_end == alias_len - 1)
1044 /* Trailing slash is totally invalid here */
1049 unsigned int local_explicit_paths = 0;
1050 unsigned int local_path_end = 0;
1051 while (*ptr != '\0')
1053 if (*ptr == '\\' || *ptr == '/')
1055 local_explicit_paths++;
1056 local_path_end = local_len;
1062 /* If the alias has more explicit paths than the real path,
1063 * no match will be possible.
1065 if (alias_explicit_paths > local_explicit_paths)
1070 if (alias_explicit_paths)
1072 /* We need to find if the paths match now. For example, these should all match:
1074 * csdm optional/csdm
1075 * csdm/ban optional/crab/csdm/ban
1077 const char *aliasptr = alias;
1078 const char *localptr = localpath;
1082 if (*aliasptr != *localptr)
1084 /* We have to knock one path off */
1085 local_explicit_paths--;
1086 if (alias_explicit_paths > local_explicit_paths)
1088 /* Skip out if we're gonna have an impossible match */
1091 /* Eat up localptr tokens until we get a result */
1092 while (((localptr - localpath) < (int)local_path_end)
1094 && *localptr != '\\')
1098 /* Check if we hit the end of our searchable area.
1099 * This probably isn't possible because of the path
1100 * count check, but it's a good idea anyway.
1102 if ((localptr - localpath) >= (int)local_path_end)
1106 /* Consume the slash token */
1109 /* Reset the alias pointer so we can continue consuming */
1115 * This is safe because if localptr terminates early, aliasptr will too
1119 /* We should never reach the end of the string because of this check. */
1120 bool aliasend = (aliasptr - alias) > (int)alias_path_end;
1121 bool localend = (localptr - localpath) > (int)local_path_end;
1122 if (aliasend || localend)
1124 if (aliasend && localend)
1126 /* we matched, and we can break out now */
1130 /* Otherwise, we've hit the end somehow and rest won't match up. Break out. */
1135 /* If we got here, it's safe to compare the next two tokens */
1136 if (*localptr != *aliasptr)
1147 /* If we got here, it's time to compare filenames */
1148 const char *aliasptr = alias;
1149 const char *localptr = localpath;
1151 if (alias_explicit_paths)
1153 aliasptr = &alias[alias_path_end + 1];
1156 if (local_explicit_paths)
1158 localptr = &localpath[local_path_end + 1];
1163 if (*aliasptr == '*')
1165 /* First, see if this is the last character */
1166 if (aliasptr - alias == alias_len - 1)
1168 /* If so, there's no need to match anything else */
1171 /* Otherwise, we need to search for an appropriate matching sequence in local.
1172 * Note that we only need to search up to the next asterisk.
1176 const char *local_orig = localptr;
1180 while (*aliasptr != '\0' && *aliasptr != '*')
1182 /* Since aliasptr is never '\0', localptr hitting the end will fail */
1183 if (*aliasptr != *localptr)
1193 /* If we didn't get a match, we need to advance the search stream.
1194 * This will let us skip tokens while still searching for another match.
1196 localptr = ++local_orig;
1197 /* Make sure we don't go out of bounds */
1198 if (*localptr == '\0')
1209 /* If we got a match, move on to the next token */
1212 } else if (*aliasptr == '\0') {
1213 if (*localptr == '\0'
1215 strcmp(localptr, ".smx") == 0)
1221 } else if (*aliasptr != *localptr) {
1231 bool CPluginManager::IsLateLoadTime() const
1233 return (m_AllPluginsLoaded || g_SourceMod.IsLateLoadInMap());
1236 void CPluginManager::OnSourceModAllInitialized()
1238 m_MyIdent = g_ShareSys.CreateCoreIdentity();
1241 g_HandleSys.InitAccessDefaults(NULL, &sec);
1243 sec.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY;
1244 sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY;
1246 g_PluginType = g_HandleSys.CreateType("Plugin", this, 0, NULL, &sec, m_MyIdent, NULL);
1247 g_PluginIdent = g_ShareSys.CreateIdentType("PLUGIN");
1250 void CPluginManager::OnSourceModShutdown()
1252 List<CPlugin *>::iterator iter;
1253 while ( (iter = m_plugins.begin()) != m_plugins.end() )
1255 UnloadPlugin((*iter));
1258 g_HandleSys.RemoveType(g_PluginType, m_MyIdent);
1259 g_ShareSys.DestroyIdentType(g_PluginIdent);
1260 g_ShareSys.DestroyIdentity(m_MyIdent);
1263 void CPluginManager::OnHandleDestroy(HandleType_t type, void *object)
1265 /* We don't care about the internal object, actually */
1268 void CPluginManager::RegisterNativesFromCore(sp_nativeinfo_t *natives)
1270 m_natives.push_back(natives);
1273 IPlugin *CPluginManager::PluginFromHandle(Handle_t handle, HandleError *err)
1281 sec.pIdentity = m_MyIdent;
1283 if ((_err=g_HandleSys.ReadHandle(handle, g_PluginType, &sec, (void **)&pPlugin)) != HandleError_None)
1296 CPlugin *CPluginManager::GetPluginByOrder(int num)
1298 if (num < 1 || num > (int)GetPluginCount())
1306 IPluginIterator *iter = GetPluginIterator();
1307 for (; iter->MorePlugins() && id<num; iter->NextPlugin(), id++) {}
1309 pl = (CPlugin *)(iter->GetPlugin());