From d946f9d1a17033d8f33470b924cc05e10a4f01d0 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 1 Sep 2022 01:05:15 +0200 Subject: [PATCH] Fixed bug when reading text files using internal file system Small oversight causing defect, but found during extensive tests and code inspection. --- r5dev/engine/cmodel_bsp.cpp | 6 ++++-- r5dev/materialsystem/cmaterialsystem.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/r5dev/engine/cmodel_bsp.cpp b/r5dev/engine/cmodel_bsp.cpp index aa625f76..d15add9a 100644 --- a/r5dev/engine/cmodel_bsp.cpp +++ b/r5dev/engine/cmodel_bsp.cpp @@ -340,16 +340,18 @@ void MOD_PreloadPakFile(const string& svLevelName) ostringstream ostream; ostream << "scripts/levels/settings/" << svLevelName << ".json"; - FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rb"); + FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rt"); if (!pFile) return; uint32_t nLen = FileSystem()->Size(pFile); uint8_t* pBuf = MemAllocSingleton()->Alloc(nLen); - FileSystem()->Read(pBuf, nLen, pFile); + int nRead = FileSystem()->Read(pBuf, nLen, pFile); FileSystem()->Close(pFile); + pBuf[nRead] = '\0'; + try { nlohmann::json jsIn = nlohmann::json::parse(pBuf); diff --git a/r5dev/materialsystem/cmaterialsystem.cpp b/r5dev/materialsystem/cmaterialsystem.cpp index 83959b75..d7e0dcff 100644 --- a/r5dev/materialsystem/cmaterialsystem.cpp +++ b/r5dev/materialsystem/cmaterialsystem.cpp @@ -19,15 +19,17 @@ void StreamDB_Init(const char* pszLevelName) ostringstream ostream; ostream << "scripts/levels/settings/" << pszLevelName << ".json"; - FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rb"); + FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rt"); if (pFile) { uint32_t nLen = FileSystem()->Size(pFile); uint8_t* pBuf = MemAllocSingleton()->Alloc(nLen); - FileSystem()->Read(pBuf, nLen, pFile); + int nRead = FileSystem()->Read(pBuf, nLen, pFile); FileSystem()->Close(pFile); + pBuf[nRead] = '\0'; + try { nlohmann::json jsIn = nlohmann::json::parse(pBuf);