// MassBuilderSaveTool // Copyright (C) 2021-2022 Guillaume Jacquemin // // 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 . #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" #include "SetPropertySerialiser.h" auto SetPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { Containers::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(); 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(prop.get()); if(!set_prop) { return false; } writer.writeUEStringToArray(set_prop->itemType); writer.writeValueToArray('\0'); bytes_written += writer.writeValueToArray(0u); bytes_written += writer.writeValueToArray(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; }