Add a way to change the story progression state.
This commit is contained in:
parent
9ebd418ed2
commit
f532803d56
7 changed files with 188 additions and 0 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <wx/busyinfo.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/menu.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/numdlg.h>
|
||||
#include <wx/regex.h>
|
||||
|
@ -107,6 +108,8 @@ EvtMainFrame::EvtMainFrame(wxWindow* parent):
|
|||
wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE|wxFSW_EVENT_MODIFY|wxFSW_EVENT_RENAME, "*.sav");
|
||||
|
||||
_gameCheckTimer.Start(2000);
|
||||
|
||||
initStoryProgressMenu();
|
||||
}
|
||||
|
||||
EvtMainFrame::~EvtMainFrame() {
|
||||
|
@ -207,6 +210,37 @@ void EvtMainFrame::companyRenameEvent(wxMouseEvent&) {
|
|||
}
|
||||
}
|
||||
|
||||
void EvtMainFrame::storyProgressSelectionEvent(wxCommandEvent& event) {
|
||||
const static std::string error_prefix = "StoryProgress change failed:\n\n";
|
||||
|
||||
std::int32_t story_progress = event.GetId() ^ (-10000);
|
||||
|
||||
if(_unsafeMode == false) {
|
||||
switch(_mbManager.gameState()) {
|
||||
case GameState::Unknown:
|
||||
errorMessage(error_prefix + "For security reasons, changing the story progression is disabled if the game's status is unknown.");
|
||||
break;
|
||||
case GameState::NotRunning:
|
||||
if(!_profileManager.currentProfile()->setStoryProgress(story_progress)) {
|
||||
errorMessage(error_prefix + _profileManager.currentProfile()->lastError());
|
||||
}
|
||||
break;
|
||||
case GameState::Running:
|
||||
errorMessage(error_prefix + "Changing the story progression is disabled while the game is running.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(!_profileManager.currentProfile()->setStoryProgress(story_progress)) {
|
||||
errorMessage(error_prefix + _profileManager.currentProfile()->lastError());
|
||||
}
|
||||
|
||||
updateProfileStats();
|
||||
}
|
||||
|
||||
void EvtMainFrame::openStoryProgressMenuEvent(wxCommandEvent&) {
|
||||
PopupMenu(_storyProgressSelectionMenu.get());
|
||||
}
|
||||
|
||||
void EvtMainFrame::importMassEvent(wxCommandEvent&) {
|
||||
const static std::string error_prefix = "Importing failed:\n\n";
|
||||
|
||||
|
@ -560,6 +594,57 @@ void EvtMainFrame::updateProfileStats() {
|
|||
}
|
||||
}
|
||||
|
||||
void EvtMainFrame::initStoryProgressMenu() {
|
||||
_storyProgressSelectionMenu.emplace();
|
||||
|
||||
if(!_storyProgressSelectionMenu) {
|
||||
errorMessage("Error initialising the story progress selection menu.");
|
||||
this->Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
wxMenu* submenu = nullptr;
|
||||
|
||||
for(const auto& pair : story_progress_map) {
|
||||
if(std::strncmp(pair.second + 10, "start", 5) == 0) {
|
||||
submenu = new wxMenu();
|
||||
|
||||
if(!submenu) {
|
||||
errorMessage("Error initialising the story progress selection menu.");
|
||||
this->Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
_storyProgressSelectionMenu->Append(wxID_ANY, wxString{pair.second, 9}, submenu);
|
||||
|
||||
wxMenuItem* item = submenu->Append(pair.first ^ (-10000), "Chapter start");
|
||||
|
||||
if(!item) {
|
||||
errorMessage("Error initialising the story progress selection menu.");
|
||||
this->Destroy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!submenu) {
|
||||
errorMessage("Error initialising the story progress selection menu.");
|
||||
this->Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
wxMenuItem* item = submenu->Append(pair.first ^ (-10000), wxString{pair.second + 12});
|
||||
|
||||
if(!item) {
|
||||
errorMessage("Error initialising the story progress selection menu.");
|
||||
this->Destroy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_storyProgressSelectionMenu->Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(EvtMainFrame::storyProgressSelectionEvent), nullptr, this);
|
||||
}
|
||||
|
||||
void EvtMainFrame::initialiseListView() {
|
||||
for(long i = 0; i < 32; i++) {
|
||||
_installedListView->InsertItem(i, wxString::Format("%.2i", i + 1));
|
||||
|
@ -627,6 +712,7 @@ void EvtMainFrame::updateCommandsState() {
|
|||
MassState mass_state = _massManager->massState(selection);
|
||||
|
||||
_companyRenameButton->Enable(_unsafeMode == true || game_state == GameState::NotRunning);
|
||||
_storyProgressChangeButton->Enable(_unsafeMode == true || game_state == GameState::NotRunning);
|
||||
|
||||
_importButton->Enable(selection != -1 && staged_selection != -1 && (_unsafeMode == true || game_state == GameState::NotRunning));
|
||||
_exportButton->Enable(selection != -1);
|
||||
|
|
|
@ -45,6 +45,8 @@ class EvtMainFrame: public MainFrame {
|
|||
void profileSelectionEvent(wxCommandEvent&);
|
||||
void backupSelectedProfileEvent(wxCommandEvent&);
|
||||
void companyRenameEvent(wxMouseEvent&);
|
||||
void storyProgressSelectionEvent(wxCommandEvent& event);
|
||||
void openStoryProgressMenuEvent(wxCommandEvent&);
|
||||
|
||||
// M.A.S.S.-related events
|
||||
void importMassEvent(wxCommandEvent&);
|
||||
|
@ -72,6 +74,7 @@ class EvtMainFrame: public MainFrame {
|
|||
void stagingFileEventHandler(int event_type, const wxString& event_file, const wxFileSystemWatcherEvent& event);
|
||||
|
||||
void updateProfileStats();
|
||||
void initStoryProgressMenu();
|
||||
|
||||
void initialiseListView();
|
||||
void isGameRunning();
|
||||
|
@ -90,6 +93,8 @@ class EvtMainFrame: public MainFrame {
|
|||
ProfileManager _profileManager;
|
||||
Containers::Pointer<MassManager> _massManager;
|
||||
|
||||
Containers::Pointer<wxMenu> _storyProgressSelectionMenu;
|
||||
|
||||
wxFileSystemWatcher _watcher;
|
||||
int _lastWatcherEventType = 0;
|
||||
};
|
||||
|
|
|
@ -114,6 +114,10 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
|
|||
_companyRenameButton = new wxButton( sbSizerGeneralInfo->GetStaticBox(), wxID_ANY, wxT("Rename company"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizerProfileCommands->Add( _companyRenameButton, 0, wxALL, 5 );
|
||||
|
||||
_storyProgressChangeButton = new wxButton( sbSizerGeneralInfo->GetStaticBox(), wxID_ANY, wxT("Change story progress"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizerProfileCommands->Add( _storyProgressChangeButton, 0, wxALL, 5 );
|
||||
|
||||
|
||||
sbSizerGeneralInfo->Add( bSizerProfileCommands, 0, wxEXPAND, 5 );
|
||||
|
||||
|
||||
|
@ -254,6 +258,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
|
|||
_openScreenshotDirButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openScreenshotDirEvent ), NULL, this );
|
||||
_unsafeCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( MainFrame::unsafeCheckboxEvent ), NULL, this );
|
||||
_companyRenameButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::companyRenameEvent ), NULL, this );
|
||||
_storyProgressChangeButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openStoryProgressMenuEvent ), NULL, this );
|
||||
_moveButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveMassEvent ), NULL, this );
|
||||
_deleteButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteMassEvent ), NULL, this );
|
||||
_renameButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::renameMassEvent ), NULL, this );
|
||||
|
@ -274,6 +279,7 @@ MainFrame::~MainFrame()
|
|||
_openScreenshotDirButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openScreenshotDirEvent ), NULL, this );
|
||||
_unsafeCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( MainFrame::unsafeCheckboxEvent ), NULL, this );
|
||||
_companyRenameButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::companyRenameEvent ), NULL, this );
|
||||
_storyProgressChangeButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openStoryProgressMenuEvent ), NULL, this );
|
||||
_moveButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveMassEvent ), NULL, this );
|
||||
_deleteButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteMassEvent ), NULL, this );
|
||||
_renameButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::renameMassEvent ), NULL, this );
|
||||
|
|
|
@ -1194,6 +1194,79 @@
|
|||
<event name="OnButtonClick">companyRenameEvent</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="1">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxButton" expanded="1">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
<property name="RightDockable">1</property>
|
||||
<property name="TopDockable">1</property>
|
||||
<property name="aui_layer"></property>
|
||||
<property name="aui_name"></property>
|
||||
<property name="aui_position"></property>
|
||||
<property name="aui_row"></property>
|
||||
<property name="best_size"></property>
|
||||
<property name="bg"></property>
|
||||
<property name="bitmap"></property>
|
||||
<property name="caption"></property>
|
||||
<property name="caption_visible">1</property>
|
||||
<property name="center_pane">0</property>
|
||||
<property name="close_button">1</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="current"></property>
|
||||
<property name="default">0</property>
|
||||
<property name="default_pane">0</property>
|
||||
<property name="disabled"></property>
|
||||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="focus"></property>
|
||||
<property name="font"></property>
|
||||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="label">Change story progress</property>
|
||||
<property name="margins"></property>
|
||||
<property name="markup">0</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="moveable">1</property>
|
||||
<property name="name">_storyProgressChangeButton</property>
|
||||
<property name="pane_border">1</property>
|
||||
<property name="pane_position"></property>
|
||||
<property name="pane_size"></property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pin_button">1</property>
|
||||
<property name="pos"></property>
|
||||
<property name="position"></property>
|
||||
<property name="pressed"></property>
|
||||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="validator_data_type"></property>
|
||||
<property name="validator_style">wxFILTER_NONE</property>
|
||||
<property name="validator_type">wxDefaultValidator</property>
|
||||
<property name="validator_variable"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnButtonClick">openStoryProgressMenuEvent</event>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
|
|
|
@ -59,6 +59,7 @@ class MainFrame : public wxFrame
|
|||
wxStaticText* _lastMissionIdLabel;
|
||||
wxStaticText* _lastMissionId;
|
||||
wxButton* _companyRenameButton;
|
||||
wxButton* _storyProgressChangeButton;
|
||||
wxPanel* _massPanel;
|
||||
wxListView* _installedListView;
|
||||
wxButton* _moveButton;
|
||||
|
@ -83,6 +84,7 @@ class MainFrame : public wxFrame
|
|||
virtual void openScreenshotDirEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void unsafeCheckboxEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void companyRenameEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void openStoryProgressMenuEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void moveMassEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void deleteMassEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void renameMassEvent( wxCommandEvent& event ) { event.Skip(); }
|
||||
|
|
|
@ -211,6 +211,21 @@ auto Profile::getStoryProgress() -> std::int32_t {
|
|||
return _storyProgress;
|
||||
}
|
||||
|
||||
auto Profile::setStoryProgress(std::int32_t progress) -> bool {
|
||||
auto mmap = Utility::Directory::map(Utility::Directory::join(_profileDirectory, _filename));
|
||||
|
||||
auto iter = std::search(mmap.begin(), mmap.end(), &story_progress_locator[0], &story_progress_locator[29]);
|
||||
|
||||
if(iter != mmap.end()) {
|
||||
*reinterpret_cast<std::int32_t*>(iter + 0x27) = progress;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
_lastError = "The profile save seems to be corrupted or the game didn't release the handle on the file.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto Profile::lastMissionId() const -> std::int32_t {
|
||||
return _lastMissionId;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ class Profile {
|
|||
|
||||
auto storyProgress() const -> std::int32_t;
|
||||
auto getStoryProgress() -> std::int32_t;
|
||||
auto setStoryProgress(std::int32_t progress) -> bool;
|
||||
|
||||
auto lastMissionId() const -> std::int32_t;
|
||||
auto getLastMissionId() -> std::int32_t;
|
||||
|
|
Loading…
Reference in a new issue