From 815e4d5b0d1983f47ac18d3a4b4d7d6bde9a0ce2 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 22 Feb 2015 00:24:48 -0800 Subject: [PATCH] Qt: Use latest cheat set for set properties --- src/gba/cheats.c | 22 ++++++++++++++++------ src/gba/cheats.h | 1 + src/platform/qt/CheatsModel.cpp | 4 ++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/gba/cheats.c b/src/gba/cheats.c index e7d71ea71..d5584d9d5 100644 --- a/src/gba/cheats.c +++ b/src/gba/cheats.c @@ -724,12 +724,7 @@ bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) { GBACheatAddSet(device, set); } if (set && !reset) { - newSet->gsaVersion = set->gsaVersion; - memcpy(newSet->gsaSeeds, set->gsaSeeds, sizeof(newSet->gsaSeeds)); - if (set->hook) { - newSet->hook = set->hook; - ++newSet->hook->refs; - } + GBACheatSetCopyProperties(newSet, set); } else { _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) { struct GBACheatDevice* device = (struct GBACheatDevice*) component; device->p = (struct GBA*) cpu->master; diff --git a/src/gba/cheats.h b/src/gba/cheats.h index 257791a1a..3acbcebeb 100644 --- a/src/gba/cheats.h +++ b/src/gba/cheats.h @@ -188,6 +188,7 @@ void GBACheatAttachDevice(struct GBA* gba, struct GBACheatDevice*); void GBACheatAddSet(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 GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line); diff --git a/src/platform/qt/CheatsModel.cpp b/src/platform/qt/CheatsModel.cpp index 227b5d02d..c5ba673f1 100644 --- a/src/platform/qt/CheatsModel.cpp +++ b/src/platform/qt/CheatsModel.cpp @@ -222,6 +222,10 @@ void CheatsModel::saveFile(const QString& path) { void CheatsModel::addSet(GBACheatSet* set) { 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); endInsertRows(); }