2013-05-23 11:10:39 +00:00
|
|
|
// Rough and ready CwCheats implementation, disabled by default.
|
2013-05-16 20:42:25 +00:00
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-05-16 20:42:25 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2013-05-23 11:10:39 +00:00
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
#include "Common/File/Path.h"
|
2013-05-23 11:10:39 +00:00
|
|
|
#include "Core/MemMap.h"
|
2013-05-16 20:42:25 +00:00
|
|
|
|
2013-10-07 14:46:18 +00:00
|
|
|
class PointerWrap;
|
|
|
|
|
2013-05-18 04:49:44 +00:00
|
|
|
void __CheatInit();
|
|
|
|
void __CheatShutdown();
|
2013-10-07 14:46:18 +00:00
|
|
|
void __CheatDoState(PointerWrap &p);
|
|
|
|
|
2014-02-15 23:28:13 +00:00
|
|
|
// Return whether cheats are enabled and in effect.
|
|
|
|
bool CheatsInEffect();
|
2013-05-16 20:42:25 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
struct CheatLine {
|
|
|
|
uint32_t part1;
|
|
|
|
uint32_t part2;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class CheatCodeFormat {
|
|
|
|
UNDEFINED,
|
|
|
|
CWCHEAT,
|
|
|
|
TEMPAR,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CheatCode {
|
|
|
|
CheatCodeFormat fmt;
|
|
|
|
std::vector<CheatLine> lines;
|
|
|
|
};
|
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
struct CheatFileInfo {
|
|
|
|
int lineNum;
|
|
|
|
std::string name;
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
struct CheatOperation;
|
|
|
|
|
2013-05-18 22:04:01 +00:00
|
|
|
class CWCheatEngine {
|
2013-05-16 20:42:25 +00:00
|
|
|
public:
|
2020-04-11 20:52:25 +00:00
|
|
|
CWCheatEngine(const std::string &gameID);
|
2020-04-11 19:43:55 +00:00
|
|
|
std::vector<CheatFileInfo> FileInfo();
|
2017-11-08 03:51:32 +00:00
|
|
|
void ParseCheats();
|
2016-06-19 22:18:35 +00:00
|
|
|
void CreateCheatFile();
|
2021-05-05 23:31:38 +00:00
|
|
|
Path CheatFilename();
|
2013-05-18 04:49:44 +00:00
|
|
|
void Run();
|
2014-02-15 23:28:13 +00:00
|
|
|
bool HasCheats();
|
2015-02-02 22:26:25 +00:00
|
|
|
void InvalidateICache(u32 addr, int size);
|
2019-03-01 09:55:43 +00:00
|
|
|
private:
|
2017-11-08 03:51:32 +00:00
|
|
|
u32 GetAddress(u32 value);
|
|
|
|
|
|
|
|
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_;
|
2020-04-11 20:52:25 +00:00
|
|
|
std::string gameID_;
|
2021-05-05 23:31:38 +00:00
|
|
|
Path filename_;
|
2013-05-23 11:10:39 +00:00
|
|
|
};
|