MassBuilderSaveTool/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp

74 lines
2.5 KiB
C++
Raw Normal View History

2021-09-22 17:37:50 +02:00
// MassBuilderSaveTool
// Copyright (C) 2021-2022 Guillaume Jacquemin
2021-09-22 17:37:50 +02:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "../BinaryReader.h"
#include "../BinaryWriter.h"
#include "../PropertySerialiser.h"
#include "SetPropertySerialiser.h"
auto SetPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{
std::string item_type;
if(!reader.readUEString(item_type)) {
return nullptr;
}
char terminator;
if(!reader.readChar(terminator) || terminator != '\0') {
return nullptr;
}
UnsignedInt four_bytes;
if(!reader.readUnsignedInt(four_bytes) || four_bytes != 0u) {
return nullptr;
}
UnsignedInt item_count;
if(!reader.readUnsignedInt(item_count)) {
return nullptr;
}
auto prop = Containers::pointer<SetProperty>();
prop->itemType = std::move(item_type);
prop->items = serialiser.readSet(reader, prop->itemType, item_count);
return prop;
}
auto SetPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{
auto set_prop = dynamic_cast<SetProperty*>(prop.get());
if(!set_prop) {
return false;
}
writer.writeUEStringToArray(set_prop->itemType);
writer.writeValueToArray<char>('\0');
bytes_written += writer.writeValueToArray<UnsignedInt>(0u);
bytes_written += writer.writeValueToArray<UnsignedInt>(UnsignedInt(set_prop->items.size()));
UnsignedLong start_pos = writer.arrayPosition();
UnsignedLong dummy_bytes_written = 0;
serialiser.writeSet(set_prop->items, set_prop->itemType, dummy_bytes_written, writer);
bytes_written += writer.arrayPosition() - start_pos;
return true;
}