Serialisers: use Logger.

This commit is contained in:
Guillaume Jacquemin 2022-11-24 09:12:41 +01:00
parent 393ec4a372
commit d0a3375d7a
18 changed files with 116 additions and 50 deletions

View file

@ -160,6 +160,7 @@ auto PropertySerialiser::deserialise(Containers::String name, Containers::String
auto serialiser = getSerialiser(type); auto serialiser = getSerialiser(type);
if(serialiser == nullptr) { if(serialiser == nullptr) {
LOG_ERROR_FORMAT("No valid serialiser found for property type {}.", type);
return nullptr; return nullptr;
} }
@ -181,6 +182,7 @@ auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, Containers::St
{ {
auto serialiser = getSerialiser(item_type); auto serialiser = getSerialiser(item_type);
if(!serialiser) { if(!serialiser) {
LOG_ERROR_FORMAT("No valid serialiser found for property type {}.", item_type);
return false; return false;
} }
return serialiser->serialise(prop, bytes_written, writer, *this); return serialiser->serialise(prop, bytes_written, writer, *this);

View file

@ -19,6 +19,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
#include "../../Logger/Logger.h"
#include "ArrayPropertySerialiser.h" #include "ArrayPropertySerialiser.h"
@ -28,16 +29,19 @@ auto ArrayPropertySerialiser::deserialiseProperty(Containers::StringView name, C
{ {
Containers::String item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
LOG_ERROR_FORMAT("Couldn't read the item type of array property {}.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in array property {}.", name);
return nullptr; return nullptr;
} }
UnsignedInt item_count; UnsignedInt item_count;
if(!reader.readUnsignedInt(item_count)) { if(!reader.readUnsignedInt(item_count)) {
LOG_ERROR_FORMAT("Couldn't read array property {}'s item count.", name);
return nullptr; return nullptr;
} }
@ -53,6 +57,7 @@ auto ArrayPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, U
{ {
auto array_prop = dynamic_cast<ArrayProperty*>(prop.get()); auto array_prop = dynamic_cast<ArrayProperty*>(prop.get());
if(!array_prop) { if(!array_prop) {
LOG_ERROR("The property is not a valid array property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "BoolPropertySerialiser.h" #include "BoolPropertySerialiser.h"
@ -30,15 +31,18 @@ auto BoolPropertySerialiser::deserialise(Containers::StringView name, Containers
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
if(value_length != 0) { if(value_length != 0) {
LOG_ERROR_FORMAT("Invalid value length for bool property {}. Expected 0, got {} instead.", name, value_length);
return nullptr; return nullptr;
} }
Short value; Short value;
if(!reader.readShort(value)) { if(!reader.readShort(value)) {
LOG_ERROR_FORMAT("Couldn't read bool property {}'s value.", name);
return nullptr; return nullptr;
} }
if(value > 1 || value < 0) { if(value > 1 || value < 0) {
LOG_ERROR_FORMAT("Bool property {}'s value is invalid. Expected 1 or 0, got {} instead.", name, value);
return nullptr; return nullptr;
} }
@ -52,8 +56,8 @@ auto BoolPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLo
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto bool_prop = dynamic_cast<BoolProperty*>(prop.get()); auto bool_prop = dynamic_cast<BoolProperty*>(prop.get());
if(!bool_prop) { if(!bool_prop) {
LOG_ERROR("The property is not a valid bool property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "BytePropertySerialiser.h" #include "BytePropertySerialiser.h"
@ -33,16 +34,19 @@ auto BytePropertySerialiser::deserialise(Containers::StringView name, Containers
if(value_length != UnsignedLong(-1)) { if(value_length != UnsignedLong(-1)) {
if(!reader.readUEString(prop->enumType)) { if(!reader.readUEString(prop->enumType)) {
LOG_ERROR_FORMAT("Couldn't read byte property {}'s enum type.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in byte property {}.", name);
return nullptr; return nullptr;
} }
} }
if(!reader.readUEString(prop->enumValue)) { if(!reader.readUEString(prop->enumValue)) {
LOG_ERROR("Couldn't read byte property's enum value.");
return nullptr; return nullptr;
} }
@ -64,8 +68,8 @@ auto BytePropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLo
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto byte_prop = dynamic_cast<ByteProperty*>(prop.get()); auto byte_prop = dynamic_cast<ByteProperty*>(prop.get());
if(!byte_prop) { if(!byte_prop) {
LOG_ERROR("The property is not a valid byte property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "ColourPropertySerialiser.h" #include "ColourPropertySerialiser.h"
@ -28,6 +29,7 @@ auto ColourPropertySerialiser::deserialiseProperty(Containers::StringView name,
if(!reader.readFloat(prop->r) || !reader.readFloat(prop->g) || if(!reader.readFloat(prop->r) || !reader.readFloat(prop->g) ||
!reader.readFloat(prop->b) || !reader.readFloat(prop->a)) !reader.readFloat(prop->b) || !reader.readFloat(prop->a))
{ {
LOG_ERROR_FORMAT("Couldn't read colour property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -38,8 +40,8 @@ auto ColourPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto colour_prop = dynamic_cast<ColourStructProperty*>(prop.get()); auto colour_prop = dynamic_cast<ColourStructProperty*>(prop.get());
if(!colour_prop) { if(!colour_prop) {
LOG_ERROR("The property is not a valid colour property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "DateTimePropertySerialiser.h" #include "DateTimePropertySerialiser.h"
@ -26,6 +27,7 @@ auto DateTimePropertySerialiser::deserialiseProperty(Containers::StringView name
auto prop = Containers::pointer<DateTimeStructProperty>(); auto prop = Containers::pointer<DateTimeStructProperty>();
if(!reader.readUnsignedLong(prop->timestamp)) { if(!reader.readUnsignedLong(prop->timestamp)) {
LOG_ERROR_FORMAT("Couldn't read date/time property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -36,8 +38,8 @@ auto DateTimePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto dt_prop = dynamic_cast<DateTimeStructProperty*>(prop.get()); auto dt_prop = dynamic_cast<DateTimeStructProperty*>(prop.get());
if(!dt_prop) { if(!dt_prop) {
LOG_ERROR("The property is not a valid date/time property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "EnumPropertySerialiser.h" #include "EnumPropertySerialiser.h"
@ -32,15 +33,18 @@ auto EnumPropertySerialiser::deserialise(Containers::StringView name, Containers
auto prop = Containers::pointer<EnumProperty>(); auto prop = Containers::pointer<EnumProperty>();
if(!reader.readUEString(prop->enumType)) { if(!reader.readUEString(prop->enumType)) {
LOG_ERROR_FORMAT("Couldn't read enum property {}'s enum type.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in enum property {}.", name);
return nullptr; return nullptr;
} }
if(!reader.readUEString(prop->value)) { if(!reader.readUEString(prop->value)) {
LOG_ERROR_FORMAT("Couldn't read enum property {}'s enum value.", name);
return nullptr; return nullptr;
} }
@ -51,8 +55,8 @@ auto EnumPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLo
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto enum_prop = dynamic_cast<EnumProperty*>(prop.get()); auto enum_prop = dynamic_cast<EnumProperty*>(prop.get());
if(!enum_prop) { if(!enum_prop) {
LOG_ERROR("The property is not a valid enum property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "FloatPropertySerialiser.h" #include "FloatPropertySerialiser.h"
@ -33,10 +34,12 @@ auto FloatPropertySerialiser::deserialise(Containers::StringView name, Container
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in float property {}.", name);
return nullptr; return nullptr;
} }
if(!reader.readFloat(prop->value)) { if(!reader.readFloat(prop->value)) {
LOG_ERROR_FORMAT("Couldn't read float property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -47,8 +50,8 @@ auto FloatPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedL
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto float_prop = dynamic_cast<FloatProperty*>(prop.get()); auto float_prop = dynamic_cast<FloatProperty*>(prop.get());
if(!float_prop) { if(!float_prop) {
LOG_ERROR("The property is not a valid float property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "GuidPropertySerialiser.h" #include "GuidPropertySerialiser.h"
@ -28,7 +29,7 @@ auto GuidPropertySerialiser::deserialiseProperty(Containers::StringView name, Co
auto prop = Containers::pointer<GuidStructProperty>(); auto prop = Containers::pointer<GuidStructProperty>();
if(!reader.readStaticArray(prop->guid)) { if(!reader.readStaticArray(prop->guid)) {
Utility::Error{} << "Couldn't read GUID in"_s << __func__; LOG_ERROR_FORMAT("Couldn't read GUID property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -39,8 +40,8 @@ auto GuidPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Un
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto guid_prop = dynamic_cast<GuidStructProperty*>(prop.get()); auto guid_prop = dynamic_cast<GuidStructProperty*>(prop.get());
if(!guid_prop) { if(!guid_prop) {
LOG_ERROR("The property is not a valid byte property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "IntPropertySerialiser.h" #include "IntPropertySerialiser.h"
@ -27,6 +28,7 @@ auto IntPropertySerialiser::deserialiseProperty(Containers::StringView name, Con
if(value_length == UnsignedLong(-1)) { if(value_length == UnsignedLong(-1)) {
if(!reader.readInt(prop->value)) { if(!reader.readInt(prop->value)) {
LOG_ERROR("Couldn't read int property's value.");
return nullptr; return nullptr;
} }
@ -36,10 +38,12 @@ auto IntPropertySerialiser::deserialiseProperty(Containers::StringView name, Con
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in int property {}.", name);
return nullptr; return nullptr;
} }
if(!reader.readInt(prop->value)) { if(!reader.readInt(prop->value)) {
LOG_ERROR_FORMAT("Couldn't read int property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -52,8 +56,8 @@ auto IntPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto int_prop = dynamic_cast<IntProperty*>(prop.get()); auto int_prop = dynamic_cast<IntProperty*>(prop.get());
if(!int_prop) { if(!int_prop) {
LOG_ERROR("The property is not a valid int property.");
return false; return false;
} }

View file

@ -17,8 +17,8 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
#include "../Types/NoneProperty.h" #include "../Types/NoneProperty.h"
#include "../../Logger/Logger.h"
#include "MapPropertySerialiser.h" #include "MapPropertySerialiser.h"
@ -31,25 +31,30 @@ auto MapPropertySerialiser::deserialiseProperty(Containers::StringView name, Con
auto prop = Containers::pointer<MapProperty>(); auto prop = Containers::pointer<MapProperty>();
if(!reader.readUEString(prop->keyType)) { if(!reader.readUEString(prop->keyType)) {
LOG_ERROR_FORMAT("Couldn't read map property {}'s key type.", name);
return nullptr; return nullptr;
} }
if(!reader.readUEString(prop->valueType)) { if(!reader.readUEString(prop->valueType)) {
LOG_ERROR_FORMAT("Couldn't read map property {}'s value type.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in map property {}.", name);
return nullptr; return nullptr;
} }
UnsignedInt null; UnsignedInt null;
if(!reader.readUnsignedInt(null) || null != 0u) { if(!reader.readUnsignedInt(null) || null != 0u) {
LOG_ERROR_FORMAT("Couldn't read a null int in map property {}.", name);
return nullptr; return nullptr;
} }
UnsignedInt count; UnsignedInt count;
if(!reader.readUnsignedInt(count)) { if(!reader.readUnsignedInt(count)) {
LOG_ERROR_FORMAT("Couldn't read map property {}'s item count.", name);
return nullptr; return nullptr;
} }
@ -64,10 +69,12 @@ auto MapPropertySerialiser::deserialiseProperty(Containers::StringView name, Con
if(prop->keyType == "IntProperty"_s || prop->keyType == "StrProperty"_s) { if(prop->keyType == "IntProperty"_s || prop->keyType == "StrProperty"_s) {
pair.key = serialiser.readItem(reader, prop->keyType, -1, name); pair.key = serialiser.readItem(reader, prop->keyType, -1, name);
if(pair.key == nullptr) { if(pair.key == nullptr) {
LOG_ERROR_FORMAT("Couldn't read a valid key in map property {}.", name);
return nullptr; return nullptr;
} }
} }
else { // Add other branches depending on key type, should more maps appear in the future. else { // Add other branches depending on key type, should more maps appear in the future.
LOG_ERROR_FORMAT("Key type {} not implemented.", prop->keyType);
return nullptr; return nullptr;
} }
@ -105,6 +112,7 @@ auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns
{ {
auto map_prop = dynamic_cast<MapProperty*>(prop.get()); auto map_prop = dynamic_cast<MapProperty*>(prop.get());
if(!map_prop) { if(!map_prop) {
LOG_ERROR("The property is not a valid map property.");
return false; return false;
} }
@ -120,17 +128,20 @@ auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns
UnsignedLong dummy_bytes_written = 0; UnsignedLong dummy_bytes_written = 0;
for(auto& pair : map_prop->map) { for(auto& pair : map_prop->map) {
if(!serialiser.writeItem(pair.key, map_prop->keyType, dummy_bytes_written, writer)) { if(!serialiser.writeItem(pair.key, map_prop->keyType, dummy_bytes_written, writer)) {
LOG_ERROR("Couldn't write a key.");
return false; return false;
} }
for(auto& value : pair.values) { for(auto& value : pair.values) {
if(map_prop->valueType == "StructProperty"_s) { if(map_prop->valueType == "StructProperty"_s) {
if(!serialiser.write(value, dummy_bytes_written, writer)) { if(!serialiser.write(value, dummy_bytes_written, writer)) {
LOG_ERROR("Couldn't write a value.");
return false; return false;
} }
} }
else { else {
if(!serialiser.writeItem(value, map_prop->valueType, dummy_bytes_written, writer)) { if(!serialiser.writeItem(value, map_prop->valueType, dummy_bytes_written, writer)) {
LOG_ERROR("Couldn't write a value.");
return false; return false;
} }
} }

View file

@ -17,9 +17,9 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
#include "../Types/IntProperty.h" #include "../Types/IntProperty.h"
#include "../Types/NoneProperty.h" #include "../Types/NoneProperty.h"
#include "../../Logger/Logger.h"
#include "ResourcePropertySerialiser.h" #include "ResourcePropertySerialiser.h"
@ -31,49 +31,46 @@ auto ResourcePropertySerialiser::deserialiseProperty(Containers::StringView name
{ {
auto prop = Containers::pointer<ResourceItemValue>(); auto prop = Containers::pointer<ResourceItemValue>();
Containers::String str; auto id_prop = serialiser.read(reader);
if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21"_s) { if(!id_prop) {
LOG_ERROR("Couldn't read the ID property."_s);
return nullptr; return nullptr;
} }
if(!reader.readUEString(str) || str != "IntProperty"_s) { if((*id_prop->name) != "ID_4_AAE08F17428E229EC7A2209F51081A21"_s ||
id_prop->propertyType != "IntProperty"_s ||
dynamic_cast<IntProperty*>(id_prop.get()) == nullptr)
{
LOG_ERROR("The ID property is invalid."_s);
return nullptr; return nullptr;
} }
if(!reader.readUnsignedLong(value_length) || value_length != 4ull) { prop->id = dynamic_cast<IntProperty*>(id_prop.get())->value;
auto value_prop = serialiser.read(reader);
if(!value_prop) {
LOG_ERROR("Couldn't read the value property."_s);
return nullptr; return nullptr;
} }
char terminator; if((*value_prop->name) != "Quantity_3_560F09B5485C365D3041888910019CE3"_s ||
if(!reader.readChar(terminator) || terminator != '\0') { value_prop->propertyType != "IntProperty"_s ||
dynamic_cast<IntProperty*>(value_prop.get()) == nullptr)
{
LOG_ERROR("The value property is invalid."_s);
return nullptr; return nullptr;
} }
if(!reader.readInt(prop->id)) { prop->quantity = dynamic_cast<IntProperty*>(value_prop.get())->value;
return nullptr;
}
if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3"_s) { auto none_prop = serialiser.read(reader);
return nullptr;
}
if(!reader.readUEString(str) || str != "IntProperty"_s) { if(!none_prop ||
return nullptr; (*none_prop->name) != "None"_s ||
} none_prop->propertyType != "NoneProperty"_s ||
!dynamic_cast<NoneProperty*>(none_prop.get()))
if(!reader.readUnsignedLong(value_length) || value_length != 4ull) { {
return nullptr; LOG_ERROR("Couldn't find a terminating NoneProperty."_s);
}
if(!reader.readChar(terminator) || terminator != '\0') {
return nullptr;
}
if(!reader.readInt(prop->quantity)) {
return nullptr;
}
if(!reader.readUEString(str) || str != "None"_s) {
return nullptr; return nullptr;
} }
@ -85,6 +82,7 @@ auto ResourcePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop
{ {
auto res_prop = dynamic_cast<ResourceItemValue*>(prop.get()); auto res_prop = dynamic_cast<ResourceItemValue*>(prop.get());
if(!res_prop) { if(!res_prop) {
LOG_ERROR("The property is not a valid ResourceItemValue property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "RotatorPropertySerialiser.h" #include "RotatorPropertySerialiser.h"
@ -26,6 +27,7 @@ auto RotatorPropertySerialiser::deserialiseProperty(Containers::StringView name,
auto prop = Containers::pointer<RotatorStructProperty>(); auto prop = Containers::pointer<RotatorStructProperty>();
if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y) || !reader.readFloat(prop->z)) { if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y) || !reader.readFloat(prop->z)) {
LOG_ERROR_FORMAT("Couldn't read rotator property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -36,8 +38,8 @@ auto RotatorPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto rotator = dynamic_cast<RotatorStructProperty*>(prop.get()); auto rotator = dynamic_cast<RotatorStructProperty*>(prop.get());
if(!rotator) { if(!rotator) {
LOG_ERROR("The property is not a valid rotator property.");
return false; return false;
} }

View file

@ -17,6 +17,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
#include "../../Logger/Logger.h"
#include "SetPropertySerialiser.h" #include "SetPropertySerialiser.h"
@ -26,21 +27,25 @@ auto SetPropertySerialiser::deserialiseProperty(Containers::StringView name, Con
{ {
Containers::String item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
LOG_ERROR_FORMAT("Couldn't read set property {}'s item type.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in set property {}.", name);
return nullptr; return nullptr;
} }
UnsignedInt four_bytes; UnsignedInt four_bytes;
if(!reader.readUnsignedInt(four_bytes) || four_bytes != 0u) { if(!reader.readUnsignedInt(four_bytes) || four_bytes != 0u) {
LOG_ERROR_FORMAT("Couldn't read four null bytes in set property {}.", name);
return nullptr; return nullptr;
} }
UnsignedInt item_count; UnsignedInt item_count;
if(!reader.readUnsignedInt(item_count)) { if(!reader.readUnsignedInt(item_count)) {
LOG_ERROR_FORMAT("Couldn't read set property {}'s item count.", name);
return nullptr; return nullptr;
} }
@ -56,6 +61,7 @@ auto SetPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns
{ {
auto set_prop = dynamic_cast<SetProperty*>(prop.get()); auto set_prop = dynamic_cast<SetProperty*>(prop.get());
if(!set_prop) { if(!set_prop) {
LOG_ERROR("The property is not a valid set property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "StringPropertySerialiser.h" #include "StringPropertySerialiser.h"
@ -36,11 +37,13 @@ auto StringPropertySerialiser::deserialise(Containers::StringView name, Containe
if(value_length != UnsignedLong(-1)) { if(value_length != UnsignedLong(-1)) {
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in string property {}.", name);
return nullptr; return nullptr;
} }
} }
if(!reader.readUEString(prop->value)) { if(!reader.readUEString(prop->value)) {
LOG_ERROR_FORMAT("Couldn't read string property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -53,8 +56,8 @@ auto StringPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, Unsigned
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto str_prop = dynamic_cast<StringProperty*>(prop.get()); auto str_prop = dynamic_cast<StringProperty*>(prop.get());
if(!str_prop) { if(!str_prop) {
LOG_ERROR("The property is not a valid string property.");
return false; return false;
} }

View file

@ -19,9 +19,9 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
#include "../Types/GenericStructProperty.h" #include "../Types/GenericStructProperty.h"
#include "../Types/NoneProperty.h" #include "../Types/NoneProperty.h"
#include "../../Logger/Logger.h"
#include "StructSerialiser.h" #include "StructSerialiser.h"
@ -36,16 +36,19 @@ auto StructSerialiser::deserialise(Containers::StringView name, Containers::Stri
{ {
Containers::String item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
LOG_ERROR_FORMAT("Couldn't read struct property {}'s item type.", name);
return nullptr; return nullptr;
} }
Containers::StaticArray<16, char> guid{ValueInit}; Containers::StaticArray<16, char> guid{ValueInit};
if(!reader.readStaticArray(guid)) { if(!reader.readStaticArray(guid)) {
LOG_ERROR_FORMAT("Couldn't read struct property {}'s GUID.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in struct property {}.", name);
return nullptr; return nullptr;
} }
@ -67,10 +70,11 @@ auto StructSerialiser::deserialise(Containers::StringView name, Containers::Stri
} }
if(!prop) { if(!prop) {
LOG_ERROR("Invalid property");
return nullptr; return nullptr;
} }
static_cast<StructProperty*>(prop.get())->structGuid = guid; dynamic_cast<StructProperty*>(prop.get())->structGuid = guid;
arrayAppend(array, std::move(prop)); arrayAppend(array, std::move(prop));
} }
@ -84,20 +88,23 @@ auto StructSerialiser::deserialise(Containers::StringView name, Containers::Stri
{ {
Containers::String item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
LOG_ERROR_FORMAT("Couldn't read struct property {}'s item type.", name);
return nullptr; return nullptr;
} }
if(item_type == "None") { if(item_type == "None") {
return Containers::pointer<NoneProperty>(); return NoneProperty::ptr{};
} }
Containers::StaticArray<16, char> guid{ValueInit}; Containers::StaticArray<16, char> guid{ValueInit};
if(!reader.readStaticArray(guid)) { if(!reader.readStaticArray(guid)) {
LOG_ERROR_FORMAT("Couldn't read struct property {}'s GUID.", name);
return nullptr; return nullptr;
} }
char terminator; char terminator;
if(!reader.readChar(terminator) || terminator != '\0') { if(!reader.readChar(terminator) || terminator != '\0') {
LOG_ERROR_FORMAT("Couldn't read a null byte in byte property {}.", name);
return nullptr; return nullptr;
} }
@ -123,6 +130,7 @@ auto StructSerialiser::serialise(Containers::ArrayView<UnrealPropertyBase::ptr>
auto struct_prop = dynamic_cast<StructProperty*>(props.front().get()); auto struct_prop = dynamic_cast<StructProperty*>(props.front().get());
if(!struct_prop) { if(!struct_prop) {
LOG_ERROR("The property is not a valid struct property.");
return false; return false;
} }
@ -135,13 +143,14 @@ auto StructSerialiser::serialise(Containers::ArrayView<UnrealPropertyBase::ptr>
UnsignedLong bytes_written_here = 0; UnsignedLong bytes_written_here = 0;
for(auto& prop : props) { for(auto& prop : props) {
struct_prop = dynamic_cast<StructProperty*>(prop.get()); struct_prop = dynamic_cast<StructProperty*>(prop.get());
if(!struct_prop) { if(!struct_prop) {
LOG_ERROR("The property is not a valid struct property.");
return false; return false;
} }
if(!serialiser.writeItem(prop, struct_prop->structType, bytes_written_here, writer)) { if(!serialiser.writeItem(prop, struct_prop->structType, bytes_written_here, writer)) {
if(!writeStructValue(struct_prop, bytes_written_here, writer, serialiser)) { if(!writeStructValue(struct_prop, bytes_written_here, writer, serialiser)) {
LOG_ERROR("Couldn't write the struct value.");
return false; return false;
} }
} }
@ -158,8 +167,8 @@ auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& by
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto struct_prop = dynamic_cast<StructProperty*>(prop.get()); auto struct_prop = dynamic_cast<StructProperty*>(prop.get());
if(!struct_prop) { if(!struct_prop) {
LOG_ERROR("The property is not a valid struct property.");
return false; return false;
} }
@ -171,6 +180,7 @@ auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& by
UnsignedLong dummy_bytes_written = 0; UnsignedLong dummy_bytes_written = 0;
UnsignedLong vl_start = writer.arrayPosition(); UnsignedLong vl_start = writer.arrayPosition();
if(!writeStructValue(struct_prop, dummy_bytes_written, writer, serialiser)) { if(!writeStructValue(struct_prop, dummy_bytes_written, writer, serialiser)) {
LOG_ERROR("Couldn't write the struct value.");
return false; return false;
} }
bytes_written += writer.arrayPosition() - vl_start; bytes_written += writer.arrayPosition() - vl_start;
@ -206,13 +216,14 @@ auto StructSerialiser::writeStructValue(StructProperty* prop, UnsignedLong& byte
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto struct_prop = dynamic_cast<GenericStructProperty*>(prop); auto struct_prop = dynamic_cast<GenericStructProperty*>(prop);
if(!struct_prop) { if(!struct_prop) {
LOG_ERROR("The property is not a valid struct property.");
return false; return false;
} }
for(auto& item : struct_prop->properties) { for(auto& item : struct_prop->properties) {
if(!serialiser.write(item, bytes_written, writer)) { if(!serialiser.write(item, bytes_written, writer)) {
LOG_ERROR("Couldn't write the struct's data.");
return false; return false;
} }
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "Vector2DPropertySerialiser.h" #include "Vector2DPropertySerialiser.h"
@ -26,6 +27,7 @@ auto Vector2DPropertySerialiser::deserialiseProperty(Containers::StringView name
auto prop = Containers::pointer<Vector2DStructProperty>(); auto prop = Containers::pointer<Vector2DStructProperty>();
if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y)) { if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y)) {
LOG_ERROR_FORMAT("Couldn't read 2D vector property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -36,8 +38,8 @@ auto Vector2DPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto vector = dynamic_cast<Vector2DStructProperty*>(prop.get()); auto vector = dynamic_cast<Vector2DStructProperty*>(prop.get());
if(!vector) { if(!vector) {
LOG_ERROR("The property is not a valid 2D vector property.");
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../../Logger/Logger.h"
#include "VectorPropertySerialiser.h" #include "VectorPropertySerialiser.h"
@ -26,6 +27,7 @@ auto VectorPropertySerialiser::deserialiseProperty(Containers::StringView name,
auto prop = Containers::pointer<VectorStructProperty>(); auto prop = Containers::pointer<VectorStructProperty>();
if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y) || !reader.readFloat(prop->z)) { if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y) || !reader.readFloat(prop->z)) {
LOG_ERROR_FORMAT("Couldn't read vector property {}'s value.", name);
return nullptr; return nullptr;
} }
@ -36,8 +38,8 @@ auto VectorPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
auto vector = dynamic_cast<VectorStructProperty*>(prop.get()); auto vector = dynamic_cast<VectorStructProperty*>(prop.get());
if(!vector) { if(!vector) {
LOG_ERROR("The property is not a valid vector property.");
return false; return false;
} }