Build viewer/editor #13
7 changed files with 63 additions and 75 deletions
|
@ -42,6 +42,7 @@ add_executable(MassBuilderSaveTool WIN32
|
|||
Profile/Profile.cpp
|
||||
MassManager/MassManager.h
|
||||
MassManager/MassManager.cpp
|
||||
Mass/Locators.h
|
||||
Mass/Mass.h
|
||||
Mass/Mass.cpp
|
||||
Maps/LastMissionId.h
|
||||
|
|
20
src/Mass/Locators.h
Normal file
20
src/Mass/Locators.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
// 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/>.
|
||||
|
||||
constexpr char mass_name_locator[] = "Name_45_A037C5D54E53456407BDF091344529BB\0\f\0\0\0StrProperty";
|
||||
constexpr char steamid_locator[] = "Account\0\f\0\0\0StrProperty";
|
|
@ -21,24 +21,24 @@
|
|||
#include <Corrade/Containers/Array.h>
|
||||
#include <Corrade/Utility/Directory.h>
|
||||
|
||||
#include "Locators.h"
|
||||
|
||||
#include "Mass.h"
|
||||
|
||||
using namespace Corrade;
|
||||
|
||||
constexpr char mass_name_locator[] = "Name_45_A037C5D54E53456407BDF091344529BB\0\x0c\0\0\0StrProperty";
|
||||
constexpr char steamid_locator[] = "Account\0\x0c\0\0\0StrProperty";
|
||||
|
||||
std::string Mass::_lastError;
|
||||
|
||||
Mass::Mass(const std::string& filename) {
|
||||
_filename = filename;
|
||||
Mass::Mass(const std::string& path) {
|
||||
_folder = Utility::Directory::path(path);
|
||||
_filename = Utility::Directory::filename(path);
|
||||
|
||||
if(!Utility::Directory::exists(_filename)) {
|
||||
_lastError = "The file " + _filename + " couldn't be found.";
|
||||
if(!Utility::Directory::exists(path)) {
|
||||
_lastError = path + " couldn't be found.";
|
||||
return;
|
||||
}
|
||||
|
||||
auto mmap = Utility::Directory::mapRead(_filename);
|
||||
auto mmap = Utility::Directory::mapRead(path);
|
||||
|
||||
auto iter = std::search(mmap.begin(), mmap.end(), &mass_name_locator[0], &mass_name_locator[56]);
|
||||
|
||||
|
@ -47,7 +47,7 @@ Mass::Mass(const std::string& filename) {
|
|||
_state = MassState::Valid;
|
||||
}
|
||||
else {
|
||||
_lastError = "The name couldn't be found in " + filename;
|
||||
_lastError = "The name couldn't be found in " + _filename;
|
||||
_state = MassState::Invalid;
|
||||
}
|
||||
}
|
||||
|
@ -56,15 +56,15 @@ auto Mass::lastError() -> std::string const& {
|
|||
return _lastError;
|
||||
}
|
||||
|
||||
auto Mass::getNameFromFile(const std::string& filename) -> std::string {
|
||||
if(!Utility::Directory::exists(filename)) {
|
||||
_lastError = "The file " + filename + " couldn't be found.";
|
||||
auto Mass::getNameFromFile(const std::string& path) -> std::string {
|
||||
if(!Utility::Directory::exists(path)) {
|
||||
_lastError = path + " couldn't be found.";
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string name = "";
|
||||
std::string name;
|
||||
|
||||
auto mmap = Utility::Directory::mapRead(filename);
|
||||
auto mmap = Utility::Directory::mapRead(path);
|
||||
|
||||
auto iter = std::search(mmap.begin(), mmap.end(), &mass_name_locator[0], &mass_name_locator[56]);
|
||||
|
||||
|
@ -72,7 +72,7 @@ auto Mass::getNameFromFile(const std::string& filename) -> std::string {
|
|||
name = std::string{iter + 70};
|
||||
}
|
||||
else {
|
||||
_lastError = "The name couldn't be found in " + filename;
|
||||
_lastError = "The name couldn't be found in " + path;
|
||||
}
|
||||
|
||||
return name;
|
||||
|
@ -86,49 +86,29 @@ auto Mass::name() -> std::string const&{
|
|||
return _name;
|
||||
}
|
||||
|
||||
auto Mass::getName() -> std::string const& {
|
||||
if(!Utility::Directory::exists(_filename)) {
|
||||
_lastError = "The file " + _filename + " couldn't be found.";
|
||||
_state = MassState::Empty;
|
||||
return _name = "";
|
||||
}
|
||||
|
||||
auto mmap = Utility::Directory::mapRead(_filename);
|
||||
|
||||
auto iter = std::search(mmap.begin(), mmap.end(), &mass_name_locator[0], &mass_name_locator[56]);
|
||||
|
||||
if(iter != mmap.end()) {
|
||||
_state = MassState::Valid;
|
||||
return _name = std::string{iter + 70};
|
||||
}
|
||||
else {
|
||||
_lastError = "The name couldn't be found in " + _filename;
|
||||
_state = MassState::Invalid;
|
||||
return _name = "";
|
||||
}
|
||||
}
|
||||
|
||||
auto Mass::state() -> MassState {
|
||||
return _state;
|
||||
}
|
||||
|
||||
auto Mass::updateSteamId(const std::string& steam_id) -> bool {
|
||||
if(!Utility::Directory::exists(_filename)) {
|
||||
_lastError = "The file " + _filename + " couldn't be found.";
|
||||
std::string path = Utility::Directory::join(_folder, _filename);
|
||||
|
||||
if(!Utility::Directory::exists(path)) {
|
||||
_lastError = path + " couldn't be found.";
|
||||
_state = MassState::Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::Directory::copy(_filename, _filename + ".tmp");
|
||||
Utility::Directory::copy(path, path + ".tmp");
|
||||
|
||||
{
|
||||
auto mmap = Utility::Directory::map(_filename + ".tmp");
|
||||
auto mmap = Utility::Directory::map(path + ".tmp");
|
||||
|
||||
auto iter = std::search(mmap.begin(), mmap.end(), &steamid_locator[0], &steamid_locator[23]);
|
||||
|
||||
if(iter == mmap.end()) {
|
||||
_lastError = "The M.A.S.S. file at " + _filename + " seems to be corrupt.";
|
||||
Utility::Directory::rm(_filename + ".tmp");
|
||||
_lastError = "The M.A.S.S. file at " + path + " seems to be corrupt.";
|
||||
Utility::Directory::rm(path + ".tmp");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -141,11 +121,11 @@ auto Mass::updateSteamId(const std::string& steam_id) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
if(Utility::Directory::exists(_filename)) {
|
||||
Utility::Directory::rm(_filename);
|
||||
if(Utility::Directory::exists(path)) {
|
||||
Utility::Directory::rm(path);
|
||||
}
|
||||
|
||||
Utility::Directory::move(_filename + ".tmp", _filename);
|
||||
Utility::Directory::move(path + ".tmp", path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ enum class MassState : UnsignedByte {
|
|||
|
||||
class Mass {
|
||||
public:
|
||||
explicit Mass(const std::string& filename);
|
||||
explicit Mass(const std::string& path);
|
||||
|
||||
Mass(const Mass&) = delete;
|
||||
Mass& operator=(const Mass&) = delete;
|
||||
|
@ -38,12 +38,11 @@ class Mass {
|
|||
|
||||
static auto lastError() -> std::string const&;
|
||||
|
||||
static auto getNameFromFile(const std::string& filename) -> std::string;
|
||||
static auto getNameFromFile(const std::string& path) -> std::string;
|
||||
|
||||
auto filename() -> std::string const&;
|
||||
|
||||
auto name() -> std::string const&;
|
||||
auto getName() -> std::string const&;
|
||||
|
||||
auto state() -> MassState;
|
||||
|
||||
|
@ -52,7 +51,8 @@ class Mass {
|
|||
private:
|
||||
static std::string _lastError;
|
||||
|
||||
std::string _filename = "";
|
||||
std::string _name = "";
|
||||
std::string _folder;
|
||||
std::string _filename;
|
||||
std::string _name;
|
||||
MassState _state = MassState::Empty;
|
||||
};
|
||||
|
|
|
@ -49,20 +49,8 @@ auto MassManager::lastError() -> std::string const& {
|
|||
return _lastError;
|
||||
}
|
||||
|
||||
auto MassManager::massName(int hangar) -> std::string const& {
|
||||
if(hangar < 0 || hangar >= 32) {
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
return _hangars[hangar].name();
|
||||
}
|
||||
|
||||
auto MassManager::massState(int hangar) -> MassState {
|
||||
if(hangar < 0 || hangar >= 32) {
|
||||
return MassState::Empty;
|
||||
}
|
||||
|
||||
return _hangars[hangar].state();
|
||||
auto MassManager::hangar(int hangar) -> Mass& {
|
||||
return _hangars[hangar];
|
||||
}
|
||||
|
||||
void MassManager::refreshHangar(int hangar) {
|
||||
|
|
|
@ -31,8 +31,7 @@ class MassManager {
|
|||
|
||||
auto lastError() -> std::string const&;
|
||||
|
||||
auto massName(int hangar) -> std::string const&;
|
||||
auto massState(int hangar) -> MassState;
|
||||
auto hangar(int hangar) -> Mass&;
|
||||
|
||||
void refreshHangar(int hangar);
|
||||
|
||||
|
|
|
@ -429,13 +429,13 @@ void SaveTool::drawMassManager() {
|
|||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Selectable(Utility::formatString("{:.2d}", i + 1).c_str(),
|
||||
false, ImGuiSelectableFlags_SpanAllColumns|ImGuiSelectableFlags_AllowItemOverlap);
|
||||
if(_massManager->massState(i) == MassState::Valid &&
|
||||
if(_massManager->hangar(i).state() == MassState::Valid &&
|
||||
ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
|
||||
{
|
||||
drag_drop_index = i;
|
||||
ImGui::SetDragDropPayload("Mass", &drag_drop_index, sizeof(int));
|
||||
|
||||
ImGui::Text("%s - Hangar %.2d", _massManager->massName(i).c_str(), i + 1);
|
||||
ImGui::Text("%s - Hangar %.2d", _massManager->hangar(i).name().c_str(), i + 1);
|
||||
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ void SaveTool::drawMassManager() {
|
|||
}
|
||||
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
switch(_massManager->massState(i)) {
|
||||
switch(_massManager->hangar(i).state()) {
|
||||
case MassState::Empty:
|
||||
ImGui::TextDisabled("<empty>");
|
||||
break;
|
||||
|
@ -484,7 +484,7 @@ void SaveTool::drawMassManager() {
|
|||
ImGui::TextDisabled("<invalid>");
|
||||
break;
|
||||
case MassState::Valid:
|
||||
ImGui::TextUnformatted(_massManager->massName(i).c_str());
|
||||
ImGui::TextUnformatted(_massManager->hangar(i).name().c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ void SaveTool::drawMassManager() {
|
|||
drawTooltip("This is the currently active frame slot.");
|
||||
}
|
||||
|
||||
if(_massManager->massState(i) != MassState::Empty) {
|
||||
if(_massManager->hangar(i).state() != MassState::Empty) {
|
||||
ImGui::TableSetColumnIndex(3);
|
||||
ImGui::PushID(i);
|
||||
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_TRASH_ALT)) {
|
||||
|
@ -588,7 +588,7 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
|
|||
return ImGui::GetID("Confirmation##DeleteMassConfirmation");
|
||||
}
|
||||
|
||||
if(_massManager->massState(mass_index) == MassState::Empty) {
|
||||
if(_massManager->hangar(mass_index).state() == MassState::Empty) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
return 0;
|
||||
|
@ -601,13 +601,13 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
|
|||
}
|
||||
|
||||
ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
|
||||
if(_massManager->massState(mass_index) == MassState::Invalid) {
|
||||
if(_massManager->hangar(mass_index).state() == MassState::Invalid) {
|
||||
ImGui::Text("Are you sure you want to delete the invalid M.A.S.S. data in hangar %.2i ? This operation is irreversible.",
|
||||
mass_index + 1);
|
||||
}
|
||||
else {
|
||||
ImGui::Text("Are you sure you want to delete the M.A.S.S. named %s in hangar %.2i ? This operation is irreversible.",
|
||||
_massManager->massName(mass_index).c_str(), mass_index + 1);
|
||||
_massManager->hangar(mass_index).name().c_str(), mass_index + 1);
|
||||
}
|
||||
ImGui::PopTextWrapPos();
|
||||
|
||||
|
|
Loading…
Reference in a new issue