From d0a3375d7ab5067cb9bfdf64ce9448290151f13b Mon Sep 17 00:00:00 2001 From: William JCM Date: Thu, 24 Nov 2022 09:12:41 +0100 Subject: [PATCH] Serialisers: use Logger. --- src/UESaveFile/PropertySerialiser.cpp | 2 + .../Serialisers/ArrayPropertySerialiser.cpp | 5 ++ .../Serialisers/BoolPropertySerialiser.cpp | 6 +- .../Serialisers/BytePropertySerialiser.cpp | 6 +- .../Serialisers/ColourPropertySerialiser.cpp | 4 +- .../DateTimePropertySerialiser.cpp | 4 +- .../Serialisers/EnumPropertySerialiser.cpp | 6 +- .../Serialisers/FloatPropertySerialiser.cpp | 5 +- .../Serialisers/GuidPropertySerialiser.cpp | 5 +- .../Serialisers/IntPropertySerialiser.cpp | 6 +- .../Serialisers/MapPropertySerialiser.cpp | 13 ++++- .../ResourcePropertySerialiser.cpp | 58 +++++++++---------- .../Serialisers/RotatorPropertySerialiser.cpp | 4 +- .../Serialisers/SetPropertySerialiser.cpp | 6 ++ .../Serialisers/StringPropertySerialiser.cpp | 5 +- .../Serialisers/StructSerialiser.cpp | 23 ++++++-- .../Vector2DPropertySerialiser.cpp | 4 +- .../Serialisers/VectorPropertySerialiser.cpp | 4 +- 18 files changed, 116 insertions(+), 50 deletions(-) diff --git a/src/UESaveFile/PropertySerialiser.cpp b/src/UESaveFile/PropertySerialiser.cpp index 77e8e4a..cca6084 100644 --- a/src/UESaveFile/PropertySerialiser.cpp +++ b/src/UESaveFile/PropertySerialiser.cpp @@ -160,6 +160,7 @@ auto PropertySerialiser::deserialise(Containers::String name, Containers::String auto serialiser = getSerialiser(type); if(serialiser == nullptr) { + LOG_ERROR_FORMAT("No valid serialiser found for property type {}.", type); return nullptr; } @@ -181,6 +182,7 @@ auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, Containers::St { auto serialiser = getSerialiser(item_type); if(!serialiser) { + LOG_ERROR_FORMAT("No valid serialiser found for property type {}.", item_type); return false; } return serialiser->serialise(prop, bytes_written, writer, *this); diff --git a/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp b/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp index 7852587..d2efbb8 100644 --- a/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp @@ -19,6 +19,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" +#include "../../Logger/Logger.h" #include "ArrayPropertySerialiser.h" @@ -28,16 +29,19 @@ auto ArrayPropertySerialiser::deserialiseProperty(Containers::StringView name, C { Containers::String item_type; if(!reader.readUEString(item_type)) { + LOG_ERROR_FORMAT("Couldn't read the item type of array property {}.", name); return nullptr; } char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in array property {}.", name); return nullptr; } UnsignedInt item_count; if(!reader.readUnsignedInt(item_count)) { + LOG_ERROR_FORMAT("Couldn't read array property {}'s item count.", name); return nullptr; } @@ -53,6 +57,7 @@ auto ArrayPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, U { auto array_prop = dynamic_cast(prop.get()); if(!array_prop) { + LOG_ERROR("The property is not a valid array property."); return false; } diff --git a/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp b/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp index 00b52ed..7f9e6cc 100644 --- a/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "BoolPropertySerialiser.h" @@ -30,15 +31,18 @@ auto BoolPropertySerialiser::deserialise(Containers::StringView name, Containers PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { if(value_length != 0) { + LOG_ERROR_FORMAT("Invalid value length for bool property {}. Expected 0, got {} instead.", name, value_length); return nullptr; } Short value; if(!reader.readShort(value)) { + LOG_ERROR_FORMAT("Couldn't read bool property {}'s value.", name); return nullptr; } if(value > 1 || value < 0) { + LOG_ERROR_FORMAT("Bool property {}'s value is invalid. Expected 1 or 0, got {} instead.", name, value); return nullptr; } @@ -52,8 +56,8 @@ auto BoolPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLo BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto bool_prop = dynamic_cast(prop.get()); - if(!bool_prop) { + LOG_ERROR("The property is not a valid bool property."); return false; } diff --git a/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp b/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp index 25e11f3..eb24db1 100644 --- a/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "BytePropertySerialiser.h" @@ -33,16 +34,19 @@ auto BytePropertySerialiser::deserialise(Containers::StringView name, Containers if(value_length != UnsignedLong(-1)) { if(!reader.readUEString(prop->enumType)) { + LOG_ERROR_FORMAT("Couldn't read byte property {}'s enum type.", name); return nullptr; } char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in byte property {}.", name); return nullptr; } } if(!reader.readUEString(prop->enumValue)) { + LOG_ERROR("Couldn't read byte property's enum value."); return nullptr; } @@ -64,8 +68,8 @@ auto BytePropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLo BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto byte_prop = dynamic_cast(prop.get()); - if(!byte_prop) { + LOG_ERROR("The property is not a valid byte property."); return false; } diff --git a/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp b/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp index a7bc6e6..d90035f 100644 --- a/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "ColourPropertySerialiser.h" @@ -28,6 +29,7 @@ auto ColourPropertySerialiser::deserialiseProperty(Containers::StringView name, if(!reader.readFloat(prop->r) || !reader.readFloat(prop->g) || !reader.readFloat(prop->b) || !reader.readFloat(prop->a)) { + LOG_ERROR_FORMAT("Couldn't read colour property {}'s value.", name); return nullptr; } @@ -38,8 +40,8 @@ auto ColourPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto colour_prop = dynamic_cast(prop.get()); - if(!colour_prop) { + LOG_ERROR("The property is not a valid colour property."); return false; } diff --git a/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp b/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp index 7a26a6f..6e32666 100644 --- a/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "DateTimePropertySerialiser.h" @@ -26,6 +27,7 @@ auto DateTimePropertySerialiser::deserialiseProperty(Containers::StringView name auto prop = Containers::pointer(); if(!reader.readUnsignedLong(prop->timestamp)) { + LOG_ERROR_FORMAT("Couldn't read date/time property {}'s value.", name); return nullptr; } @@ -36,8 +38,8 @@ auto DateTimePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto dt_prop = dynamic_cast(prop.get()); - if(!dt_prop) { + LOG_ERROR("The property is not a valid date/time property."); return false; } diff --git a/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp b/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp index 29a20db..4cb5835 100644 --- a/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "EnumPropertySerialiser.h" @@ -32,15 +33,18 @@ auto EnumPropertySerialiser::deserialise(Containers::StringView name, Containers auto prop = Containers::pointer(); if(!reader.readUEString(prop->enumType)) { + LOG_ERROR_FORMAT("Couldn't read enum property {}'s enum type.", name); return nullptr; } char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in enum property {}.", name); return nullptr; } if(!reader.readUEString(prop->value)) { + LOG_ERROR_FORMAT("Couldn't read enum property {}'s enum value.", name); return nullptr; } @@ -51,8 +55,8 @@ auto EnumPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLo BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto enum_prop = dynamic_cast(prop.get()); - if(!enum_prop) { + LOG_ERROR("The property is not a valid enum property."); return false; } diff --git a/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp b/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp index d4f0cd4..4134f94 100644 --- a/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "FloatPropertySerialiser.h" @@ -33,10 +34,12 @@ auto FloatPropertySerialiser::deserialise(Containers::StringView name, Container char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in float property {}.", name); return nullptr; } if(!reader.readFloat(prop->value)) { + LOG_ERROR_FORMAT("Couldn't read float property {}'s value.", name); return nullptr; } @@ -47,8 +50,8 @@ auto FloatPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedL BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto float_prop = dynamic_cast(prop.get()); - if(!float_prop) { + LOG_ERROR("The property is not a valid float property."); return false; } diff --git a/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp b/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp index 35d9ad4..dd0036b 100644 --- a/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "GuidPropertySerialiser.h" @@ -28,7 +29,7 @@ auto GuidPropertySerialiser::deserialiseProperty(Containers::StringView name, Co auto prop = Containers::pointer(); 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; } @@ -39,8 +40,8 @@ auto GuidPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Un BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto guid_prop = dynamic_cast(prop.get()); - if(!guid_prop) { + LOG_ERROR("The property is not a valid byte property."); return false; } diff --git a/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp b/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp index ecc7bc3..3c2e50f 100644 --- a/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "IntPropertySerialiser.h" @@ -27,6 +28,7 @@ auto IntPropertySerialiser::deserialiseProperty(Containers::StringView name, Con if(value_length == UnsignedLong(-1)) { if(!reader.readInt(prop->value)) { + LOG_ERROR("Couldn't read int property's value."); return nullptr; } @@ -36,10 +38,12 @@ auto IntPropertySerialiser::deserialiseProperty(Containers::StringView name, Con char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in int property {}.", name); return nullptr; } if(!reader.readInt(prop->value)) { + LOG_ERROR_FORMAT("Couldn't read int property {}'s value.", name); return nullptr; } @@ -52,8 +56,8 @@ auto IntPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto int_prop = dynamic_cast(prop.get()); - if(!int_prop) { + LOG_ERROR("The property is not a valid int property."); return false; } diff --git a/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp b/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp index 0305e2f..35a9055 100644 --- a/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp @@ -17,8 +17,8 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" - #include "../Types/NoneProperty.h" +#include "../../Logger/Logger.h" #include "MapPropertySerialiser.h" @@ -31,25 +31,30 @@ auto MapPropertySerialiser::deserialiseProperty(Containers::StringView name, Con auto prop = Containers::pointer(); if(!reader.readUEString(prop->keyType)) { + LOG_ERROR_FORMAT("Couldn't read map property {}'s key type.", name); return nullptr; } if(!reader.readUEString(prop->valueType)) { + LOG_ERROR_FORMAT("Couldn't read map property {}'s value type.", name); return nullptr; } char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in map property {}.", name); return nullptr; } UnsignedInt null; if(!reader.readUnsignedInt(null) || null != 0u) { + LOG_ERROR_FORMAT("Couldn't read a null int in map property {}.", name); return nullptr; } UnsignedInt count; if(!reader.readUnsignedInt(count)) { + LOG_ERROR_FORMAT("Couldn't read map property {}'s item count.", name); return nullptr; } @@ -64,10 +69,12 @@ auto MapPropertySerialiser::deserialiseProperty(Containers::StringView name, Con if(prop->keyType == "IntProperty"_s || prop->keyType == "StrProperty"_s) { pair.key = serialiser.readItem(reader, prop->keyType, -1, name); if(pair.key == nullptr) { + LOG_ERROR_FORMAT("Couldn't read a valid key in map property {}.", name); return nullptr; } } 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; } @@ -105,6 +112,7 @@ auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns { auto map_prop = dynamic_cast(prop.get()); if(!map_prop) { + LOG_ERROR("The property is not a valid map property."); return false; } @@ -120,17 +128,20 @@ auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns UnsignedLong dummy_bytes_written = 0; for(auto& pair : map_prop->map) { if(!serialiser.writeItem(pair.key, map_prop->keyType, dummy_bytes_written, writer)) { + LOG_ERROR("Couldn't write a key."); return false; } for(auto& value : pair.values) { if(map_prop->valueType == "StructProperty"_s) { if(!serialiser.write(value, dummy_bytes_written, writer)) { + LOG_ERROR("Couldn't write a value."); return false; } } else { if(!serialiser.writeItem(value, map_prop->valueType, dummy_bytes_written, writer)) { + LOG_ERROR("Couldn't write a value."); return false; } } diff --git a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp index 0362e63..6113c11 100644 --- a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp @@ -17,9 +17,9 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" - #include "../Types/IntProperty.h" #include "../Types/NoneProperty.h" +#include "../../Logger/Logger.h" #include "ResourcePropertySerialiser.h" @@ -31,49 +31,46 @@ auto ResourcePropertySerialiser::deserialiseProperty(Containers::StringView name { auto prop = Containers::pointer(); - Containers::String str; - if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21"_s) { + auto id_prop = serialiser.read(reader); + if(!id_prop) { + LOG_ERROR("Couldn't read the ID property."_s); return nullptr; } - if(!reader.readUEString(str) || str != "IntProperty"_s) { + if((*id_prop->name) != "ID_4_AAE08F17428E229EC7A2209F51081A21"_s || + id_prop->propertyType != "IntProperty"_s || + dynamic_cast(id_prop.get()) == nullptr) + { + LOG_ERROR("The ID property is invalid."_s); return nullptr; } - if(!reader.readUnsignedLong(value_length) || value_length != 4ull) { + prop->id = dynamic_cast(id_prop.get())->value; + + auto value_prop = serialiser.read(reader); + if(!value_prop) { + LOG_ERROR("Couldn't read the value property."_s); return nullptr; } - char terminator; - if(!reader.readChar(terminator) || terminator != '\0') { + if((*value_prop->name) != "Quantity_3_560F09B5485C365D3041888910019CE3"_s || + value_prop->propertyType != "IntProperty"_s || + dynamic_cast(value_prop.get()) == nullptr) + { + LOG_ERROR("The value property is invalid."_s); return nullptr; } - if(!reader.readInt(prop->id)) { - return nullptr; - } + prop->quantity = dynamic_cast(value_prop.get())->value; - if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3"_s) { - return nullptr; - } + auto none_prop = serialiser.read(reader); - if(!reader.readUEString(str) || str != "IntProperty"_s) { - return nullptr; - } - - if(!reader.readUnsignedLong(value_length) || value_length != 4ull) { - return nullptr; - } - - if(!reader.readChar(terminator) || terminator != '\0') { - return nullptr; - } - - if(!reader.readInt(prop->quantity)) { - return nullptr; - } - - if(!reader.readUEString(str) || str != "None"_s) { + if(!none_prop || + (*none_prop->name) != "None"_s || + none_prop->propertyType != "NoneProperty"_s || + !dynamic_cast(none_prop.get())) + { + LOG_ERROR("Couldn't find a terminating NoneProperty."_s); return nullptr; } @@ -85,6 +82,7 @@ auto ResourcePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop { auto res_prop = dynamic_cast(prop.get()); if(!res_prop) { + LOG_ERROR("The property is not a valid ResourceItemValue property."); return false; } diff --git a/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp b/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp index 4e95409..ecd125d 100644 --- a/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "RotatorPropertySerialiser.h" @@ -26,6 +27,7 @@ auto RotatorPropertySerialiser::deserialiseProperty(Containers::StringView name, auto prop = Containers::pointer(); 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; } @@ -36,8 +38,8 @@ auto RotatorPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto rotator = dynamic_cast(prop.get()); - if(!rotator) { + LOG_ERROR("The property is not a valid rotator property."); return false; } diff --git a/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp b/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp index c9b38cb..cfa9bd0 100644 --- a/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp @@ -17,6 +17,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" +#include "../../Logger/Logger.h" #include "SetPropertySerialiser.h" @@ -26,21 +27,25 @@ auto SetPropertySerialiser::deserialiseProperty(Containers::StringView name, Con { 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; } UnsignedInt four_bytes; if(!reader.readUnsignedInt(four_bytes) || four_bytes != 0u) { + LOG_ERROR_FORMAT("Couldn't read four null bytes in set property {}.", name); return nullptr; } UnsignedInt item_count; if(!reader.readUnsignedInt(item_count)) { + LOG_ERROR_FORMAT("Couldn't read set property {}'s item count.", name); return nullptr; } @@ -56,6 +61,7 @@ auto SetPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns { auto set_prop = dynamic_cast(prop.get()); if(!set_prop) { + LOG_ERROR("The property is not a valid set property."); return false; } diff --git a/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp b/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp index 4cfe00c..3cb4208 100644 --- a/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "StringPropertySerialiser.h" @@ -36,11 +37,13 @@ auto StringPropertySerialiser::deserialise(Containers::StringView name, Containe if(value_length != UnsignedLong(-1)) { char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in string property {}.", name); return nullptr; } } if(!reader.readUEString(prop->value)) { + LOG_ERROR_FORMAT("Couldn't read string property {}'s value.", name); return nullptr; } @@ -53,8 +56,8 @@ auto StringPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, Unsigned BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto str_prop = dynamic_cast(prop.get()); - if(!str_prop) { + LOG_ERROR("The property is not a valid string property."); return false; } diff --git a/src/UESaveFile/Serialisers/StructSerialiser.cpp b/src/UESaveFile/Serialisers/StructSerialiser.cpp index 1367465..95001b7 100644 --- a/src/UESaveFile/Serialisers/StructSerialiser.cpp +++ b/src/UESaveFile/Serialisers/StructSerialiser.cpp @@ -19,9 +19,9 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" - #include "../Types/GenericStructProperty.h" #include "../Types/NoneProperty.h" +#include "../../Logger/Logger.h" #include "StructSerialiser.h" @@ -36,16 +36,19 @@ auto StructSerialiser::deserialise(Containers::StringView name, Containers::Stri { Containers::String item_type; if(!reader.readUEString(item_type)) { + LOG_ERROR_FORMAT("Couldn't read struct property {}'s item type.", name); return nullptr; } Containers::StaticArray<16, char> guid{ValueInit}; if(!reader.readStaticArray(guid)) { + LOG_ERROR_FORMAT("Couldn't read struct property {}'s GUID.", name); return nullptr; } char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in struct property {}.", name); return nullptr; } @@ -67,10 +70,11 @@ auto StructSerialiser::deserialise(Containers::StringView name, Containers::Stri } if(!prop) { + LOG_ERROR("Invalid property"); return nullptr; } - static_cast(prop.get())->structGuid = guid; + dynamic_cast(prop.get())->structGuid = guid; arrayAppend(array, std::move(prop)); } @@ -84,20 +88,23 @@ auto StructSerialiser::deserialise(Containers::StringView name, Containers::Stri { Containers::String item_type; if(!reader.readUEString(item_type)) { + LOG_ERROR_FORMAT("Couldn't read struct property {}'s item type.", name); return nullptr; } if(item_type == "None") { - return Containers::pointer(); + return NoneProperty::ptr{}; } Containers::StaticArray<16, char> guid{ValueInit}; if(!reader.readStaticArray(guid)) { + LOG_ERROR_FORMAT("Couldn't read struct property {}'s GUID.", name); return nullptr; } char terminator; if(!reader.readChar(terminator) || terminator != '\0') { + LOG_ERROR_FORMAT("Couldn't read a null byte in byte property {}.", name); return nullptr; } @@ -123,6 +130,7 @@ auto StructSerialiser::serialise(Containers::ArrayView auto struct_prop = dynamic_cast(props.front().get()); if(!struct_prop) { + LOG_ERROR("The property is not a valid struct property."); return false; } @@ -135,13 +143,14 @@ auto StructSerialiser::serialise(Containers::ArrayView UnsignedLong bytes_written_here = 0; for(auto& prop : props) { struct_prop = dynamic_cast(prop.get()); - if(!struct_prop) { + LOG_ERROR("The property is not a valid struct property."); return false; } if(!serialiser.writeItem(prop, struct_prop->structType, bytes_written_here, writer)) { if(!writeStructValue(struct_prop, bytes_written_here, writer, serialiser)) { + LOG_ERROR("Couldn't write the struct value."); return false; } } @@ -158,8 +167,8 @@ auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& by BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto struct_prop = dynamic_cast(prop.get()); - if(!struct_prop) { + LOG_ERROR("The property is not a valid struct property."); return false; } @@ -171,6 +180,7 @@ auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& by UnsignedLong dummy_bytes_written = 0; UnsignedLong vl_start = writer.arrayPosition(); if(!writeStructValue(struct_prop, dummy_bytes_written, writer, serialiser)) { + LOG_ERROR("Couldn't write the struct value."); return false; } bytes_written += writer.arrayPosition() - vl_start; @@ -206,13 +216,14 @@ auto StructSerialiser::writeStructValue(StructProperty* prop, UnsignedLong& byte BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto struct_prop = dynamic_cast(prop); - if(!struct_prop) { + LOG_ERROR("The property is not a valid struct property."); return false; } for(auto& item : struct_prop->properties) { if(!serialiser.write(item, bytes_written, writer)) { + LOG_ERROR("Couldn't write the struct's data."); return false; } } diff --git a/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp b/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp index c133d8f..ef002c7 100644 --- a/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "Vector2DPropertySerialiser.h" @@ -26,6 +27,7 @@ auto Vector2DPropertySerialiser::deserialiseProperty(Containers::StringView name auto prop = Containers::pointer(); if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y)) { + LOG_ERROR_FORMAT("Couldn't read 2D vector property {}'s value.", name); return nullptr; } @@ -36,8 +38,8 @@ auto Vector2DPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto vector = dynamic_cast(prop.get()); - if(!vector) { + LOG_ERROR("The property is not a valid 2D vector property."); return false; } diff --git a/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp b/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp index 44255eb..97bd0a8 100644 --- a/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp @@ -16,6 +16,7 @@ #include "../BinaryReader.h" #include "../BinaryWriter.h" +#include "../../Logger/Logger.h" #include "VectorPropertySerialiser.h" @@ -26,6 +27,7 @@ auto VectorPropertySerialiser::deserialiseProperty(Containers::StringView name, auto prop = Containers::pointer(); 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; } @@ -36,8 +38,8 @@ auto VectorPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { auto vector = dynamic_cast(prop.get()); - if(!vector) { + LOG_ERROR("The property is not a valid vector property."); return false; }