Build viewer/editor #13
70 changed files with 3794 additions and 0 deletions
|
@ -28,6 +28,83 @@ set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
|
||||||
|
|
||||||
corrade_add_resource(Assets assets.conf)
|
corrade_add_resource(Assets assets.conf)
|
||||||
|
|
||||||
|
add_library(UESaveFile STATIC EXCLUDE_FROM_ALL
|
||||||
|
UESaveFile/Serialisers/AbstractUnrealCollectionPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/AbstractUnrealPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h
|
||||||
|
UESaveFile/Serialisers/ArrayPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/ArrayPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/BoolPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/BoolPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/BytePropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/BytePropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/ColourPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/ColourPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/DateTimePropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/DateTimePropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/EnumPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/EnumPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/FloatPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/FloatPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/GuidPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/GuidPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/IntPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/IntPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/MapPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/MapPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/RotatorPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/RotatorPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/StringPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/StringPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/SetPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/SetPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/StructSerialiser.h
|
||||||
|
UESaveFile/Serialisers/StructSerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/TextPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/TextPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/UnrealPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/VectorPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/VectorPropertySerialiser.cpp
|
||||||
|
UESaveFile/Serialisers/Vector2DPropertySerialiser.h
|
||||||
|
UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp
|
||||||
|
|
||||||
|
UESaveFile/Types/ArrayProperty.h
|
||||||
|
UESaveFile/Types/BoolProperty.h
|
||||||
|
UESaveFile/Types/ByteProperty.h
|
||||||
|
UESaveFile/Types/ColourStructProperty.h
|
||||||
|
UESaveFile/Types/DateTimeStructProperty.h
|
||||||
|
UESaveFile/Types/EnumProperty.h
|
||||||
|
UESaveFile/Types/FloatProperty.h
|
||||||
|
UESaveFile/Types/GenericStructProperty.h
|
||||||
|
UESaveFile/Types/GuidStructProperty.h
|
||||||
|
UESaveFile/Types/IntProperty.h
|
||||||
|
UESaveFile/Types/MapProperty.h
|
||||||
|
UESaveFile/Types/NoneProperty.h
|
||||||
|
UESaveFile/Types/RotatorStructProperty.h
|
||||||
|
UESaveFile/Types/SetProperty.h
|
||||||
|
UESaveFile/Types/StringProperty.h
|
||||||
|
UESaveFile/Types/StructProperty.h
|
||||||
|
UESaveFile/Types/TextProperty.h
|
||||||
|
UESaveFile/Types/UnrealProperty.h
|
||||||
|
UESaveFile/Types/UnrealPropertyBase.h
|
||||||
|
UESaveFile/Types/VectorStructProperty.h
|
||||||
|
|
||||||
|
UESaveFile/Debug.h
|
||||||
|
UESaveFile/Debug.cpp
|
||||||
|
UESaveFile/UESaveFile.h
|
||||||
|
UESaveFile/UESaveFile.cpp
|
||||||
|
UESaveFile/BinaryReader.h
|
||||||
|
UESaveFile/BinaryReader.cpp
|
||||||
|
UESaveFile/BinaryWriter.h
|
||||||
|
UESaveFile/BinaryWriter.cpp
|
||||||
|
UESaveFile/PropertySerialiser.h
|
||||||
|
UESaveFile/PropertySerialiser.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(UESaveFile PRIVATE
|
||||||
|
Corrade::Containers
|
||||||
|
Corrade::Utility
|
||||||
|
Magnum::Magnum)
|
||||||
|
|
||||||
add_executable(MassBuilderSaveTool WIN32
|
add_executable(MassBuilderSaveTool WIN32
|
||||||
main.cpp
|
main.cpp
|
||||||
SaveTool/SaveTool.h
|
SaveTool/SaveTool.h
|
||||||
|
@ -78,6 +155,7 @@ target_link_libraries(MassBuilderSaveTool PRIVATE
|
||||||
Magnum::GL
|
Magnum::GL
|
||||||
Magnum::Sdl2Application
|
Magnum::Sdl2Application
|
||||||
MagnumIntegration::ImGui
|
MagnumIntegration::ImGui
|
||||||
|
UESaveFile
|
||||||
efsw
|
efsw
|
||||||
zip
|
zip
|
||||||
cpr::cpr
|
cpr::cpr
|
||||||
|
|
122
src/UESaveFile/BinaryReader.cpp
Normal file
122
src/UESaveFile/BinaryReader.cpp
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "BinaryReader.h"
|
||||||
|
|
||||||
|
BinaryReader::BinaryReader(const std::string& filename) {
|
||||||
|
_file = std::fopen(filename.c_str(), "rb");
|
||||||
|
|
||||||
|
if(!_file) {
|
||||||
|
Utility::Error{} << "Couldn't open" << filename.c_str() << "for reading:\n"
|
||||||
|
<< std::strerror(errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryReader::~BinaryReader() {
|
||||||
|
closeFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::open() -> bool {
|
||||||
|
return _file;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::eof() -> bool {
|
||||||
|
return std::feof(_file) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::position() -> Long {
|
||||||
|
return _ftelli64(_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryReader::closeFile() {
|
||||||
|
std::fclose(_file);
|
||||||
|
_file = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readChar(char& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(char), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readByte(Byte& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(Byte), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readUnsignedByte(UnsignedByte& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(UnsignedByte), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readShort(Short& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(Short), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readUnsignedShort(UnsignedShort& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(UnsignedShort), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readInt(Int& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(Int), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readUnsignedInt(UnsignedInt& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(UnsignedInt), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readLong(Long& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(Long), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readUnsignedLong(UnsignedLong& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(UnsignedLong), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readFloat(Float& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(Float), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readDouble(Double& value) -> bool {
|
||||||
|
return std::fread(&value, sizeof(Double), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readArray(Containers::Array<char>& array, std::size_t count) -> bool {
|
||||||
|
if(array.size() < count) {
|
||||||
|
array = Containers::Array<char>{ValueInit, count};
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::fread(array.data(), sizeof(char), count, _file) == count;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::readUEString(std::string& str) -> bool {
|
||||||
|
UnsignedInt length = 0;
|
||||||
|
if(!readUnsignedInt(length) || length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = std::string{};
|
||||||
|
str.resize(length - 1);
|
||||||
|
|
||||||
|
return std::fread(&str[0], sizeof(char), length, _file) == length;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryReader::peekChar() -> Int {
|
||||||
|
Int c;
|
||||||
|
c = std::fgetc(_file);
|
||||||
|
std::ungetc(c, _file);
|
||||||
|
return c;
|
||||||
|
}
|
65
src/UESaveFile/BinaryReader.h
Normal file
65
src/UESaveFile/BinaryReader.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/Array.h>
|
||||||
|
#include <Corrade/Containers/StaticArray.h>
|
||||||
|
#include <Corrade/Utility/StlForwardString.h>
|
||||||
|
|
||||||
|
#include <Magnum/Types.h>
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
class BinaryReader {
|
||||||
|
public:
|
||||||
|
explicit BinaryReader(const std::string& filename);
|
||||||
|
~BinaryReader();
|
||||||
|
|
||||||
|
auto open() -> bool;
|
||||||
|
auto eof() -> bool;
|
||||||
|
auto position() -> Long;
|
||||||
|
|
||||||
|
void closeFile();
|
||||||
|
|
||||||
|
auto readChar(char& value) -> bool;
|
||||||
|
auto readByte(Byte& value) -> bool;
|
||||||
|
auto readUnsignedByte(UnsignedByte& value) -> bool;
|
||||||
|
auto readShort(Short& value) -> bool;
|
||||||
|
auto readUnsignedShort(UnsignedShort& value) -> bool;
|
||||||
|
auto readInt(Int& value) -> bool;
|
||||||
|
auto readUnsignedInt(UnsignedInt& value) -> bool;
|
||||||
|
auto readLong(Long& value) -> bool;
|
||||||
|
auto readUnsignedLong(UnsignedLong& value) -> bool;
|
||||||
|
auto readFloat(Float& value) -> bool;
|
||||||
|
auto readDouble(Double& value) -> bool;
|
||||||
|
auto readArray(Containers::Array<char>& array, std::size_t count) -> bool;
|
||||||
|
|
||||||
|
template<std::size_t S>
|
||||||
|
auto readStaticArray(Containers::StaticArray<S, char>& array) -> bool {
|
||||||
|
return std::fread(array.data(), sizeof(char), S, _file) == S;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto readUEString(std::string& str) -> bool;
|
||||||
|
|
||||||
|
auto peekChar() -> Int;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::FILE* _file = nullptr;
|
||||||
|
};
|
133
src/UESaveFile/BinaryWriter.cpp
Normal file
133
src/UESaveFile/BinaryWriter.cpp
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "BinaryWriter.h"
|
||||||
|
|
||||||
|
BinaryWriter::BinaryWriter(const std::string& filename) {
|
||||||
|
_file = std::fopen(filename.c_str(), "wb");
|
||||||
|
if(!_file) {
|
||||||
|
Utility::Error{} << "Couldn't open" << filename.c_str() << "for reading:\n"
|
||||||
|
<< std::strerror(errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryWriter::~BinaryWriter() {
|
||||||
|
closeFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::open() -> bool {
|
||||||
|
return _file;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryWriter::closeFile() {
|
||||||
|
std::fflush(_file);
|
||||||
|
std::fclose(_file);
|
||||||
|
_file = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::position() -> Long {
|
||||||
|
return _ftelli64(_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::arrayPosition() const -> UnsignedLong {
|
||||||
|
return _index;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::flushToFile() -> bool {
|
||||||
|
bool ret = writeArray(_data);
|
||||||
|
std::fflush(_file);
|
||||||
|
_data = Containers::Array<char>{};
|
||||||
|
_index = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeChar(char value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(char), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeByte(Byte value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(Byte), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeUnsignedByte(UnsignedByte value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(UnsignedByte), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeShort(Short value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(Short), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeUnsignedShort(UnsignedShort value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(UnsignedShort), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeInt(Int value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(Int), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeUnsignedInt(UnsignedInt value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(UnsignedInt), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeLong(Long value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(Long), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeUnsignedLong(UnsignedLong value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(UnsignedLong), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeFloat(Float value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(Float), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeDouble(Double value) -> bool {
|
||||||
|
return std::fwrite(&value, sizeof(Double), 1, _file) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeArray(Containers::ArrayView<char> array) -> bool {
|
||||||
|
if(array.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::fwrite(array.data(), sizeof(char), array.size(), _file) == array.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeUEString(const std::string& str) -> bool {
|
||||||
|
if(str.length() > UINT32_MAX) {
|
||||||
|
Utility::Error{} << "BinaryWriter::writeUEString(): string is too big.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeUnsignedInt(static_cast<UnsignedInt>(str.length()) + 1);
|
||||||
|
|
||||||
|
if(str.length() > 0) {
|
||||||
|
std::size_t count = std::fwrite(&str[0], sizeof(char), str.length(), _file);
|
||||||
|
if(count != str.length()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return writeChar('\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BinaryWriter::writeUEStringToArray(const std::string& value) -> UnsignedLong {
|
||||||
|
Containers::ArrayView<const char> view{value.c_str(), value.length()};
|
||||||
|
return writeValueToArray<UnsignedInt>(UnsignedInt(value.length()) + 1u) + writeDataToArray(view) + writeValueToArray<char>('\0');
|
||||||
|
}
|
99
src/UESaveFile/BinaryWriter.h
Normal file
99
src/UESaveFile/BinaryWriter.h
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/ArrayView.h>
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
#include <Corrade/Containers/StaticArray.h>
|
||||||
|
#include <Corrade/Utility/StlForwardString.h>
|
||||||
|
|
||||||
|
#include <Magnum/Types.h>
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
class BinaryWriter {
|
||||||
|
public:
|
||||||
|
explicit BinaryWriter(const std::string& filename);
|
||||||
|
~BinaryWriter();
|
||||||
|
|
||||||
|
auto open() -> bool;
|
||||||
|
|
||||||
|
void closeFile();
|
||||||
|
|
||||||
|
auto position() -> Long;
|
||||||
|
|
||||||
|
auto arrayPosition() const -> UnsignedLong;
|
||||||
|
auto flushToFile() -> bool;
|
||||||
|
|
||||||
|
auto writeByte(Byte value) -> bool;
|
||||||
|
auto writeChar(char value) -> bool;
|
||||||
|
auto writeUnsignedByte(UnsignedByte value) -> bool;
|
||||||
|
auto writeShort(Short value) -> bool;
|
||||||
|
auto writeUnsignedShort(UnsignedShort value) -> bool;
|
||||||
|
auto writeInt(Int value) -> bool;
|
||||||
|
auto writeUnsignedInt(UnsignedInt value) -> bool;
|
||||||
|
auto writeLong(Long value) -> bool;
|
||||||
|
auto writeUnsignedLong(UnsignedLong value) -> bool;
|
||||||
|
auto writeFloat(Float value) -> bool;
|
||||||
|
auto writeDouble(Double value) -> bool;
|
||||||
|
auto writeArray(Containers::ArrayView<char> array) -> bool;
|
||||||
|
|
||||||
|
template<std::size_t S>
|
||||||
|
auto writeStaticArray(Containers::StaticArrayView<S, const char> array) -> bool {
|
||||||
|
return std::fwrite(array.data(), sizeof(char), S, _file) == S;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto writeUEString(const std::string& str) -> bool;
|
||||||
|
|
||||||
|
template<typename T, typename U = std::conditional_t<std::is_trivially_copyable<T>::value, T, T&>>
|
||||||
|
auto writeValueToArray(U value) -> UnsignedLong {
|
||||||
|
Containers::ArrayView<U> view{&value, 1};
|
||||||
|
return writeDataToArray(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto writeUEStringToArray(const std::string& value) -> UnsignedLong;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void writeValueToArrayAt(T& value, UnsignedLong position) {
|
||||||
|
Containers::ArrayView<T> view{&value, 1};
|
||||||
|
writeDataToArrayAt(view, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto writeDataToArray(Containers::ArrayView<T> view) -> UnsignedLong {
|
||||||
|
arrayAppend(_data, Containers::arrayCast<const char>(view));
|
||||||
|
_index += sizeof(T) * view.size();
|
||||||
|
return sizeof(T) * view.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void writeDataToArrayAt(Containers::ArrayView<T> view, UnsignedLong position) {
|
||||||
|
auto casted_view = Containers::arrayCast<const char>(view);
|
||||||
|
for(UnsignedLong i = 0; i < casted_view.size(); i++) {
|
||||||
|
_data[position + i] = casted_view[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FILE* _file = nullptr;
|
||||||
|
|
||||||
|
Containers::Array<char> _data;
|
||||||
|
UnsignedLong _index = 0;
|
||||||
|
};
|
76
src/UESaveFile/Debug.cpp
Normal file
76
src/UESaveFile/Debug.cpp
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "Types/UnrealPropertyBase.h"
|
||||||
|
#include "Types/ArrayProperty.h"
|
||||||
|
#include "Types/SetProperty.h"
|
||||||
|
#include "Types/StructProperty.h"
|
||||||
|
#include "Types/GenericStructProperty.h"
|
||||||
|
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const ArrayProperty* prop) {
|
||||||
|
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" <<
|
||||||
|
prop->propertyType.c_str() << "of" << prop->items.size() << prop->itemType.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const SetProperty* prop) {
|
||||||
|
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" <<
|
||||||
|
prop->propertyType.c_str() << "of" << prop->items.size() << prop->itemType.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const GenericStructProperty* prop) {
|
||||||
|
debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" <<
|
||||||
|
prop->structType.c_str() << "(" << Utility::Debug::nospace << prop->propertyType.c_str() << Utility::Debug::nospace <<
|
||||||
|
") Contents:";
|
||||||
|
for(const auto& item : prop->properties) {
|
||||||
|
debug << "\n " << Utility::Debug::nospace << item.get();
|
||||||
|
}
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const StructProperty* prop) {
|
||||||
|
auto cast = dynamic_cast<const GenericStructProperty*>(prop);
|
||||||
|
if(cast) {
|
||||||
|
return debug << cast;
|
||||||
|
}
|
||||||
|
|
||||||
|
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" <<
|
||||||
|
prop->structType.c_str() << "(" << Utility::Debug::nospace << prop->propertyType.c_str() << Utility::Debug::nospace << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const UnrealPropertyBase* prop) {
|
||||||
|
if(prop->propertyType == "ArrayProperty") {
|
||||||
|
auto array_prop = dynamic_cast<const ArrayProperty*>(prop);
|
||||||
|
if(array_prop) {
|
||||||
|
return debug << array_prop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(prop->propertyType == "SetProperty") {
|
||||||
|
auto set_prop = dynamic_cast<const SetProperty*>(prop);
|
||||||
|
if(set_prop) {
|
||||||
|
return debug << set_prop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(prop->propertyType == "StructProperty") {
|
||||||
|
auto struct_prop = dynamic_cast<const StructProperty*>(prop);
|
||||||
|
if(struct_prop) {
|
||||||
|
return debug << struct_prop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << prop->propertyType.c_str();
|
||||||
|
}
|
33
src/UESaveFile/Debug.h
Normal file
33
src/UESaveFile/Debug.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Utility/Debug.h>
|
||||||
|
|
||||||
|
struct ArrayProperty;
|
||||||
|
struct SetProperty;
|
||||||
|
struct GenericStructProperty;
|
||||||
|
struct StructProperty;
|
||||||
|
struct UnrealPropertyBase;
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const ArrayProperty* prop);
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const SetProperty* prop);
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const GenericStructProperty* prop);
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const StructProperty* prop);
|
||||||
|
Utility::Debug& operator<<(Utility::Debug& debug, const UnrealPropertyBase* prop);
|
252
src/UESaveFile/PropertySerialiser.cpp
Normal file
252
src/UESaveFile/PropertySerialiser.cpp
Normal file
|
@ -0,0 +1,252 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "Serialisers/ArrayPropertySerialiser.h"
|
||||||
|
#include "Serialisers/BoolPropertySerialiser.h"
|
||||||
|
#include "Serialisers/BytePropertySerialiser.h"
|
||||||
|
#include "Serialisers/ColourPropertySerialiser.h"
|
||||||
|
#include "Serialisers/DateTimePropertySerialiser.h"
|
||||||
|
#include "Serialisers/EnumPropertySerialiser.h"
|
||||||
|
#include "Serialisers/FloatPropertySerialiser.h"
|
||||||
|
#include "Serialisers/GuidPropertySerialiser.h"
|
||||||
|
#include "Serialisers/IntPropertySerialiser.h"
|
||||||
|
#include "Serialisers/MapPropertySerialiser.h"
|
||||||
|
#include "Serialisers/RotatorPropertySerialiser.h"
|
||||||
|
#include "Serialisers/StringPropertySerialiser.h"
|
||||||
|
#include "Serialisers/SetPropertySerialiser.h"
|
||||||
|
#include "Serialisers/StructSerialiser.h"
|
||||||
|
#include "Serialisers/TextPropertySerialiser.h"
|
||||||
|
#include "Serialisers/VectorPropertySerialiser.h"
|
||||||
|
#include "Serialisers/Vector2DPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "Types/NoneProperty.h"
|
||||||
|
|
||||||
|
#include "BinaryReader.h"
|
||||||
|
#include "BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "PropertySerialiser.h"
|
||||||
|
|
||||||
|
|
||||||
|
PropertySerialiser::PropertySerialiser() {
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<ArrayPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<BoolPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<BytePropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<ColourPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<DateTimePropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<EnumPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<FloatPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<GuidPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<IntPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<MapPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<RotatorPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<StringPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<SetPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<TextPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<VectorPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<Vector2DPropertySerialiser>());
|
||||||
|
arrayAppend(_serialisers, Containers::pointer<StructSerialiser>());
|
||||||
|
|
||||||
|
arrayAppend(_collectionSerialisers, Containers::pointer<StructSerialiser>());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr {
|
||||||
|
if(reader.peekChar() < 0 || reader.eof()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
if(!reader.readUEString(name)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(name == "None") {
|
||||||
|
return Containers::pointer<NoneProperty>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string type;
|
||||||
|
if(!reader.readUEString(type)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedLong value_length;
|
||||||
|
if(!reader.readUnsignedLong(value_length)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return deserialise(std::move(name), std::move(type), value_length, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::readItem(BinaryReader& reader, std::string type, UnsignedLong value_length, std::string name) -> UnrealPropertyBase::ptr {
|
||||||
|
if(reader.peekChar() < 0 || reader.eof()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return deserialise(std::move(name), std::move(type), value_length, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_type, UnsignedInt count) -> Containers::Array<UnrealPropertyBase::ptr> {
|
||||||
|
if(reader.peekChar() < 0 || reader.eof()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto serialiser = getCollectionSerialiser(item_type);
|
||||||
|
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> array;
|
||||||
|
|
||||||
|
if(serialiser) {
|
||||||
|
std::string name;
|
||||||
|
if(!reader.readUEString(name)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string type;
|
||||||
|
if(!reader.readUEString(type)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedLong value_length;
|
||||||
|
if(!reader.readUnsignedLong(value_length)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
array = serialiser->deserialise(name, type, value_length, count, reader, *this);
|
||||||
|
|
||||||
|
for(auto& item : array) {
|
||||||
|
if(item->name == Containers::NullOpt) {
|
||||||
|
item->name.emplace(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(UnsignedInt i = 0; i < count; i++) {
|
||||||
|
auto item = readItem(reader, item_type, -1, "");
|
||||||
|
arrayAppend(array, std::move(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::deserialise(std::string name, std::string type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
UnrealPropertyBase::ptr prop;
|
||||||
|
auto serialiser = getSerialiser(type);
|
||||||
|
|
||||||
|
if(serialiser == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop = serialiser->deserialise(name, type, value_length, reader, *this);
|
||||||
|
|
||||||
|
if(!prop) {
|
||||||
|
!Utility::Error{} << "No prop in" << __func__;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop->name = std::move(name);
|
||||||
|
prop->propertyType = std::move(type);
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer) -> bool
|
||||||
|
{
|
||||||
|
auto serialiser = getSerialiser(item_type);
|
||||||
|
if(!serialiser) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return serialiser->serialise(prop, bytes_written, writer, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::write(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool {
|
||||||
|
if(prop->name == "None" && prop->propertyType == "NoneProperty" && dynamic_cast<NoneProperty*>(prop.get())) {
|
||||||
|
bytes_written += writer.writeUEStringToArray(*prop->name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeUEStringToArray(*prop->name);
|
||||||
|
bytes_written += writer.writeUEStringToArray(prop->propertyType);
|
||||||
|
|
||||||
|
UnsignedLong value_length = 0;
|
||||||
|
UnsignedLong vl_position = writer.arrayPosition();
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<UnsignedLong>(value_length);
|
||||||
|
|
||||||
|
bool ret = serialise(prop, prop->propertyType, value_length, writer);
|
||||||
|
|
||||||
|
writer.writeValueToArrayAt(value_length, vl_position);
|
||||||
|
|
||||||
|
bytes_written += value_length;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::writeItem(UnrealPropertyBase::ptr& prop, const std::string& item_type,
|
||||||
|
UnsignedLong& bytes_written, BinaryWriter& writer) -> bool
|
||||||
|
{
|
||||||
|
if(prop->name == "None" && prop->propertyType == "NoneProperty" && dynamic_cast<NoneProperty*>(prop.get())) {
|
||||||
|
bytes_written += writer.writeUEStringToArray(*prop->name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return serialise(prop, item_type, bytes_written, writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::writeSet(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type,
|
||||||
|
UnsignedLong& bytes_written, BinaryWriter& writer) -> bool
|
||||||
|
{
|
||||||
|
auto serialiser = getCollectionSerialiser(item_type);
|
||||||
|
if(serialiser) {
|
||||||
|
return serialiser->serialise(props, item_type, bytes_written, writer, *this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(auto& prop : props) {
|
||||||
|
if(!writeItem(prop, item_type, bytes_written, writer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::getSerialiser(const std::string& item_type) -> AbstractUnrealPropertySerialiser* {
|
||||||
|
for(auto& item : _serialisers) {
|
||||||
|
for(const std::string& serialiser_type : item->types()) {
|
||||||
|
if(item_type == serialiser_type) {
|
||||||
|
return item.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PropertySerialiser::getCollectionSerialiser(const std::string& item_type) -> AbstractUnrealCollectionPropertySerialiser* {
|
||||||
|
for(auto& item : _collectionSerialisers) {
|
||||||
|
for(const std::string& serialiser_type : item->types()) {
|
||||||
|
if(item_type == serialiser_type) {
|
||||||
|
return item.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
51
src/UESaveFile/PropertySerialiser.h
Normal file
51
src/UESaveFile/PropertySerialiser.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
|
||||||
|
#include "Serialisers/AbstractUnrealPropertySerialiser.h"
|
||||||
|
#include "Serialisers/AbstractUnrealCollectionPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "Types/UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
|
||||||
|
class BinaryReader;
|
||||||
|
class BinaryWriter;
|
||||||
|
|
||||||
|
class PropertySerialiser {
|
||||||
|
public:
|
||||||
|
PropertySerialiser();
|
||||||
|
|
||||||
|
auto read(BinaryReader& reader) -> UnrealPropertyBase::ptr;
|
||||||
|
auto readItem(BinaryReader& reader, std::string type, UnsignedLong value_length, std::string name) -> UnrealPropertyBase::ptr;
|
||||||
|
auto readSet(BinaryReader& reader, const std::string& item_type, UnsignedInt count) -> Containers::Array<UnrealPropertyBase::ptr>;
|
||||||
|
auto deserialise(std::string name, std::string type, UnsignedLong value_length, BinaryReader& reader) -> UnrealPropertyBase::ptr;
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool;
|
||||||
|
auto write(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool;
|
||||||
|
auto writeItem(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool;
|
||||||
|
auto writeSet(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool;
|
||||||
|
|
||||||
|
private:
|
||||||
|
auto getSerialiser(const std::string& item_type) -> AbstractUnrealPropertySerialiser*;
|
||||||
|
auto getCollectionSerialiser(const std::string& item_type) -> AbstractUnrealCollectionPropertySerialiser*;
|
||||||
|
|
||||||
|
Containers::Array<AbstractUnrealPropertySerialiser::ptr> _serialisers;
|
||||||
|
Containers::Array<AbstractUnrealCollectionPropertySerialiser::ptr> _collectionSerialisers;
|
||||||
|
};
|
|
@ -0,0 +1,47 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/Array.h>
|
||||||
|
#include <Corrade/Containers/ArrayView.h>
|
||||||
|
#include <Corrade/Containers/Pointer.h>
|
||||||
|
|
||||||
|
#include <Magnum/Types.h>
|
||||||
|
|
||||||
|
#include "../Types/UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
class BinaryReader;
|
||||||
|
class BinaryWriter;
|
||||||
|
class PropertySerialiser;
|
||||||
|
|
||||||
|
class AbstractUnrealCollectionPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<AbstractUnrealCollectionPropertySerialiser>;
|
||||||
|
|
||||||
|
virtual ~AbstractUnrealCollectionPropertySerialiser() = default;
|
||||||
|
|
||||||
|
virtual auto types() -> Containers::ArrayView<const std::string> = 0;
|
||||||
|
|
||||||
|
virtual auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> = 0;
|
||||||
|
|
||||||
|
virtual auto serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0;
|
||||||
|
};
|
|
@ -0,0 +1,46 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/Array.h>
|
||||||
|
#include <Corrade/Containers/Pointer.h>
|
||||||
|
|
||||||
|
#include <Magnum/Types.h>
|
||||||
|
|
||||||
|
#include "../Types/UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
class BinaryReader;
|
||||||
|
class BinaryWriter;
|
||||||
|
class PropertySerialiser;
|
||||||
|
|
||||||
|
class AbstractUnrealPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<AbstractUnrealPropertySerialiser>;
|
||||||
|
|
||||||
|
virtual ~AbstractUnrealPropertySerialiser() = default;
|
||||||
|
|
||||||
|
virtual auto types() -> Containers::ArrayView<const std::string> = 0;
|
||||||
|
|
||||||
|
virtual auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr = 0;
|
||||||
|
|
||||||
|
virtual auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0;
|
||||||
|
};
|
46
src/UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h
Normal file
46
src/UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/Array.h>
|
||||||
|
#include <Corrade/Containers/ArrayView.h>
|
||||||
|
#include <Corrade/Containers/Pointer.h>
|
||||||
|
|
||||||
|
#include <Magnum/Types.h>
|
||||||
|
|
||||||
|
#include "../Types/UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
class BinaryReader;
|
||||||
|
class BinaryWriter;
|
||||||
|
|
||||||
|
class AbstractUnrealStructSerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<AbstractUnrealStructSerialiser>;
|
||||||
|
|
||||||
|
virtual ~AbstractUnrealStructSerialiser() = default;
|
||||||
|
|
||||||
|
virtual auto supportsType(const std::string& type) -> bool = 0;
|
||||||
|
|
||||||
|
virtual auto deserialise(BinaryReader& reader) -> UnrealPropertyBase::ptr = 0;
|
||||||
|
|
||||||
|
virtual auto serialise(UnrealPropertyBase::ptr& structProp, BinaryWriter& writer, UnsignedLong& bytes_written) -> bool = 0;
|
||||||
|
};
|
66
src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp
Normal file
66
src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
#include "../PropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "ArrayPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto ArrayPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
std::string item_type;
|
||||||
|
if(!reader.readUEString(item_type)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedInt item_count;
|
||||||
|
if(!reader.readUnsignedInt(item_count)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto prop = Containers::pointer<ArrayProperty>();
|
||||||
|
prop->itemType = std::move(item_type);
|
||||||
|
prop->items = serialiser.readSet(reader, prop->itemType, item_count);
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ArrayPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto array_prop = dynamic_cast<ArrayProperty*>(prop.get());
|
||||||
|
if(!array_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeUEStringToArray(array_prop->itemType);
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
bytes_written += writer.writeValueToArray<UnsignedInt>(UnsignedInt(array_prop->items.size()));
|
||||||
|
|
||||||
|
UnsignedLong start_pos = writer.arrayPosition();
|
||||||
|
UnsignedLong dummy_bytes_written = 0;
|
||||||
|
bool ret = serialiser.writeSet(array_prop->items, array_prop->itemType, dummy_bytes_written, writer);
|
||||||
|
bytes_written += writer.arrayPosition() - start_pos;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/ArrayPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/ArrayPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/ArrayProperty.h"
|
||||||
|
|
||||||
|
class ArrayPropertySerialiser : public UnrealPropertySerialiser<ArrayProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<ArrayPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
61
src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp
Normal file
61
src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "BoolPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto BoolPropertySerialiser::types() -> Containers::ArrayView<const std::string> {
|
||||||
|
static const Containers::Array<std::string> types{InPlaceInit, {"BoolProperty"}};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BoolPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
if(value_length != 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Short value;
|
||||||
|
if(!reader.readShort(value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(value > 1 || value < 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto prop = Containers::pointer<BoolProperty>();
|
||||||
|
prop->value = value;
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BoolPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto bool_prop = dynamic_cast<BoolProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!bool_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeValueToArray<Short>(Short(bool_prop->value));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
32
src/UESaveFile/Serialisers/BoolPropertySerialiser.h
Normal file
32
src/UESaveFile/Serialisers/BoolPropertySerialiser.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/BoolProperty.h"
|
||||||
|
|
||||||
|
class BoolPropertySerialiser : public AbstractUnrealPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<BoolPropertySerialiser>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override;
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
};
|
75
src/UESaveFile/Serialisers/BytePropertySerialiser.cpp
Normal file
75
src/UESaveFile/Serialisers/BytePropertySerialiser.cpp
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "BytePropertySerialiser.h"
|
||||||
|
|
||||||
|
auto BytePropertySerialiser::types() -> Containers::ArrayView<const std::string> {
|
||||||
|
static const Containers::Array<std::string> types{InPlaceInit, {"ByteProperty"}};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BytePropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<ByteProperty>();
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->enumType)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->enumValue)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//UnsignedInt count = 0;
|
||||||
|
//if(!reader.readUnsignedInt(count)) {
|
||||||
|
// return nullptr;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//if(!reader.readArray(prop->value, count)) {
|
||||||
|
// return nullptr;
|
||||||
|
//}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BytePropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto byte_prop = dynamic_cast<ByteProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!byte_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//writer.writeValueToArray<char>('\0');
|
||||||
|
//bytes_written += writer.writeValueToArray<UnsignedInt>(byte_prop->value.size());
|
||||||
|
//bytes_written += writer.writeDataToArray<char>(byte_prop->value);
|
||||||
|
|
||||||
|
writer.writeUEStringToArray(byte_prop->enumType);
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
bytes_written += writer.writeUEStringToArray(byte_prop->enumValue);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
32
src/UESaveFile/Serialisers/BytePropertySerialiser.h
Normal file
32
src/UESaveFile/Serialisers/BytePropertySerialiser.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/ByteProperty.h"
|
||||||
|
|
||||||
|
class BytePropertySerialiser : public AbstractUnrealPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<BytePropertySerialiser>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override;
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
};
|
49
src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp
Normal file
49
src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "ColourPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto ColourPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<ColourStructProperty>();
|
||||||
|
|
||||||
|
if(!reader.readFloat(prop->r) || !reader.readFloat(prop->g) ||
|
||||||
|
!reader.readFloat(prop->b) || !reader.readFloat(prop->a))
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ColourPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto colour_prop = dynamic_cast<ColourStructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!colour_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<Float>(colour_prop->r) + writer.writeValueToArray<Float>(colour_prop->g) +
|
||||||
|
writer.writeValueToArray<Float>(colour_prop->b) + writer.writeValueToArray<Float>(colour_prop->a);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/ColourPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/ColourPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/ColourStructProperty.h"
|
||||||
|
|
||||||
|
class ColourPropertySerialiser : public UnrealPropertySerialiser<ColourStructProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<ColourPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
46
src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp
Normal file
46
src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "DateTimePropertySerialiser.h"
|
||||||
|
|
||||||
|
auto DateTimePropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<DateTimeStructProperty>();
|
||||||
|
|
||||||
|
if(!reader.readUnsignedLong(prop->timestamp)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto DateTimePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto dt_prop = dynamic_cast<DateTimeStructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!dt_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<UnsignedLong>(dt_prop->timestamp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/DateTimePropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/DateTimePropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/DateTimeStructProperty.h"
|
||||||
|
|
||||||
|
class DateTimePropertySerialiser : public UnrealPropertySerialiser<DateTimeStructProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<DateTimePropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
62
src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp
Normal file
62
src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "EnumPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto EnumPropertySerialiser::types() -> Containers::ArrayView<const std::string> {
|
||||||
|
static const Containers::Array<std::string> types{InPlaceInit, {"EnumProperty"}};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto EnumPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<EnumProperty>();
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->enumType)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto EnumPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto enum_prop = dynamic_cast<EnumProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!enum_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeUEStringToArray(enum_prop->enumType);
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
bytes_written += writer.writeUEStringToArray(enum_prop->value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
32
src/UESaveFile/Serialisers/EnumPropertySerialiser.h
Normal file
32
src/UESaveFile/Serialisers/EnumPropertySerialiser.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/EnumProperty.h"
|
||||||
|
|
||||||
|
class EnumPropertySerialiser : public AbstractUnrealPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<EnumPropertySerialiser>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override;
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
};
|
57
src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp
Normal file
57
src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "FloatPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto FloatPropertySerialiser::types() -> Containers::ArrayView<const std::string> {
|
||||||
|
static const Containers::Array<std::string> types{InPlaceInit, {"FloatProperty"}};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto FloatPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<FloatProperty>();
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readFloat(prop->value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto FloatPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto float_prop = dynamic_cast<FloatProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!float_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
bytes_written += writer.writeValueToArray<Float>(float_prop->value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
32
src/UESaveFile/Serialisers/FloatPropertySerialiser.h
Normal file
32
src/UESaveFile/Serialisers/FloatPropertySerialiser.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/FloatProperty.h"
|
||||||
|
|
||||||
|
class FloatPropertySerialiser : public AbstractUnrealPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<FloatPropertySerialiser>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override;
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
};
|
47
src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp
Normal file
47
src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "GuidPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto GuidPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<GuidStructProperty>();
|
||||||
|
|
||||||
|
if(!reader.readStaticArray(prop->guid)) {
|
||||||
|
Utility::Error{} << "Couldn't read guid in" << __func__;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto GuidPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto guid_prop = dynamic_cast<GuidStructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!guid_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeDataToArray<char>({guid_prop->guid.data(), guid_prop->guid.size()});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
31
src/UESaveFile/Serialisers/GuidPropertySerialiser.h
Normal file
31
src/UESaveFile/Serialisers/GuidPropertySerialiser.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/GuidStructProperty.h"
|
||||||
|
|
||||||
|
class GuidPropertySerialiser : public UnrealPropertySerialiser<GuidStructProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<GuidPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
66
src/UESaveFile/Serialisers/IntPropertySerialiser.cpp
Normal file
66
src/UESaveFile/Serialisers/IntPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "IntPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto IntPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<IntProperty>();
|
||||||
|
|
||||||
|
if(value_length == UnsignedLong(-1)) {
|
||||||
|
if(!reader.readInt(prop->value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop->valueLength = UnsignedLong(-1);
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readInt(prop->value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop->name.emplace(name);
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto IntPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto int_prop = dynamic_cast<IntProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!int_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(prop->valueLength != UnsignedLong(-1)) {
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<Int>(int_prop->value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/IntPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/IntPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/IntProperty.h"
|
||||||
|
|
||||||
|
class IntPropertySerialiser : public UnrealPropertySerialiser<IntProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<IntPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
124
src/UESaveFile/Serialisers/MapPropertySerialiser.cpp
Normal file
124
src/UESaveFile/Serialisers/MapPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
#include "../PropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/NoneProperty.h"
|
||||||
|
|
||||||
|
#include "MapPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<MapProperty>();
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->keyType)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->valueType)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedInt null;
|
||||||
|
if(!reader.readUnsignedInt(null) || null != 0u) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedInt count;
|
||||||
|
if(!reader.readUnsignedInt(count)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Begin dirty code because the MapProperty format doesn't seem to match any of the GVAS reading stuff I've found,
|
||||||
|
// so I'm just gonna write stuff that matches the only MapProperty I can find in MB's save files.
|
||||||
|
|
||||||
|
arrayReserve(prop->map, count);
|
||||||
|
|
||||||
|
for(UnsignedInt i = 0; i < count; i++) {
|
||||||
|
MapProperty::KeyValuePair pair;
|
||||||
|
|
||||||
|
if(prop->keyType == "IntProperty") {
|
||||||
|
pair.key = serialiser.readItem(reader, prop->keyType, -1, name);
|
||||||
|
if(pair.key == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // Add other branches depending on key type, should more maps appear in the future.
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnrealPropertyBase::ptr value_item;
|
||||||
|
while((value_item = serialiser.read(reader)) != nullptr) {
|
||||||
|
arrayAppend(pair.values, std::move(value_item));
|
||||||
|
|
||||||
|
if(pair.values.back()->name == "None" &&
|
||||||
|
pair.values.back()->propertyType == "NoneProperty" &&
|
||||||
|
dynamic_cast<NoneProperty*>(pair.values.back().get()) != nullptr)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayAppend(prop->map, std::move(pair));
|
||||||
|
}
|
||||||
|
|
||||||
|
// End dirty code
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto map_prop = dynamic_cast<MapProperty*>(prop.get());
|
||||||
|
if(!map_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeUEStringToArray(map_prop->keyType);
|
||||||
|
writer.writeUEStringToArray(map_prop->valueType);
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
|
||||||
|
UnsignedLong value_start = writer.arrayPosition();
|
||||||
|
writer.writeValueToArray<UnsignedInt>(0u);
|
||||||
|
|
||||||
|
writer.writeValueToArray<UnsignedInt>(UnsignedInt(map_prop->map.size()));
|
||||||
|
|
||||||
|
UnsignedLong dummy_bytes_written = 0;
|
||||||
|
for(auto& pair : map_prop->map) {
|
||||||
|
if(!serialiser.writeItem(pair.key, map_prop->keyType, dummy_bytes_written, writer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& value : pair.values) {
|
||||||
|
if(!serialiser.write(value, dummy_bytes_written, writer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += (writer.arrayPosition() - value_start);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/MapPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/MapPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/MapProperty.h"
|
||||||
|
|
||||||
|
class MapPropertySerialiser : public UnrealPropertySerialiser<MapProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<MapPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
47
src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp
Normal file
47
src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "RotatorPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto RotatorPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<RotatorStructProperty>();
|
||||||
|
|
||||||
|
if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y) || !reader.readFloat(prop->z)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto RotatorPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto rotator = dynamic_cast<RotatorStructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!rotator) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<Float>(rotator->x) + writer.writeValueToArray<Float>(rotator->y) +
|
||||||
|
writer.writeValueToArray<Float>(rotator->z);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/RotatorPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/RotatorPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/RotatorStructProperty.h"
|
||||||
|
|
||||||
|
class RotatorPropertySerialiser : public UnrealPropertySerialiser<RotatorStructProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<RotatorPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
73
src/UESaveFile/Serialisers/SetPropertySerialiser.cpp
Normal file
73
src/UESaveFile/Serialisers/SetPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
#include "../PropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "SetPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto SetPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
std::string item_type;
|
||||||
|
if(!reader.readUEString(item_type)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedInt four_bytes;
|
||||||
|
if(!reader.readUnsignedInt(four_bytes) || four_bytes != 0u) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedInt item_count;
|
||||||
|
if(!reader.readUnsignedInt(item_count)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto prop = Containers::pointer<SetProperty>();
|
||||||
|
prop->itemType = std::move(item_type);
|
||||||
|
prop->items = serialiser.readSet(reader, prop->itemType, item_count);
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto SetPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto set_prop = dynamic_cast<SetProperty*>(prop.get());
|
||||||
|
if(!set_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeUEStringToArray(set_prop->itemType);
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<UnsignedInt>(0u);
|
||||||
|
bytes_written += writer.writeValueToArray<UnsignedInt>(UnsignedInt(set_prop->items.size()));
|
||||||
|
|
||||||
|
UnsignedLong start_pos = writer.arrayPosition();
|
||||||
|
UnsignedLong dummy_bytes_written = 0;
|
||||||
|
serialiser.writeSet(set_prop->items, set_prop->itemType, dummy_bytes_written, writer);
|
||||||
|
bytes_written += writer.arrayPosition() - start_pos;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/SetPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/SetPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/SetProperty.h"
|
||||||
|
|
||||||
|
class SetPropertySerialiser : public UnrealPropertySerialiser<SetProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<SetPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
64
src/UESaveFile/Serialisers/StringPropertySerialiser.cpp
Normal file
64
src/UESaveFile/Serialisers/StringPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "StringPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto StringPropertySerialiser::types() -> Containers::ArrayView<const std::string> {
|
||||||
|
static const Containers::Array<std::string> types{InPlaceInit, {"NameProperty", "StrProperty", "SoftObjectProperty", "ObjectProperty"}};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StringPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<StringProperty>(type);
|
||||||
|
|
||||||
|
if(value_length != UnsignedLong(-1)) {
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUEString(prop->value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop->valueLength = value_length;
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StringPropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto str_prop = dynamic_cast<StringProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!str_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(str_prop->valueLength != UnsignedLong(-1)) {
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeUEStringToArray(str_prop->value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
32
src/UESaveFile/Serialisers/StringPropertySerialiser.h
Normal file
32
src/UESaveFile/Serialisers/StringPropertySerialiser.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/StringProperty.h"
|
||||||
|
|
||||||
|
class StringPropertySerialiser : public AbstractUnrealPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<StringPropertySerialiser>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override;
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
};
|
210
src/UESaveFile/Serialisers/StructSerialiser.cpp
Normal file
210
src/UESaveFile/Serialisers/StructSerialiser.cpp
Normal file
|
@ -0,0 +1,210 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
#include "../PropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/GenericStructProperty.h"
|
||||||
|
#include "../Types/NoneProperty.h"
|
||||||
|
|
||||||
|
#include "StructSerialiser.h"
|
||||||
|
|
||||||
|
auto StructSerialiser::types() -> Containers::ArrayView<const std::string> {
|
||||||
|
static const Containers::Array<std::string> types{InPlaceInit, {"StructProperty"}};
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StructSerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr>
|
||||||
|
{
|
||||||
|
std::string item_type;
|
||||||
|
if(!reader.readUEString(item_type)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::StaticArray<16, char> guid{ValueInit};
|
||||||
|
if(!reader.readStaticArray(guid)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> array;
|
||||||
|
|
||||||
|
if(count == 0) {
|
||||||
|
auto prop = Containers::pointer<GenericStructProperty>();
|
||||||
|
prop->structType = std::move(item_type);
|
||||||
|
prop->structGuid = std::move(guid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(UnsignedInt i = 0; i < count; i++) {
|
||||||
|
auto prop = readStructValue(name, item_type, value_length, reader, serialiser);
|
||||||
|
|
||||||
|
if(!prop) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop->structGuid = guid;
|
||||||
|
|
||||||
|
arrayAppend(array, std::move(prop));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StructSerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
std::string item_type;
|
||||||
|
if(!reader.readUEString(item_type)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item_type == "None") {
|
||||||
|
return Containers::pointer<NoneProperty>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::StaticArray<16, char> guid{ValueInit};
|
||||||
|
if(!reader.readStaticArray(guid)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnrealPropertyBase::ptr prop = serialiser.readItem(reader, item_type, value_length, name);
|
||||||
|
|
||||||
|
if(!prop) {
|
||||||
|
prop = readStructValue(name, item_type, value_length, reader, serialiser);
|
||||||
|
if(prop) {
|
||||||
|
dynamic_cast<GenericStructProperty*>(prop.get())->structGuid = std::move(guid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StructSerialiser::serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type,
|
||||||
|
UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
bytes_written += writer.writeUEStringToArray(*(props.front()->name));
|
||||||
|
bytes_written += writer.writeUEStringToArray(item_type);
|
||||||
|
UnsignedLong vl_pos = writer.arrayPosition();
|
||||||
|
bytes_written += writer.writeValueToArray<UnsignedLong>(0ull);
|
||||||
|
|
||||||
|
auto struct_prop = dynamic_cast<StructProperty*>(props.front().get());
|
||||||
|
if(!struct_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeUEStringToArray(struct_prop->structType);
|
||||||
|
bytes_written += writer.writeDataToArray(arrayView(struct_prop->structGuid));
|
||||||
|
bytes_written += writer.writeValueToArray<char>('\0');
|
||||||
|
|
||||||
|
UnsignedLong vl_start = writer.arrayPosition();
|
||||||
|
|
||||||
|
UnsignedLong bytes_written_here = 0;
|
||||||
|
for(auto& prop : props) {
|
||||||
|
struct_prop = dynamic_cast<StructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!struct_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!writeStructValue(struct_prop, bytes_written_here, writer, serialiser)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedLong vl_stop = writer.arrayPosition() - vl_start;
|
||||||
|
writer.writeValueToArrayAt(vl_stop, vl_pos);
|
||||||
|
bytes_written += vl_stop;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto struct_prop = dynamic_cast<StructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!struct_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeUEStringToArray(struct_prop->structType);
|
||||||
|
writer.writeDataToArray(arrayView(struct_prop->structGuid));
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
|
||||||
|
if(!serialiser.writeItem(prop, struct_prop->structType, bytes_written, writer)) {
|
||||||
|
UnsignedLong dummy_bytes_written = 0;
|
||||||
|
UnsignedLong vl_start = writer.arrayPosition();
|
||||||
|
if(!writeStructValue(struct_prop, dummy_bytes_written, writer, serialiser)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bytes_written += writer.arrayPosition() - vl_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StructSerialiser::readStructValue(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> StructProperty::ptr
|
||||||
|
{
|
||||||
|
auto st_prop = Containers::pointer<GenericStructProperty>();
|
||||||
|
st_prop->structType = type;
|
||||||
|
|
||||||
|
UnrealPropertyBase::ptr prop;
|
||||||
|
while((prop = serialiser.read(reader)) != nullptr) {
|
||||||
|
arrayAppend(st_prop->properties, std::move(prop));
|
||||||
|
|
||||||
|
if(st_prop->properties.back()->name == "None" &&
|
||||||
|
st_prop->properties.back()->propertyType == "NoneProperty" &&
|
||||||
|
dynamic_cast<NoneProperty*>(st_prop->properties.back().get()) != nullptr)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
st_prop->name.emplace(name);
|
||||||
|
|
||||||
|
return st_prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto StructSerialiser::writeStructValue(StructProperty* prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto struct_prop = dynamic_cast<GenericStructProperty*>(prop);
|
||||||
|
|
||||||
|
if(!struct_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& item : struct_prop->properties) {
|
||||||
|
if(!serialiser.write(item, bytes_written, writer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
45
src/UESaveFile/Serialisers/StructSerialiser.h
Normal file
45
src/UESaveFile/Serialisers/StructSerialiser.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "AbstractUnrealCollectionPropertySerialiser.h"
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
#include "AbstractUnrealStructSerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/StructProperty.h"
|
||||||
|
|
||||||
|
class StructSerialiser : public AbstractUnrealPropertySerialiser, public AbstractUnrealCollectionPropertySerialiser {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<StructSerialiser>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override;
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, UnsignedInt count,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> override;
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
|
||||||
|
|
||||||
|
auto serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
auto readStructValue(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> StructProperty::ptr;
|
||||||
|
auto writeStructValue(StructProperty* prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool;
|
||||||
|
};
|
84
src/UESaveFile/Serialisers/TextPropertySerialiser.cpp
Normal file
84
src/UESaveFile/Serialisers/TextPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "TextPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto TextPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<TextProperty>();
|
||||||
|
|
||||||
|
Long start_position = reader.position();
|
||||||
|
|
||||||
|
char terminator;
|
||||||
|
if(!reader.readChar(terminator) || terminator != '\0') {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reader.peekChar() > 0) {
|
||||||
|
if(!reader.readArray(prop->flags, 8)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(!reader.readArray(prop->flags, 4)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readChar(prop->id)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto interval = reader.position() - start_position;
|
||||||
|
|
||||||
|
do {
|
||||||
|
std::string str;
|
||||||
|
|
||||||
|
if(!reader.readUEString(str)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayAppend(prop->data, std::move(str));
|
||||||
|
|
||||||
|
interval = reader.position() - start_position;
|
||||||
|
} while(UnsignedLong(interval) < value_length);
|
||||||
|
|
||||||
|
prop->value = prop->data.back();
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto TextPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto text_prop = dynamic_cast<TextProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!text_prop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeValueToArray<char>('\0');
|
||||||
|
bytes_written += writer.writeDataToArray<char>(text_prop->flags);
|
||||||
|
for(const auto& str : text_prop->data) {
|
||||||
|
bytes_written += writer.writeUEStringToArray(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/TextPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/TextPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/TextProperty.h"
|
||||||
|
|
||||||
|
class TextPropertySerialiser : public UnrealPropertySerialiser<TextProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<TextPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
58
src/UESaveFile/Serialisers/UnrealPropertySerialiser.h
Normal file
58
src/UESaveFile/Serialisers/UnrealPropertySerialiser.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include "AbstractUnrealPropertySerialiser.h"
|
||||||
|
#include "../Types/StructProperty.h"
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class UnrealPropertySerialiser : public AbstractUnrealPropertySerialiser {
|
||||||
|
static_assert(std::is_base_of<UnrealPropertyBase, T>::value, "T must be derived from UnrealPropertyBase.");
|
||||||
|
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<UnrealPropertySerialiser<T>>;
|
||||||
|
|
||||||
|
auto types() -> Containers::ArrayView<const std::string> override {
|
||||||
|
static const Containers::Array<std::string> types = []{
|
||||||
|
Containers::Array<std::string> array;
|
||||||
|
Containers::Pointer<T> p(new T);
|
||||||
|
if(std::is_base_of<StructProperty, T>::value) {
|
||||||
|
array = Containers::Array<std::string>{InPlaceInit, {dynamic_cast<StructProperty*>(p.get())->structType}};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
array = Containers::Array<std::string>{InPlaceInit, {p->propertyType}};
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}();
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override {
|
||||||
|
return deserialiseProperty(name, type, value_length, reader, serialiser);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override {
|
||||||
|
return serialiseProperty(prop, bytes_written, writer, serialiser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> typename UnrealPropertyBase::ptr = 0;
|
||||||
|
|
||||||
|
virtual auto serialiseProperty(typename UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0;
|
||||||
|
};
|
46
src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp
Normal file
46
src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "Vector2DPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto Vector2DPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<Vector2DStructProperty>();
|
||||||
|
|
||||||
|
if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Vector2DPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto vector = dynamic_cast<Vector2DStructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!vector) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<Float>(vector->x) + writer.writeValueToArray<Float>(vector->y);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/Vector2DPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/Vector2DPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/Vector2DStructProperty.h"
|
||||||
|
|
||||||
|
class Vector2DPropertySerialiser : public UnrealPropertySerialiser<Vector2DStructProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<Vector2DPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
47
src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp
Normal file
47
src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "../BinaryReader.h"
|
||||||
|
#include "../BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "VectorPropertySerialiser.h"
|
||||||
|
|
||||||
|
auto VectorPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length,
|
||||||
|
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
|
||||||
|
{
|
||||||
|
auto prop = Containers::pointer<VectorStructProperty>();
|
||||||
|
|
||||||
|
if(!reader.readFloat(prop->x) || !reader.readFloat(prop->y) || !reader.readFloat(prop->z)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto VectorPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
|
||||||
|
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
|
||||||
|
{
|
||||||
|
auto vector = dynamic_cast<VectorStructProperty*>(prop.get());
|
||||||
|
|
||||||
|
if(!vector) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_written += writer.writeValueToArray<Float>(vector->x) + writer.writeValueToArray<Float>(vector->y) +
|
||||||
|
writer.writeValueToArray<Float>(vector->z);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
30
src/UESaveFile/Serialisers/VectorPropertySerialiser.h
Normal file
30
src/UESaveFile/Serialisers/VectorPropertySerialiser.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertySerialiser.h"
|
||||||
|
|
||||||
|
#include "../Types/VectorStructProperty.h"
|
||||||
|
|
||||||
|
class VectorPropertySerialiser : public UnrealPropertySerialiser<VectorStructProperty> {
|
||||||
|
public:
|
||||||
|
using ptr = Containers::Pointer<VectorPropertySerialiser>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
40
src/UESaveFile/Types/ArrayProperty.h
Normal file
40
src/UESaveFile/Types/ArrayProperty.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
|
||||||
|
#include "UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
struct ArrayProperty : public UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<ArrayProperty>;
|
||||||
|
|
||||||
|
ArrayProperty() {
|
||||||
|
propertyType = "ArrayProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto at(std::size_t index) -> UnrealPropertyBase* {
|
||||||
|
if(index >= items.size()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return items[index].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string itemType;
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> items;
|
||||||
|
};
|
27
src/UESaveFile/Types/BoolProperty.h
Normal file
27
src/UESaveFile/Types/BoolProperty.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct BoolProperty : public UnrealProperty<bool> {
|
||||||
|
using ptr = Containers::Pointer<BoolProperty>;
|
||||||
|
|
||||||
|
BoolProperty() {
|
||||||
|
propertyType = "BoolProperty";
|
||||||
|
}
|
||||||
|
};
|
33
src/UESaveFile/Types/ByteProperty.h
Normal file
33
src/UESaveFile/Types/ByteProperty.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct ByteProperty : public UnrealProperty<Containers::Array<char>> {
|
||||||
|
using ptr = Containers::Pointer<ByteProperty>;
|
||||||
|
|
||||||
|
ByteProperty() {
|
||||||
|
propertyType = "ByteProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
// For some reason, M.A.S.S. Builder stores EnumProperties as ByteProperties. Ugh...
|
||||||
|
std::string enumType;
|
||||||
|
std::string enumValue;
|
||||||
|
};
|
27
src/UESaveFile/Types/ColourStructProperty.h
Normal file
27
src/UESaveFile/Types/ColourStructProperty.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct ColourStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<ColourStructProperty>;
|
||||||
|
ColourStructProperty() {
|
||||||
|
structType = "LinearColor";
|
||||||
|
}
|
||||||
|
Float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f;
|
||||||
|
};
|
29
src/UESaveFile/Types/DateTimeStructProperty.h
Normal file
29
src/UESaveFile/Types/DateTimeStructProperty.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct DateTimeStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<DateTimeStructProperty>;
|
||||||
|
|
||||||
|
DateTimeStructProperty() {
|
||||||
|
structType = "DateTime";
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedLong timestamp = 0;
|
||||||
|
};
|
29
src/UESaveFile/Types/EnumProperty.h
Normal file
29
src/UESaveFile/Types/EnumProperty.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct EnumProperty : public UnrealProperty<std::string> {
|
||||||
|
using ptr = Containers::Pointer<EnumProperty>;
|
||||||
|
|
||||||
|
EnumProperty() {
|
||||||
|
propertyType = "EnumProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string enumType;
|
||||||
|
};
|
27
src/UESaveFile/Types/FloatProperty.h
Normal file
27
src/UESaveFile/Types/FloatProperty.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct FloatProperty : public UnrealProperty<Float> {
|
||||||
|
using ptr = Containers::Pointer<FloatProperty>;
|
||||||
|
|
||||||
|
FloatProperty() {
|
||||||
|
propertyType = "FloatProperty";
|
||||||
|
}
|
||||||
|
};
|
43
src/UESaveFile/Types/GenericStructProperty.h
Normal file
43
src/UESaveFile/Types/GenericStructProperty.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct GenericStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<GenericStructProperty>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto at(const std::string& name) -> T* {
|
||||||
|
for(auto& item : properties) {
|
||||||
|
if(item->name == name) {
|
||||||
|
return static_cast<T*>(item.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto props() -> Containers::ArrayView<UnrealPropertyBase::ptr> {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> properties;
|
||||||
|
};
|
31
src/UESaveFile/Types/GuidStructProperty.h
Normal file
31
src/UESaveFile/Types/GuidStructProperty.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/StaticArray.h>
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct GuidStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<GuidStructProperty>;
|
||||||
|
|
||||||
|
GuidStructProperty() {
|
||||||
|
structType = "Guid";
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::StaticArray<16, char> guid{ValueInit};
|
||||||
|
};
|
27
src/UESaveFile/Types/IntProperty.h
Normal file
27
src/UESaveFile/Types/IntProperty.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct IntProperty : public UnrealProperty<Int> {
|
||||||
|
using ptr = Containers::Pointer<IntProperty>;
|
||||||
|
|
||||||
|
IntProperty() {
|
||||||
|
propertyType = "IntProperty";
|
||||||
|
}
|
||||||
|
};
|
37
src/UESaveFile/Types/MapProperty.h
Normal file
37
src/UESaveFile/Types/MapProperty.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
struct MapProperty : public UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<MapProperty>;
|
||||||
|
|
||||||
|
MapProperty() {
|
||||||
|
propertyType = "MapProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string keyType;
|
||||||
|
std::string valueType;
|
||||||
|
|
||||||
|
struct KeyValuePair {
|
||||||
|
UnrealPropertyBase::ptr key;
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> values;
|
||||||
|
};
|
||||||
|
|
||||||
|
Containers::Array<KeyValuePair> map;
|
||||||
|
};
|
28
src/UESaveFile/Types/NoneProperty.h
Normal file
28
src/UESaveFile/Types/NoneProperty.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
struct NoneProperty : UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<NoneProperty>;
|
||||||
|
|
||||||
|
NoneProperty() {
|
||||||
|
name.emplace("None");
|
||||||
|
propertyType = "NoneProperty";
|
||||||
|
}
|
||||||
|
};
|
29
src/UESaveFile/Types/RotatorStructProperty.h
Normal file
29
src/UESaveFile/Types/RotatorStructProperty.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct RotatorStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<RotatorStructProperty>;
|
||||||
|
|
||||||
|
RotatorStructProperty() {
|
||||||
|
structType = "Rotator";
|
||||||
|
}
|
||||||
|
|
||||||
|
Float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||||
|
};
|
40
src/UESaveFile/Types/SetProperty.h
Normal file
40
src/UESaveFile/Types/SetProperty.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
|
||||||
|
#include "UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
struct SetProperty : public UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<SetProperty>;
|
||||||
|
|
||||||
|
SetProperty() {
|
||||||
|
propertyType = "SetProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto at(std::size_t index) -> UnrealPropertyBase* {
|
||||||
|
if(index >= items.size()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return items[index].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string itemType;
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> items;
|
||||||
|
};
|
27
src/UESaveFile/Types/StringProperty.h
Normal file
27
src/UESaveFile/Types/StringProperty.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct StringProperty : public UnrealProperty<std::string> {
|
||||||
|
using ptr = Containers::Pointer<StringProperty>;
|
||||||
|
|
||||||
|
explicit StringProperty(const std::string& type = "StrProperty") {
|
||||||
|
propertyType = type;
|
||||||
|
}
|
||||||
|
};
|
32
src/UESaveFile/Types/StructProperty.h
Normal file
32
src/UESaveFile/Types/StructProperty.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/StaticArray.h>
|
||||||
|
|
||||||
|
#include "UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
struct StructProperty : public UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<StructProperty>;
|
||||||
|
|
||||||
|
StructProperty() {
|
||||||
|
std::string propertyType = "StructProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::StaticArray<16, char> structGuid{ValueInit};
|
||||||
|
std::string structType;
|
||||||
|
};
|
31
src/UESaveFile/Types/TextProperty.h
Normal file
31
src/UESaveFile/Types/TextProperty.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealProperty.h"
|
||||||
|
|
||||||
|
struct TextProperty : public UnrealProperty<std::string> {
|
||||||
|
using ptr = Containers::Pointer<TextProperty>;
|
||||||
|
|
||||||
|
TextProperty() {
|
||||||
|
propertyType = "TextProperty";
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::Array<char> flags;
|
||||||
|
char id = 0;
|
||||||
|
Containers::Array<std::string> data;
|
||||||
|
};
|
26
src/UESaveFile/Types/UnrealProperty.h
Normal file
26
src/UESaveFile/Types/UnrealProperty.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct UnrealProperty : public UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<UnrealProperty<T>>;
|
||||||
|
|
||||||
|
T value;
|
||||||
|
};
|
37
src/UESaveFile/Types/UnrealPropertyBase.h
Normal file
37
src/UESaveFile/Types/UnrealPropertyBase.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/Optional.h>
|
||||||
|
#include <Corrade/Containers/Pointer.h>
|
||||||
|
|
||||||
|
#include <Magnum/Types.h>
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
struct UnrealPropertyBase {
|
||||||
|
using ptr = Containers::Pointer<UnrealPropertyBase>;
|
||||||
|
|
||||||
|
virtual ~UnrealPropertyBase() = default;
|
||||||
|
|
||||||
|
Containers::Optional<std::string> name = Containers::NullOpt;
|
||||||
|
std::string propertyType;
|
||||||
|
UnsignedLong valueLength;
|
||||||
|
};
|
29
src/UESaveFile/Types/Vector2DStructProperty.h
Normal file
29
src/UESaveFile/Types/Vector2DStructProperty.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct Vector2DStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<Vector2DStructProperty>;
|
||||||
|
|
||||||
|
Vector2DStructProperty() {
|
||||||
|
structType = "Vector2D";
|
||||||
|
}
|
||||||
|
|
||||||
|
Float x = 0.0f, y = 0.0f;
|
||||||
|
};
|
29
src/UESaveFile/Types/VectorStructProperty.h
Normal file
29
src/UESaveFile/Types/VectorStructProperty.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "StructProperty.h"
|
||||||
|
|
||||||
|
struct VectorStructProperty : public StructProperty {
|
||||||
|
using ptr = Containers::Pointer<VectorStructProperty>;
|
||||||
|
|
||||||
|
VectorStructProperty() {
|
||||||
|
structType = "Vector";
|
||||||
|
}
|
||||||
|
|
||||||
|
Float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||||
|
};
|
189
src/UESaveFile/UESaveFile.cpp
Normal file
189
src/UESaveFile/UESaveFile.cpp
Normal file
|
@ -0,0 +1,189 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <Corrade/Containers/ArrayView.h>
|
||||||
|
#include <Corrade/Containers/Optional.h>
|
||||||
|
#include <Corrade/Utility/Directory.h>
|
||||||
|
|
||||||
|
#include "BinaryReader.h"
|
||||||
|
#include "BinaryWriter.h"
|
||||||
|
|
||||||
|
#include "UESaveFile.h"
|
||||||
|
|
||||||
|
UESaveFile::UESaveFile(std::string filepath)
|
||||||
|
{
|
||||||
|
_filepath = std::move(filepath);
|
||||||
|
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto UESaveFile::valid() const -> bool {
|
||||||
|
return _valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto UESaveFile::lastError() const -> const std::string& {
|
||||||
|
return _lastError;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto UESaveFile::reloadData() -> bool {
|
||||||
|
loadData();
|
||||||
|
return valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto UESaveFile::at(const std::string& name) -> UnrealPropertyBase* {
|
||||||
|
for(auto& prop : _properties) {
|
||||||
|
if(*(prop->name) == name) {
|
||||||
|
return prop.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto UESaveFile::props() -> Containers::ArrayView<UnrealPropertyBase::ptr> {
|
||||||
|
return _properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto UESaveFile::saveToFile() -> bool {
|
||||||
|
BinaryWriter writer{_filepath + ".other"};
|
||||||
|
|
||||||
|
if(!writer.open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!writer.writeStaticArray(staticArrayView(_magicBytes)) ||
|
||||||
|
!writer.writeUnsignedInt(_saveVersion) ||
|
||||||
|
!writer.writeUnsignedInt(_packageVersion) ||
|
||||||
|
!writer.writeUnsignedShort(_engineVersion.major) ||
|
||||||
|
!writer.writeUnsignedShort(_engineVersion.minor) ||
|
||||||
|
!writer.writeUnsignedShort(_engineVersion.patch) ||
|
||||||
|
!writer.writeUnsignedInt(_engineVersion.build) ||
|
||||||
|
!writer.writeUEString(_engineVersion.buildId))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!writer.writeUnsignedInt(_customFormatVersion) ||
|
||||||
|
!writer.writeUnsignedInt(_customFormatData.size()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(UnsignedLong i = 0; i < _customFormatData.size(); i++) {
|
||||||
|
if(!writer.writeStaticArray(Containers::StaticArrayView<16, const char>{_customFormatData[i].id}) ||
|
||||||
|
!writer.writeUnsignedInt(_customFormatData[i].value))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!writer.writeUEString(_saveType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& prop : _properties) {
|
||||||
|
UnsignedLong bytes_written = 0;
|
||||||
|
if(!_propSerialiser.write(prop, bytes_written, writer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!writer.flushToFile()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeUnsignedInt(0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UESaveFile::loadData() {
|
||||||
|
_valid = false;
|
||||||
|
|
||||||
|
if(!Utility::Directory::exists(_filepath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryReader reader{_filepath};
|
||||||
|
|
||||||
|
if(!reader.open()) {
|
||||||
|
_lastError = _filepath + " couldn't be opened.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Containers::Array<char> magic;
|
||||||
|
if(!reader.readArray(magic, 4)) {
|
||||||
|
_lastError = "Couldn't read magic bytes in " + _filepath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string invalid = _filepath + " isn't a valid UE4 save.";
|
||||||
|
|
||||||
|
if(std::strncmp(magic.data(), _magicBytes.data(), 4) != 0) {
|
||||||
|
_lastError = std::move(invalid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUnsignedInt(_saveVersion) ||
|
||||||
|
!reader.readUnsignedInt(_packageVersion) ||
|
||||||
|
!reader.readUnsignedShort(_engineVersion.major) ||
|
||||||
|
!reader.readUnsignedShort(_engineVersion.minor) ||
|
||||||
|
!reader.readUnsignedShort(_engineVersion.patch) ||
|
||||||
|
!reader.readUnsignedInt(_engineVersion.build) ||
|
||||||
|
!reader.readUEString(_engineVersion.buildId))
|
||||||
|
{
|
||||||
|
_lastError = std::move(invalid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUnsignedInt(_customFormatVersion)) {
|
||||||
|
_lastError = std::move(invalid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnsignedInt custom_format_data_size = 0;
|
||||||
|
|
||||||
|
if(!reader.readUnsignedInt(custom_format_data_size)) {
|
||||||
|
_lastError = std::move(invalid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayReserve(_customFormatData, custom_format_data_size);
|
||||||
|
|
||||||
|
for(UnsignedInt i = 0; i < custom_format_data_size; i++) {
|
||||||
|
CustomFormatDataEntry entry;
|
||||||
|
|
||||||
|
if(!reader.readStaticArray(entry.id) ||
|
||||||
|
!reader.readInt(entry.value))
|
||||||
|
{
|
||||||
|
_lastError = std::move(invalid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayAppend(_customFormatData, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!reader.readUEString(_saveType)) {
|
||||||
|
_lastError = std::move(invalid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnrealPropertyBase::ptr prop;
|
||||||
|
while((prop = _propSerialiser.read(reader)) != nullptr) {
|
||||||
|
arrayAppend(_properties, std::move(prop));
|
||||||
|
}
|
||||||
|
|
||||||
|
_valid = true;
|
||||||
|
}
|
81
src/UESaveFile/UESaveFile.h
Normal file
81
src/UESaveFile/UESaveFile.h
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <Corrade/Containers/Array.h>
|
||||||
|
#include <Corrade/Containers/GrowableArray.h>
|
||||||
|
#include <Corrade/Containers/StaticArray.h>
|
||||||
|
|
||||||
|
#include <Magnum/Magnum.h>
|
||||||
|
|
||||||
|
#include "Types/UnrealPropertyBase.h"
|
||||||
|
|
||||||
|
#include "PropertySerialiser.h"
|
||||||
|
|
||||||
|
using namespace Corrade;
|
||||||
|
using namespace Magnum;
|
||||||
|
|
||||||
|
class UESaveFile {
|
||||||
|
public:
|
||||||
|
explicit UESaveFile(std::string filepath);
|
||||||
|
|
||||||
|
auto valid() const -> bool;
|
||||||
|
auto lastError() const -> std::string const&;
|
||||||
|
|
||||||
|
auto reloadData() -> bool;
|
||||||
|
|
||||||
|
auto at(const std::string& name) -> UnrealPropertyBase*;
|
||||||
|
|
||||||
|
auto props() -> Containers::ArrayView<UnrealPropertyBase::ptr>;
|
||||||
|
|
||||||
|
auto saveToFile() -> bool;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadData();
|
||||||
|
|
||||||
|
bool _valid{false};
|
||||||
|
std::string _lastError;
|
||||||
|
|
||||||
|
std::string _filepath;
|
||||||
|
|
||||||
|
const Containers::StaticArray<4, char> _magicBytes{'G', 'V', 'A', 'S'};
|
||||||
|
|
||||||
|
UnsignedInt _saveVersion = 0;
|
||||||
|
UnsignedInt _packageVersion = 0;
|
||||||
|
struct {
|
||||||
|
UnsignedShort major = 0;
|
||||||
|
UnsignedShort minor = 0;
|
||||||
|
UnsignedShort patch = 0;
|
||||||
|
UnsignedInt build = 0;
|
||||||
|
std::string buildId;
|
||||||
|
} _engineVersion;
|
||||||
|
|
||||||
|
UnsignedInt _customFormatVersion = 0;
|
||||||
|
struct CustomFormatDataEntry {
|
||||||
|
Containers::StaticArray<16, char> id;
|
||||||
|
Int value = 0;
|
||||||
|
};
|
||||||
|
Containers::Array<CustomFormatDataEntry> _customFormatData;
|
||||||
|
|
||||||
|
std::string _saveType;
|
||||||
|
|
||||||
|
Containers::Array<UnrealPropertyBase::ptr> _properties;
|
||||||
|
|
||||||
|
PropertySerialiser _propSerialiser;
|
||||||
|
};
|
Loading…
Reference in a new issue