350 lines
12 KiB
C++
350 lines
12 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 "../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);
|
|
}
|