diff --git a/core/GameConfigs.cpp b/core/GameConfigs.cpp index 18ffaeb5..354f3d19 100644 --- a/core/GameConfigs.cpp +++ b/core/GameConfigs.cpp @@ -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) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 39e2c9eb..2a84f142 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -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; diff --git a/core/HalfLife2.h b/core/HalfLife2.h index e6bcf05a..90059620 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -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(); diff --git a/core/smn_keyvalues.cpp b/core/smn_keyvalues.cpp index 45cfb93e..825b26f1 100644 --- a/core/smn_keyvalues.cpp +++ b/core/smn_keyvalues.cpp @@ -33,6 +33,7 @@ #include "sourcemm_api.h" #include "sm_stringutil.h" #include "HandleSys.h" +#include "HalfLife2.h" #include #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)