GBA: Cheat set disabling

This commit is contained in:
Jeffrey Pfau 2015-02-14 23:01:39 -08:00
parent ca6b2e7b09
commit 8c7d5b5b86
3 changed files with 21 additions and 3 deletions

View File

@ -424,6 +424,7 @@ void GBACheatSetInit(struct GBACheatSet* set, const char* name) {
} else { } else {
set->name = 0; set->name = 0;
} }
set->enabled = true;
} }
void GBACheatSetDeinit(struct GBACheatSet* set) { void GBACheatSetDeinit(struct GBACheatSet* set) {
@ -693,6 +694,7 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
struct GBACheatSet* set = 0; struct GBACheatSet* set = 0;
struct GBACheatSet* newSet; struct GBACheatSet* newSet;
int gsaVersion = 0; int gsaVersion = 0;
bool nextDisabled = false;
while (true) { while (true) {
size_t i = 0; size_t i = 0;
ssize_t bytesRead = vf->readline(vf, cheat, sizeof(cheat)); ssize_t bytesRead = vf->readline(vf, cheat, sizeof(cheat));
@ -712,6 +714,8 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
} while (isspace(cheat[i])); } while (isspace(cheat[i]));
newSet = malloc(sizeof(*set)); newSet = malloc(sizeof(*set));
GBACheatSetInit(newSet, &cheat[i]); GBACheatSetInit(newSet, &cheat[i]);
newSet->enabled = !nextDisabled;
nextDisabled = false;
if (set) { if (set) {
GBACheatAddSet(device, set); GBACheatAddSet(device, set);
newSet->gsaVersion = set->gsaVersion; newSet->gsaVersion = set->gsaVersion;
@ -732,12 +736,19 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
if (strncasecmp(&cheat[i], "GSAv", 4) == 0 || strncasecmp(&cheat[i], "PARv", 4) == 0) { if (strncasecmp(&cheat[i], "GSAv", 4) == 0 || strncasecmp(&cheat[i], "PARv", 4) == 0) {
i += 4; i += 4;
gsaVersion = atoi(&cheat[i]); gsaVersion = atoi(&cheat[i]);
break;
}
if (strcasecmp(&cheat[i], "disabled") == 0) {
nextDisabled = true;
break;
} }
break; break;
default: default:
if (!set) { if (!set) {
set = malloc(sizeof(*set)); set = malloc(sizeof(*set));
GBACheatSetInit(set, 0); GBACheatSetInit(set, 0);
set->enabled = !nextDisabled;
nextDisabled = false;
_setGameSharkVersion(set, gsaVersion); _setGameSharkVersion(set, gsaVersion);
} }
GBACheatAddLine(set, cheat); GBACheatAddLine(set, cheat);
@ -779,6 +790,9 @@ bool GBACheatAddLine(struct GBACheatSet* cheats, const char* line) {
} }
void GBACheatRefresh(struct GBACheatDevice* device, struct GBACheatSet* cheats) { void GBACheatRefresh(struct GBACheatDevice* device, struct GBACheatSet* cheats) {
if (!cheats->enabled) {
return;
}
bool condition = true; bool condition = true;
int conditionRemaining = 0; int conditionRemaining = 0;
_patchROM(device, cheats); _patchROM(device, cheats);

View File

@ -163,6 +163,7 @@ struct GBACheatSet {
int remainingAddresses; int remainingAddresses;
char* name; char* name;
bool enabled;
struct StringList lines; struct StringList lines;
}; };

View File

@ -46,7 +46,7 @@ QVariant CheatsModel::data(const QModelIndex& index, int role) const {
case Qt::EditRole: case Qt::EditRole:
return cheats->name ? cheats->name : tr("(untitled)"); return cheats->name ? cheats->name : tr("(untitled)");
case Qt::CheckStateRole: case Qt::CheckStateRole:
return Qt::Checked; return cheats->enabled ? Qt::Checked : Qt::Unchecked;
default: default:
return QVariant(); return QVariant();
} }
@ -67,9 +67,12 @@ bool CheatsModel::setData(const QModelIndex& index, const QVariant& value, int r
cheats->name = nullptr; cheats->name = nullptr;
} }
cheats->name = strdup(value.toString().toLocal8Bit().constData()); cheats->name = strdup(value.toString().toLocal8Bit().constData());
emit dataChanged(index, index);
return true; return true;
case Qt::CheckStateRole: case Qt::CheckStateRole:
return false; cheats->enabled = value == Qt::Checked;
emit dataChanged(index, index);
return true;
default: default:
return false; return false;
} }
@ -108,7 +111,7 @@ Qt::ItemFlags CheatsModel::flags(const QModelIndex &index) const {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 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 { int CheatsModel::columnCount(const QModelIndex& parent) const {