diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index c021d767..4201b18a 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -116,6 +116,14 @@ void CoreConfig::OnSourceModAllInitialized() g_pOnAutoConfigsBuffered = g_Forwards.CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL); } +CoreConfig::CoreConfig() : m_Strings(512) +{ +} + +CoreConfig::~CoreConfig() +{ +} + void CoreConfig::OnSourceModShutdown() { g_RootMenu.RemoveRootConsoleCommand("config", this); @@ -212,6 +220,10 @@ void CoreConfig::Initialize() /* Format path to config file */ g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg); + /* Reset cached key values */ + m_KeyValues.clear(); + m_Strings.Reset(); + /* Parse config file */ if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay) { @@ -250,9 +262,21 @@ ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value, pBase = pBase->m_pGlobalClassNext; } + m_KeyValues.replace(option, m_Strings.AddString(value)); + return ConfigResult_Ignore; } +const char *CoreConfig::GetCoreConfigValue(const char *key) +{ + int *pKey = m_KeyValues.retrieve(key); + if (pKey == NULL) + { + return NULL; + } + return m_Strings.GetString(*pKey); +} + bool SM_AreConfigsExecuted() { return g_bConfigsExecd; diff --git a/core/CoreConfig.h b/core/CoreConfig.h index 5b1c605d..6bf28591 100644 --- a/core/CoreConfig.h +++ b/core/CoreConfig.h @@ -35,6 +35,8 @@ #include "sm_globals.h" #include #include +#include +#include "sm_memtable.h" using namespace SourceMod; @@ -43,6 +45,9 @@ class CoreConfig : public ITextListener_SMC, public IRootConsoleCommand { +public: + CoreConfig(); + ~CoreConfig(); public: // SMGlobalClass void OnSourceModAllInitialized(); void OnSourceModShutdown(); @@ -56,11 +61,15 @@ public: * Initializes CoreConfig by reading from core.cfg file */ void Initialize(); + const char *GetCoreConfigValue(const char *key); private: /** * Sets configuration option by notifying SourceMod components that rely on core.cfg */ ConfigResult SetConfigOption(const char *option, const char *value, ConfigSource, char *Error, size_t maxlength); +private: + BaseStringTable m_Strings; + KTrie m_KeyValues; }; extern bool SM_AreConfigsExecuted(); diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index f1b6161c..0b3d7360 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -712,6 +712,11 @@ void SourceModBase::AddFrameAction(FRAMEACTION fn, void *data) ::AddFrameAction(FrameAction(fn, data)); } +const char *SourceModBase::GetCoreConfigValue(const char *key) +{ + return g_CoreConfig.GetCoreConfigValue(key); +} + SMGlobalClass *SMGlobalClass::head = NULL; SMGlobalClass::SMGlobalClass() diff --git a/core/sourcemod.h b/core/sourcemod.h index a436b42e..ecf23921 100644 --- a/core/sourcemod.h +++ b/core/sourcemod.h @@ -132,6 +132,7 @@ public: // ISourceMod size_t Format(char *buffer, size_t maxlength, const char *fmt, ...); size_t FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap); void AddFrameAction(FRAMEACTION fn, void *data); + const char *GetCoreConfigValue(const char *key); private: CStack m_freepacks; char m_SMBaseDir[PLATFORM_MAX_PATH]; diff --git a/public/ISourceMod.h b/public/ISourceMod.h index 09d4bedf..69fe1f0c 100644 --- a/public/ISourceMod.h +++ b/public/ISourceMod.h @@ -43,7 +43,7 @@ #include #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod" -#define SMINTERFACE_SOURCEMOD_VERSION 9 +#define SMINTERFACE_SOURCEMOD_VERSION 10 /** * @brief Forward declaration of the KeyValues class. @@ -287,6 +287,15 @@ namespace SourceMod * @param data Data to pass to function. */ virtual void AddFrameAction(FRAMEACTION fn, void *data) = 0; + + /** + * @brief Retrieves a core.cfg configuration value. + * + * @param key Core.cfg key phrase. + * @return Value string, or NULL on failure. + * The string will be destroyed on core.cfg reparses. + */ + virtual const char *GetCoreConfigValue(const char *key) = 0; }; }