diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index 904c557..017a957 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -652,7 +652,6 @@ auto Mass::writeArmourPart(UnsignedLong index) -> bool { auto decals_array = part_prop->at("Decals_42_F358794A4F18497970F56BA9627D3603"); for(UnsignedInt i = 0; i < decals_array->items.size(); i++) { auto decal_prop = decals_array->at(i); - auto& decal = part.decals[i]; decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; @@ -775,6 +774,10 @@ void Mass::getMeleeWeapons() { getWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee); } +auto Mass::writeMeleeWeapons() -> bool { + return writeWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee); +} + auto Mass::shields() -> Containers::ArrayView { return _weapons.shields; } @@ -783,6 +786,10 @@ void Mass::getShields() { getWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields); } +auto Mass::writeShields() -> bool { + return writeWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields); +} + auto Mass::bulletShooters() -> Containers::ArrayView { return _weapons.bulletShooters; } @@ -791,6 +798,10 @@ void Mass::getBulletShooters() { getWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters); } +auto Mass::writeBulletShooters() -> bool { + return writeWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters); +} + auto Mass::energyShooters() -> Containers::ArrayView { return _weapons.energyShooters; } @@ -799,6 +810,10 @@ void Mass::getEnergyShooters() { getWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters); } +auto Mass::writeEnergyShooters() -> bool { + return writeWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters); +} + auto Mass::bulletLaunchers() -> Containers::ArrayView { return _weapons.bulletLaunchers; } @@ -807,6 +822,10 @@ void Mass::getBulletLaunchers() { getWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers); } +auto Mass::writeBulletLaunchers() -> bool { + return writeWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers); +} + auto Mass::energyLaunchers() -> Containers::ArrayView { return _weapons.energyLaunchers; } @@ -815,6 +834,10 @@ void Mass::getEnergyLaunchers() { getWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers); } +auto Mass::writeEnergyLaunchers() -> bool { + return writeWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers); +} + auto Mass::globalStyles() -> Containers::ArrayView { return _globalStyles; } @@ -1054,3 +1077,122 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we weapon.effectColour = Color4{effect_colour->r, effect_colour->g, effect_colour->b, effect_colour->a}; } } + +auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView weapon_array) -> bool { + auto unit_data = _mass->at("UnitData"); + if(!unit_data) { + _state = State::Invalid; + return false; + } + + auto prop = unit_data->at(prop_name); + if(!prop) { + _state = State::Invalid; + return false; + } + + if(prop->items.size() != weapon_array.size()) { + _state = State::Invalid; + return false; + } + + for(UnsignedInt i = 0; i < weapon_array.size(); i++) { + auto weapon_prop = prop->at(i); + auto& weapon = weapon_array[i]; + + weapon_prop->at("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value = weapon.name; + weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue = weapon.type; + + auto parts_prop = weapon_prop->at("Element_6_8E4617CC4B2C1F1490435599784EC6E0"); + if(parts_prop->items.size() != weapon_array.size()) { + _state = State::Invalid; + return false; + } + + for(UnsignedInt j = 0; j < parts_prop->items.size(); j++) { + auto part_prop = parts_prop->at(j); + auto& part = weapon.parts[j]; + + part_prop->at("ID_2_A74D75434308158E5926178822DD28EE")->value = part.id; + + auto part_styles = part_prop->at("Styles_17_994C97C34A90667BE5B716BFD0B97588"); + for(UnsignedInt k = 0; k < part_styles->items.size(); k++) { + part_styles->at(k)->value = part.styles[k]; + } + + auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"); + for(UnsignedInt k = 0; k < part_decals->items.size(); k++) { + auto decal_prop = part_decals->at(k); + auto& decal = part.decals[k]; + + decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; + auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"); + 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("Position_41_022C8FE84E1AAFE587261E88F2C72250"); + pos_prop->x = decal.position.x(); + pos_prop->y = decal.position.y(); + pos_prop->z = decal.position.z(); + auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"); + u_prop->x = decal.uAxis.x(); + u_prop->y = decal.uAxis.y(); + u_prop->z = decal.uAxis.z(); + auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"); + v_prop->x = decal.vAxis.x(); + v_prop->y = decal.vAxis.y(); + v_prop->z = decal.vAxis.z(); + auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"); + offset_prop->x = decal.offset.x(); + offset_prop->y = decal.offset.y(); + decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value = decal.scale; + decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value = decal.rotation; + decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value = decal.flip; + decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value = decal.wrap; + } + + if(!_demo) { + auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); + if(!part_accs) { + _demo = true; + continue; + } + + if(part_accs->items.size() != part.accessories.size()) { + _state = State::Invalid; + return false; + } + + getAccessories(part.accessories, part_accs); + } + } + + auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"); + if(!custom_styles) { + _state = State::Invalid; + return false; + } + + if(custom_styles->items.size() != weapon.customStyles.size()) { + _state = State::Invalid; + return false; + } + + for(UnsignedInt j = 0; j < weapon.customStyles.size(); j++) { + setCustomStyle(weapon.customStyles[j], j, custom_styles); + } + + weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value = weapon.attached; + weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue = weapon.damageType; + weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield; + weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = weapon.effectColourMode; + auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); + effect_colour->r = weapon.effectColour.r(); + effect_colour->g = weapon.effectColour.g(); + effect_colour->b = weapon.effectColour.b(); + effect_colour->a = weapon.effectColour.a(); + } + + return _mass->saveToFile(); +} diff --git a/src/Mass/Mass.h b/src/Mass/Mass.h index 022c6c9..a161046 100644 --- a/src/Mass/Mass.h +++ b/src/Mass/Mass.h @@ -206,6 +206,7 @@ class Mass { void getAccessories(Containers::ArrayView accessories, ArrayProperty* accessory_array); void getWeaponType(const char* prop_name, Containers::ArrayView weapon_array); + auto writeWeaponType(const char* prop_name, Containers::ArrayView weapon_array) -> bool; Containers::Optional _mass;