From e08b4cdf1e167a9d3ad5c2cd455f069d350882b4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 15 Oct 2007 04:27:56 +0000 Subject: [PATCH] - LibraryExists() now works on extensions - geoip and cstrike now work as libraries --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401579 --- core/smn_core.cpp | 12 +++++++++++- core/systems/ExtensionSys.cpp | 23 +++++++++++++++++++++++ core/systems/ExtensionSys.h | 1 + extensions/cstrike/extension.cpp | 1 + extensions/geoip/extension.cpp | 1 + plugins/include/cstrike.inc | 10 +++++++++- plugins/include/geoip.inc | 9 +++++++++ plugins/include/sourcemod.inc | 7 +++++-- 8 files changed, 60 insertions(+), 4 deletions(-) diff --git a/core/smn_core.cpp b/core/smn_core.cpp index 2a7dbf29..b55042ed 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -463,7 +463,17 @@ static cell_t LibraryExists(IPluginContext *pContext, const cell_t *params) char *str; pContext->LocalToString(params[1], &str); - return g_PluginSys.LibraryExists(str) ? 1 : 0; + if (g_PluginSys.LibraryExists(str)) + { + return 1; + } + + if (g_Extensions.LibraryExists(str)) + { + return 1; + } + + return 0; } static cell_t sm_LogAction(IPluginContext *pContext, const cell_t *params) diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index f0ec6af0..88b6ea52 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -1118,3 +1118,26 @@ void CExtensionManager::AddLibrary(IExtension *pSource, const char *library) pExt->AddLibrary(library); g_PluginSys.OnLibraryAction(library, false, false); } + +bool CExtensionManager::LibraryExists(const char *library) +{ + CExtension *pExt; + + for (List::iterator iter = m_Libs.begin(); + iter != m_Libs.end(); + iter++) + { + pExt = (*iter); + for (List::iterator s_iter = pExt->m_Libraries.begin(); + s_iter != pExt->m_Libraries.end(); + s_iter++) + { + if ((*s_iter).compare(library) == 0) + { + return true; + } + } + } + + return false; +} diff --git a/core/systems/ExtensionSys.h b/core/systems/ExtensionSys.h index 8ad05a8d..0816fb0c 100644 --- a/core/systems/ExtensionSys.h +++ b/core/systems/ExtensionSys.h @@ -135,6 +135,7 @@ public: void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload); void TryAutoload(); void AddLibrary(IExtension *pSource, const char *library); + bool LibraryExists(const char *library); public: CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); void Shutdown(); diff --git a/extensions/cstrike/extension.cpp b/extensions/cstrike/extension.cpp index c2402f96..182ae75e 100644 --- a/extensions/cstrike/extension.cpp +++ b/extensions/cstrike/extension.cpp @@ -65,6 +65,7 @@ bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late) } sharesys->AddNatives(myself, g_CSNatives); + sharesys->RegisterLibrary(myself, "cstrike"); return true; } diff --git a/extensions/geoip/extension.cpp b/extensions/geoip/extension.cpp index b2013ee5..191470b0 100644 --- a/extensions/geoip/extension.cpp +++ b/extensions/geoip/extension.cpp @@ -55,6 +55,7 @@ bool GeoIP_Extension::SDK_OnLoad(char *error, size_t maxlength, bool late) } g_pShareSys->AddNatives(myself, geoip_natives); + g_pShareSys->RegisterLibrary(myself, "GeoIP"); g_pSM->LogMessage(myself, "GeoIP database info: %s", GeoIP_database_info(gi)); return true; diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index 50107b3d..b0e867cd 100644 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -71,7 +71,7 @@ native CS_SwitchTeam(client, team); */ public Extension:__ext_cstrike = { - name = "CStrike", + name = "cstrike", file = "games/game.cstrike.ext", autoload = 0, #if defined REQUIRE_EXTENSIONS @@ -80,3 +80,11 @@ public Extension:__ext_cstrike = required = 0, #endif }; + +#if !defined REQUIRE_EXTENSIONS +public __ext_cstrike_SetNTVOptional() +{ + MarkNativeAsOptional("CS_RespawnPlayer"); + MarkNativeAsOptional("CS_SwitchTeam"); +} +#endif diff --git a/plugins/include/geoip.inc b/plugins/include/geoip.inc index 03f3cff3..07fbb0fb 100644 --- a/plugins/include/geoip.inc +++ b/plugins/include/geoip.inc @@ -91,3 +91,12 @@ public Extension:__ext_geoip = required = 0, #endif }; + +#if !defined REQUIRE_EXTENSIONS +public __ext_geoip_SetNTVOptional() +{ + MarkNativeAsOptional("GeoipCode2"); + MarkNativeAsOptional("GeoipCode3"); + MarkNativeAsOptional("GeoipCountry"); +} +#endif diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index aa33535a..bab00c80 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -446,9 +446,12 @@ native MarkNativeAsOptional(const String:name[]); native RegPluginLibrary(const String:name[]); /** - * Returns whether a library exists. + * Returns whether a library exists. This function should be considered + * expensive; it should only be called on plugin to determine availability + * of resources. Use OnLibraryAdded()/OnLibraryRemoved() to detect changes + * in optional resources. * - * @param name Library name. + * @param name Library name of a plugin or extension. * @return True if exists, false otherwise. */ native bool:LibraryExists(const String:name[]);