diff --git a/Source/Core/Core/Src/GeckoCode.cpp b/Source/Core/Core/Src/GeckoCode.cpp index f93bbd1b4c..c7127ef018 100644 --- a/Source/Core/Core/Src/GeckoCode.cpp +++ b/Source/Core/Core/Src/GeckoCode.cpp @@ -63,6 +63,38 @@ u32 GeckoCode::Code::GetAddress() const return gcaddress + (use_po ? pointer_address : (base_address & 0xFE000000)); } +// return true if a code exists +bool GeckoCode::Exist(u32 address, u32 data) +{ + std::vector::const_iterator + codes_iter = codes.begin(), + codes_end = codes.end(); + for (; codes_iter != codes_end; ++codes_iter) + { + if (codes_iter->address == address && codes_iter->data == data) + return true; + } + return false; +} + +// return true if the code is identical +bool GeckoCode::Compare(GeckoCode compare) const +{ + if (codes.size() != compare.codes.size()) + return false; + + int exist = 0; + std::vector::const_iterator + codes_iter = codes.begin(), + codes_end = codes.end(); + for (; codes_iter != codes_end; ++codes_iter) + { + if (compare.Exist(codes_iter->address, codes_iter->data)) + exist++; + } + return exist == codes.size(); +} + static std::mutex active_codes_lock; // currently running code diff --git a/Source/Core/Core/Src/GeckoCode.h b/Source/Core/Core/Src/GeckoCode.h index 42ac941523..59da6fd091 100644 --- a/Source/Core/Core/Src/GeckoCode.h +++ b/Source/Core/Core/Src/GeckoCode.h @@ -66,6 +66,9 @@ namespace Gecko std::vector notes; bool enabled; + + bool Compare(GeckoCode compare) const; + bool Exist(u32 address, u32 data); }; void SetActiveCodes(const std::vector& gcodes); diff --git a/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp b/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp index efd4a3a990..39130bcf8e 100644 --- a/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp +++ b/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp @@ -283,9 +283,8 @@ void CodeConfigPanel::DownloadCodes(wxCommandEvent&) break; } - // code with this name+creator exists - if (existing_gcodes_iter->name == gcodes_iter->name && - existing_gcodes_iter->creator == gcodes_iter->creator) + // code exists + if (existing_gcodes_iter->Compare(*gcodes_iter)) break; } }