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

@ -50,12 +50,14 @@ public:
u32 value;
u32 first;
std::string cheat_line;
bool valid = true;
};
GatewayCheat(std::string name, std::vector<CheatLine> cheat_lines, std::string comments);
GatewayCheat(std::string name, std::string code, std::string comments);
~GatewayCheat();
void Execute(Core::System& system) override;
void Execute(Core::System& system) const override;
bool IsEnabled() const override;
void SetEnabled(bool enabled) override;
@ -63,6 +65,7 @@ public:
std::string GetComments() const override;
std::string GetName() const override;
std::string GetType() const override;
std::string GetCode() const override;
std::string ToString() const override;
/// Gateway cheats look like:
@ -77,7 +80,7 @@ public:
private:
std::atomic<bool> enabled = false;
const std::string name;
const std::vector<CheatLine> cheat_lines;
std::vector<CheatLine> cheat_lines;
const std::string comments;
};
} // namespace Cheats