2021-09-22 17:37:50 +02:00
|
|
|
// MassBuilderSaveTool
|
2024-03-08 20:25:32 +01:00
|
|
|
// Copyright (C) 2021-2024 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"
|
2022-11-24 09:12:41 +01:00
|
|
|
#include "../../Logger/Logger.h"
|
2021-09-22 17:37:50 +02:00
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
#include "SetProperty.h"
|
2021-09-22 17:37:50 +02:00
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
namespace Gvas { namespace Serialisers {
|
|
|
|
|
|
|
|
Types::UnrealPropertyBase::ptr
|
|
|
|
SetProperty::deserialiseProperty(Containers::StringView name, Containers::StringView type, std::size_t value_length,
|
|
|
|
BinaryReader& reader, PropertySerialiser& serialiser)
|
2021-09-22 17:37:50 +02:00
|
|
|
{
|
2022-03-04 21:18:55 +01:00
|
|
|
Containers::String item_type;
|
2021-09-22 17:37:50 +02:00
|
|
|
if(!reader.readUEString(item_type)) {
|
2022-11-24 09:12:41 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't read set property {}'s item type.", name);
|
2021-09-22 17:37:50 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
char terminator;
|
|
|
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
2022-11-24 09:12:41 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't read a null byte in set property {}.", name);
|
2021-09-22 17:37:50 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
std::uint32_t four_bytes;
|
|
|
|
if(!reader.readUint32(four_bytes) || four_bytes != 0u) {
|
2022-11-24 09:12:41 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't read four null bytes in set property {}.", name);
|
2021-09-22 17:37:50 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
std::uint32_t item_count;
|
|
|
|
if(!reader.readUint32(item_count)) {
|
2022-11-24 09:12:41 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't read set property {}'s item count.", name);
|
2021-09-22 17:37:50 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto prop = Containers::pointer<Types::SetProperty>();
|
2021-09-22 17:37:50 +02:00
|
|
|
prop->itemType = std::move(item_type);
|
|
|
|
prop->items = serialiser.readSet(reader, prop->itemType, item_count);
|
|
|
|
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
bool
|
2023-11-29 12:33:26 +01:00
|
|
|
SetProperty::serialiseProperty(Types::UnrealPropertyBase::ptr& prop, std::size_t& bytes_written, BinaryWriter& writer,
|
|
|
|
PropertySerialiser& serialiser)
|
2021-09-22 17:37:50 +02:00
|
|
|
{
|
2023-11-29 12:33:26 +01:00
|
|
|
auto set_prop = dynamic_cast<Types::SetProperty*>(prop.get());
|
2021-09-22 17:37:50 +02:00
|
|
|
if(!set_prop) {
|
2022-11-24 09:12:41 +01:00
|
|
|
LOG_ERROR("The property is not a valid set property.");
|
2021-09-22 17:37:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.writeUEStringToArray(set_prop->itemType);
|
|
|
|
writer.writeValueToArray<char>('\0');
|
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
bytes_written += writer.writeValueToArray<std::uint32_t>(0u);
|
|
|
|
bytes_written += writer.writeValueToArray<std::uint32_t>(std::uint32_t(set_prop->items.size()));
|
2021-09-22 17:37:50 +02:00
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
std::size_t start_pos = writer.arrayPosition();
|
|
|
|
std::size_t dummy_bytes_written = 0;
|
2021-09-22 17:37:50 +02:00
|
|
|
serialiser.writeSet(set_prop->items, set_prop->itemType, dummy_bytes_written, writer);
|
|
|
|
bytes_written += writer.arrayPosition() - start_pos;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-29 12:33:26 +01:00
|
|
|
|
|
|
|
}}
|