mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 07:10:00 -06:00
Allow AREngine
to be used independently of ARCodeFile
(#2108)
* Make `EmuInstance::cheatFile` use a `unique_ptr` - Fixes a memory leak, as the cheat file wasn't cleaned up in the destructor * Split `AREngine` and `ARCodeFile` apart - Suitable for frontends that have their own way of storing cheats - Store the cheats in `AREngine` in a `std::vector` - Apparently cheats are _supposed_ to be executed each frame; I didn't understand this until recently
This commit is contained in:
@ -686,12 +686,8 @@ void EmuInstance::undoStateLoad()
|
||||
|
||||
void EmuInstance::unloadCheats()
|
||||
{
|
||||
if (cheatFile)
|
||||
{
|
||||
delete cheatFile;
|
||||
cheatFile = nullptr;
|
||||
nds->AREngine.SetCodeFile(nullptr);
|
||||
}
|
||||
cheatFile = nullptr; // cleaned up by unique_ptr
|
||||
nds->AREngine.Cheats.clear();
|
||||
}
|
||||
|
||||
void EmuInstance::loadCheats()
|
||||
@ -701,9 +697,16 @@ void EmuInstance::loadCheats()
|
||||
std::string filename = getAssetPath(false, globalCfg.GetString("CheatFilePath"), ".mch");
|
||||
|
||||
// TODO: check for error (malformed cheat file, ...)
|
||||
cheatFile = new ARCodeFile(filename);
|
||||
cheatFile = std::make_unique<ARCodeFile>(filename);
|
||||
|
||||
nds->AREngine.SetCodeFile(cheatsOn ? cheatFile : nullptr);
|
||||
if (cheatsOn)
|
||||
{
|
||||
nds->AREngine.Cheats = cheatFile->GetCodes();
|
||||
}
|
||||
else
|
||||
{
|
||||
nds->AREngine.Cheats.clear();
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<ARM9BIOSImage> EmuInstance::loadARM9BIOS() noexcept
|
||||
@ -1013,12 +1016,14 @@ void EmuInstance::enableCheats(bool enable)
|
||||
{
|
||||
cheatsOn = enable;
|
||||
if (cheatFile)
|
||||
nds->AREngine.SetCodeFile(cheatsOn ? cheatFile : nullptr);
|
||||
nds->AREngine.Cheats = cheatFile->GetCodes();
|
||||
else
|
||||
nds->AREngine.Cheats.clear();
|
||||
}
|
||||
|
||||
ARCodeFile* EmuInstance::getCheatFile()
|
||||
{
|
||||
return cheatFile;
|
||||
return cheatFile.get();
|
||||
}
|
||||
|
||||
void EmuInstance::setBatteryLevels()
|
||||
|
@ -256,7 +256,7 @@ private:
|
||||
bool savestateLoaded;
|
||||
std::string previousSaveFile;
|
||||
|
||||
melonDS::ARCodeFile* cheatFile;
|
||||
std::unique_ptr<melonDS::ARCodeFile> cheatFile;
|
||||
bool cheatsOn;
|
||||
|
||||
SDL_AudioDeviceID audioDevice;
|
||||
|
Reference in New Issue
Block a user