diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index b3f6b096f6..bed9e3ea7a 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "Common/ChunkFile.h" @@ -20,6 +21,26 @@ namespace Gecko { static constexpr u32 CODE_SIZE = 8; +bool operator==(const GeckoCode& lhs, const GeckoCode& rhs) +{ + return lhs.codes == rhs.codes; +} + +bool operator!=(const GeckoCode& lhs, const GeckoCode& rhs) +{ + return !operator==(lhs, rhs); +} + +bool operator==(const GeckoCode::Code& lhs, const GeckoCode::Code& rhs) +{ + return std::tie(lhs.address, lhs.data) == std::tie(rhs.address, rhs.data); +} + +bool operator!=(const GeckoCode::Code& lhs, const GeckoCode::Code& rhs) +{ + return !operator==(lhs, rhs); +} + // return true if a code exists bool GeckoCode::Exist(u32 address, u32 data) const { @@ -28,16 +49,6 @@ bool GeckoCode::Exist(u32 address, u32 data) const }) != codes.end(); } -// return true if the code is identical -bool GeckoCode::Compare(const GeckoCode& compare) const -{ - return codes.size() == compare.codes.size() && - std::equal(codes.begin(), codes.end(), compare.codes.begin(), - [](const Code& a, const Code& b) { - return a.address == b.address && a.data == b.data; - }); -} - enum class Installation { Uninstalled, diff --git a/Source/Core/Core/GeckoCode.h b/Source/Core/Core/GeckoCode.h index 8324f85b02..838ed66b0c 100644 --- a/Source/Core/Core/GeckoCode.h +++ b/Source/Core/Core/GeckoCode.h @@ -31,10 +31,15 @@ public: bool enabled; bool user_defined; - bool Compare(const GeckoCode& compare) const; bool Exist(u32 address, u32 data) const; }; +bool operator==(const GeckoCode& lhs, const GeckoCode& rhs); +bool operator!=(const GeckoCode& lhs, const GeckoCode& rhs); + +bool operator==(const GeckoCode::Code& lhs, const GeckoCode::Code& rhs); +bool operator!=(const GeckoCode::Code& lhs, const GeckoCode::Code& rhs); + // Installation address for codehandler.bin in the Game's RAM constexpr u32 INSTALLER_BASE_ADDRESS = 0x80001800; constexpr u32 INSTALLER_END_ADDRESS = 0x80003000; diff --git a/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp b/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp index 4fb77fdb65..8625324b94 100644 --- a/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp +++ b/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp @@ -275,8 +275,8 @@ void CodeConfigPanel::DownloadCodes(wxCommandEvent&) for (const GeckoCode& code : gcodes) { // only add codes which do not already exist - std::vector::const_iterator existing_gcodes_iter = m_gcodes.begin(), - existing_gcodes_end = m_gcodes.end(); + auto existing_gcodes_iter = m_gcodes.begin(); + auto existing_gcodes_end = m_gcodes.end(); for (;; ++existing_gcodes_iter) { if (existing_gcodes_end == existing_gcodes_iter) @@ -287,7 +287,7 @@ void CodeConfigPanel::DownloadCodes(wxCommandEvent&) } // code exists - if (existing_gcodes_iter->Compare(code)) + if (*existing_gcodes_iter == code) break; } }