diff --git a/cheat-base/src/cheat-base/cheat/CheatManagerBase.cpp b/cheat-base/src/cheat-base/cheat/CheatManagerBase.cpp index 3930a32..03fd714 100644 --- a/cheat-base/src/cheat-base/cheat/CheatManagerBase.cpp +++ b/cheat-base/src/cheat-base/cheat/CheatManagerBase.cpp @@ -173,6 +173,11 @@ namespace cheat config::RemoveProfile(profileName); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Delete"); + + if (ImGui::SmallButton("Dupe")) + config::DuplicateProfile(profileName); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Duplicate Profile"); } void CheatManagerBase::DrawProfileEntry(const std::string& profileName) diff --git a/cheat-base/src/cheat-base/config/Config.cpp b/cheat-base/src/cheat-base/config/Config.cpp index 0b7b75b..9a09a00 100644 --- a/cheat-base/src/cheat-base/config/Config.cpp +++ b/cheat-base/src/cheat-base/config/Config.cpp @@ -371,6 +371,27 @@ namespace config ProfileChanged(); } + void DuplicateProfile(const std::string& profileName) + { + // Find a unique name for the new profile + uint32_t counter = 0; + std::ostringstream buffer; + std::string newProfileName; + do + { + buffer.str(std::string()); + buffer.clear(); + counter++; + buffer << profileName << " (" << counter << ")"; + newProfileName = buffer.str(); + } while (s_Profiles->contains(newProfileName)); + + // nlohmann::json copy constructor will take care of duplicating + (*s_Profiles)[newProfileName] = (*s_Profiles)[profileName]; + UpdateProfilesNames(); + Save(); + } + std::vector const& GetProfiles() { return s_ProfilesNames; diff --git a/cheat-base/src/cheat-base/config/Config.h b/cheat-base/src/cheat-base/config/Config.h index 634a9f6..e5e5271 100644 --- a/cheat-base/src/cheat-base/config/Config.h +++ b/cheat-base/src/cheat-base/config/Config.h @@ -63,6 +63,7 @@ namespace config void RemoveProfile(const std::string& profileName); void RenameProfile(const std::string& oldProfileName, const std::string& newProfileName); void ChangeProfile(const std::string& profileName); + void DuplicateProfile(const std::string& profileName); std::vector const& GetProfiles(); std::string const& CurrentProfileName();