core/cheats: Add and change a few functions

Added a few interfaces for adding/deleting/replacing/saving cheats. The cheats list is guarded by a std::shared_mutex, and would only need a exclusive lock when it's being updated.

I marked the `Execute` function as `const` to avoid accidentally changing the internal state of the cheat on execution, so that execution can be considered a "read" operation which only needs a shared lock.

Whether a cheat is enabled or not is now saved by a special comment line `*citra_enabled`.
This commit is contained in:
zhupengfei
2019-01-30 23:03:44 +08:00
parent 2731437a17
commit 573036b38e
5 changed files with 117 additions and 16 deletions

View File

@@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <shared_mutex>
#include <vector>
#include "common/common_types.h"
@@ -25,12 +26,17 @@ class CheatEngine {
public:
explicit CheatEngine(Core::System& system);
~CheatEngine();
const std::vector<std::unique_ptr<CheatBase>>& GetCheats() const;
std::vector<std::shared_ptr<CheatBase>> GetCheats() const;
void AddCheat(const std::shared_ptr<CheatBase>& cheat);
void RemoveCheat(int index);
void UpdateCheat(int index, const std::shared_ptr<CheatBase>& new_cheat);
void SaveCheatFile() const;
private:
void LoadCheatFile();
void RunCallback(u64 userdata, int cycles_late);
std::vector<std::unique_ptr<CheatBase>> cheats_list;
std::vector<std::shared_ptr<CheatBase>> cheats_list;
mutable std::shared_mutex cheats_list_mutex;
Core::TimingEventType* event;
Core::System& system;
};