Compare commits
3 commits
8791eb32ac
...
771e008e62
Author | SHA1 | Date | |
---|---|---|---|
771e008e62 | |||
4d9fc46003 | |||
db3eba5b59 |
11 changed files with 1201 additions and 1057 deletions
|
@ -134,6 +134,11 @@ add_executable(MassBuilderSaveTool WIN32
|
|||
Mass/Joints.h
|
||||
Mass/Mass.h
|
||||
Mass/Mass.cpp
|
||||
Mass/Mass_Frame.cpp
|
||||
Mass/Mass_Armour.cpp
|
||||
Mass/Mass_Weapons.cpp
|
||||
Mass/Mass_Styles.cpp
|
||||
Mass/Mass_DecalsAccessories.cpp
|
||||
Mass/Weapon.h
|
||||
Mass/Weapon.cpp
|
||||
Mass/WeaponPart.h
|
||||
|
|
1021
src/Mass/Mass.cpp
1021
src/Mass/Mass.cpp
File diff suppressed because it is too large
Load diff
|
@ -140,7 +140,7 @@ class Mass {
|
|||
|
||||
private:
|
||||
void getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayProperty* style_array);
|
||||
auto setCustomStyle(const CustomStyle& style, UnsignedLong index, ArrayProperty* style_array) -> bool;
|
||||
auto writeCustomStyle(const CustomStyle& style, UnsignedLong index, ArrayProperty* style_array) -> bool;
|
||||
|
||||
void getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array);
|
||||
void writeDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array);
|
||||
|
|
211
src/Mass/Mass_Armour.cpp
Normal file
211
src/Mass/Mass_Armour.cpp
Normal file
|
@ -0,0 +1,211 @@
|
|||
// 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);
|
||||
}
|
143
src/Mass/Mass_DecalsAccessories.cpp
Normal file
143
src/Mass/Mass_DecalsAccessories.cpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
// 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 "../UESaveFile/Types/ArrayProperty.h"
|
||||
#include "../UESaveFile/Types/BoolProperty.h"
|
||||
#include "../UESaveFile/Types/ColourStructProperty.h"
|
||||
#include "../UESaveFile/Types/FloatProperty.h"
|
||||
#include "../UESaveFile/Types/GenericStructProperty.h"
|
||||
#include "../UESaveFile/Types/RotatorStructProperty.h"
|
||||
#include "../UESaveFile/Types/VectorStructProperty.h"
|
||||
#include "../UESaveFile/Types/Vector2DStructProperty.h"
|
||||
#include "../UESaveFile/Types/IntProperty.h"
|
||||
|
||||
#include "Mass.h"
|
||||
|
||||
using namespace Containers::Literals;
|
||||
|
||||
void Mass::getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
|
||||
for(UnsignedInt i = 0; i < decal_array->items.size(); i++) {
|
||||
auto decal_prop = decal_array->at<GenericStructProperty>(i);
|
||||
auto& decal = decals[i];
|
||||
|
||||
decal.id = decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value;
|
||||
auto colour_prop = decal_prop->at<ColourStructProperty>("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"_s);
|
||||
decal.colour = Color4{colour_prop->r, colour_prop->g, colour_prop->b, colour_prop->a};
|
||||
auto pos_prop = decal_prop->at<VectorStructProperty>("Position_41_022C8FE84E1AAFE587261E88F2C72250"_s);
|
||||
decal.position = Vector3{pos_prop->x, pos_prop->y, pos_prop->z};
|
||||
auto u_prop = decal_prop->at<VectorStructProperty>("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"_s);
|
||||
decal.uAxis = Vector3{u_prop->x, u_prop->y, u_prop->z};
|
||||
auto v_prop = decal_prop->at<VectorStructProperty>("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"_s);
|
||||
decal.vAxis = Vector3{v_prop->x, v_prop->y, v_prop->z};
|
||||
auto offset_prop = decal_prop->at<Vector2DStructProperty>("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"_s);
|
||||
decal.offset = Vector2{offset_prop->x, offset_prop->y};
|
||||
decal.scale = decal_prop->at<FloatProperty>("Scale_32_959D1C2747AFD8D62808468235CBBA40"_s)->value;
|
||||
decal.rotation = decal_prop->at<FloatProperty>("Rotation_27_12D7C314493D203D5C2326A03C5F910F"_s)->value;
|
||||
decal.flip = decal_prop->at<BoolProperty>("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1"_s)->value;
|
||||
decal.wrap = decal_prop->at<BoolProperty>("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62"_s)->value;
|
||||
}
|
||||
}
|
||||
|
||||
void Mass::writeDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
|
||||
for(UnsignedInt i = 0; i < decal_array->items.size(); i++) {
|
||||
auto decal_prop = decal_array->at<GenericStructProperty>(i);
|
||||
auto& decal = decals[i];
|
||||
|
||||
decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value = decal.id;
|
||||
auto colour_prop = decal_prop->at<ColourStructProperty>("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"_s);
|
||||
colour_prop->r = decal.colour.r();
|
||||
colour_prop->g = decal.colour.g();
|
||||
colour_prop->b = decal.colour.b();
|
||||
colour_prop->a = decal.colour.a();
|
||||
auto pos_prop = decal_prop->at<VectorStructProperty>("Position_41_022C8FE84E1AAFE587261E88F2C72250"_s);
|
||||
pos_prop->x = decal.position.x();
|
||||
pos_prop->y = decal.position.y();
|
||||
pos_prop->z = decal.position.z();
|
||||
auto u_prop = decal_prop->at<VectorStructProperty>("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"_s);
|
||||
u_prop->x = decal.uAxis.x();
|
||||
u_prop->y = decal.uAxis.y();
|
||||
u_prop->z = decal.uAxis.z();
|
||||
auto v_prop = decal_prop->at<VectorStructProperty>("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"_s);
|
||||
v_prop->x = decal.vAxis.x();
|
||||
v_prop->y = decal.vAxis.y();
|
||||
v_prop->z = decal.vAxis.z();
|
||||
auto offset_prop = decal_prop->at<Vector2DStructProperty>("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"_s);
|
||||
offset_prop->x = decal.offset.x();
|
||||
offset_prop->y = decal.offset.y();
|
||||
decal_prop->at<FloatProperty>("Scale_32_959D1C2747AFD8D62808468235CBBA40"_s)->value = decal.scale;
|
||||
decal_prop->at<FloatProperty>("Rotation_27_12D7C314493D203D5C2326A03C5F910F"_s)->value = decal.rotation;
|
||||
decal_prop->at<BoolProperty>("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1"_s)->value = decal.flip;
|
||||
decal_prop->at<BoolProperty>("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62"_s)->value = decal.wrap;
|
||||
}
|
||||
}
|
||||
|
||||
void Mass::getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array) {
|
||||
for(UnsignedInt i = 0; i < accessory_array->items.size(); i++) {
|
||||
auto acc_prop = accessory_array->at<GenericStructProperty>(i);
|
||||
auto& accessory = accessories[i];
|
||||
|
||||
accessory.attachIndex = acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value;
|
||||
accessory.id = acc_prop->at<IntProperty>("ID_4_5757B32647BAE263266259B8A7DFFFC1"_s)->value;
|
||||
auto acc_styles = acc_prop->at<ArrayProperty>("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"_s);
|
||||
for(UnsignedInt j = 0; j < acc_styles->items.size(); j++) {
|
||||
accessory.styles[j] = acc_styles->at<IntProperty>(j)->value;
|
||||
}
|
||||
auto rel_pos_prop = acc_prop->at<VectorStructProperty>("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"_s);
|
||||
accessory.relativePosition = Vector3{rel_pos_prop->x, rel_pos_prop->y, rel_pos_prop->z};
|
||||
auto rel_pos_offset_prop = acc_prop->at<VectorStructProperty>("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"_s);
|
||||
accessory.relativePositionOffset = Vector3{rel_pos_offset_prop->x, rel_pos_offset_prop->y, rel_pos_offset_prop->z};
|
||||
auto rel_rot_prop = acc_prop->at<RotatorStructProperty>("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"_s);
|
||||
accessory.relativeRotation = Vector3{rel_rot_prop->x, rel_rot_prop->y, rel_rot_prop->z};
|
||||
auto rel_rot_offset_prop = acc_prop->at<RotatorStructProperty>("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"_s);
|
||||
accessory.relativeRotationOffset = Vector3{rel_rot_offset_prop->x, rel_rot_offset_prop->y, rel_rot_offset_prop->z};
|
||||
auto local_scale_prop = acc_prop->at<VectorStructProperty>("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"_s);
|
||||
accessory.localScale = Vector3{local_scale_prop->x, local_scale_prop->y, local_scale_prop->z};
|
||||
}
|
||||
}
|
||||
|
||||
void Mass::writeAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accs_array) {
|
||||
for(UnsignedInt i = 0; i < accs_array->items.size(); i++) {
|
||||
auto acc_prop = accs_array->at<GenericStructProperty>(i);
|
||||
auto& accessory = accessories[i];
|
||||
|
||||
acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value = accessory.attachIndex;
|
||||
acc_prop->at<IntProperty>("ID_4_5757B32647BAE263266259B8A7DFFFC1"_s)->value = accessory.id;
|
||||
auto acc_styles = acc_prop->at<ArrayProperty>("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"_s);
|
||||
for(UnsignedInt j = 0; j < acc_styles->items.size(); j++) {
|
||||
acc_styles->at<IntProperty>(j)->value = accessory.styles[j];
|
||||
}
|
||||
auto rel_pos_prop = acc_prop->at<VectorStructProperty>("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"_s);
|
||||
rel_pos_prop->x = accessory.relativePosition.x();
|
||||
rel_pos_prop->y = accessory.relativePosition.y();
|
||||
rel_pos_prop->z = accessory.relativePosition.z();
|
||||
auto rel_pos_offset_prop = acc_prop->at<VectorStructProperty>("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"_s);
|
||||
rel_pos_offset_prop->x = accessory.relativePositionOffset.x();
|
||||
rel_pos_offset_prop->y = accessory.relativePositionOffset.y();
|
||||
rel_pos_offset_prop->z = accessory.relativePositionOffset.z();
|
||||
auto rel_rot_prop = acc_prop->at<RotatorStructProperty>("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"_s);
|
||||
rel_rot_prop->x = accessory.relativeRotation.x();
|
||||
rel_rot_prop->y = accessory.relativeRotation.y();
|
||||
rel_rot_prop->z = accessory.relativeRotation.z();
|
||||
auto rel_rot_offset_prop = acc_prop->at<RotatorStructProperty>("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"_s);
|
||||
rel_rot_offset_prop->x = accessory.relativeRotationOffset.x();
|
||||
rel_rot_offset_prop->y = accessory.relativeRotationOffset.y();
|
||||
rel_rot_offset_prop->z = accessory.relativeRotationOffset.z();
|
||||
auto local_scale_prop = acc_prop->at<VectorStructProperty>("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"_s);
|
||||
local_scale_prop->x = accessory.localScale.x();
|
||||
local_scale_prop->y = accessory.localScale.y();
|
||||
local_scale_prop->z = accessory.localScale.z();
|
||||
}
|
||||
}
|
349
src/Mass/Mass_Frame.cpp
Normal file
349
src/Mass/Mass_Frame.cpp
Normal file
|
@ -0,0 +1,349 @@
|
|||
// 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 "../UESaveFile/Types/ArrayProperty.h"
|
||||
#include "../UESaveFile/Types/ColourStructProperty.h"
|
||||
#include "../UESaveFile/Types/FloatProperty.h"
|
||||
#include "../UESaveFile/Types/GenericStructProperty.h"
|
||||
#include "../UESaveFile/Types/IntProperty.h"
|
||||
|
||||
#include "Mass.h"
|
||||
|
||||
using namespace Containers::Literals;
|
||||
|
||||
auto Mass::jointSliders() -> Joints& {
|
||||
return _frame.joints;
|
||||
}
|
||||
|
||||
void Mass::getJointSliders() {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
|
||||
if(!frame_prop) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto length = frame_prop->at<FloatProperty>("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"_s);
|
||||
_frame.joints.neck = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"_s);
|
||||
_frame.joints.body = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"_s);
|
||||
_frame.joints.shoulders = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"_s);
|
||||
_frame.joints.hips = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"_s);
|
||||
_frame.joints.upperArms = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"_s);
|
||||
_frame.joints.lowerArms = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"_s);
|
||||
_frame.joints.upperLegs = (length ? length->value : 0.0f);
|
||||
length = frame_prop->at<FloatProperty>("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"_s);
|
||||
_frame.joints.lowerLegs = (length ? length->value : 0.0f);
|
||||
}
|
||||
|
||||
auto Mass::writeJointSliders() -> bool {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No unit data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
|
||||
|
||||
if(!frame_prop) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No frame data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
Containers::Array<UnrealPropertyBase::ptr> temp;
|
||||
|
||||
auto length = frame_prop->atMove<FloatProperty>("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"_s);
|
||||
if(_frame.joints.neck != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"_s);
|
||||
}
|
||||
length->value = _frame.joints.neck;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"_s);
|
||||
if(_frame.joints.body != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"_s);
|
||||
}
|
||||
length->value = _frame.joints.body;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"_s);
|
||||
if(_frame.joints.shoulders != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"_s);
|
||||
}
|
||||
length->value = _frame.joints.shoulders;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"_s);
|
||||
if(_frame.joints.upperArms != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"_s);
|
||||
}
|
||||
length->value = _frame.joints.upperArms;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"_s);
|
||||
if(_frame.joints.lowerArms != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"_s);
|
||||
}
|
||||
length->value = _frame.joints.lowerArms;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"_s);
|
||||
if(_frame.joints.hips != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"_s);
|
||||
}
|
||||
length->value = _frame.joints.hips;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"_s);
|
||||
if(_frame.joints.upperLegs != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"_s);
|
||||
}
|
||||
length->value = _frame.joints.upperLegs;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
length = frame_prop->atMove<FloatProperty>("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"_s);
|
||||
if(_frame.joints.lowerLegs != 0.0f) {
|
||||
if(!length) {
|
||||
length.emplace();
|
||||
length->name.emplace("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"_s);
|
||||
}
|
||||
length->value = _frame.joints.lowerLegs;
|
||||
arrayAppend(temp, std::move(length));
|
||||
}
|
||||
|
||||
arrayAppend(temp, std::move(frame_prop->properties[frame_prop->properties.size() - 3]));
|
||||
arrayAppend(temp, std::move(frame_prop->properties[frame_prop->properties.size() - 2]));
|
||||
arrayAppend(temp, std::move(frame_prop->properties[frame_prop->properties.size() - 1]));
|
||||
|
||||
frame_prop->properties = std::move(temp);
|
||||
|
||||
if(!_mass->saveToFile()) {
|
||||
_lastError = _mass->lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Mass::frameStyles() -> Containers::ArrayView<Int> {
|
||||
return _frame.styles;
|
||||
}
|
||||
|
||||
void Mass::getFrameStyles() {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
|
||||
if(!frame_prop) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto frame_styles = frame_prop->at<ArrayProperty>("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s);
|
||||
if(!frame_styles) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
if(frame_styles->items.size() != _frame.styles.size()) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
for(UnsignedInt i = 0; i < frame_styles->items.size(); i++) {
|
||||
_frame.styles[i] = frame_styles->at<IntProperty>(i)->value;
|
||||
}
|
||||
}
|
||||
|
||||
auto Mass::writeFrameStyles() -> bool {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No unit data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto frame = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
|
||||
if(!frame) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No frame data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto frame_styles = frame->at<ArrayProperty>("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s);
|
||||
if(!frame_styles) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No frame styles in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(UnsignedInt i = 0; i < frame_styles->items.size(); i++) {
|
||||
frame_styles->at<IntProperty>(i)->value = _frame.styles[i];
|
||||
}
|
||||
|
||||
if(!_mass->saveToFile()) {
|
||||
_lastError = _mass->lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Mass::eyeFlareColour() -> Color4& {
|
||||
return _frame.eyeFlare;
|
||||
}
|
||||
|
||||
void Mass::getEyeFlareColour() {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
|
||||
if(!frame_prop) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto eye_flare_prop = frame_prop->at<ColourStructProperty>("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s);
|
||||
if(!eye_flare_prop) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
_frame.eyeFlare = Color4{eye_flare_prop->r, eye_flare_prop->g, eye_flare_prop->b, eye_flare_prop->a};
|
||||
}
|
||||
|
||||
auto Mass::writeEyeFlareColour() -> bool {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No unit data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto frame = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
|
||||
if(!frame) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No frame data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto eye_flare_prop = frame->at<ColourStructProperty>("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s);
|
||||
if(!eye_flare_prop) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No eye flare property in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
eye_flare_prop->r = _frame.eyeFlare.r();
|
||||
eye_flare_prop->g = _frame.eyeFlare.g();
|
||||
eye_flare_prop->b = _frame.eyeFlare.b();
|
||||
eye_flare_prop->a = _frame.eyeFlare.a();
|
||||
|
||||
if(!_mass->saveToFile()) {
|
||||
_lastError = _mass->lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto Mass::frameCustomStyles() -> Containers::ArrayView<CustomStyle> {
|
||||
return _frame.customStyles;
|
||||
}
|
||||
|
||||
void Mass::getFrameCustomStyles() {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto frame_styles = unit_data->at<ArrayProperty>("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s);
|
||||
if(!frame_styles) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
if(frame_styles->items.size() != _frame.customStyles.size()) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
getCustomStyles(_frame.customStyles, frame_styles);
|
||||
}
|
||||
|
||||
auto Mass::writeFrameCustomStyle(UnsignedLong index) -> bool {
|
||||
if(index > _frame.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 = "No unit data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto frame_styles = unit_data->at<ArrayProperty>("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s);
|
||||
if(!frame_styles) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No frame styles in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
return writeCustomStyle(_frame.customStyles[index], index, frame_styles);
|
||||
}
|
133
src/Mass/Mass_Styles.cpp
Normal file
133
src/Mass/Mass_Styles.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
// 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 "../UESaveFile/Types/ArrayProperty.h"
|
||||
#include "../UESaveFile/Types/ColourStructProperty.h"
|
||||
#include "../UESaveFile/Types/FloatProperty.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::globalStyles() -> Containers::ArrayView<CustomStyle> {
|
||||
return _globalStyles;
|
||||
}
|
||||
|
||||
void Mass::getGlobalStyles() {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto global_styles = unit_data->at<ArrayProperty>("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"_s);
|
||||
if(!global_styles) {
|
||||
_globalStyles = Containers::Array<CustomStyle>{0};
|
||||
return;
|
||||
}
|
||||
|
||||
if(global_styles->items.size() != _globalStyles.size()) {
|
||||
_globalStyles = Containers::Array<CustomStyle>{global_styles->items.size()};
|
||||
}
|
||||
|
||||
getCustomStyles(_globalStyles, global_styles);
|
||||
}
|
||||
|
||||
auto Mass::writeGlobalStyle(UnsignedLong index) -> bool {
|
||||
if(index > _globalStyles.size()) {
|
||||
_lastError = "Global style index out of range"_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No unit data found in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto global_styles = unit_data->at<ArrayProperty>("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"_s);
|
||||
if(!global_styles) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No global styles found in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
return writeCustomStyle(_globalStyles[index], index, global_styles);
|
||||
}
|
||||
|
||||
void Mass::getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayProperty* style_array) {
|
||||
for(UnsignedInt i = 0; i < style_array->items.size(); i++) {
|
||||
auto style_prop = style_array->at<GenericStructProperty>(i);
|
||||
auto& style = styles[i];
|
||||
|
||||
style.name = style_prop->at<StringProperty>("Name_27_1532115A46EF2B2FA283908DF561A86B"_s)->value;
|
||||
auto colour_prop = style_prop->at<ColourStructProperty>("Color_5_F0D383DF40474C9464AE48A0984A212E"_s);
|
||||
style.colour = Color4{colour_prop->r, colour_prop->g, colour_prop->b, colour_prop->a};
|
||||
style.metallic = style_prop->at<FloatProperty>("Metallic_10_0A4CD1E4482CBF41CA61D0A856DE90B9"_s)->value;
|
||||
style.gloss = style_prop->at<FloatProperty>("Gloss_11_9769599842CC275A401C4282A236E240"_s)->value;
|
||||
style.glow = colour_prop->a == 0.0f ? false : true;
|
||||
|
||||
style.patternId = style_prop->at<IntProperty>("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311"_s)->value;
|
||||
style.opacity = style_prop->at<FloatProperty>("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131"_s)->value;
|
||||
style.offset = Vector2{
|
||||
style_prop->at<FloatProperty>("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48"_s)->value,
|
||||
style_prop->at<FloatProperty>("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F"_s)->value
|
||||
};
|
||||
style.rotation = style_prop->at<FloatProperty>("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D"_s)->value;
|
||||
style.scale = style_prop->at<FloatProperty>("Scale_26_19DF0708409262183E1247B317137671"_s)->value;
|
||||
}
|
||||
}
|
||||
|
||||
auto Mass::writeCustomStyle(const CustomStyle& style, UnsignedLong index, ArrayProperty* style_array) -> bool {
|
||||
if(!style_array) {
|
||||
_lastError = "Mass::setCustomStyle(): style_array is null."_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto style_prop = style_array->at<GenericStructProperty>(index);
|
||||
|
||||
if(!style_prop) {
|
||||
_lastError = "Style index is out of range in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
style_prop->at<StringProperty>("Name_27_1532115A46EF2B2FA283908DF561A86B"_s)->value = style.name;
|
||||
auto colour_prop = style_prop->at<ColourStructProperty>("Color_5_F0D383DF40474C9464AE48A0984A212E"_s);
|
||||
colour_prop->r = style.colour.r();
|
||||
colour_prop->g = style.colour.g();
|
||||
colour_prop->b = style.colour.b();
|
||||
colour_prop->a = style.glow ? 1.0f : 0.0f;
|
||||
style_prop->at<FloatProperty>("Metallic_10_0A4CD1E4482CBF41CA61D0A856DE90B9"_s)->value = style.metallic;
|
||||
style_prop->at<FloatProperty>("Gloss_11_9769599842CC275A401C4282A236E240"_s)->value = style.gloss;
|
||||
|
||||
style_prop->at<IntProperty>("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311"_s)->value = style.patternId;
|
||||
style_prop->at<FloatProperty>("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131"_s)->value = style.opacity;
|
||||
style_prop->at<FloatProperty>("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48"_s)->value = style.offset.x();
|
||||
style_prop->at<FloatProperty>("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F"_s)->value = style.offset.y();
|
||||
style_prop->at<FloatProperty>("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D"_s)->value = style.rotation;
|
||||
style_prop->at<FloatProperty>("Scale_26_19DF0708409262183E1247B317137671"_s)->value = style.scale;
|
||||
|
||||
if(!_mass->saveToFile()) {
|
||||
_lastError = _mass->lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
319
src/Mass/Mass_Weapons.cpp
Normal file
319
src/Mass/Mass_Weapons.cpp
Normal file
|
@ -0,0 +1,319 @@
|
|||
// 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 "../UESaveFile/Types/ArrayProperty.h"
|
||||
#include "../UESaveFile/Types/BoolProperty.h"
|
||||
#include "../UESaveFile/Types/ByteProperty.h"
|
||||
#include "../UESaveFile/Types/ColourStructProperty.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::meleeWeapons() -> Containers::ArrayView<Weapon> {
|
||||
return _weapons.melee;
|
||||
}
|
||||
|
||||
void Mass::getMeleeWeapons() {
|
||||
getWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7"_s, _weapons.melee);
|
||||
}
|
||||
|
||||
auto Mass::writeMeleeWeapons() -> bool {
|
||||
return writeWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7"_s, _weapons.melee);
|
||||
}
|
||||
|
||||
auto Mass::shields() -> Containers::ArrayView<Weapon> {
|
||||
return _weapons.shields;
|
||||
}
|
||||
|
||||
void Mass::getShields() {
|
||||
getWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E"_s, _weapons.shields);
|
||||
}
|
||||
|
||||
auto Mass::writeShields() -> bool {
|
||||
return writeWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E"_s, _weapons.shields);
|
||||
}
|
||||
|
||||
auto Mass::bulletShooters() -> Containers::ArrayView<Weapon> {
|
||||
return _weapons.bulletShooters;
|
||||
}
|
||||
|
||||
void Mass::getBulletShooters() {
|
||||
getWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED"_s, _weapons.bulletShooters);
|
||||
}
|
||||
|
||||
auto Mass::writeBulletShooters() -> bool {
|
||||
return writeWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED"_s, _weapons.bulletShooters);
|
||||
}
|
||||
|
||||
auto Mass::energyShooters() -> Containers::ArrayView<Weapon> {
|
||||
return _weapons.energyShooters;
|
||||
}
|
||||
|
||||
void Mass::getEnergyShooters() {
|
||||
getWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99"_s, _weapons.energyShooters);
|
||||
}
|
||||
|
||||
auto Mass::writeEnergyShooters() -> bool {
|
||||
return writeWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99"_s, _weapons.energyShooters);
|
||||
}
|
||||
|
||||
auto Mass::bulletLaunchers() -> Containers::ArrayView<Weapon> {
|
||||
return _weapons.bulletLaunchers;
|
||||
}
|
||||
|
||||
void Mass::getBulletLaunchers() {
|
||||
getWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E"_s, _weapons.bulletLaunchers);
|
||||
}
|
||||
|
||||
auto Mass::writeBulletLaunchers() -> bool {
|
||||
return writeWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E"_s, _weapons.bulletLaunchers);
|
||||
}
|
||||
|
||||
auto Mass::energyLaunchers() -> Containers::ArrayView<Weapon> {
|
||||
return _weapons.energyLaunchers;
|
||||
}
|
||||
|
||||
void Mass::getEnergyLaunchers() {
|
||||
getWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995"_s, _weapons.energyLaunchers);
|
||||
}
|
||||
|
||||
auto Mass::writeEnergyLaunchers() -> bool {
|
||||
return writeWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995"_s, _weapons.energyLaunchers);
|
||||
}
|
||||
|
||||
void Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
auto prop = unit_data->at<ArrayProperty>(prop_name);
|
||||
if(!prop) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
if(prop->items.size() != weapon_array.size()) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
for(UnsignedInt i = 0; i < weapon_array.size(); i++) {
|
||||
auto weapon_prop = prop->at<GenericStructProperty>(i);
|
||||
auto& weapon = weapon_array[i];
|
||||
|
||||
weapon.name = weapon_prop->at<StringProperty>("Name_13_7BF0D31F4E50C50C47231BB36A485D92"_s)->value;
|
||||
auto& weapon_type = weapon_prop->at<ByteProperty>("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976"_s)->enumValue;
|
||||
#define c(enumerator, strenum, name) if(weapon_type == (strenum)) { weapon.type = WeaponType::enumerator; } else
|
||||
#include "../Maps/WeaponTypes.hpp"
|
||||
#undef c
|
||||
{
|
||||
_state = State::Invalid;
|
||||
Utility::Warning{} << "Invalid weapon type enum value in getWeaponType()."_s;
|
||||
}
|
||||
|
||||
auto parts_prop = weapon_prop->at<ArrayProperty>("Element_6_8E4617CC4B2C1F1490435599784EC6E0"_s);
|
||||
weapon.parts = Containers::Array<WeaponPart>{ValueInit, parts_prop->items.size()};
|
||||
|
||||
for(UnsignedInt j = 0; j < parts_prop->items.size(); j++) {
|
||||
auto part_prop = parts_prop->at<GenericStructProperty>(j);
|
||||
auto& part = weapon.parts[j];
|
||||
|
||||
part.id = part_prop->at<IntProperty>("ID_2_A74D75434308158E5926178822DD28EE"_s)->value;
|
||||
|
||||
auto part_styles = part_prop->at<ArrayProperty>("Styles_17_994C97C34A90667BE5B716BFD0B97588"_s);
|
||||
for(UnsignedInt k = 0; k < part_styles->items.size(); k++) {
|
||||
part.styles[k] = part_styles->at<IntProperty>(k)->value;
|
||||
}
|
||||
|
||||
auto part_decals = part_prop->at<ArrayProperty>("Decals_13_8B81112B453D7230C0CDE982185E14F1"_s);
|
||||
if(part_decals->items.size() != part.decals.size()) {
|
||||
part.decals = Containers::Array<Decal>{part_decals->items.size()};
|
||||
}
|
||||
|
||||
getDecals(part.decals, part_decals);
|
||||
|
||||
auto part_accs = part_prop->at<ArrayProperty>("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"_s);
|
||||
if(!part_accs) {
|
||||
part.accessories = Containers::Array<Accessory>{0};
|
||||
continue;
|
||||
}
|
||||
|
||||
if(part_accs->items.size() != part.accessories.size()) {
|
||||
part.accessories = Containers::Array<Accessory>{part_accs->items.size()};
|
||||
}
|
||||
getAccessories(part.accessories, part_accs);
|
||||
}
|
||||
|
||||
auto custom_styles = weapon_prop->at<ArrayProperty>("Styles_10_8C3C82444B986AD7A99595AD4985912D"_s);
|
||||
if(!custom_styles) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
if(custom_styles->items.size() != weapon.customStyles.size()) {
|
||||
_state = State::Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
getCustomStyles(weapon.customStyles, custom_styles);
|
||||
|
||||
weapon.attached = weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3"_s)->value;
|
||||
auto& damage_type = weapon_prop->at<ByteProperty>("DamageType_18_E1FFA53540591A9087EC698117A65C83"_s)->enumValue;
|
||||
#define c(enumerator, strenum) if(damage_type == (strenum)) { weapon.damageType = DamageType::enumerator; } else
|
||||
#include "../Maps/DamageTypes.hpp"
|
||||
#undef c
|
||||
{
|
||||
_state = State::Invalid;
|
||||
Utility::Warning{} << "Invalid damage type enum value in getWeaponType()."_s;
|
||||
}
|
||||
weapon.dualWield = weapon_prop->at<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222"_s)->value;
|
||||
auto& effect_colour_mode = weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014"_s)->enumValue;
|
||||
#define c(enumerator, strenum) if(effect_colour_mode == (strenum)) { weapon.effectColourMode = EffectColourMode::enumerator; } else
|
||||
#include "../Maps/EffectColourModes.hpp"
|
||||
#undef c
|
||||
{
|
||||
_state = State::Invalid;
|
||||
Utility::Warning{} << "Invalid effect colour mode in getWeaponType()."_s;
|
||||
}
|
||||
auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC"_s);
|
||||
weapon.effectColour = Color4{effect_colour->r, effect_colour->g, effect_colour->b, effect_colour->a};
|
||||
}
|
||||
}
|
||||
|
||||
auto Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) -> bool {
|
||||
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
|
||||
if(!unit_data) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No unit data in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto prop = unit_data->at<ArrayProperty>(prop_name);
|
||||
if(!prop) {
|
||||
_state = State::Invalid;
|
||||
_lastError = prop_name + " not found in "_s + _filename;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(prop->items.size() != weapon_array.size()) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "Weapon type array size mismatch."_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(UnsignedInt i = 0; i < weapon_array.size(); i++) {
|
||||
auto weapon_prop = prop->at<GenericStructProperty>(i);
|
||||
auto& weapon = weapon_array[i];
|
||||
|
||||
weapon_prop->at<StringProperty>("Name_13_7BF0D31F4E50C50C47231BB36A485D92"_s)->value = weapon.name;
|
||||
switch(weapon.type) {
|
||||
#define c(enumerator, strenum, name) case WeaponType::enumerator: weapon_prop->at<ByteProperty>("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976"_s)->enumValue = strenum; break;
|
||||
#include "../Maps/WeaponTypes.hpp"
|
||||
#undef c
|
||||
default:
|
||||
Utility::Warning{} << "Invalid weapon type enum value in writeWeaponType()."_s;
|
||||
}
|
||||
|
||||
auto parts_prop = weapon_prop->at<ArrayProperty>("Element_6_8E4617CC4B2C1F1490435599784EC6E0"_s);
|
||||
if(parts_prop->items.size() != weapon.parts.size()) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "Weapon parts array size mismatch."_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(UnsignedInt j = 0; j < parts_prop->items.size(); j++) {
|
||||
auto part_prop = parts_prop->at<GenericStructProperty>(j);
|
||||
auto& part = weapon.parts[j];
|
||||
|
||||
part_prop->at<IntProperty>("ID_2_A74D75434308158E5926178822DD28EE"_s)->value = part.id;
|
||||
|
||||
auto part_styles = part_prop->at<ArrayProperty>("Styles_17_994C97C34A90667BE5B716BFD0B97588"_s);
|
||||
for(UnsignedInt k = 0; k < part_styles->items.size(); k++) {
|
||||
part_styles->at<IntProperty>(k)->value = part.styles[k];
|
||||
}
|
||||
|
||||
auto part_decals = part_prop->at<ArrayProperty>("Decals_13_8B81112B453D7230C0CDE982185E14F1"_s);
|
||||
writeDecals(part.decals, part_decals);
|
||||
|
||||
auto part_accs = part_prop->at<ArrayProperty>("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"_s);
|
||||
if(!part_accs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(part_accs->items.size() != part.accessories.size()) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "Accessories array size mismatch."_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
writeAccessories(part.accessories, part_accs);
|
||||
}
|
||||
|
||||
auto custom_styles = weapon_prop->at<ArrayProperty>("Styles_10_8C3C82444B986AD7A99595AD4985912D"_s);
|
||||
if(!custom_styles) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "No custom styles found for weapon."_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(custom_styles->items.size() != weapon.customStyles.size()) {
|
||||
_state = State::Invalid;
|
||||
_lastError = "Custom styles array size mismatch."_s;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(UnsignedInt j = 0; j < weapon.customStyles.size(); j++) {
|
||||
writeCustomStyle(weapon.customStyles[j], j, custom_styles);
|
||||
}
|
||||
|
||||
weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3"_s)->value = weapon.attached;
|
||||
switch(weapon.damageType) {
|
||||
#define c(enumerator, strenum) case DamageType::enumerator: weapon_prop->at<ByteProperty>("DamageType_18_E1FFA53540591A9087EC698117A65C83"_s)->enumValue = strenum; break;
|
||||
#include "../Maps/DamageTypes.hpp"
|
||||
#undef c
|
||||
default:
|
||||
Utility::Warning{} << "Unknown damage type enum value in writeWeaponType()."_s;
|
||||
}
|
||||
weapon_prop->at<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222"_s)->value = weapon.dualWield;
|
||||
switch(weapon.effectColourMode) {
|
||||
#define c(enumerator, enumstr) case EffectColourMode::enumerator: \
|
||||
weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014"_s)->enumValue = enumstr; \
|
||||
break;
|
||||
#include "../Maps/EffectColourModes.hpp"
|
||||
#undef c
|
||||
default:
|
||||
Utility::Warning{} << "Unknown effect colour mode in writeWeaponType()."_s;
|
||||
}
|
||||
auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC"_s);
|
||||
effect_colour->r = weapon.effectColour.r();
|
||||
effect_colour->g = weapon.effectColour.g();
|
||||
effect_colour->b = weapon.effectColour.b();
|
||||
effect_colour->a = weapon.effectColour.a();
|
||||
}
|
||||
|
||||
if(!_mass->saveToFile()) {
|
||||
_lastError = _mass->lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -96,36 +96,7 @@ SaveTool::SaveTool(const Arguments& arguments):
|
|||
|
||||
_updateEventId = _initEventId + 1;
|
||||
|
||||
_backupsDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "backups");
|
||||
_stagingDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging");
|
||||
_armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury");
|
||||
_armoursDir = Utility::Directory::join(_armouryDir, "armours");
|
||||
_weaponsDir = Utility::Directory::join(_armouryDir, "weapons");
|
||||
_stylesDir = Utility::Directory::join(_armouryDir, "styles");
|
||||
|
||||
if(!Utility::Directory::exists(_backupsDir)) {
|
||||
Utility::Directory::mkpath(_backupsDir);
|
||||
}
|
||||
|
||||
if(!Utility::Directory::exists(_stagingDir)) {
|
||||
Utility::Directory::mkpath(_stagingDir);
|
||||
}
|
||||
|
||||
if(!Utility::Directory::exists(_armouryDir)) {
|
||||
Utility::Directory::mkpath(_armouryDir);
|
||||
}
|
||||
|
||||
if(!Utility::Directory::exists(_armoursDir)) {
|
||||
Utility::Directory::mkpath(_armoursDir);
|
||||
}
|
||||
|
||||
if(!Utility::Directory::exists(_weaponsDir)) {
|
||||
Utility::Directory::mkpath(_weaponsDir);
|
||||
}
|
||||
|
||||
if(!Utility::Directory::exists(_stylesDir)) {
|
||||
Utility::Directory::mkpath(_stylesDir);
|
||||
}
|
||||
initialiseToolDirectories();
|
||||
|
||||
if(!findGameDataDirectory()) {
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
|
||||
|
@ -563,6 +534,39 @@ void SaveTool::initialiseManager() {
|
|||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
void SaveTool::initialiseToolDirectories() {
|
||||
_backupsDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "backups");
|
||||
_stagingDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging");
|
||||
//_armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury");
|
||||
//_armoursDir = Utility::Directory::join(_armouryDir, "armours");
|
||||
//_weaponsDir = Utility::Directory::join(_armouryDir, "weapons");
|
||||
//_stylesDir = Utility::Directory::join(_armouryDir, "styles");
|
||||
|
||||
if(!Utility::Directory::exists(_backupsDir)) {
|
||||
Utility::Directory::mkpath(_backupsDir);
|
||||
}
|
||||
|
||||
if(!Utility::Directory::exists(_stagingDir)) {
|
||||
Utility::Directory::mkpath(_stagingDir);
|
||||
}
|
||||
|
||||
//if(!Utility::Directory::exists(_armouryDir)) {
|
||||
// Utility::Directory::mkpath(_armouryDir);
|
||||
//}
|
||||
|
||||
//if(!Utility::Directory::exists(_armoursDir)) {
|
||||
// Utility::Directory::mkpath(_armoursDir);
|
||||
//}
|
||||
|
||||
//if(!Utility::Directory::exists(_weaponsDir)) {
|
||||
// Utility::Directory::mkpath(_weaponsDir);
|
||||
//}
|
||||
|
||||
//if(!Utility::Directory::exists(_stylesDir)) {
|
||||
// Utility::Directory::mkpath(_stylesDir);
|
||||
//}
|
||||
}
|
||||
|
||||
auto SaveTool::findGameDataDirectory() -> bool {
|
||||
wchar_t* localappdata_path = nullptr;
|
||||
Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree};
|
||||
|
|
|
@ -87,6 +87,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
|
|||
void initialiseConfiguration();
|
||||
void initialiseGui();
|
||||
void initialiseManager();
|
||||
void initialiseToolDirectories();
|
||||
auto findGameDataDirectory() -> bool;
|
||||
void initialiseMassManager();
|
||||
void initialiseFileWatcher();
|
||||
|
@ -226,10 +227,10 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
|
|||
|
||||
Containers::String _backupsDir;
|
||||
Containers::String _stagingDir;
|
||||
Containers::String _armouryDir;
|
||||
Containers::String _armoursDir;
|
||||
Containers::String _weaponsDir;
|
||||
Containers::String _stylesDir;
|
||||
//Containers::String _armouryDir;
|
||||
//Containers::String _armoursDir;
|
||||
//Containers::String _weaponsDir;
|
||||
//Containers::String _stylesDir;
|
||||
|
||||
enum class GameState : UnsignedByte {
|
||||
Unknown, NotRunning, Running
|
||||
|
|
|
@ -225,7 +225,7 @@ void SaveTool::drawAbout() {
|
|||
drawAlignedText(ICON_FA_GITHUB " %s", efsw_repo);
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Copy to clipboard")) {
|
||||
ImGui::SetClipboardText(efsw_repo.data());
|
||||
ImGui::SetClipboardText(efsw_repo);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Open in browser")) {
|
||||
|
|
Loading…
Reference in a new issue