all repos — mgba @ 815e4d5b0d1983f47ac18d3a4b4d7d6bde9a0ce2

mGBA Game Boy Advance Emulator

Qt: Use latest cheat set for set properties
Jeffrey Pfau jeffrey@endrift.com
Sun, 22 Feb 2015 00:24:48 -0800
commit

815e4d5b0d1983f47ac18d3a4b4d7d6bde9a0ce2

parent

097feb0a554737d6429381b082fae9161dd0cb4b

3 files changed, 21 insertions(+), 6 deletions(-)

jump to
M src/gba/cheats.csrc/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.hsrc/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.cppsrc/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(); }