Mesen-SX/Core/CheatManager.h

48 lines
909 B
C
Raw Normal View History

2019-10-12 22:40:25 -04:00
#pragma once
#include "stdafx.h"
class Console;
struct CheatCode
{
uint32_t Address;
uint8_t Value;
};
class CheatManager
{
private:
Console* _console;
bool _hasCheats = false;
bool _bankHasCheats[0x100] = {};
vector<CheatCode> _cheats;
unordered_map<uint32_t, CheatCode> _cheatsByAddress;
2020-12-19 23:30:09 +03:00
void AddCheat(CheatCode code);
2019-10-12 22:40:25 -04:00
public:
CheatManager(Console* console);
void AddStringCheat(string code);
void SetCheats(vector<CheatCode> codes);
2019-10-12 22:40:25 -04:00
void SetCheats(uint32_t codes[], uint32_t length);
void ClearCheats(bool showMessage = true);
vector<CheatCode> GetCheats();
2020-12-19 23:30:09 +03:00
__forceinline void ApplyCheat(uint32_t addr, uint8_t& value);
2019-10-12 22:40:25 -04:00
};
2020-12-19 23:30:09 +03:00
__forceinline void CheatManager::ApplyCheat(uint32_t addr, uint8_t& value)
2019-10-12 22:40:25 -04:00
{
2020-12-19 23:30:09 +03:00
if (_hasCheats && _bankHasCheats[addr >> 16])
{
auto result = _cheatsByAddress.find(addr);
2020-12-19 23:30:09 +03:00
if (result != _cheatsByAddress.end())
{
value = result->second.Value;
2019-10-12 22:40:25 -04:00
}
}
}