2021-06-11 19:24:52 +02:00
|
|
|
// 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/Array.h>
|
2021-09-23 19:01:42 +02:00
|
|
|
#include <Corrade/Containers/StaticArray.h>
|
2021-06-11 19:24:52 +02:00
|
|
|
#include <Corrade/Utility/Directory.h>
|
|
|
|
#include <Corrade/Utility/FormatStl.h>
|
|
|
|
#include <Corrade/Utility/String.h>
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
#include "../UESaveFile/Types/ArrayProperty.h"
|
|
|
|
#include "../UESaveFile/Types/ResourceItemValue.h"
|
|
|
|
#include "../UESaveFile/Types/IntProperty.h"
|
|
|
|
#include "../UESaveFile/Types/StringProperty.h"
|
|
|
|
|
2021-06-11 19:24:52 +02:00
|
|
|
#include "Profile.h"
|
|
|
|
|
|
|
|
using namespace Corrade;
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
Profile::Profile(const std::string& path):
|
|
|
|
_profile(path)
|
|
|
|
{
|
2021-06-11 19:24:52 +02:00
|
|
|
_profileDirectory = Utility::Directory::path(path);
|
|
|
|
_filename = Utility::Directory::filename(path);
|
|
|
|
|
|
|
|
if(Utility::String::beginsWith(_filename, "Demo")) {
|
|
|
|
_type = ProfileType::Demo;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_type = ProfileType::FullGame;
|
|
|
|
}
|
|
|
|
|
|
|
|
_steamId = Utility::String::ltrim(Utility::String::rtrim(_filename, ".sav"), (_type == ProfileType::Demo ? "Demo" : "") + std::string{"Profile"});
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
_valid = _profile.valid();
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::valid() const -> bool {
|
|
|
|
return _valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::lastError() const -> std::string const& {
|
|
|
|
return _lastError;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::filename() const -> std::string const& {
|
|
|
|
return _filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::type() const -> ProfileType {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::steamId() const -> std::string const& {
|
|
|
|
return _steamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Profile::refreshValues() {
|
2021-09-23 19:01:42 +02:00
|
|
|
_profile.reloadData();
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::companyName() -> std::string const& {
|
|
|
|
return _profile.at<StringProperty>("CompanyName")->value;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::renameCompany(const std::string& new_name) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
auto name_prop = _profile.at<StringProperty>("CompanyName");
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
name_prop->value = new_name;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
|
|
|
_lastError = "Couldn't save the profile.";
|
2021-06-11 19:24:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::activeFrameSlot() -> Int {
|
|
|
|
auto active_frame_slot_prop = _profile.at<IntProperty>("ActiveFrameSlot");
|
|
|
|
return active_frame_slot_prop ? active_frame_slot_prop->value : 0;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::credits() -> Int {
|
|
|
|
auto credits_prop = _profile.at<IntProperty>("Credit");
|
|
|
|
return credits_prop ? credits_prop->value : 0;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setCredits(Int amount) -> bool {
|
|
|
|
auto credits_prop = _profile.at<IntProperty>("Credit");
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!credits_prop) {
|
|
|
|
credits_prop = new IntProperty;
|
|
|
|
_profile.appendProperty(IntProperty::ptr{credits_prop});
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
credits_prop->value = amount;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
|
|
|
_lastError = "Couldn't save the profile.";
|
2021-06-11 19:24:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::storyProgress() -> Int {
|
|
|
|
auto story_progress_prop = _profile.at<IntProperty>("StoryProgress");
|
|
|
|
return story_progress_prop ? story_progress_prop->value : 0;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setStoryProgress(Int progress) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
auto story_progress_prop = _profile.at<IntProperty>("StoryProgress");
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!story_progress_prop) {
|
|
|
|
story_progress_prop = new IntProperty;
|
|
|
|
_profile.appendProperty(IntProperty::ptr{story_progress_prop});
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
story_progress_prop->value = progress;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
|
|
|
_lastError = "Couldn't save the profile.";
|
|
|
|
return false;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::lastMissionId() -> Int {
|
|
|
|
auto last_mission_id_prop = _profile.at<IntProperty>("LastMissionID");
|
|
|
|
return last_mission_id_prop ? last_mission_id_prop->value : 0;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::verseSteel() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3500);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setVerseSteel(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3500, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::undinium() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3501);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setUndinium(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3501, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::necriumAlloy() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3502);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setNecriumAlloy(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3502, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::lunarite() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3503);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setLunarite(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3503, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::asterite() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3504);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAsterite(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3504, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::ednil() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC350A);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setEdnil(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC350A, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::nuflalt() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC350B);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setNuflalt(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC350B, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::aurelene() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC350C);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAurelene(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC350C, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::soldus() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC350D);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setSoldus(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC350D, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::synthesizedN() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC350E);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setSynthesizedN(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC350E, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::alcarbonite() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3514);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAlcarbonite(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3514, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::keriphene() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3515);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setKeriphene(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3515, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::nitinolCM() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3516);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setNitinolCM(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3516, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::quarkium() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3517);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setQuarkium(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3517, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::alterene() -> Int {
|
|
|
|
return resource("ResourceMaterial", 0xC3518);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAlterene(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceMaterial", 0xC3518, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::mixedComposition() -> Int {
|
|
|
|
return resource("ResourceQuarkData", 0xDBBA0);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setMixedComposition(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceQuarkData", 0xDBBA0, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::voidResidue() -> Int {
|
|
|
|
return resource("ResourceQuarkData", 0xDBBA1);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setVoidResidue(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceQuarkData", 0xDBBA1, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::muscularConstruction() -> Int {
|
|
|
|
return resource("ResourceQuarkData", 0xDBBA2);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setMuscularConstruction(Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
return setResource("ResourceQuarkData", 0xDBBA2, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::mineralExoskeletology() -> Int {
|
|
|
|
return resource("ResourceQuarkData", 0xDBBA3);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setMineralExoskeletology(Int amount) -> bool {
|
|
|
|
return setResource("ResourceQuarkData", 0xDBBA3, amount);
|
|
|
|
}
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::carbonizedSkin() -> Int {
|
|
|
|
return resource("ResourceQuarkData", 0xDBBA4);
|
|
|
|
}
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setCarbonizedSkin(Int amount) -> bool {
|
|
|
|
return setResource("ResourceQuarkData", 0xDBBA4, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::resource(const char* container, Int id) -> Int {
|
|
|
|
auto mats_prop = _profile.at<ArrayProperty>(container);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
static auto predicate = [&id](UnrealPropertyBase::ptr& prop){
|
|
|
|
auto res_prop = static_cast<ResourceItemValue*>(prop.get());
|
|
|
|
return res_prop->id == id;
|
|
|
|
};
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto it = std::find_if(mats_prop->items.begin(), mats_prop->items.end(), predicate);
|
|
|
|
return it != mats_prop->items.end() ? static_cast<ResourceItemValue*>(it->get())->quantity : 0;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setResource(const char* container, Int id, Int amount) -> bool {
|
|
|
|
auto mats_prop = _profile.at<ArrayProperty>(container);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
static auto predicate = [&id](UnrealPropertyBase::ptr& prop){
|
|
|
|
auto res_prop = static_cast<ResourceItemValue*>(prop.get());
|
|
|
|
return res_prop->id == id;
|
|
|
|
};
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto it = std::find_if(mats_prop->items.begin(), mats_prop->items.end(), predicate);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
ResourceItemValue* res_prop;
|
|
|
|
if(it == mats_prop->items.end()) {
|
|
|
|
res_prop = new ResourceItemValue;
|
|
|
|
res_prop->id = id;
|
|
|
|
ResourceItemValue::ptr prop{res_prop};
|
|
|
|
arrayAppend(mats_prop->items, std::move(prop));
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-09-23 19:01:42 +02:00
|
|
|
res_prop = static_cast<ResourceItemValue*>(it->get());
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
res_prop->quantity = amount;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
|
|
|
_lastError = _profile.lastError();
|
2021-06-11 19:24:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-23 19:01:42 +02:00
|
|
|
|
|
|
|
return _profile.saveToFile();
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|