2017-11-08 03:51:32 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cstdint>
|
2021-05-09 23:28:50 +00:00
|
|
|
#include <cstdio>
|
2023-03-25 09:29:18 +00:00
|
|
|
|
2020-10-01 11:05:04 +00:00
|
|
|
#include "Common/Data/Text/I18n.h"
|
2013-12-29 22:28:31 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2020-08-10 07:12:51 +00:00
|
|
|
#include "Common/Serialize/Serializer.h"
|
|
|
|
#include "Common/Serialize/SerializeFuncs.h"
|
2023-03-25 09:29:18 +00:00
|
|
|
#include "Common/System/System.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/FileUtil.h"
|
2013-12-29 22:28:31 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
#include "Core/CoreParameter.h"
|
|
|
|
#include "Core/CwCheat.h"
|
2013-05-30 07:08:20 +00:00
|
|
|
#include "Core/Config.h"
|
2021-02-03 08:09:21 +00:00
|
|
|
#include "Core/MemMapHelpers.h"
|
2013-12-29 22:28:31 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-12-29 23:11:29 +00:00
|
|
|
#include "Core/ELF/ParamSFO.h"
|
|
|
|
#include "Core/System.h"
|
2014-06-26 02:23:56 +00:00
|
|
|
#include "Core/HLE/sceCtrl.h"
|
2016-05-01 08:35:37 +00:00
|
|
|
#include "Core/MIPS/JitCommon/JitCommon.h"
|
2020-05-17 17:06:23 +00:00
|
|
|
#include "GPU/Common/PostShader.h"
|
2015-02-02 22:26:25 +00:00
|
|
|
|
2014-06-05 02:41:42 +00:00
|
|
|
#ifdef _WIN32
|
2020-10-01 11:05:04 +00:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
2014-06-05 02:41:42 +00:00
|
|
|
#endif
|
2013-05-18 22:52:24 +00:00
|
|
|
|
2013-05-18 04:49:44 +00:00
|
|
|
static int CheatEvent = -1;
|
2013-05-23 11:10:39 +00:00
|
|
|
static CWCheatEngine *cheatEngine;
|
2013-10-14 00:49:05 +00:00
|
|
|
static bool cheatsEnabled;
|
2020-04-12 13:08:46 +00:00
|
|
|
using namespace SceCtrl;
|
|
|
|
|
2013-05-23 11:10:39 +00:00
|
|
|
void hleCheat(u64 userdata, int cyclesLate);
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
static inline std::string TrimString(const std::string &s) {
|
|
|
|
auto wsfront = std::find_if_not(s.begin(), s.end(), [](int c) {
|
2018-02-11 19:10:02 +00:00
|
|
|
// isspace() expects 0 - 255, so convert any sign-extended value.
|
|
|
|
return std::isspace(c & 0xFF);
|
2017-11-08 03:51:32 +00:00
|
|
|
});
|
|
|
|
auto wsback = std::find_if_not(s.rbegin(), s.rend(), [](int c){
|
2018-02-11 19:10:02 +00:00
|
|
|
return std::isspace(c & 0xFF);
|
2017-11-08 03:51:32 +00:00
|
|
|
}).base();
|
|
|
|
return wsback > wsfront ? std::string(wsfront, wsback) : std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
class CheatFileParser {
|
|
|
|
public:
|
2021-05-05 23:31:38 +00:00
|
|
|
CheatFileParser(const Path &filename, const std::string &gameID = "") {
|
2021-05-09 23:28:50 +00:00
|
|
|
fp_ = File::OpenCFile(filename, "rt");
|
2017-11-08 03:51:32 +00:00
|
|
|
validGameID_ = ReplaceAll(gameID, "-", "");
|
|
|
|
}
|
2021-05-09 23:28:50 +00:00
|
|
|
~CheatFileParser() {
|
|
|
|
if (fp_)
|
|
|
|
fclose(fp_);
|
|
|
|
}
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
bool Parse();
|
|
|
|
|
|
|
|
std::vector<std::string> GetErrors() const {
|
|
|
|
return errors_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CheatCode> GetCheats() const {
|
|
|
|
return cheats_;
|
|
|
|
}
|
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
std::vector<CheatFileInfo> GetFileInfo() const {
|
|
|
|
return cheatInfo_;
|
|
|
|
}
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
protected:
|
|
|
|
void Flush();
|
2020-04-11 19:43:55 +00:00
|
|
|
void FlushCheatInfo();
|
2017-11-08 03:51:32 +00:00
|
|
|
void AddError(const std::string &msg);
|
|
|
|
void ParseLine(const std::string &line);
|
|
|
|
void ParseDataLine(const std::string &line, CheatCodeFormat format);
|
|
|
|
bool ValidateGameID(const std::string &gameID);
|
|
|
|
|
2021-05-09 23:28:50 +00:00
|
|
|
FILE *fp_ = nullptr;
|
2017-11-08 03:51:32 +00:00
|
|
|
std::string validGameID_;
|
|
|
|
|
|
|
|
int line_ = 0;
|
|
|
|
int games_ = 0;
|
|
|
|
std::vector<std::string> errors_;
|
2020-04-11 19:43:55 +00:00
|
|
|
std::vector<CheatFileInfo> cheatInfo_;
|
2017-11-08 03:51:32 +00:00
|
|
|
std::vector<CheatCode> cheats_;
|
|
|
|
std::vector<CheatLine> pendingLines_;
|
|
|
|
CheatCodeFormat codeFormat_ = CheatCodeFormat::UNDEFINED;
|
2020-04-11 19:43:55 +00:00
|
|
|
CheatFileInfo lastCheatInfo_;
|
2017-11-08 03:51:32 +00:00
|
|
|
bool gameEnabled_ = true;
|
|
|
|
bool gameRiskyEnabled_ = false;
|
|
|
|
bool cheatEnabled_ = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CheatFileParser::Parse() {
|
2021-05-09 23:28:50 +00:00
|
|
|
for (line_ = 1; fp_ && !feof(fp_); ++line_) {
|
|
|
|
char temp[2048];
|
|
|
|
char *tempLine = fgets(temp, sizeof(temp), fp_);
|
|
|
|
if (!tempLine)
|
|
|
|
continue;
|
|
|
|
|
2021-07-26 09:47:21 +00:00
|
|
|
// Detect UTF-8 BOM sequence, and ignore it.
|
|
|
|
if (line_ == 1 && memcmp(tempLine, "\xEF\xBB\xBF", 3) == 0)
|
|
|
|
tempLine += 3;
|
2021-05-09 23:28:50 +00:00
|
|
|
std::string line = TrimString(tempLine);
|
2017-11-08 03:51:32 +00:00
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
// Minimum length 5 is shortest possible _ lines name of the game "_G N+"
|
2017-11-30 06:51:15 +00:00
|
|
|
// and a minimum of 1 displayable character in cheat name string "_C0 1"
|
|
|
|
// which both equal to 5 characters.
|
2017-11-30 00:32:19 +00:00
|
|
|
if (line.length() >= 5 && line[0] == '_') {
|
2017-11-08 03:51:32 +00:00
|
|
|
ParseLine(line);
|
|
|
|
} else if (line.length() >= 2 && line[0] == '/' && line[1] == '/') {
|
|
|
|
// Comment, ignore.
|
|
|
|
} else if (line.length() >= 1 && line[0] == '#') {
|
|
|
|
// Comment, ignore.
|
|
|
|
} else if (line.length() > 0) {
|
|
|
|
errors_.push_back(StringFromFormat("Unrecognized content on line %d: expecting _", line_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
return errors_.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheatFileParser::Flush() {
|
|
|
|
if (!pendingLines_.empty()) {
|
2020-04-11 19:43:55 +00:00
|
|
|
FlushCheatInfo();
|
2017-11-08 03:51:32 +00:00
|
|
|
cheats_.push_back({ codeFormat_, pendingLines_ });
|
|
|
|
pendingLines_.clear();
|
|
|
|
}
|
|
|
|
codeFormat_ = CheatCodeFormat::UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
void CheatFileParser::FlushCheatInfo() {
|
|
|
|
if (lastCheatInfo_.lineNum != 0) {
|
|
|
|
cheatInfo_.push_back(lastCheatInfo_);
|
|
|
|
lastCheatInfo_ = { 0 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
void CheatFileParser::AddError(const std::string &err) {
|
|
|
|
errors_.push_back(StringFromFormat("Error on line %d: %s", line_, err.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheatFileParser::ParseLine(const std::string &line) {
|
|
|
|
switch (line[1]) {
|
|
|
|
case 'S':
|
|
|
|
// Disc ID, validate (for multi-disc cheat files)?
|
|
|
|
Flush();
|
|
|
|
++games_;
|
|
|
|
|
|
|
|
if (ValidateGameID(line.substr(2))) {
|
|
|
|
if (gameRiskyEnabled_) {
|
|
|
|
// We found the right one, so let's not use this risky stuff.
|
|
|
|
cheats_.clear();
|
2020-04-11 19:43:55 +00:00
|
|
|
cheatInfo_.clear();
|
2017-11-08 03:51:32 +00:00
|
|
|
gameRiskyEnabled_ = false;
|
|
|
|
}
|
|
|
|
gameEnabled_ = true;
|
|
|
|
} else if (games_ == 1) {
|
|
|
|
// Old behavior was to ignore.
|
|
|
|
// For BC, let's allow if the game id doesn't match, but there's only one line.
|
|
|
|
gameRiskyEnabled_ = true;
|
|
|
|
gameEnabled_ = true;
|
|
|
|
} else {
|
|
|
|
if (gameRiskyEnabled_) {
|
|
|
|
// There are multiple games here, kill the risky stuff.
|
|
|
|
cheats_.clear();
|
2020-04-11 19:43:55 +00:00
|
|
|
cheatInfo_.clear();
|
2017-11-08 03:51:32 +00:00
|
|
|
gameRiskyEnabled_ = false;
|
|
|
|
}
|
|
|
|
gameEnabled_ = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
// Game title.
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'C':
|
2020-04-11 19:43:55 +00:00
|
|
|
Flush();
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
// Cheat name and activation status.
|
2017-11-08 14:51:25 +00:00
|
|
|
if (line.length() >= 3 && line[2] >= '1' && line[2] <= '9') {
|
2020-04-11 19:43:55 +00:00
|
|
|
lastCheatInfo_ = { line_, line.length() >= 5 ? line.substr(4) : "", true };
|
2017-11-08 03:51:32 +00:00
|
|
|
cheatEnabled_ = true;
|
|
|
|
} else if (line.length() >= 3 && line[2] == '0') {
|
2020-04-11 19:43:55 +00:00
|
|
|
lastCheatInfo_ = { line_, line.length() >= 5 ? line.substr(4) : "", false };
|
2017-11-08 03:51:32 +00:00
|
|
|
cheatEnabled_ = false;
|
|
|
|
} else {
|
|
|
|
AddError("could not parse cheat name line");
|
|
|
|
cheatEnabled_ = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
// CwCheat data line.
|
|
|
|
ParseDataLine(line.substr(2), CheatCodeFormat::CWCHEAT);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
// TempAR data line.
|
|
|
|
ParseDataLine(line.substr(2), CheatCodeFormat::TEMPAR);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
AddError("unknown line type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheatFileParser::ParseDataLine(const std::string &line, CheatCodeFormat format) {
|
|
|
|
if (codeFormat_ == CheatCodeFormat::UNDEFINED) {
|
|
|
|
codeFormat_ = format;
|
|
|
|
} else if (codeFormat_ != format) {
|
|
|
|
AddError("mixed code format (cwcheat/tempar)");
|
2020-04-11 19:43:55 +00:00
|
|
|
lastCheatInfo_ = { 0 };
|
2017-11-08 03:51:32 +00:00
|
|
|
pendingLines_.clear();
|
|
|
|
cheatEnabled_ = false;
|
|
|
|
}
|
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
if (!gameEnabled_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!cheatEnabled_) {
|
|
|
|
FlushCheatInfo();
|
2017-11-08 03:51:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheatLine cheatLine;
|
|
|
|
int len = 0;
|
|
|
|
if (sscanf(line.c_str(), "%x %x %n", &cheatLine.part1, &cheatLine.part2, &len) == 2) {
|
|
|
|
if ((size_t)len < line.length()) {
|
|
|
|
AddError("junk after line data");
|
|
|
|
}
|
|
|
|
pendingLines_.push_back(cheatLine);
|
|
|
|
} else {
|
|
|
|
AddError("expecting two values");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheatFileParser::ValidateGameID(const std::string &gameID) {
|
|
|
|
return validGameID_.empty() || ReplaceAll(TrimString(gameID), "-", "") == validGameID_;
|
|
|
|
}
|
2013-05-18 04:49:44 +00:00
|
|
|
|
2013-10-14 00:49:05 +00:00
|
|
|
static void __CheatStop() {
|
2017-11-08 03:51:32 +00:00
|
|
|
if (cheatEngine) {
|
2013-10-14 00:49:05 +00:00
|
|
|
delete cheatEngine;
|
2017-11-08 03:51:32 +00:00
|
|
|
cheatEngine = nullptr;
|
2013-10-14 00:49:05 +00:00
|
|
|
}
|
|
|
|
cheatsEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __CheatStart() {
|
|
|
|
__CheatStop();
|
|
|
|
|
2021-02-28 18:52:35 +00:00
|
|
|
cheatEngine = new CWCheatEngine(g_paramSFO.GetDiscID());
|
2020-04-11 20:52:25 +00:00
|
|
|
// This only generates ini files on boot, let's leave homebrew ini file for UI.
|
2021-02-28 18:52:35 +00:00
|
|
|
std::string realGameID = g_paramSFO.GetValueString("DISC_ID");
|
2020-04-11 21:01:32 +00:00
|
|
|
if (!realGameID.empty()) {
|
2016-06-20 09:32:31 +00:00
|
|
|
cheatEngine->CreateCheatFile();
|
|
|
|
}
|
2013-10-07 14:46:18 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
cheatEngine->ParseCheats();
|
2013-10-14 00:49:05 +00:00
|
|
|
g_Config.bReloadCheats = false;
|
|
|
|
cheatsEnabled = true;
|
|
|
|
}
|
2013-06-01 05:24:25 +00:00
|
|
|
|
2019-03-01 09:55:43 +00:00
|
|
|
static int GetRefreshMs() {
|
|
|
|
int refresh = g_Config.iCwCheatRefreshRate;
|
|
|
|
|
|
|
|
if (!cheatsEnabled)
|
|
|
|
refresh = 1000;
|
|
|
|
|
|
|
|
// Horrible hack for Tony Hawk - Underground 2. See #3854. Avoids crashing somehow
|
|
|
|
// but still causes regular JIT invalidations which causes stutters.
|
|
|
|
if (PSP_CoreParameter().compat.flags().JitInvalidationHack) {
|
|
|
|
refresh = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return refresh;
|
|
|
|
}
|
|
|
|
|
2013-10-14 00:49:05 +00:00
|
|
|
void __CheatInit() {
|
|
|
|
// Always register the event, want savestates to be compatible whether cheats on or off.
|
|
|
|
CheatEvent = CoreTiming::RegisterEvent("CheatEvent", &hleCheat);
|
2013-05-30 07:08:20 +00:00
|
|
|
|
2013-10-14 00:49:05 +00:00
|
|
|
if (g_Config.bEnableCheats) {
|
|
|
|
__CheatStart();
|
2013-05-18 22:04:01 +00:00
|
|
|
}
|
2013-10-14 00:49:05 +00:00
|
|
|
|
|
|
|
// Only check once a second for cheats to be enabled.
|
2019-03-01 09:55:43 +00:00
|
|
|
CoreTiming::ScheduleEvent(msToCycles(GetRefreshMs()), CheatEvent, 0);
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
2013-05-23 11:10:39 +00:00
|
|
|
|
2013-05-18 04:49:44 +00:00
|
|
|
void __CheatShutdown() {
|
2013-10-14 00:49:05 +00:00
|
|
|
__CheatStop();
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 14:46:18 +00:00
|
|
|
void __CheatDoState(PointerWrap &p) {
|
2013-10-14 01:03:23 +00:00
|
|
|
auto s = p.Section("CwCheat", 0, 2);
|
2013-10-07 14:46:18 +00:00
|
|
|
if (!s) {
|
2020-12-28 21:29:19 +00:00
|
|
|
CheatEvent = -1;
|
|
|
|
CoreTiming::RestoreRegisterEvent(CheatEvent, "CheatEvent", &hleCheat);
|
2013-10-07 14:46:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-10 04:20:42 +00:00
|
|
|
Do(p, CheatEvent);
|
2013-10-07 14:46:18 +00:00
|
|
|
CoreTiming::RestoreRegisterEvent(CheatEvent, "CheatEvent", &hleCheat);
|
2013-10-14 01:03:23 +00:00
|
|
|
|
|
|
|
if (s < 2) {
|
|
|
|
// Before this we didn't have a checkpoint, so reset didn't work.
|
|
|
|
// Let's just force one in.
|
|
|
|
CoreTiming::RemoveEvent(CheatEvent);
|
2019-03-01 09:55:43 +00:00
|
|
|
CoreTiming::ScheduleEvent(msToCycles(GetRefreshMs()), CheatEvent, 0);
|
2013-10-14 01:03:23 +00:00
|
|
|
}
|
2013-10-07 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 04:49:44 +00:00
|
|
|
void hleCheat(u64 userdata, int cyclesLate) {
|
2013-10-14 00:49:05 +00:00
|
|
|
if (cheatsEnabled != g_Config.bEnableCheats) {
|
|
|
|
// Okay, let's move to the desired state, then.
|
|
|
|
if (g_Config.bEnableCheats) {
|
|
|
|
__CheatStart();
|
|
|
|
} else {
|
|
|
|
__CheatStop();
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 07:08:20 +00:00
|
|
|
|
2019-03-01 09:55:43 +00:00
|
|
|
// Check periodically for cheats.
|
|
|
|
CoreTiming::ScheduleEvent(msToCycles(GetRefreshMs()), CheatEvent, 0);
|
|
|
|
|
|
|
|
if (PSP_CoreParameter().compat.flags().JitInvalidationHack) {
|
|
|
|
std::string gameTitle = g_paramSFO.GetValueString("DISC_ID");
|
|
|
|
|
|
|
|
// Horrible hack for Tony Hawk - Underground 2. See #3854. Avoids crashing somehow
|
|
|
|
// but still causes regular JIT invalidations which causes stutters.
|
|
|
|
if (gameTitle == "ULUS10014") {
|
|
|
|
cheatEngine->InvalidateICache(0x08865600, 72);
|
|
|
|
cheatEngine->InvalidateICache(0x08865690, 4);
|
2019-03-01 13:31:28 +00:00
|
|
|
} else if (gameTitle == "ULES00033" || gameTitle == "ULES00034" || gameTitle == "ULES00035") { // euro, also 34 and 35
|
2019-03-01 09:55:43 +00:00
|
|
|
cheatEngine->InvalidateICache(0x088655D8, 72);
|
|
|
|
cheatEngine->InvalidateICache(0x08865668, 4);
|
2021-07-17 10:59:15 +00:00
|
|
|
} else if (gameTitle == "ULUS10138") { // MTX MotoTrax US
|
2019-03-01 09:55:43 +00:00
|
|
|
cheatEngine->InvalidateICache(0x0886DCC0, 72);
|
|
|
|
cheatEngine->InvalidateICache(0x0886DC20, 4);
|
|
|
|
cheatEngine->InvalidateICache(0x0886DD40, 4);
|
2021-07-17 10:59:15 +00:00
|
|
|
} else if (gameTitle == "ULES00581") { // MTX MotoTrax EU (ported from US cwcheat codes)
|
|
|
|
cheatEngine->InvalidateICache(0x0886E1D8, 72);
|
|
|
|
cheatEngine->InvalidateICache(0x0886E138, 4);
|
|
|
|
cheatEngine->InvalidateICache(0x0886E258, 4);
|
2019-03-01 09:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-14 00:49:05 +00:00
|
|
|
|
|
|
|
if (!cheatEngine || !cheatsEnabled)
|
2013-06-24 08:31:29 +00:00
|
|
|
return;
|
2019-03-01 09:55:43 +00:00
|
|
|
|
2013-06-24 08:31:29 +00:00
|
|
|
if (g_Config.bReloadCheats) { //Checks if the "reload cheats" button has been pressed.
|
2017-11-08 03:51:32 +00:00
|
|
|
cheatEngine->ParseCheats();
|
2013-05-30 07:08:20 +00:00
|
|
|
g_Config.bReloadCheats = false;
|
2013-06-01 05:24:25 +00:00
|
|
|
}
|
2013-10-14 00:49:05 +00:00
|
|
|
cheatEngine->Run();
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
2013-05-18 22:04:01 +00:00
|
|
|
|
2020-04-11 20:52:25 +00:00
|
|
|
CWCheatEngine::CWCheatEngine(const std::string &gameID) : gameID_(gameID) {
|
2021-05-05 23:31:38 +00:00
|
|
|
filename_ = GetSysDirectory(DIRECTORY_CHEATS) / (gameID_ + ".ini");
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 22:18:35 +00:00
|
|
|
void CWCheatEngine::CreateCheatFile() {
|
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS));
|
|
|
|
|
2020-04-11 20:52:25 +00:00
|
|
|
if (!File::Exists(filename_)) {
|
|
|
|
FILE *f = File::OpenCFile(filename_, "wb");
|
2016-06-19 22:18:35 +00:00
|
|
|
if (f) {
|
|
|
|
fwrite("\xEF\xBB\xBF\n", 1, 4, f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2020-04-11 20:52:25 +00:00
|
|
|
if (!File::Exists(filename_)) {
|
2023-04-05 22:34:50 +00:00
|
|
|
auto err = GetI18NCategory(I18NCat::ERRORS);
|
2023-06-20 12:40:46 +00:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_ERROR, err->T("Unable to create cheat file, disk may be full"));
|
2016-06-19 22:18:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
Path CWCheatEngine::CheatFilename() {
|
2020-04-11 20:52:25 +00:00
|
|
|
return filename_;
|
|
|
|
}
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
void CWCheatEngine::ParseCheats() {
|
2020-04-11 20:52:25 +00:00
|
|
|
CheatFileParser parser(filename_, gameID_);
|
2013-05-18 04:49:44 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
parser.Parse();
|
|
|
|
// TODO: Report errors.
|
2013-05-18 22:04:01 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
cheats_ = parser.GetCheats();
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
u32 CWCheatEngine::GetAddress(u32 value) {
|
|
|
|
// Returns static address used by ppsspp. Some games may not like this, and causes cheats to not work without offset
|
|
|
|
u32 address = (value + 0x08800000) & 0x3FFFFFFF;
|
2013-06-18 22:50:28 +00:00
|
|
|
return address;
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
std::vector<CheatFileInfo> CWCheatEngine::FileInfo() {
|
2020-04-11 20:52:25 +00:00
|
|
|
CheatFileParser parser(filename_, gameID_);
|
2017-11-08 03:51:32 +00:00
|
|
|
|
2020-04-11 19:43:55 +00:00
|
|
|
parser.Parse();
|
|
|
|
return parser.GetFileInfo();
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 22:26:25 +00:00
|
|
|
void CWCheatEngine::InvalidateICache(u32 addr, int size) {
|
2022-12-04 03:26:32 +00:00
|
|
|
// Round start down and size up to the nearest word.
|
|
|
|
u32 aligned = addr & ~3;
|
|
|
|
int alignedSize = (addr + size - aligned + 3) & ~3;
|
|
|
|
currentMIPS->InvalidateICache(aligned, alignedSize);
|
2015-02-02 22:26:25 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
enum class CheatOp {
|
|
|
|
Invalid,
|
|
|
|
Noop,
|
2013-05-18 22:04:01 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
Write,
|
|
|
|
Add,
|
|
|
|
Subtract,
|
|
|
|
Or,
|
|
|
|
And,
|
|
|
|
Xor,
|
2013-05-18 04:49:44 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
MultiWrite,
|
2013-08-14 02:24:35 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
CopyBytesFrom,
|
2020-04-12 13:08:46 +00:00
|
|
|
Vibration,
|
|
|
|
VibrationFromMemory,
|
2020-05-16 20:01:16 +00:00
|
|
|
PostShader,
|
2020-05-16 22:13:11 +00:00
|
|
|
PostShaderFromMemory,
|
2017-11-08 03:51:32 +00:00
|
|
|
Delay,
|
2013-05-18 22:04:01 +00:00
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
Assert,
|
|
|
|
|
|
|
|
IfEqual,
|
|
|
|
IfNotEqual,
|
|
|
|
IfLess,
|
|
|
|
IfGreater,
|
|
|
|
|
|
|
|
IfAddrEqual,
|
|
|
|
IfAddrNotEqual,
|
|
|
|
IfAddrLess,
|
|
|
|
IfAddrGreater,
|
|
|
|
|
|
|
|
IfPressed,
|
|
|
|
IfNotPressed,
|
|
|
|
|
|
|
|
CwCheatPointerCommands,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CheatOperation {
|
|
|
|
CheatOp op;
|
|
|
|
uint32_t addr;
|
|
|
|
int sz;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint32_t count;
|
|
|
|
uint32_t step;
|
|
|
|
uint32_t add;
|
|
|
|
} multiWrite;
|
|
|
|
struct {
|
|
|
|
uint32_t destAddr;
|
|
|
|
} copyBytesFrom;
|
|
|
|
struct {
|
|
|
|
uint32_t skip;
|
|
|
|
} ifTypes;
|
|
|
|
struct {
|
|
|
|
uint32_t skip;
|
|
|
|
uint32_t compareAddr;
|
|
|
|
} ifAddrTypes;
|
|
|
|
struct {
|
|
|
|
int offset;
|
|
|
|
int baseOffset;
|
|
|
|
int count;
|
|
|
|
int type;
|
|
|
|
} pointerCommands;
|
2020-04-12 13:08:46 +00:00
|
|
|
struct {
|
|
|
|
uint16_t vibrL;
|
|
|
|
uint16_t vibrR;
|
|
|
|
uint8_t vibrLTime;
|
|
|
|
uint8_t vibrRTime;
|
|
|
|
} vibrationValues;
|
2020-05-16 20:01:16 +00:00
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
float f;
|
2020-05-17 17:06:23 +00:00
|
|
|
uint32_t u;
|
2020-05-16 20:01:16 +00:00
|
|
|
} value;
|
2020-05-17 17:06:23 +00:00
|
|
|
uint8_t shader;
|
2020-05-16 20:01:16 +00:00
|
|
|
uint8_t uniform;
|
2020-05-16 22:13:11 +00:00
|
|
|
uint8_t format;
|
2020-05-16 20:01:16 +00:00
|
|
|
} PostShaderUniform;
|
2017-11-08 03:51:32 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
CheatOperation CWCheatEngine::InterpretNextCwCheat(const CheatCode &cheat, size_t &i) {
|
|
|
|
const CheatLine &line1 = cheat.lines[i++];
|
|
|
|
const uint32_t &arg = line1.part2;
|
|
|
|
|
|
|
|
// Filled as needed.
|
|
|
|
u32 addr;
|
|
|
|
|
|
|
|
int type = line1.part1 >> 28;
|
|
|
|
switch (type) {
|
|
|
|
case 0x0: // Write 8-bit data (up to 4 bytes.)
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
if (arg & 0xFFFF0000)
|
|
|
|
return { CheatOp::Write, addr, 4, arg };
|
|
|
|
else if (arg & 0x0000FF00)
|
|
|
|
return { CheatOp::Write, addr, 2, arg };
|
|
|
|
else
|
|
|
|
return { CheatOp::Write, addr, 1, arg };
|
|
|
|
|
|
|
|
case 0x1: // Write 16-bit data.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
return { CheatOp::Write, addr, 2, arg };
|
|
|
|
|
|
|
|
case 0x2: // Write 32-bit data.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
return { CheatOp::Write, addr, 4, arg };
|
|
|
|
|
|
|
|
case 0x3: // Increment/decrement data.
|
|
|
|
addr = GetAddress(arg & 0x0FFFFFFF);
|
|
|
|
switch ((line1.part1 >> 20) & 0xF) {
|
|
|
|
case 1:
|
|
|
|
return { CheatOp::Add, addr, 1, line1.part1 & 0xFF };
|
|
|
|
case 2:
|
|
|
|
return { CheatOp::Subtract, addr, 1, line1.part1 & 0xFF };
|
|
|
|
case 3:
|
|
|
|
return { CheatOp::Add, addr, 2, line1.part1 & 0xFFFF };
|
|
|
|
case 4:
|
|
|
|
return { CheatOp::Subtract, addr, 2, line1.part1 & 0xFFFF };
|
|
|
|
case 5:
|
|
|
|
if (i < cheat.lines.size())
|
|
|
|
return { CheatOp::Add, addr, 4, cheat.lines[i++].part1 };
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
case 6:
|
|
|
|
if (i < cheat.lines.size())
|
|
|
|
return { CheatOp::Subtract, addr, 4, cheat.lines[i++].part1 };
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4: // 32-bit multi-write patch data.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
if (i < cheat.lines.size()) {
|
|
|
|
const CheatLine &line2 = cheat.lines[i++];
|
|
|
|
|
|
|
|
CheatOperation op = { CheatOp::MultiWrite, addr, 4, line2.part1 };
|
|
|
|
op.multiWrite.count = arg >> 16;
|
|
|
|
op.multiWrite.step = (arg & 0xFFFF) * 4;
|
|
|
|
op.multiWrite.add = line2.part2;
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
|
|
|
case 0x5: // Memcpy command.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
if (i < cheat.lines.size()) {
|
|
|
|
const CheatLine &line2 = cheat.lines[i++];
|
|
|
|
|
|
|
|
CheatOperation op = { CheatOp::CopyBytesFrom, addr, 0, arg };
|
|
|
|
op.copyBytesFrom.destAddr = GetAddress(line2.part1 & 0x0FFFFFFF);
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
|
|
|
case 0x6: // Pointer commands.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
if (i < cheat.lines.size()) {
|
|
|
|
const CheatLine &line2 = cheat.lines[i++];
|
2017-11-09 06:24:05 +00:00
|
|
|
int count = (line2.part1 & 0xFFFF) - 1;
|
2017-11-08 03:51:32 +00:00
|
|
|
|
2017-11-09 06:24:05 +00:00
|
|
|
// Validate lines to process - make sure we stay inside cheat.lines.
|
2017-11-09 01:48:33 +00:00
|
|
|
if (i + count > cheat.lines.size())
|
2017-11-09 06:24:05 +00:00
|
|
|
return { CheatOp::Invalid };
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
CheatOperation op = { CheatOp::CwCheatPointerCommands, addr, 0, arg };
|
|
|
|
op.pointerCommands.offset = (int)line2.part2;
|
|
|
|
// TODO: Verify sign handling. Is this really supposed to sign extend?
|
|
|
|
op.pointerCommands.baseOffset = ((int)line2.part1 >> 20) * 4;
|
|
|
|
op.pointerCommands.count = count;
|
2017-11-08 16:39:22 +00:00
|
|
|
op.pointerCommands.type = (line2.part1 >> 16) & 0xF;
|
2017-11-08 03:51:32 +00:00
|
|
|
return op;
|
|
|
|
}
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
|
|
|
case 0x7: // Boolean data operations.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
switch (arg >> 16) {
|
|
|
|
case 0x0000: // 8-bit OR.
|
|
|
|
return { CheatOp::Or, addr, 1, arg & 0xFF };
|
|
|
|
case 0x0001: // 16-bit OR.
|
|
|
|
return { CheatOp::Or, addr, 2, arg & 0xFFFF };
|
|
|
|
case 0x0002: // 8-bit AND.
|
|
|
|
return { CheatOp::And, addr, 1, arg & 0xFF };
|
|
|
|
case 0x0003: // 16-bit AND.
|
|
|
|
return { CheatOp::And, addr, 2, arg & 0xFFFF };
|
|
|
|
case 0x0004: // 8-bit XOR.
|
|
|
|
return { CheatOp::Xor, addr, 1, arg & 0xFF };
|
|
|
|
case 0x0005: // 16-bit XOR.
|
|
|
|
return { CheatOp::Xor, addr, 2, arg & 0xFFFF };
|
|
|
|
}
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
|
|
|
case 0x8: // 8-bit or 16-bit multi-write patch data.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
if (i < cheat.lines.size()) {
|
|
|
|
const CheatLine &line2 = cheat.lines[i++];
|
|
|
|
const bool is8Bit = (line2.part1 & 0xFFFF0000) == 0;
|
|
|
|
const uint32_t val = is8Bit ? (line2.part1 & 0xFF) : (line2.part1 & 0xFFFF);
|
|
|
|
|
|
|
|
CheatOperation op = { CheatOp::MultiWrite, addr, is8Bit ? 1 : 2, val };
|
|
|
|
op.multiWrite.count = arg >> 16;
|
|
|
|
op.multiWrite.step = (arg & 0xFFFF) * (is8Bit ? 1 : 2);
|
|
|
|
op.multiWrite.add = line2.part2;
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
2020-04-12 13:08:46 +00:00
|
|
|
case 0xA: // PPSSPP specific cheats
|
|
|
|
switch (line1.part1 >> 24 & 0xF) {
|
|
|
|
case 0x0: // 0x0 sets gamepad vibration by cheat parameters
|
|
|
|
{
|
|
|
|
CheatOperation op = { CheatOp::Vibration };
|
|
|
|
op.vibrationValues.vibrL = line1.part1 & 0x0000FFFF;
|
|
|
|
op.vibrationValues.vibrR = line1.part2 & 0x0000FFFF;
|
|
|
|
op.vibrationValues.vibrLTime = (line1.part1 >> 16) & 0x000000FF;
|
|
|
|
op.vibrationValues.vibrRTime = (line1.part2 >> 16) & 0x000000FF;
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
case 0x1: // 0x1 reads value for gamepad vibration from memory
|
|
|
|
addr = line1.part2;
|
|
|
|
return { CheatOp::VibrationFromMemory, addr };
|
2020-05-16 20:01:16 +00:00
|
|
|
case 0x2: // 0x2 sets postprocessing shader uniform
|
|
|
|
{
|
|
|
|
CheatOperation op = { CheatOp::PostShader };
|
|
|
|
op.PostShaderUniform.uniform = line1.part1 & 0x000000FF;
|
2020-05-17 17:06:23 +00:00
|
|
|
op.PostShaderUniform.shader = (line1.part1 >> 16) & 0x000000FF;
|
|
|
|
op.PostShaderUniform.value.u = line1.part2;
|
2020-05-16 20:01:16 +00:00
|
|
|
return op;
|
|
|
|
}
|
2020-05-16 22:13:11 +00:00
|
|
|
case 0x3: // 0x3 sets postprocessing shader uniform from memory
|
|
|
|
{
|
|
|
|
addr = line1.part2;
|
|
|
|
CheatOperation op = { CheatOp::PostShaderFromMemory, addr };
|
|
|
|
op.PostShaderUniform.uniform = line1.part1 & 0x000000FF;
|
|
|
|
op.PostShaderUniform.format = (line1.part1 >> 8) & 0x000000FF;
|
2020-05-17 17:06:23 +00:00
|
|
|
op.PostShaderUniform.shader = (line1.part1 >> 16) & 0x000000FF;
|
2020-05-16 22:13:11 +00:00
|
|
|
return op;
|
|
|
|
}
|
2020-04-12 13:08:46 +00:00
|
|
|
// Place for other PPSSPP specific cheats
|
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0xB: // Delay command.
|
|
|
|
return { CheatOp::Delay, 0, 0, arg };
|
|
|
|
|
|
|
|
case 0xC: // 32-bit equal check / code stopper.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
return { CheatOp::Assert, addr, 4, arg };
|
|
|
|
|
|
|
|
case 0xD: // Line skip tests & joker codes.
|
|
|
|
switch (arg >> 28) {
|
|
|
|
case 0x0: // 16-bit next line skip test.
|
|
|
|
case 0x2: // 8-bit next line skip test.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
{
|
|
|
|
const bool is8Bit = (arg >> 28) == 0x2;
|
|
|
|
const uint32_t val = is8Bit ? (arg & 0xFF) : (arg & 0xFFFF);
|
|
|
|
|
|
|
|
CheatOp opcode;
|
|
|
|
switch ((arg >> 20) & 0xF) {
|
|
|
|
case 0x0:
|
|
|
|
opcode = CheatOp::IfEqual;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x1:
|
|
|
|
opcode = CheatOp::IfNotEqual;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x2:
|
|
|
|
opcode = CheatOp::IfLess;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x3:
|
|
|
|
opcode = CheatOp::IfGreater;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
|
|
|
|
CheatOperation op = { opcode, addr, is8Bit ? 1 : 2, val };
|
|
|
|
op.ifTypes.skip = 1;
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x1: // Joker code - button pressed.
|
|
|
|
case 0x3: // Inverse joker code - button not pressed.
|
|
|
|
{
|
|
|
|
bool pressed = (arg >> 28) == 0x1;
|
|
|
|
CheatOperation op = { pressed ? CheatOp::IfPressed : CheatOp::IfNotPressed, 0, 0, arg & 0x0FFFFFFF };
|
|
|
|
op.ifTypes.skip = (line1.part1 & 0xFF) + 1;
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x4: // Adress equal test.
|
|
|
|
case 0x5: // Address not equal test.
|
|
|
|
case 0x6: // Address less than test.
|
|
|
|
case 0x7: // Address greater than test.
|
|
|
|
addr = GetAddress(line1.part1 & 0x0FFFFFFF);
|
|
|
|
if (i < cheat.lines.size()) {
|
|
|
|
const CheatLine &line2 = cheat.lines[i++];
|
|
|
|
const int sz = 1 << (line2.part2 & 0xF);
|
|
|
|
|
|
|
|
CheatOp opcode;
|
|
|
|
switch (arg >> 28) {
|
|
|
|
case 0x4:
|
|
|
|
opcode = CheatOp::IfAddrEqual;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x5:
|
|
|
|
opcode = CheatOp::IfAddrNotEqual;
|
|
|
|
break;
|
|
|
|
case 0x6:
|
|
|
|
opcode = CheatOp::IfAddrLess;
|
|
|
|
break;
|
|
|
|
case 0x7:
|
|
|
|
opcode = CheatOp::IfAddrGreater;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
CheatOperation op = { opcode, addr, sz, 0 };
|
|
|
|
op.ifAddrTypes.skip = line2.part1;
|
|
|
|
op.ifAddrTypes.compareAddr = GetAddress(arg & 0x0FFFFFFF);
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
|
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0xE: // Multiple line skip tests.
|
|
|
|
addr = GetAddress(arg & 0x0FFFFFFF);
|
|
|
|
{
|
|
|
|
const bool is8Bit = (line1.part1 >> 24) == 0xE1;
|
|
|
|
const uint32_t val = is8Bit ? (line1.part1 & 0xFF) : (line1.part1 & 0xFFFF);
|
|
|
|
|
|
|
|
CheatOp opcode;
|
|
|
|
switch (arg >> 28) {
|
|
|
|
case 0x0:
|
|
|
|
opcode = CheatOp::IfEqual;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x1:
|
|
|
|
opcode = CheatOp::IfNotEqual;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x2:
|
|
|
|
opcode = CheatOp::IfLess;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
case 0x3:
|
|
|
|
opcode = CheatOp::IfGreater;
|
2013-05-18 04:49:44 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
|
|
|
|
CheatOperation op = { opcode, addr, is8Bit ? 1 : 2, val };
|
|
|
|
op.ifTypes.skip = (line1.part1 >> 16) & (is8Bit ? 0xFF : 0xFFF);
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CheatOperation CWCheatEngine::InterpretNextTempAR(const CheatCode &cheat, size_t &i) {
|
|
|
|
// TODO
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
|
|
|
|
|
|
|
CheatOperation CWCheatEngine::InterpretNextOp(const CheatCode &cheat, size_t &i) {
|
|
|
|
if (cheat.fmt == CheatCodeFormat::CWCHEAT)
|
|
|
|
return InterpretNextCwCheat(cheat, i);
|
|
|
|
else if (cheat.fmt == CheatCodeFormat::TEMPAR)
|
|
|
|
return InterpretNextTempAR(cheat, i);
|
2021-02-13 17:35:08 +00:00
|
|
|
else {
|
|
|
|
// This shouldn't happen, but apparently does: #14082
|
|
|
|
// Either I'm missing a path or we have memory corruption.
|
|
|
|
// Not sure whether to log here though, feels like we could end up with a
|
|
|
|
// ton of logspam...
|
|
|
|
return { CheatOp::Invalid };
|
|
|
|
}
|
2017-11-08 03:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWCheatEngine::ApplyMemoryOperator(const CheatOperation &op, uint32_t(*oper)(uint32_t, uint32_t)) {
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, op.sz)) {
|
|
|
|
InvalidateICache(op.addr, op.sz);
|
2017-11-08 03:51:32 +00:00
|
|
|
if (op.sz == 1)
|
|
|
|
Memory::Write_U8((u8)oper(Memory::Read_U8(op.addr), op.val), op.addr);
|
|
|
|
else if (op.sz == 2)
|
|
|
|
Memory::Write_U16((u16)oper(Memory::Read_U16(op.addr), op.val),op. addr);
|
|
|
|
else if (op.sz == 4)
|
|
|
|
Memory::Write_U32((u32)oper(Memory::Read_U32(op.addr), op.val), op.addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CWCheatEngine::TestIf(const CheatOperation &op, bool(*oper)(int, int)) {
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, op.sz)) {
|
|
|
|
InvalidateICache(op.addr, op.sz);
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
int memoryValue = 0;
|
|
|
|
if (op.sz == 1)
|
|
|
|
memoryValue = (int)Memory::Read_U8(op.addr);
|
|
|
|
else if (op.sz == 2)
|
|
|
|
memoryValue = (int)Memory::Read_U16(op.addr);
|
|
|
|
else if (op.sz == 4)
|
|
|
|
memoryValue = (int)Memory::Read_U32(op.addr);
|
|
|
|
|
|
|
|
return oper(memoryValue, (int)op.val);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CWCheatEngine::TestIfAddr(const CheatOperation &op, bool(*oper)(int, int)) {
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, op.sz) && Memory::IsValidRange(op.ifAddrTypes.compareAddr, op.sz)) {
|
|
|
|
InvalidateICache(op.addr, op.sz);
|
|
|
|
InvalidateICache(op.addr, op.ifAddrTypes.compareAddr);
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
int memoryValue1 = 0;
|
|
|
|
int memoryValue2 = 0;
|
|
|
|
if (op.sz == 1) {
|
|
|
|
memoryValue1 = (int)Memory::Read_U8(op.addr);
|
|
|
|
memoryValue2 = (int)Memory::Read_U8(op.ifAddrTypes.compareAddr);
|
|
|
|
} else if (op.sz == 2) {
|
|
|
|
memoryValue1 = (int)Memory::Read_U16(op.addr);
|
|
|
|
memoryValue2 = (int)Memory::Read_U16(op.ifAddrTypes.compareAddr);
|
|
|
|
} else if (op.sz == 4) {
|
|
|
|
memoryValue1 = (int)Memory::Read_U32(op.addr);
|
|
|
|
memoryValue2 = (int)Memory::Read_U32(op.ifAddrTypes.compareAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return oper(memoryValue1, memoryValue2);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, size_t &i) {
|
|
|
|
switch (op.op) {
|
|
|
|
case CheatOp::Invalid:
|
|
|
|
i = cheat.lines.size();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Noop:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Write:
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, op.sz)) {
|
|
|
|
InvalidateICache(op.addr, op.sz);
|
2017-11-08 03:51:32 +00:00
|
|
|
if (op.sz == 1)
|
|
|
|
Memory::Write_U8((u8)op.val, op.addr);
|
|
|
|
else if (op.sz == 2)
|
|
|
|
Memory::Write_U16((u16)op.val, op.addr);
|
|
|
|
else if (op.sz == 4)
|
|
|
|
Memory::Write_U32((u32)op.val, op.addr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Add:
|
|
|
|
ApplyMemoryOperator(op, [](uint32_t a, uint32_t b) {
|
|
|
|
return a + b;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Subtract:
|
|
|
|
ApplyMemoryOperator(op, [](uint32_t a, uint32_t b) {
|
|
|
|
return a - b;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Or:
|
|
|
|
ApplyMemoryOperator(op, [](uint32_t a, uint32_t b) {
|
|
|
|
return a | b;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::And:
|
|
|
|
ApplyMemoryOperator(op, [](uint32_t a, uint32_t b) {
|
|
|
|
return a & b;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Xor:
|
|
|
|
ApplyMemoryOperator(op, [](uint32_t a, uint32_t b) {
|
|
|
|
return a ^ b;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::MultiWrite:
|
|
|
|
if (Memory::IsValidAddress(op.addr)) {
|
|
|
|
InvalidateICache(op.addr, op.multiWrite.count * op.multiWrite.step + op.sz);
|
|
|
|
|
|
|
|
uint32_t data = op.val;
|
|
|
|
uint32_t addr = op.addr;
|
|
|
|
for (uint32_t a = 0; a < op.multiWrite.count; a++) {
|
|
|
|
if (Memory::IsValidAddress(addr)) {
|
|
|
|
if (op.sz == 1)
|
|
|
|
Memory::Write_U8((u8)data, addr);
|
|
|
|
else if (op.sz == 2)
|
|
|
|
Memory::Write_U16((u16)data, addr);
|
|
|
|
else if (op.sz == 4)
|
|
|
|
Memory::Write_U32((u32)data, addr);
|
|
|
|
}
|
|
|
|
addr += op.multiWrite.step;
|
|
|
|
data += op.multiWrite.add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::CopyBytesFrom:
|
|
|
|
if (Memory::IsValidRange(op.addr, op.val) && Memory::IsValidRange(op.copyBytesFrom.destAddr, op.val)) {
|
|
|
|
InvalidateICache(op.addr, op.val);
|
|
|
|
InvalidateICache(op.copyBytesFrom.destAddr, op.val);
|
|
|
|
|
2021-02-03 08:09:21 +00:00
|
|
|
Memory::Memcpy(op.copyBytesFrom.destAddr, op.addr, op.val, "CwCheat");
|
2017-11-08 03:51:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-12 13:08:46 +00:00
|
|
|
case CheatOp::Vibration:
|
|
|
|
if (op.vibrationValues.vibrL > 0) {
|
|
|
|
SetLeftVibration(op.vibrationValues.vibrL);
|
|
|
|
SetVibrationLeftDropout(op.vibrationValues.vibrLTime);
|
|
|
|
}
|
|
|
|
if (op.vibrationValues.vibrR > 0) {
|
|
|
|
SetRightVibration(op.vibrationValues.vibrR);
|
|
|
|
SetVibrationRightDropout(op.vibrationValues.vibrRTime);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::VibrationFromMemory:
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, 8)) {
|
2020-04-12 13:08:46 +00:00
|
|
|
uint16_t checkLeftVibration = Memory::Read_U16(op.addr);
|
|
|
|
uint16_t checkRightVibration = Memory::Read_U16(op.addr + 0x2);
|
|
|
|
if (checkLeftVibration > 0) {
|
|
|
|
SetLeftVibration(checkLeftVibration);
|
|
|
|
SetVibrationLeftDropout(Memory::Read_U8(op.addr + 0x4));
|
|
|
|
}
|
|
|
|
if (checkRightVibration > 0) {
|
|
|
|
SetRightVibration(checkRightVibration);
|
|
|
|
SetVibrationRightDropout(Memory::Read_U8(op.addr + 0x6));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-05-16 20:01:16 +00:00
|
|
|
case CheatOp::PostShader:
|
2020-05-17 17:06:23 +00:00
|
|
|
{
|
2020-05-18 09:17:45 +00:00
|
|
|
auto shaderChain = GetFullPostShadersChain(g_Config.vPostShaderNames);
|
2020-05-17 17:06:23 +00:00
|
|
|
if (op.PostShaderUniform.shader < shaderChain.size()) {
|
|
|
|
std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section;
|
2022-12-13 03:11:20 +00:00
|
|
|
g_Config.mPostShaderSetting[StringFromFormat("%sSettingCurrentValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f;
|
2020-05-17 17:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-16 20:01:16 +00:00
|
|
|
break;
|
|
|
|
|
2020-05-16 22:13:11 +00:00
|
|
|
case CheatOp::PostShaderFromMemory:
|
2020-05-17 17:06:23 +00:00
|
|
|
{
|
2020-05-18 09:17:45 +00:00
|
|
|
auto shaderChain = GetFullPostShadersChain(g_Config.vPostShaderNames);
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, 4) && op.PostShaderUniform.shader < shaderChain.size()) {
|
2020-05-17 17:06:23 +00:00
|
|
|
union {
|
|
|
|
float f;
|
|
|
|
uint32_t u;
|
|
|
|
} value;
|
|
|
|
value.u = Memory::Read_U32(op.addr);
|
|
|
|
std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section;
|
2021-04-11 01:35:23 +00:00
|
|
|
switch (op.PostShaderUniform.format) {
|
|
|
|
case 0:
|
2022-12-13 03:11:20 +00:00
|
|
|
g_Config.mPostShaderSetting[StringFromFormat("%sSettingCurrentValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF;
|
2021-04-11 01:35:23 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-12-13 03:11:20 +00:00
|
|
|
g_Config.mPostShaderSetting[StringFromFormat("%sSettingCurrentValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF;
|
2021-04-11 01:35:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-12-13 03:11:20 +00:00
|
|
|
g_Config.mPostShaderSetting[StringFromFormat("%sSettingCurrentValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u;
|
2021-04-11 01:35:23 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-12-13 03:11:20 +00:00
|
|
|
g_Config.mPostShaderSetting[StringFromFormat("%sSettingCurrentValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f;
|
2021-04-11 01:35:23 +00:00
|
|
|
break;
|
2020-05-17 17:06:23 +00:00
|
|
|
}
|
2020-05-16 22:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-11-08 03:51:32 +00:00
|
|
|
case CheatOp::Delay:
|
|
|
|
// TODO: Not supported.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::Assert:
|
2022-12-04 03:26:32 +00:00
|
|
|
if (Memory::IsValidRange(op.addr, 4)) {
|
2017-11-08 03:51:32 +00:00
|
|
|
InvalidateICache(op.addr, 4);
|
|
|
|
if (Memory::Read_U32(op.addr) != op.val) {
|
|
|
|
i = cheat.lines.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfEqual:
|
|
|
|
if (!TestIf(op, [](int a, int b) { return a == b; })) {
|
|
|
|
i += (size_t)op.ifTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfNotEqual:
|
|
|
|
if (!TestIf(op, [](int a, int b) { return a != b; })) {
|
|
|
|
i += (size_t)op.ifTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfLess:
|
|
|
|
if (!TestIf(op, [](int a, int b) { return a < b; })) {
|
|
|
|
i += (size_t)op.ifTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfGreater:
|
|
|
|
if (!TestIf(op, [](int a, int b) { return a > b; })) {
|
|
|
|
i += (size_t)op.ifTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfAddrEqual:
|
2018-07-07 13:45:56 +00:00
|
|
|
if (!TestIfAddr(op, [](int a, int b) { return a == b; })) {
|
2017-11-08 03:51:32 +00:00
|
|
|
i += (size_t)op.ifAddrTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfAddrNotEqual:
|
2018-07-07 13:45:56 +00:00
|
|
|
if (!TestIfAddr(op, [](int a, int b) { return a != b; })) {
|
2017-11-08 03:51:32 +00:00
|
|
|
i += (size_t)op.ifAddrTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfAddrLess:
|
2018-07-07 13:45:56 +00:00
|
|
|
if (!TestIfAddr(op, [](int a, int b) { return a < b; })) {
|
2017-11-08 03:51:32 +00:00
|
|
|
i += (size_t)op.ifAddrTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfAddrGreater:
|
2018-07-07 13:45:56 +00:00
|
|
|
if (!TestIfAddr(op, [](int a, int b) { return a > b; })) {
|
2017-11-08 03:51:32 +00:00
|
|
|
i += (size_t)op.ifAddrTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfPressed:
|
|
|
|
// Button Code
|
|
|
|
// SELECT 0x00000001
|
|
|
|
// START 0x00000008
|
|
|
|
// DPAD UP 0x00000010
|
|
|
|
// DPAD RIGHT 0x00000020
|
|
|
|
// DPAD DOWN 0x00000040
|
|
|
|
// DPAD LEFT 0x00000080
|
|
|
|
// L TRIGGER 0x00000100
|
|
|
|
// R TRIGGER 0x00000200
|
|
|
|
// TRIANGLE 0x00001000
|
|
|
|
// CIRCLE 0x00002000
|
|
|
|
// CROSS 0x00004000
|
|
|
|
// SQUARE 0x00008000
|
|
|
|
// HOME 0x00010000
|
|
|
|
// HOLD 0x00020000
|
|
|
|
// WLAN 0x00040000
|
|
|
|
// REMOTE HOLD 0x00080000
|
|
|
|
// VOLUME UP 0x00100000
|
|
|
|
// VOLUME DOWN 0x00200000
|
|
|
|
// SCREEN 0x00400000
|
|
|
|
// NOTE 0x00800000
|
|
|
|
if ((__CtrlPeekButtons() & op.val) != op.val) {
|
|
|
|
i += (size_t)op.ifTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::IfNotPressed:
|
|
|
|
if ((__CtrlPeekButtons() & op.val) == op.val) {
|
|
|
|
i += (size_t)op.ifTypes.skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CheatOp::CwCheatPointerCommands:
|
|
|
|
{
|
|
|
|
InvalidateICache(op.addr + op.pointerCommands.baseOffset, 4);
|
|
|
|
u32 base = Memory::Read_U32(op.addr + op.pointerCommands.baseOffset);
|
|
|
|
u32 val = op.val;
|
|
|
|
int type = op.pointerCommands.type;
|
2017-11-09 06:24:05 +00:00
|
|
|
for (int a = 0; a < op.pointerCommands.count; ++a) {
|
2017-11-08 03:51:32 +00:00
|
|
|
const CheatLine &line = cheat.lines[i++];
|
|
|
|
switch (line.part1 >> 28) {
|
|
|
|
case 0x1: // type copy byte
|
|
|
|
{
|
|
|
|
InvalidateICache(op.addr, 4);
|
|
|
|
u32 srcAddr = Memory::Read_U32(op.addr) + op.pointerCommands.offset;
|
|
|
|
u32 dstAddr = Memory::Read_U32(op.addr + op.pointerCommands.baseOffset) + (line.part1 & 0x0FFFFFFF);
|
|
|
|
if (Memory::IsValidRange(dstAddr, val) && Memory::IsValidRange(srcAddr, val)) {
|
|
|
|
InvalidateICache(dstAddr, val);
|
|
|
|
InvalidateICache(srcAddr, val);
|
2021-02-03 08:09:21 +00:00
|
|
|
Memory::Memcpy(dstAddr, srcAddr, val, "CwCheat");
|
2014-06-26 02:23:56 +00:00
|
|
|
}
|
2017-11-08 03:51:32 +00:00
|
|
|
// Don't perform any further action.
|
|
|
|
type = -1;
|
2014-06-26 02:23:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
case 0x2:
|
|
|
|
case 0x3: // type pointer walk
|
|
|
|
{
|
|
|
|
int walkOffset = (int)line.part1 & 0x0FFFFFFF;
|
|
|
|
if ((line.part1 >> 28) == 0x3) {
|
|
|
|
walkOffset = -walkOffset;
|
2014-06-26 02:23:56 +00:00
|
|
|
}
|
2017-11-08 03:51:32 +00:00
|
|
|
InvalidateICache(base + walkOffset, 4);
|
|
|
|
base = Memory::Read_U32(base + walkOffset);
|
|
|
|
switch (line.part2 >> 28) {
|
|
|
|
case 0x2:
|
|
|
|
case 0x3: // type pointer walk
|
|
|
|
walkOffset = line.part2 & 0x0FFFFFFF;
|
|
|
|
if ((line.part2 >> 28) == 0x3) {
|
|
|
|
walkOffset = -walkOffset;
|
|
|
|
}
|
|
|
|
InvalidateICache(base + walkOffset, 4);
|
|
|
|
base = Memory::Read_U32(base + walkOffset);
|
2013-05-18 22:04:01 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// Unexpected value in cheat line?
|
2013-05-18 22:04:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-18 04:49:44 +00:00
|
|
|
}
|
2013-05-18 22:04:01 +00:00
|
|
|
break;
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
case 0x9: // type multi address write
|
|
|
|
base += line.part1 & 0x0FFFFFFF;
|
|
|
|
val += line.part2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Unexpected value in cheat line?
|
2013-08-30 00:08:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-18 22:04:01 +00:00
|
|
|
}
|
2017-11-08 03:51:32 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 0: // 8 bit write
|
2022-12-04 03:26:32 +00:00
|
|
|
InvalidateICache(base + op.pointerCommands.offset, 1);
|
2017-11-08 03:51:32 +00:00
|
|
|
Memory::Write_U8((u8)val, base + op.pointerCommands.offset);
|
|
|
|
break;
|
|
|
|
case 1: // 16-bit write
|
2022-12-04 03:26:32 +00:00
|
|
|
InvalidateICache(base + op.pointerCommands.offset, 2);
|
2017-11-08 03:51:32 +00:00
|
|
|
Memory::Write_U16((u16)val, base + op.pointerCommands.offset);
|
|
|
|
break;
|
|
|
|
case 2: // 32-bit write
|
|
|
|
InvalidateICache(base + op.pointerCommands.offset, 4);
|
|
|
|
Memory::Write_U32((u32)val, base + op.pointerCommands.offset);
|
|
|
|
break;
|
|
|
|
case 3: // 8 bit inverse write
|
2022-12-04 03:26:32 +00:00
|
|
|
InvalidateICache(base - op.pointerCommands.offset, 1);
|
2017-11-08 03:51:32 +00:00
|
|
|
Memory::Write_U8((u8)val, base - op.pointerCommands.offset);
|
|
|
|
break;
|
|
|
|
case 4: // 16-bit inverse write
|
2022-12-04 03:26:32 +00:00
|
|
|
InvalidateICache(base - op.pointerCommands.offset, 2);
|
2017-11-08 03:51:32 +00:00
|
|
|
Memory::Write_U16((u16)val, base - op.pointerCommands.offset);
|
|
|
|
break;
|
|
|
|
case 5: // 32-bit inverse write
|
|
|
|
InvalidateICache(base - op.pointerCommands.offset, 4);
|
|
|
|
Memory::Write_U32((u32)val, base - op.pointerCommands.offset);
|
|
|
|
break;
|
|
|
|
case -1: // Operation already performed, nothing to do
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-08-15 22:38:55 +00:00
|
|
|
_assert_(false);
|
2017-11-08 03:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWCheatEngine::Run() {
|
|
|
|
for (CheatCode cheat : cheats_) {
|
|
|
|
// InterpretNextOp and ExecuteOp move i.
|
|
|
|
for (size_t i = 0; i < cheat.lines.size(); ) {
|
|
|
|
CheatOperation op = InterpretNextOp(cheat, i);
|
|
|
|
ExecuteOp(op, cheat, i);
|
2013-05-18 22:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-18 04:49:44 +00:00
|
|
|
|
2014-02-15 23:28:13 +00:00
|
|
|
bool CWCheatEngine::HasCheats() {
|
2017-11-08 03:51:32 +00:00
|
|
|
return !cheats_.empty();
|
2014-02-15 23:28:13 +00:00
|
|
|
}
|
2013-05-18 04:49:44 +00:00
|
|
|
|
2014-02-15 23:28:13 +00:00
|
|
|
bool CheatsInEffect() {
|
|
|
|
if (!cheatEngine || !cheatsEnabled)
|
|
|
|
return false;
|
|
|
|
return cheatEngine->HasCheats();
|
|
|
|
}
|
2013-05-16 20:43:06 +00:00
|
|
|
|