Added API to grab arbitrary kv pairs from core.cfg.
This commit is contained in:
		
							parent
							
								
									97e25c37de
								
							
						
					
					
						commit
						9e445a5adf
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,8 @@
 | 
			
		||||
#include "sm_globals.h"
 | 
			
		||||
#include <ITextParsers.h>
 | 
			
		||||
#include <IRootConsoleMenu.h>
 | 
			
		||||
#include <sm_trie_tpl.h>
 | 
			
		||||
#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<int> m_KeyValues;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern bool SM_AreConfigsExecuted();
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
 | 
			
		||||
@ -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<CDataPack *> m_freepacks;
 | 
			
		||||
	char m_SMBaseDir[PLATFORM_MAX_PATH];
 | 
			
		||||
 | 
			
		||||
@ -43,7 +43,7 @@
 | 
			
		||||
#include <time.h>
 | 
			
		||||
 | 
			
		||||
#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;
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user