From b8b156a724a7492e54586af61cffd00f6ed23e55 Mon Sep 17 00:00:00 2001 From: William JCM Date: Thu, 23 Sep 2021 15:09:02 +0200 Subject: [PATCH] Add a serialiser for struct sttResourceItemValue. --- src/CMakeLists.txt | 3 + src/UESaveFile/PropertySerialiser.cpp | 2 + .../ResourcePropertySerialiser.cpp | 103 ++++++++++++++++++ .../Serialisers/ResourcePropertySerialiser.h | 30 +++++ src/UESaveFile/Types/ResourceItemValue.h | 30 +++++ 5 files changed, 168 insertions(+) create mode 100644 src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp create mode 100644 src/UESaveFile/Serialisers/ResourcePropertySerialiser.h create mode 100644 src/UESaveFile/Types/ResourceItemValue.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1c8e24..671640e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,8 @@ add_library(UESaveFile STATIC EXCLUDE_FROM_ALL UESaveFile/Serialisers/IntPropertySerialiser.cpp UESaveFile/Serialisers/MapPropertySerialiser.h UESaveFile/Serialisers/MapPropertySerialiser.cpp + UESaveFile/Serialisers/ResourcePropertySerialiser.h + UESaveFile/Serialisers/ResourcePropertySerialiser.cpp UESaveFile/Serialisers/RotatorPropertySerialiser.h UESaveFile/Serialisers/RotatorPropertySerialiser.cpp UESaveFile/Serialisers/StringPropertySerialiser.h @@ -84,6 +86,7 @@ add_library(UESaveFile STATIC EXCLUDE_FROM_ALL UESaveFile/Types/SetProperty.h UESaveFile/Types/StringProperty.h UESaveFile/Types/StructProperty.h + UESaveFile/Types/ResourceItemValue.h UESaveFile/Types/TextProperty.h UESaveFile/Types/UnrealProperty.h UESaveFile/Types/UnrealPropertyBase.h diff --git a/src/UESaveFile/PropertySerialiser.cpp b/src/UESaveFile/PropertySerialiser.cpp index cc69f68..cb65cea 100644 --- a/src/UESaveFile/PropertySerialiser.cpp +++ b/src/UESaveFile/PropertySerialiser.cpp @@ -26,6 +26,7 @@ #include "Serialisers/GuidPropertySerialiser.h" #include "Serialisers/IntPropertySerialiser.h" #include "Serialisers/MapPropertySerialiser.h" +#include "Serialisers/ResourcePropertySerialiser.h" #include "Serialisers/RotatorPropertySerialiser.h" #include "Serialisers/StringPropertySerialiser.h" #include "Serialisers/SetPropertySerialiser.h" @@ -53,6 +54,7 @@ PropertySerialiser::PropertySerialiser() { arrayAppend(_serialisers, Containers::pointer()); arrayAppend(_serialisers, Containers::pointer()); arrayAppend(_serialisers, Containers::pointer()); + arrayAppend(_serialisers, Containers::pointer()); arrayAppend(_serialisers, Containers::pointer()); arrayAppend(_serialisers, Containers::pointer()); arrayAppend(_serialisers, Containers::pointer()); diff --git a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp new file mode 100644 index 0000000..a92406f --- /dev/null +++ b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp @@ -0,0 +1,103 @@ +// MassBuilderSaveTool +// Copyright (C) 2021 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 "../Types/IntProperty.h" +#include "../Types/NoneProperty.h" + +#include "ResourcePropertySerialiser.h" + +auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +{ + auto prop = Containers::pointer(); + + std::string str; + if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21") { + return nullptr; + } + + if(!reader.readUEString(str) || str != "IntProperty") { + return nullptr; + } + + if(!reader.readUnsignedLong(value_length) || value_length != 4ull) { + return nullptr; + } + + char terminator; + if(!reader.readChar(terminator) || terminator != '\0') { + return nullptr; + } + + if(!reader.readInt(prop->id)) { + return nullptr; + } + + if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3") { + return nullptr; + } + + if(!reader.readUEString(str) || str != "IntProperty") { + 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") { + return nullptr; + } + + return prop; +} + +auto ResourcePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, + BinaryWriter& writer, PropertySerialiser& serialiser) -> bool +{ + auto res_prop = dynamic_cast(prop.get()); + if(!res_prop) { + return false; + } + + bytes_written += writer.writeUEStringToArray("ID_4_AAE08F17428E229EC7A2209F51081A21") + + writer.writeUEStringToArray("IntProperty") + + writer.writeValueToArray(4ull) + + writer.writeValueToArray('\0') + + writer.writeValueToArray(res_prop->id); + + bytes_written += writer.writeUEStringToArray("Quantity_3_560F09B5485C365D3041888910019CE3") + + writer.writeUEStringToArray("IntProperty") + + writer.writeValueToArray(4ull) + + writer.writeValueToArray('\0') + + writer.writeValueToArray(res_prop->quantity); + + bytes_written += writer.writeUEStringToArray("None"); + + return true; +} diff --git a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h new file mode 100644 index 0000000..b085667 --- /dev/null +++ b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h @@ -0,0 +1,30 @@ +#pragma once + +// MassBuilderSaveTool +// Copyright (C) 2021 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 "UnrealPropertySerialiser.h" + +#include "../Types/ResourceItemValue.h" + +class ResourcePropertySerialiser : public UnrealPropertySerialiser { + public: + using ptr = Containers::Pointer; + + private: + auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; +}; diff --git a/src/UESaveFile/Types/ResourceItemValue.h b/src/UESaveFile/Types/ResourceItemValue.h new file mode 100644 index 0000000..d5f5221 --- /dev/null +++ b/src/UESaveFile/Types/ResourceItemValue.h @@ -0,0 +1,30 @@ +#pragma once + +// MassBuilderSaveTool +// Copyright (C) 2021 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 "StructProperty.h" + +struct ResourceItemValue : public StructProperty { + using ptr = Containers::Pointer; + + ResourceItemValue() { + structType = "sttResourceItemValue"; + structGuid = Containers::StaticArray<16, char>{'\xB7', '\xA7', '\x77', '\xAB', '\xD3', '\x1B', '\xA6', '\x43', '\xAF', '\x42', '\xE5', '\x9E', '\xBF', '\xFD', '\x37', '\x55'}; + } + + Int id = 0, quantity = 0; +};