Qt: Use latest cheat set for set properties

This commit is contained in:
Jeffrey Pfau 2015-02-22 00:24:48 -08:00
parent 097feb0a55
commit 815e4d5b0d
3 changed files with 21 additions and 6 deletions

View File

@ -724,12 +724,7 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) {
GBACheatAddSet(device, set); GBACheatAddSet(device, set);
} }
if (set && !reset) { if (set && !reset) {
newSet->gsaVersion = set->gsaVersion; GBACheatSetCopyProperties(newSet, set);
memcpy(newSet->gsaSeeds, set->gsaSeeds, sizeof(newSet->gsaSeeds));
if (set->hook) {
newSet->hook = set->hook;
++newSet->hook->refs;
}
} else { } else {
_setGameSharkVersion(newSet, gsaVersion); _setGameSharkVersion(newSet, gsaVersion);
} }
@ -935,6 +930,21 @@ void GBACheatRefresh(struct GBACheatDevice* device, struct GBACheatSet* cheats)
} }
} }
void GBACheatSetCopyProperties(struct GBACheatSet* newSet, struct GBACheatSet* set) {
newSet->gsaVersion = set->gsaVersion;
memcpy(newSet->gsaSeeds, set->gsaSeeds, sizeof(newSet->gsaSeeds));
if (set->hook) {
if (newSet->hook) {
--newSet->hook->refs;
if (newSet->hook->refs == 0) {
free(newSet->hook);
}
}
newSet->hook = set->hook;
++newSet->hook->refs;
}
}
void GBACheatDeviceInit(struct ARMCore* cpu, struct ARMComponent* component) { void GBACheatDeviceInit(struct ARMCore* cpu, struct ARMComponent* component) {
struct GBACheatDevice* device = (struct GBACheatDevice*) component; struct GBACheatDevice* device = (struct GBACheatDevice*) component;
device->p = (struct GBA*) cpu->master; device->p = (struct GBA*) cpu->master;

View File

@ -188,6 +188,7 @@ void GBACheatAttachDevice(struct GBA* gba, struct GBACheatDevice*);
void GBACheatAddSet(struct GBACheatDevice*, struct GBACheatSet*); void GBACheatAddSet(struct GBACheatDevice*, struct GBACheatSet*);
void GBACheatRemoveSet(struct GBACheatDevice*, struct GBACheatSet*); void GBACheatRemoveSet(struct GBACheatDevice*, struct GBACheatSet*);
void GBACheatSetCopyProperties(struct GBACheatSet* newSet, struct GBACheatSet* set);
bool GBACheatAddCodeBreaker(struct GBACheatSet*, uint32_t op1, uint16_t op2); bool GBACheatAddCodeBreaker(struct GBACheatSet*, uint32_t op1, uint16_t op2);
bool GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line); bool GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line);

View File

@ -222,6 +222,10 @@ void CheatsModel::saveFile(const QString& path) {
void CheatsModel::addSet(GBACheatSet* set) { void CheatsModel::addSet(GBACheatSet* set) {
beginInsertRows(QModelIndex(), GBACheatSetsSize(&m_device->cheats), GBACheatSetsSize(&m_device->cheats)); beginInsertRows(QModelIndex(), GBACheatSetsSize(&m_device->cheats), GBACheatSetsSize(&m_device->cheats));
size_t size = GBACheatSetsSize(&m_device->cheats);
if (size) {
GBACheatSetCopyProperties(set, *GBACheatSetsGetPointer(&m_device->cheats, size - 1));
}
GBACheatAddSet(m_device, set); GBACheatAddSet(m_device, set);
endInsertRows(); endInsertRows();
} }