212 lines
7.2 KiB
C++
212 lines
7.2 KiB
C++
|
// MassBuilderSaveTool
|
||
|
// Copyright (C) 2021-2022 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 "../UESaveFile/Types/ArrayProperty.h"
|
||
|
#include "../UESaveFile/Types/ByteProperty.h"
|
||
|
#include "../UESaveFile/Types/GenericStructProperty.h"
|
||
|
#include "../UESaveFile/Types/IntProperty.h"
|
||
|
#include "../UESaveFile/Types/StringProperty.h"
|
||
|
|
||
|
#include "Mass.h"
|
||
|
|
||
|
using namespace Containers::Literals;
|
||
|
|
||
|
auto Mass::armourParts() -> Containers::ArrayView<ArmourPart> {
|
||
|
return _armour.parts;
|
||
|
}
|
||
|
|
||
|
void Mass::getArmourParts() {
|
||
|
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||
|
if(!unit_data) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
auto armour_array = unit_data->at<ArrayProperty>("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"_s);
|
||
|
if(!armour_array) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if(armour_array->items.size() != _armour.parts.size()) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for(UnsignedInt i = 0; i < armour_array->items.size(); i++) {
|
||
|
auto part_prop = armour_array->at<GenericStructProperty>(i);
|
||
|
auto& part = _armour.parts[i];
|
||
|
|
||
|
auto& armour_slot = part_prop->at<ByteProperty>("Slot_3_408BA56F4C9605C7E805CF91B642249C"_s)->enumValue;
|
||
|
#define c(enumerator, strenum, name) if(armour_slot == (strenum)) { part.slot = ArmourSlot::enumerator; } else
|
||
|
#include "../Maps/ArmourSlots.hpp"
|
||
|
#undef c
|
||
|
{
|
||
|
_state = State::Invalid;
|
||
|
Utility::Warning{} << "Invalid armour slot enum value in getArmourParts()."_s;
|
||
|
}
|
||
|
|
||
|
part.id = part_prop->at<IntProperty>("ID_5_ACD101864D3481DE96EDACACC09BDD25"_s)->value;
|
||
|
|
||
|
auto part_styles = part_prop->at<ArrayProperty>("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"_s);
|
||
|
if(!part_styles) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if(part_styles->items.size() != part.styles.size()) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for(UnsignedInt j = 0; j < part_styles->items.size(); j++) {
|
||
|
part.styles[j] = part_styles->at<IntProperty>(j)->value;
|
||
|
}
|
||
|
|
||
|
auto decals_array = part_prop->at<ArrayProperty>("Decals_42_F358794A4F18497970F56BA9627D3603"_s);
|
||
|
if(!decals_array) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
part.decals = Containers::Array<Decal>{decals_array->items.size()};
|
||
|
|
||
|
getDecals(part.decals, decals_array);
|
||
|
|
||
|
auto accs_array = part_prop->at<ArrayProperty>("Accessories_52_D902DD4241FA0050C2529596255153F3"_s);
|
||
|
if(!accs_array) {
|
||
|
part.accessories = Containers::Array<Accessory>{};
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if(part.accessories.size() != accs_array->items.size()) {
|
||
|
part.accessories = Containers::Array<Accessory>{accs_array->items.size()};
|
||
|
}
|
||
|
|
||
|
getAccessories(part.accessories, accs_array);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
auto Mass::writeArmourPart(ArmourSlot slot) -> bool {
|
||
|
auto& part = *std::find_if(_armour.parts.begin(), _armour.parts.end(), [&slot](const ArmourPart& part){ return slot == part.slot; });
|
||
|
|
||
|
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||
|
|
||
|
auto armour_array = unit_data->at<ArrayProperty>("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"_s);
|
||
|
|
||
|
Containers::StringView slot_str = nullptr;
|
||
|
switch(slot) {
|
||
|
#define c(enumerator, strenum, name) case ArmourSlot::enumerator: \
|
||
|
slot_str = strenum; \
|
||
|
break;
|
||
|
#include "../Maps/ArmourSlots.hpp"
|
||
|
#undef c
|
||
|
}
|
||
|
|
||
|
GenericStructProperty* part_prop = nullptr;
|
||
|
|
||
|
for(UnsignedInt i = 0; i < armour_array->items.size(); i++) {
|
||
|
part_prop = armour_array->at<GenericStructProperty>(i);
|
||
|
if(slot_str != part_prop->at<StringProperty>("Slot_3_408BA56F4C9605C7E805CF91B642249C"_s)->value) {
|
||
|
part_prop = nullptr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(!part_prop) {
|
||
|
auto prefix = "Couldn't find the armour part for slot "_s;
|
||
|
switch(slot) {
|
||
|
#define c(enumerator, strenum, name) case ArmourSlot::enumerator: \
|
||
|
_lastError = prefix + "ArmourSlot::" #enumerator "."_s; \
|
||
|
break;
|
||
|
#include "../Maps/ArmourSlots.hpp"
|
||
|
#undef c
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
part_prop->at<IntProperty>("ID_5_ACD101864D3481DE96EDACACC09BDD25"_s)->value = part.id;
|
||
|
|
||
|
auto part_styles = part_prop->at<ArrayProperty>("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"_s);
|
||
|
for(UnsignedInt i = 0; i < part.styles.size(); i++) {
|
||
|
part_styles->at<IntProperty>(i)->value = part.styles[i];
|
||
|
}
|
||
|
|
||
|
auto decals_array = part_prop->at<ArrayProperty>("Decals_42_F358794A4F18497970F56BA9627D3603"_s);
|
||
|
writeDecals(part.decals, decals_array);
|
||
|
|
||
|
if(part.accessories.size() != 0) {
|
||
|
auto accs_array = part_prop->at<ArrayProperty>("Accessories_52_D902DD4241FA0050C2529596255153F3"_s);
|
||
|
writeAccessories(part.accessories, accs_array);
|
||
|
}
|
||
|
|
||
|
if(!_mass->saveToFile()) {
|
||
|
_lastError = _mass->lastError();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
auto Mass::armourCustomStyles() -> Containers::ArrayView<CustomStyle> {
|
||
|
return _armour.customStyles;
|
||
|
}
|
||
|
|
||
|
void Mass::getArmourCustomStyles() {
|
||
|
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||
|
if(!unit_data) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
auto armour_styles = unit_data->at<ArrayProperty>("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"_s);
|
||
|
if(!armour_styles) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if(armour_styles->items.size() != _armour.customStyles.size()) {
|
||
|
_state = State::Invalid;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
getCustomStyles(_armour.customStyles, armour_styles);
|
||
|
}
|
||
|
|
||
|
auto Mass::writeArmourCustomStyle(UnsignedLong index) -> bool {
|
||
|
if(index > _armour.customStyles.size()) {
|
||
|
_lastError = "Style index out of range."_s;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||
|
if(!unit_data) {
|
||
|
_state = State::Invalid;
|
||
|
_lastError = "Couldn't find unit data in "_s + _filename;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
auto armour_styles = unit_data->at<ArrayProperty>("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"_s);
|
||
|
if(!armour_styles) {
|
||
|
_lastError = "Couldn't find armour custom styles in "_s + _filename;
|
||
|
_state = State::Invalid;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return writeCustomStyle(_armour.customStyles[index], index, armour_styles);
|
||
|
}
|