bool UWizardsSaveGame::LoadGameDataFromFile() { //Load the data array, // you do not need to pre-initialize this array, // UE4 C++ is awesome and fills it // with whatever contents of file are, // and however many bytes that is TArray<uint8> TheBinaryArray; if (!FFileHelper::LoadFileToArray(TheBinaryArray, *ThePath)) { return false; } //File Load Error if (TheBinaryArray.Num() <= 0) return false; //~ // Read the Data Retrieved by GFileManager //~ FMemoryReader FromBinary = FMemoryReader(TheBinaryArray, true); //true, free data after done FromBinary.Seek(0); SaveLoadData(FromBinary, spellBook); //~ // Clean up //~ FromBinary.FlushCache(); // Empty & Close Buffer TheBinaryArray.Empty(); FromBinary.Close(); return true; }
bool ULevelDBPluginBPLibrary::ReadObjectFromLevelDB(ULevelDBObject* DatabaseObject, FString Key, UObject* & Value) { if (DatabaseObject->db != NULL) { UObject* FinalObject = NULL; TArray<uint8> ObjectBytes; std::string result; leveldb::Status s = DatabaseObject->db->Get(leveldb::ReadOptions(), TCHAR_TO_UTF8(*Key), &result); ObjectBytes.Append((uint8*)result.data(), result.size()); FMemoryReader MemoryReader = FMemoryReader(ObjectBytes, true); FString ObjectClassName; MemoryReader << ObjectClassName; // Try and find it, and failing that, load it UClass* ObjectClass = FindObject<UClass>(ANY_PACKAGE, *ObjectClassName); if (ObjectClass == NULL) { ObjectClass = LoadObject<UClass>(NULL, *ObjectClassName); } // If we have a class, try and load it. if (ObjectClass != NULL) { Value = NewObject<UObject>(GetTransientPackage(), ObjectClass); FObjectAndNameAsStringProxyArchive Ar(MemoryReader, true); Value->Serialize(Ar); if (IsValid(Value)) return true; } } return false; }