Qt: Use latest cheat set for set properties
Jeffrey Pfau jeffrey@endrift.com
Sun, 22 Feb 2015 00:24:48 -0800
3 files changed,
21 insertions(+),
6 deletions(-)
M
src/gba/cheats.c
→
src/gba/cheats.c
@@ -724,12 +724,7 @@ if (set) {
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); }@@ -932,6 +927,21 @@
address += cheat->addressOffset; operand += cheat->operandOffset; } + } +} + +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; } }
M
src/gba/cheats.h
→
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);
M
src/platform/qt/CheatsModel.cpp
→
src/platform/qt/CheatsModel.cpp
@@ -222,6 +222,10 @@ }
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(); }