Merge.
This commit is contained in:
+26
-5
@@ -79,9 +79,7 @@ void Hook_ExecDispatchPre()
|
||||
|
||||
const char *arg = cmd.Arg(1);
|
||||
|
||||
if (!g_bServerExecd
|
||||
&& arg != NULL
|
||||
&& strcmp(arg, g_ServerCfgFile->GetString()) == 0)
|
||||
if (!g_bServerExecd && arg != NULL && strcmp(arg, g_ServerCfgFile->GetString()) == 0)
|
||||
{
|
||||
g_bGotTrigger = true;
|
||||
}
|
||||
@@ -103,8 +101,7 @@ void Hook_ExecDispatchPost()
|
||||
|
||||
void CheckAndFinalizeConfigs()
|
||||
{
|
||||
if ((g_bServerExecd || g_ServerCfgFile == NULL)
|
||||
&& g_bGotServerStart)
|
||||
if ((g_bServerExecd || g_ServerCfgFile == NULL) && g_bGotServerStart)
|
||||
{
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
g_PendingInternalPush = true;
|
||||
@@ -122,6 +119,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);
|
||||
@@ -218,6 +223,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)
|
||||
{
|
||||
@@ -256,9 +265,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();
|
||||
|
||||
+38
-11
@@ -749,6 +749,44 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse the contents of the 'custom' directory */
|
||||
g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "gamedata/%s/custom", m_File);
|
||||
IDirectory *customDir = g_LibSys.OpenDirectory(path);
|
||||
|
||||
if (!customDir)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
while (customDir->MoreFiles())
|
||||
{
|
||||
if (!customDir->IsEntryFile())
|
||||
{
|
||||
customDir->NextEntry();
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *curFile = customDir->GetEntryName();
|
||||
|
||||
/* Only allow .txt files */
|
||||
int len = strlen(curFile);
|
||||
if (len > 4 && strcmp(&curFile[len-4], ".txt") != 0)
|
||||
{
|
||||
customDir->NextEntry();
|
||||
continue;
|
||||
}
|
||||
|
||||
UTIL_Format(path, sizeof(path), "%s/custom/%s", m_File, curFile);
|
||||
if (!EnterFile(path, error, maxlength))
|
||||
{
|
||||
g_LibSys.CloseDirectory(customDir);
|
||||
return false;
|
||||
}
|
||||
|
||||
customDir->NextEntry();
|
||||
}
|
||||
|
||||
g_LibSys.CloseDirectory(customDir);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -764,15 +802,11 @@ bool CGameConfig::EnterFile(const char *file, char *error, size_t maxlength)
|
||||
bShouldBeReadingDefault = true;
|
||||
m_ParseState = PSTATE_NONE;
|
||||
|
||||
g_GameConfigs.AcquireLock();
|
||||
|
||||
if ((err=textparsers->ParseSMCFile(m_CurFile, this, &state, error, maxlength))
|
||||
!= SMCError_Okay)
|
||||
{
|
||||
const char *msg;
|
||||
|
||||
g_GameConfigs.ReleaseLock();
|
||||
|
||||
msg = textparsers->GetSMCErrorString(err);
|
||||
|
||||
g_Logger.LogError("[SM] Error parsing gameconfig file \"%s\":", m_CurFile);
|
||||
@@ -793,8 +827,6 @@ bool CGameConfig::EnterFile(const char *file, char *error, size_t maxlength)
|
||||
return false;
|
||||
}
|
||||
|
||||
g_GameConfigs.ReleaseLock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -862,8 +894,6 @@ GameConfigManager::~GameConfigManager()
|
||||
|
||||
void GameConfigManager::OnSourceModStartup(bool late)
|
||||
{
|
||||
m_FileLock = g_pThreader->MakeMutex();
|
||||
|
||||
LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0);
|
||||
|
||||
strncopy(g_Game, g_SourceMod.GetGameFolderName(), sizeof(g_Game));
|
||||
@@ -898,7 +928,6 @@ void GameConfigManager::OnSourceModAllInitialized()
|
||||
void GameConfigManager::OnSourceModAllShutdown()
|
||||
{
|
||||
CloseGameConfigFile(g_pGameConf);
|
||||
m_FileLock->DestroyThis();
|
||||
}
|
||||
|
||||
bool GameConfigManager::LoadGameConfigFile(const char *file, IGameConfig **_pConfig, char *error, size_t maxlength)
|
||||
@@ -993,10 +1022,8 @@ void GameConfigManager::RemoveUserConfigHook(const char *sectionname, ITextListe
|
||||
|
||||
void GameConfigManager::AcquireLock()
|
||||
{
|
||||
m_FileLock->Lock();
|
||||
}
|
||||
|
||||
void GameConfigManager::ReleaseLock()
|
||||
{
|
||||
m_FileLock->Unlock();
|
||||
}
|
||||
|
||||
@@ -120,7 +120,6 @@ public: //SMGlobalClass
|
||||
private:
|
||||
List<CGameConfig *> m_cfgs;
|
||||
Trie *m_pLookup;
|
||||
IMutex *m_FileLock;
|
||||
public:
|
||||
KTrie<ITextListener_SMC *> m_customHandlers;
|
||||
};
|
||||
|
||||
@@ -348,6 +348,8 @@ void UserMessages::OnMessageEnd_Post()
|
||||
MsgIter iter;
|
||||
ListenerInfo *pInfo;
|
||||
|
||||
m_InHook = false;
|
||||
|
||||
pList = &m_msgIntercepts[m_CurId];
|
||||
for (iter=pList->begin(); iter!=pList->end(); )
|
||||
{
|
||||
@@ -367,8 +369,6 @@ void UserMessages::OnMessageEnd_Post()
|
||||
iter++;
|
||||
}
|
||||
|
||||
m_InHook = false;
|
||||
|
||||
pList = &m_msgHooks[m_CurId];
|
||||
for (iter=pList->begin(); iter!=pList->end(); )
|
||||
{
|
||||
|
||||
+28
-7
@@ -70,6 +70,12 @@ typedef ISourcePawnEngine *(*GET_SP_V1)();
|
||||
typedef ISourcePawnEngine2 *(*GET_SP_V2)();
|
||||
typedef void (*NOTIFYSHUTDOWN)();
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
ConVar sm_basepath("sm_basepath", "addons\\sourcemod", 0, "SourceMod base path (set via command line)");
|
||||
#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE
|
||||
ConVar sm_basepath("sm_basepath", "addons/sourcemod", 0, "SourceMod base path (set via command line)");
|
||||
#endif
|
||||
|
||||
void ShutdownJIT()
|
||||
{
|
||||
NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
|
||||
@@ -145,16 +151,26 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize CoreConfig so we can get SourceMod base path properly - this basically parses core.cfg */
|
||||
g_CoreConfig.Initialize();
|
||||
|
||||
/* This shouldn't happen, but can't hurt to be safe */
|
||||
if (!g_LibSys.PathExists(m_SMBaseDir) || !m_GotBasePath)
|
||||
const char *basepath = icvar->GetCommandLineValue("sm_basepath");
|
||||
/* Set a custom base path if there is one. */
|
||||
if (basepath != NULL && basepath[0] != '\0')
|
||||
{
|
||||
g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str());
|
||||
g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "addons/sourcemod");
|
||||
m_GotBasePath = true;
|
||||
}
|
||||
/* Otherwise, use a default and keep the m_GotBasePath unlocked. */
|
||||
else
|
||||
{
|
||||
basepath = sm_basepath.GetDefault();
|
||||
}
|
||||
|
||||
g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath);
|
||||
g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath);
|
||||
|
||||
/* Initialize CoreConfig to get the SourceMod base path properly - this parses core.cfg */
|
||||
g_CoreConfig.Initialize();
|
||||
|
||||
/* There will always be a path by this point, since it was force-set above. */
|
||||
m_GotBasePath = true;
|
||||
|
||||
/* Attempt to load the JIT! */
|
||||
char file[PLATFORM_MAX_PATH];
|
||||
@@ -696,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];
|
||||
|
||||
Reference in New Issue
Block a user