85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
// MassBuilderSaveTool
|
|
// Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
|
|
|
#include "../BinaryReader.h"
|
|
#include "../BinaryWriter.h"
|
|
#include "../PropertySerialiser.h"
|
|
#include "../../Logger/Logger.h"
|
|
|
|
#include "SetProperty.h"
|
|
|
|
namespace Gvas { namespace Serialisers {
|
|
|
|
Types::UnrealPropertyBase::ptr
|
|
SetProperty::deserialiseProperty(Containers::StringView name, Containers::StringView type, std::size_t value_length,
|
|
BinaryReader& reader, PropertySerialiser& serialiser)
|
|
{
|
|
Containers::String item_type;
|
|
if(!reader.readUEString(item_type)) {
|
|
LOG_ERROR_FORMAT("Couldn't read set property {}'s item type.", name);
|
|
return nullptr;
|
|
}
|
|
|
|
char terminator;
|
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
|
LOG_ERROR_FORMAT("Couldn't read a null byte in set property {}.", name);
|
|
return nullptr;
|
|
}
|
|
|
|
std::uint32_t four_bytes;
|
|
if(!reader.readUint32(four_bytes) || four_bytes != 0u) {
|
|
LOG_ERROR_FORMAT("Couldn't read four null bytes in set property {}.", name);
|
|
return nullptr;
|
|
}
|
|
|
|
std::uint32_t item_count;
|
|
if(!reader.readUint32(item_count)) {
|
|
LOG_ERROR_FORMAT("Couldn't read set property {}'s item count.", name);
|
|
return nullptr;
|
|
}
|
|
|
|
auto prop = Containers::pointer<Types::SetProperty>();
|
|
prop->itemType = std::move(item_type);
|
|
prop->items = serialiser.readSet(reader, prop->itemType, item_count);
|
|
|
|
return prop;
|
|
}
|
|
|
|
bool
|
|
SetProperty::serialiseProperty(Types::UnrealPropertyBase::ptr& prop, std::size_t& bytes_written, BinaryWriter& writer,
|
|
PropertySerialiser& serialiser)
|
|
{
|
|
auto set_prop = dynamic_cast<Types::SetProperty*>(prop.get());
|
|
if(!set_prop) {
|
|
LOG_ERROR("The property is not a valid set property.");
|
|
return false;
|
|
}
|
|
|
|
writer.writeUEStringToArray(set_prop->itemType);
|
|
writer.writeValueToArray<char>('\0');
|
|
|
|
bytes_written += writer.writeValueToArray<std::uint32_t>(0u);
|
|
bytes_written += writer.writeValueToArray<std::uint32_t>(std::uint32_t(set_prop->items.size()));
|
|
|
|
std::size_t start_pos = writer.arrayPosition();
|
|
std::size_t dummy_bytes_written = 0;
|
|
serialiser.writeSet(set_prop->items, set_prop->itemType, dummy_bytes_written, writer);
|
|
bytes_written += writer.arrayPosition() - start_pos;
|
|
|
|
return true;
|
|
}
|
|
|
|
}}
|