Compare commits

...

2 commits

Author SHA1 Message Date
22c9627b84 Main: add single-instance checking. 2021-07-28 15:17:46 +02:00
e99ff14749 SaveTool: add a "cheat mode" toggle. 2021-07-28 15:00:15 +02:00
5 changed files with 70 additions and 25 deletions

View file

@ -145,6 +145,7 @@ SaveTool::SaveTool(const Arguments& arguments):
SaveTool::~SaveTool() {
SDL_RemoveTimer(_gameCheckTimerId);
_conf.setValue("cheat_mode", _cheatMode);
_conf.setValue("unsafe_mode", _unsafeMode);
_conf.setValue("startup_update_check", _checkUpdatesOnStartup);
_conf.save();
@ -357,6 +358,13 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
}
void SaveTool::initialiseConfiguration() {
if(_conf.hasValue("cheat_mode")) {
_cheatMode = _conf.value<bool>("cheat_mode");
}
else {
_conf.setValue("cheat_mode", _cheatMode);
}
if(_conf.hasValue("unsafe_mode")) {
_unsafeMode = _conf.value<bool>("unsafe_mode");
}

View file

@ -204,4 +204,6 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
std::string _latestVersion;
std::string _releaseLink;
std::string _downloadLink;
bool _cheatMode{false};
};

View file

@ -231,6 +231,10 @@ void SaveTool::drawGeneralInfo() {
}
}
if(!_cheatMode) {
return;
}
ImGui::SameLine();
static Int credits;
@ -301,7 +305,8 @@ void SaveTool::drawResearchInventory() {
ImGui::TextUnformatted((name)); \
ImGui::TableSetColumnIndex(1); \
if(_currentProfile->getter() != -1) { \
drawUnsafeText("%i", _currentProfile->getter()); \
ImGui::Text("%i", _currentProfile->getter()); \
if(_cheatMode) { \
ImGui::TableSetColumnIndex(2); \
ImGui::PushID(#setter); \
static Int var = _currentProfile->getter(); \
@ -317,6 +322,7 @@ void SaveTool::drawResearchInventory() {
} \
ImGui::PopID(); \
} \
} \
else { \
ImGui::TextDisabled("Not found in the save file"); \
}

View file

@ -55,8 +55,15 @@ void SaveTool::drawMainMenu() {
ImGui::Separator();
if(ImGui::BeginMenu(ICON_FA_COG " Settings")) {
ImGui::Checkbox("Cheat mode", &_cheatMode);
ImGui::SameLine();
ImGui::AlignTextToFramePadding();
drawHelpMarker("This gives access to save edition features that can be considered cheats.",
Float(windowSize().x()) * 0.4f);
ImGui::Checkbox("Unsafe mode", &_unsafeMode);
ImGui::SameLine();
ImGui::AlignTextToFramePadding();
drawHelpMarker("This allows changing the state of save files in the game's save folder even when the game is running.",
Float(windowSize().x()) * 0.4f);

View file

@ -18,7 +18,25 @@
#include <fstream>
#include <errhandlingapi.h>
#include <synchapi.h>
#include <winerror.h>
int main(int argc, char** argv) {
void* mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
if(!mutex_handle) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
"There was an error initialising the mutex.",nullptr);
return EXIT_FAILURE;
}
if(GetLastError() == ERROR_ALREADY_EXISTS) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
"There can be only one running instance of the application.",nullptr);
return EXIT_FAILURE;
}
#ifndef SAVETOOL_DEBUG_BUILD
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
@ -28,5 +46,9 @@ int main(int argc, char** argv) {
#endif
SaveTool app({argc, argv});
return app.exec();
Int result = app.exec();
ReleaseMutex(mutex_handle);
return result;
}