From 441072d31e305ba3fa60e96a5d0c55ea6d9ac067 Mon Sep 17 00:00:00 2001 From: omegadox Date: Sun, 23 Nov 2008 05:55:48 +0000 Subject: [PATCH] 1. You can now toggle cheats with the ISO properties GUI. 2. Added "SetLines" function in the IniFile class. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1264 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/IniFile.cpp | 10 +++ Source/Core/Common/Src/IniFile.h | 2 + Source/Core/DolphinWX/Src/ISOProperties.cpp | 91 +++++++++++++++++++-- Source/Core/DolphinWX/Src/ISOProperties.h | 3 +- 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/Src/IniFile.cpp b/Source/Core/Common/Src/IniFile.cpp index 199cd92624..dc3f8095dd 100644 --- a/Source/Core/Common/Src/IniFile.cpp +++ b/Source/Core/Common/Src/IniFile.cpp @@ -195,6 +195,16 @@ void IniFile::Set(const char* sectionName, const char* key, bool newValue) } +void IniFile::SetLines(const char* sectionName, const std::vector &lines) +{ + Section* section = GetOrCreateSection(sectionName); + section->lines.clear(); + + for (std::vector::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) + { + section->lines.push_back(*iter); + } +} bool IniFile::Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue) { Section* section = GetSection(sectionName); diff --git a/Source/Core/Common/Src/IniFile.h b/Source/Core/Common/Src/IniFile.h index 07a244ad2e..de4c5836d0 100644 --- a/Source/Core/Common/Src/IniFile.h +++ b/Source/Core/Common/Src/IniFile.h @@ -55,6 +55,8 @@ public: void Set(const char* sectionName, const char* key, const std::string& newValue) {Set(sectionName, key, newValue.c_str());} void Set(const char* sectionName, const char* key, const std::vector& newValues); + void SetLines(const char* sectionName, const std::vector &lines); + // getter should be const bool Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue = ""); bool Get(const char* sectionName, const char* key, int* value, int defaultValue = 0); diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 81d3541da0..c8ded255d6 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -22,6 +22,13 @@ #include "Filesystem.h" #include "ISOProperties.h" +struct ARListCode { + std::string name; + bool enabled; + std::vector ops; + u32 uiIndex; +}; + BEGIN_EVENT_TABLE(CISOProperties, wxDialog) EVT_CLOSE(CISOProperties::OnClose) EVT_BUTTON(ID_CLOSE, CISOProperties::OnCloseClick) @@ -35,6 +42,7 @@ END_EVENT_TABLE() DiscIO::IVolume *OpenISO = NULL; DiscIO::IFileSystem *pFileSystem = NULL; +std::vector ARCodes; CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style) : wxDialog(parent, id, title, position, size, style) @@ -244,8 +252,6 @@ void CISOProperties::CreateGUIControls() Patches->Append(_("Not yet functional")); Patches->Enable(false); AddPatch->Enable(false); - Cheats->Append(_("Not yet functional")); - Cheats->Enable(false); AddCheat->Enable(false); // -------------------------------------- @@ -507,10 +513,9 @@ void CISOProperties::LoadGameConfig() } EmuState->SetSelection(iTemp); - // TODO handle patches+cheats - //LoadActionReplayCodes(GameIni, true); - //for (int i = 0; i < arCodes.size(); i++) - // Cheats->Append(wxString(arCodes[i].name.c_str(), wxConvUTF8)); + ActionReplayList_Load(); + + // TODO handle patches } bool CISOProperties::SaveGameConfig() @@ -542,9 +547,11 @@ bool CISOProperties::SaveGameConfig() GameIni.Set("EmuState", "EmulationStateId", EmuState->GetSelection()); + ActionReplayList_Save(); + return GameIni.Save(GameIniFile.c_str()); - // TODO save patches+cheats + // TODO save patches } void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event)) @@ -562,3 +569,73 @@ void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event)) bRefreshList = true; // Just in case } } + +void CISOProperties::ActionReplayList_Load() +{ + ARCodes.clear(); + std::vector lines; + + if (!GameIni.GetLines("ActionReplay", lines)) + return; + + ARListCode code; + + for (std::vector::const_iterator it = lines.begin(); it != lines.end(); ++it) + { + std::string line = *it; + + if (line[0] == '+' || line[0] == '$') + { + // Take care of the previous code + if (code.ops.size()) + { + code.uiIndex = Cheats->Append(_T(code.name)); + ARCodes.push_back(code); + Cheats->Check(code.uiIndex, code.enabled); + code.ops.clear(); + } + + // Give name and enabled to current code + if(line.size() > 1) + { + if (line[0] == '+') + { + code.enabled = true; + code.name = line.substr(2, line.size() - 2); + } + else + { + code.enabled = false; + code.name = line.substr(1, line.size() - 1); + } + } + + continue; + } + + code.ops.push_back(line); + } + + if (code.ops.size()) + { + code.uiIndex = Cheats->Append(_T(code.name)); + ARCodes.push_back(code); + Cheats->Check(code.uiIndex, code.enabled); + } +} +void CISOProperties::ActionReplayList_Save() +{ + std::vector lines; + for (std::vector::const_iterator iter = ARCodes.begin(); iter != ARCodes.end(); ++iter) + { + ARListCode code = *iter; + + lines.push_back(Cheats->IsChecked(code.uiIndex) ? "+$" + code.name : "$" + code.name); + + for (std::vector::const_iterator iter2 = code.ops.begin(); iter2 != code.ops.end(); ++iter2) + { + lines.push_back(*iter2); + } + } + GameIni.SetLines("ActionReplay", lines); +} \ No newline at end of file diff --git a/Source/Core/DolphinWX/Src/ISOProperties.h b/Source/Core/DolphinWX/Src/ISOProperties.h index 4c346b8480..026c685862 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.h +++ b/Source/Core/DolphinWX/Src/ISOProperties.h @@ -192,6 +192,8 @@ class CISOProperties : public wxDialog void OnExtractDir(wxCommandEvent& event); void SetRefresh(wxCommandEvent& event); void OnEditConfig(wxCommandEvent& event); + void ActionReplayList_Load(); + void ActionReplayList_Save(); std::vector Our_Files; typedef std::vector::iterator fileIter; @@ -205,5 +207,4 @@ class CISOProperties : public wxDialog void LoadGameConfig(); bool SaveGameConfig(); }; - #endif