GBA: Cheat set disabling
Jeffrey Pfau jeffrey@endrift.com
Sat, 14 Feb 2015 23:01:39 -0800
3 files changed,
21 insertions(+),
3 deletions(-)
M
src/gba/cheats.c
→
src/gba/cheats.c
@@ -424,6 +424,7 @@ set->name = strdup(name);
} else { set->name = 0; } + set->enabled = true; } void GBACheatSetDeinit(struct GBACheatSet* set) {@@ -693,6 +694,7 @@ char cheat[MAX_LINE_LENGTH];
struct GBACheatSet* set = 0; struct GBACheatSet* newSet; int gsaVersion = 0; + bool nextDisabled = false; while (true) { size_t i = 0; ssize_t bytesRead = vf->readline(vf, cheat, sizeof(cheat));@@ -712,6 +714,8 @@ ++i;
} while (isspace(cheat[i])); newSet = malloc(sizeof(*set)); GBACheatSetInit(newSet, &cheat[i]); + newSet->enabled = !nextDisabled; + nextDisabled = false; if (set) { GBACheatAddSet(device, set); newSet->gsaVersion = set->gsaVersion;@@ -732,12 +736,19 @@ } while (isspace(cheat[i]));
if (strncasecmp(&cheat[i], "GSAv", 4) == 0 || strncasecmp(&cheat[i], "PARv", 4) == 0) { i += 4; gsaVersion = atoi(&cheat[i]); + break; + } + if (strcasecmp(&cheat[i], "disabled") == 0) { + nextDisabled = true; + break; } break; default: if (!set) { set = malloc(sizeof(*set)); GBACheatSetInit(set, 0); + set->enabled = !nextDisabled; + nextDisabled = false; _setGameSharkVersion(set, gsaVersion); } GBACheatAddLine(set, cheat);@@ -779,6 +790,9 @@ return GBACheatAddAutodetect(cheats, op1, realOp2);
} void GBACheatRefresh(struct GBACheatDevice* device, struct GBACheatSet* cheats) { + if (!cheats->enabled) { + return; + } bool condition = true; int conditionRemaining = 0; _patchROM(device, cheats);
M
src/gba/cheats.h
→
src/gba/cheats.h
@@ -163,6 +163,7 @@ uint32_t gsaSeeds[4];
int remainingAddresses; char* name; + bool enabled; struct StringList lines; };
M
src/platform/qt/CheatsModel.cpp
→
src/platform/qt/CheatsModel.cpp
@@ -46,7 +46,7 @@ case Qt::DisplayRole:
case Qt::EditRole: return cheats->name ? cheats->name : tr("(untitled)"); case Qt::CheckStateRole: - return Qt::Checked; + return cheats->enabled ? Qt::Checked : Qt::Unchecked; default: return QVariant(); }@@ -67,9 +67,12 @@ free(cheats->name);
cheats->name = nullptr; } cheats->name = strdup(value.toString().toLocal8Bit().constData()); + emit dataChanged(index, index); return true; case Qt::CheckStateRole: - return false; + cheats->enabled = value == Qt::Checked; + emit dataChanged(index, index); + return true; default: return false; }@@ -108,7 +111,7 @@ if (index.parent().isValid()) {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } - return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; } int CheatsModel::columnCount(const QModelIndex& parent) const {