Cheats: Split parsing and execution.

This makes the code easier to read, and makes it easier to add other types
later on.

Also, the parser can now handle a file with multiple game ids.
This commit is contained in:
Unknown W. Brackets 2017-11-07 19:51:32 -08:00
parent 70c70b1e76
commit c62a53c223
3 changed files with 882 additions and 605 deletions

File diff suppressed because it is too large Load Diff

View File

@ -18,25 +18,45 @@ void __CheatDoState(PointerWrap &p);
// Return whether cheats are enabled and in effect.
bool CheatsInEffect();
struct CheatLine {
uint32_t part1;
uint32_t part2;
};
enum class CheatCodeFormat {
UNDEFINED,
CWCHEAT,
TEMPAR,
};
struct CheatCode {
CheatCodeFormat fmt;
std::vector<CheatLine> lines;
};
struct CheatOperation;
class CWCheatEngine {
public:
CWCheatEngine();
std::vector<std::string> GetCodesList();
void CreateCodeList();
void ParseCheats();
void CreateCheatFile();
void Exit();
void Run();
std::vector<int> GetNextCode();
bool HasCheats();
private:
void InvalidateICache(u32 addr, int size);
void SkipCodes(int count);
void SkipAllCodes();
bool exit2, cheatEnabled;
int GetAddress(int value);
std::vector<std::string> codeNameList;
u32 GetAddress(u32 value);
std::vector<std::string> codes, initialCodesList, parts;
size_t currentCode;
CheatOperation InterpretNextOp(const CheatCode &cheat, size_t &i);
CheatOperation InterpretNextCwCheat(const CheatCode &cheat, size_t &i);
CheatOperation InterpretNextTempAR(const CheatCode &cheat, size_t &i);
void ExecuteOp(const CheatOperation &op, const CheatCode &cheat, size_t &i);
void ApplyMemoryOperator(const CheatOperation &op, uint32_t(*oper)(uint32_t, uint32_t));
bool TestIf(const CheatOperation &op, bool(*oper)(int a, int b));
bool TestIfAddr(const CheatOperation &op, bool(*oper)(int a, int b));
std::vector<CheatCode> cheats_;
};

View File

@ -155,6 +155,7 @@ UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams &params) {
}
fs.close();
g_Config.bReloadCheats = true;
return UI::EVENT_DONE;
}