1.1 --- a/core/smn_core.cpp Sun Jul 15 22:34:30 2007 +0000
1.2 +++ b/core/smn_core.cpp Mon Jul 16 02:06:02 2007 +0000
1.3 @@ -339,7 +339,8 @@
1.4 pContext->LocalToString(params[1], &name);
1.5 if (pContext->FindNativeByName(name, &idx) != SP_ERROR_NONE)
1.6 {
1.7 - return pContext->ThrowNativeError("Unable to find native \"%s\"", name);
1.8 + /* Oops! This HAS to silently fail! */
1.9 + return 0;
1.10 }
1.11
1.12 ctx->natives[idx].flags |= SP_NTVFLAG_OPTIONAL;
1.13 @@ -359,6 +360,14 @@
1.14 return 1;
1.15 }
1.16
1.17 +static cell_t LibraryExists(IPluginContext *pContext, const cell_t *params)
1.18 +{
1.19 + char *str;
1.20 + pContext->LocalToString(params[1], &str);
1.21 +
1.22 + return g_PluginSys.LibraryExists(str) ? 1 : 0;
1.23 +}
1.24 +
1.25 REGISTER_NATIVES(coreNatives)
1.26 {
1.27 {"AutoExecConfig", AutoExecConfig},
1.28 @@ -376,5 +385,6 @@
1.29 {"FormatTime", FormatTime},
1.30 {"MarkNativeAsOptional", MarkNativeAsOptional},
1.31 {"RegPluginLibrary", RegPluginLibrary},
1.32 + {"LibraryExists", LibraryExists},
1.33 {NULL, NULL},
1.34 };
2.1 --- a/core/systems/PluginSys.cpp Sun Jul 15 22:34:30 2007 +0000
2.2 +++ b/core/systems/PluginSys.cpp Mon Jul 16 02:06:02 2007 +0000
2.3 @@ -425,15 +425,31 @@
2.4 return ((m_ctx.ctx->flags & SP_FLAG_DEBUG) == SP_FLAG_DEBUG);
2.5 }
2.6
2.7 +void CPlugin::LibraryActions(bool dropping)
2.8 +{
2.9 + List<String>::iterator iter;
2.10 + for (iter = m_Libraries.begin();
2.11 + iter != m_Libraries.end();
2.12 + iter++)
2.13 + {
2.14 + g_PluginSys.OnLibraryAction((*iter).c_str(), dropping);
2.15 + }
2.16 +}
2.17 +
2.18 bool CPlugin::SetPauseState(bool paused)
2.19 {
2.20 - if (paused && GetStatus() != Plugin_Paused)
2.21 + if (paused && GetStatus() != Plugin_Running)
2.22 {
2.23 return false;
2.24 - } else if (!paused && GetStatus() != Plugin_Running) {
2.25 + } else if (!paused && GetStatus() != Plugin_Paused) {
2.26 return false;
2.27 }
2.28
2.29 + if (paused)
2.30 + {
2.31 + LibraryActions(true);
2.32 + }
2.33 +
2.34 IPluginFunction *pFunction = m_ctx.base->GetFunctionByName("OnPluginPauseChange");
2.35 if (pFunction)
2.36 {
2.37 @@ -453,6 +469,11 @@
2.38
2.39 g_PluginSys._SetPauseState(this, paused);
2.40
2.41 + if (!paused)
2.42 + {
2.43 + LibraryActions(false);
2.44 + }
2.45 +
2.46 return true;
2.47 }
2.48
2.49 @@ -1253,6 +1274,15 @@
2.50 }
2.51 }
2.52
2.53 + /* Go through our libraries and tell other plugins they're added */
2.54 + List<String>::iterator s_iter;
2.55 + for (s_iter = pPlugin->m_Libraries.begin();
2.56 + s_iter != pPlugin->m_Libraries.end();
2.57 + s_iter++)
2.58 + {
2.59 + OnLibraryAction((*s_iter).c_str(), false);
2.60 + }
2.61 +
2.62 return true;
2.63 }
2.64
2.65 @@ -1395,6 +1425,15 @@
2.66 m_plugins.remove(pPlugin);
2.67 sm_trie_delete(m_LoadLookup, pPlugin->m_filename);
2.68
2.69 + /* Go through our libraries and tell other plugins they're gone */
2.70 + List<String>::iterator s_iter;
2.71 + for (s_iter = pPlugin->m_Libraries.begin();
2.72 + s_iter != pPlugin->m_Libraries.end();
2.73 + s_iter++)
2.74 + {
2.75 + OnLibraryAction((*s_iter).c_str(), true);
2.76 + }
2.77 +
2.78 /* Go through all dependent plugins and tell them this plugin is now gone */
2.79 List<CPlugin *>::iterator pl_iter;
2.80 CPlugin *pOther;
2.81 @@ -2190,9 +2229,88 @@
2.82 return (CPlugin *)(pToken->ptr);
2.83 }
2.84
2.85 -void CPluginManager::ExecAndGenPluginConfs()
2.86 +void CPluginManager::OnLibraryAction(const char *lib, bool drop)
2.87 {
2.88 List<CPlugin *>::iterator iter;
2.89
2.90 - //for (iter =
2.91 + struct _pl
2.92 + {
2.93 + cell_t name;
2.94 + cell_t file;
2.95 + cell_t required;
2.96 + } *plc;
2.97 +
2.98 + const char *name = drop ? "OnLibraryRemoved" : "OnLibraryAdded";
2.99 +
2.100 + for (iter=m_plugins.begin();
2.101 + iter!=m_plugins.end();
2.102 + iter++)
2.103 + {
2.104 + CPlugin *pl = (*iter);
2.105 + if (pl->GetStatus() != Plugin_Running)
2.106 + {
2.107 + continue;
2.108 + }
2.109 + IPluginContext *pContext = pl->GetBaseContext();
2.110 + IPluginFunction *pf = pContext->GetFunctionByName(name);
2.111 + if (!pf)
2.112 + {
2.113 + continue;
2.114 + }
2.115 + sp_context_t *ctx = pContext->GetContext();
2.116 + uint32_t num_vars = pContext->GetPubVarsNum();
2.117 + for (uint32_t i=0; i<num_vars; i++)
2.118 + {
2.119 + sp_pubvar_t *pubvar;
2.120 + if (pContext->GetPubvarByIndex(i, &pubvar) != SP_ERROR_NONE)
2.121 + {
2.122 + continue;
2.123 + }
2.124 + if (strncmp(pubvar->name, "__pl_", 5) != 0)
2.125 + {
2.126 + continue;
2.127 + }
2.128 + plc = (_pl *)pubvar->offs;
2.129 + if (plc->required)
2.130 + {
2.131 + continue;
2.132 + }
2.133 + char *str;
2.134 + pContext->LocalToString(plc->name, &str);
2.135 + if (strcmp(str, lib) != 0)
2.136 + {
2.137 + continue;
2.138 + }
2.139 + pf->PushString(lib);
2.140 + pf->Execute(NULL);
2.141 + }
2.142 + }
2.143 }
2.144 +
2.145 +bool CPluginManager::LibraryExists(const char *lib)
2.146 +{
2.147 + List<CPlugin *>::iterator iter;
2.148 +
2.149 + for (iter=m_plugins.begin();
2.150 + iter!=m_plugins.end();
2.151 + iter++)
2.152 + {
2.153 + CPlugin *pl = (*iter);
2.154 + if (pl->GetStatus() != Plugin_Running)
2.155 + {
2.156 + continue;
2.157 + }
2.158 + List<String>::iterator s_iter;
2.159 + for (s_iter = pl->m_Libraries.begin();
2.160 + s_iter != pl->m_Libraries.end();
2.161 + s_iter++)
2.162 + {
2.163 + if ((*s_iter).compare(lib) == 0)
2.164 + {
2.165 + return true;
2.166 + }
2.167 + }
2.168 + }
2.169 +
2.170 + return false;
2.171 +}
3.1 --- a/core/systems/PluginSys.h Sun Jul 15 22:34:30 2007 +0000
3.2 +++ b/core/systems/PluginSys.h Mon Jul 16 02:06:02 2007 +0000
3.3 @@ -250,6 +250,7 @@
3.4 {
3.5 m_Libraries.push_back(name);
3.6 }
3.7 + void LibraryActions(bool dropping);
3.8 protected:
3.9 void UpdateInfo();
3.10 void SetTimeStamp(time_t t);
3.11 @@ -398,6 +399,9 @@
3.12
3.13 void Shutdown();
3.14
3.15 + void OnLibraryAction(const char *lib, bool drop);
3.16 +
3.17 + bool LibraryExists(const char *lib);
3.18 private:
3.19 LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
3.20
3.21 @@ -434,8 +438,6 @@
3.22 bool FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size_t maxlength);
3.23
3.24 void _SetPauseState(CPlugin *pPlugin, bool pause);
3.25 -
3.26 - void ExecAndGenPluginConfs();
3.27 protected:
3.28 /**
3.29 * Caching internal objects
4.1 --- a/plugins/include/sourcemod.inc Sun Jul 15 22:34:30 2007 +0000
4.2 +++ b/plugins/include/sourcemod.inc Mon Jul 16 02:06:02 2007 +0000
4.3 @@ -348,5 +348,29 @@
4.4 */
4.5 native RegPluginLibrary(const String:name[]);
4.6
4.7 +/**
4.8 + * Returns whether a library exists.
4.9 + *
4.10 + * @param name Library name.
4.11 + * @return True if exists, false otherwise.
4.12 + */
4.13 +native bool:LibraryExists(const String:name[]);
4.14 +
4.15 +/**
4.16 + * Called after a library (plugin) is added that the
4.17 + * current plugin references optionally.
4.18 + *
4.19 + * @param name Library name.
4.20 + */
4.21 +forward OnLibraryAdded(const String:name[]);
4.22 +
4.23 +/**
4.24 + * Called right before a library (plugin) is removed that the
4.25 + * current plugin references optionally.
4.26 + *
4.27 + * @param name Library name.
4.28 + */
4.29 +forward OnLibraryRemoved(const String:name[]);
4.30 +
4.31 #include <helpers>
4.32 #include <entity>