MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / KVLoadFromFile

Method KVLoadFromFile

core/HalfLife2.cpp:799–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

797}
798
799bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
800{
801 if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
802 {
803 Assert(filesystem);
804#ifdef _MSC_VER
805 Assert(_heapchk() == _HEAPOK);
806#endif
807
808 FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
809 if (!f)
810 return false;
811
812 // load file into a null-terminated buffer
813 int fileSize = filesystem->Size(f);
814 char *buffer = (char *)MemAllocScratch(fileSize + 1);
815
816 Assert(buffer);
817
818 filesystem->Read(buffer, fileSize, f); // read into local buffer
819
820 buffer[fileSize] = 0; // null terminate file as EOF
821
822 filesystem->Close( f ); // close file after reading
823
824 bool retOK = kv->LoadFromBuffer( resourceName, buffer, filesystem );
825
826 MemFreeScratch();
827
828 return retOK;
829 }
830 else
831 {
832 return kv->LoadFromFile(filesystem, resourceName, pathID);
833 }
834}
835
836void CHalfLife2::PushCommandStack(const ICommandArgs *cmd)
837{

Callers 2

GetGameNameMethod · 0.80
smn_FileToKeyValuesFunction · 0.80

Calls 4

OpenMethod · 0.45
SizeMethod · 0.45
ReadMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected