Merged crash fix (amb1539) from 1.0.1 branch

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401958
This commit is contained in:
Scott Ehlert 2008-03-21 04:26:53 +00:00
parent 83a1ebcf0f
commit 3bcd296d99
4 changed files with 47 additions and 2 deletions

View File

@ -598,7 +598,7 @@ void GameConfigManager::OnSourceModStartup(bool late)
strncopy(g_GameDesc + 1, SERVER_CALL(GetGameDescription)(), sizeof(g_GameDesc) - 1);
KeyValues *pGameInfo = new KeyValues("GameInfo");
if (pGameInfo->LoadFromFile(basefilesystem, "gameinfo.txt"))
if (g_HL2.KVLoadFromFile(pGameInfo, basefilesystem, "gameinfo.txt"))
{
const char *str;
if ((str = pGameInfo->GetString("game", NULL)) != NULL)

View File

@ -435,6 +435,47 @@ bool CHalfLife2::IsLANServer()
return (sv_lan->GetInt() != 0);
}
bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
{
#if defined METAMOD_PLAPI_VERSION
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
#else
if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
#endif
{
Assert(filesystem);
#ifdef _MSC_VER
Assert(_heapchk() == _HEAPOK);
#endif
FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
if (!f)
return false;
// load file into a null-terminated buffer
int fileSize = filesystem->Size(f);
char *buffer = (char *)MemAllocScratch(fileSize + 1);
Assert(buffer);
filesystem->Read(buffer, fileSize, f); // read into local buffer
buffer[fileSize] = 0; // null terminate file as EOF
filesystem->Close( f ); // close file after reading
bool retOK = kv->LoadFromBuffer( resourceName, buffer, filesystem );
MemFreeScratch();
return retOK;
}
else
{
return kv->LoadFromFile(filesystem, resourceName, pathID);
}
}
void CHalfLife2::PushCommandStack(const CCommand *cmd)
{
CachedCommandInfo info;

View File

@ -99,6 +99,7 @@ public: //IGameHelpers
bool HintTextMsg(int client, const char *msg);
bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
bool IsLANServer();
bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
public:
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
void ProcessFakeCliCmdQueue();

View File

@ -33,6 +33,7 @@
#include "sourcemm_api.h"
#include "sm_stringutil.h"
#include "HandleSys.h"
#include "HalfLife2.h"
#include <KeyValues.h>
#include "utlbuffer.h"
@ -782,6 +783,7 @@ static cell_t smn_FileToKeyValues(IPluginContext *pCtx, const cell_t *params)
HandleSecurity sec;
char *path;
KeyValueStack *pStk;
KeyValues *kv;
sec.pOwner = NULL;
sec.pIdentity = g_pCoreIdent;
@ -797,7 +799,8 @@ static cell_t smn_FileToKeyValues(IPluginContext *pCtx, const cell_t *params)
char realpath[PLATFORM_MAX_PATH];
g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
return pStk->pCurRoot.front()->LoadFromFile(basefilesystem, realpath);
kv = pStk->pCurRoot.front();
return g_HL2.KVLoadFromFile(kv, basefilesystem, realpath);
}
static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *params)