diff --git a/Core/CheatManager.cpp b/Core/CheatManager.cpp index cba90c1..73fdbf7 100644 --- a/Core/CheatManager.cpp +++ b/Core/CheatManager.cpp @@ -13,6 +13,7 @@ CheatManager::CheatManager(Console* console) void CheatManager::AddCheat(CheatCode code) { _cheats.push_back(code); + _cheatsByAddress.emplace(code.Address, code); _hasCheats = true; _bankHasCheats[code.Address >> 16] = true; @@ -70,6 +71,7 @@ void CheatManager::ClearCheats(bool showMessage) bool hadCheats = !_cheats.empty(); _cheats.clear(); + _cheatsByAddress.clear(); _hasCheats = false; memset(_bankHasCheats, 0, sizeof(_bankHasCheats)); diff --git a/Core/CheatManager.h b/Core/CheatManager.h index 1751d32..ce2fd6a 100644 --- a/Core/CheatManager.h +++ b/Core/CheatManager.h @@ -16,6 +16,7 @@ private: bool _hasCheats = false; bool _bankHasCheats[0x100] = {}; vector _cheats; + unordered_map _cheatsByAddress; void AddCheat(CheatCode code); @@ -36,11 +37,9 @@ public: __forceinline void CheatManager::ApplyCheat(uint32_t addr, uint8_t &value) { if(_hasCheats && _bankHasCheats[addr >> 16]) { - for(CheatCode &cheat : _cheats) { - if(cheat.Address == addr) { - value = cheat.Value; - break; - } + auto result = _cheatsByAddress.find(addr); + if(result != _cheatsByAddress.end()) { + value = result->second.Value; } } }