r5sdk/r5dev/vpc/rson.cpp
Kawe Mazidjatari 5f64cd83d8 Fix FileSystem size integer truncation
The implementation in the engine always took/returned signed 64bit size types, but I made a mistake when reversing the virtual function table. All types have been changed to what they should be (mostly signed 64bit, very few unsigned), and usage in-SDK has been adjusted accordingly.
2023-08-09 14:43:54 +02:00

42 lines
1.5 KiB
C++

#include "core/stdafx.h"
#include <tier0/memstd.h>
#include "tier1/utlbuffer.h"
#include <filesystem/filesystem.h>
#include "vpc/rson.h"
//-----------------------------------------------------------------------------
// Purpose: loads an RSON from a buffer
// Input : *pszBufferName -
// *pBuffer -
// rootType -
// Output : pointer to RSON object on success, nullptr otherwise
//-----------------------------------------------------------------------------
RSON::Node_t* RSON::LoadFromBuffer(const char* pszBufferName, char* pBuffer, RSON::eFieldType rootType)
{
return RSON_LoadFromBuffer(pszBufferName, pBuffer, rootType, 0, NULL);
}
//-----------------------------------------------------------------------------
// Purpose: loads an RSON from a file
// Input : *pszFilePath -
// *pPathID -
// Output : pointer to RSON object on success, nullptr otherwise
//-----------------------------------------------------------------------------
RSON::Node_t* RSON::LoadFromFile(const char* pszFilePath, const char* pPathID)
{
FileHandle_t file = FileSystem()->Open(pszFilePath, "rt", pPathID);
if (!file)
return NULL;
const ssize_t nFileSize = FileSystem()->Size(file);
std::unique_ptr<char[]> fileBuf(new char[nFileSize + 1]);
const ssize_t nRead = FileSystem()->Read(fileBuf.get(), nFileSize, file);
FileSystem()->Close(file);
fileBuf[nRead] = '\0';
RSON::Node_t* node = RSON::LoadFromBuffer(pszFilePath, fileBuf.get(), eFieldType::RSON_OBJECT);
return node;
}