File size: 1,655 Bytes
034d0a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <memory>
#include <optional>
#include <shared_mutex>
#include <span>
#include <vector>
#include "common/common_types.h"

namespace Core {
class System;
struct TimingEventType;
} // namespace Core

namespace CoreTiming {
struct EventType;
}

namespace Cheats {

class CheatBase;

class CheatEngine {
public:
    explicit CheatEngine(Core::System& system);
    ~CheatEngine();

    /// Registers the cheat execution callback.
    void Connect();

    /// Returns a span of the currently active cheats.
    std::span<const std::shared_ptr<CheatBase>> GetCheats() const;

    /// Adds a cheat to the cheat engine.
    void AddCheat(std::shared_ptr<CheatBase>&& cheat);

    /// Removes a cheat at the specified index in the cheats list.
    void RemoveCheat(std::size_t index);

    /// Updates a cheat at the specified index in the cheats list.
    void UpdateCheat(std::size_t index, std::shared_ptr<CheatBase>&& new_cheat);

    /// Loads the cheat file from disk for the specified title id.
    void LoadCheatFile(u64 title_id);

    /// Saves currently active cheats to file for the specified title id.
    void SaveCheatFile(u64 title_id) const;

private:
    /// The cheat execution callback.
    void RunCallback(std::uintptr_t user_data, s64 cycles_late);

private:
    Core::System& system;
    Core::TimingEventType* event;
    std::optional<u64> loaded_title_id;
    std::vector<std::shared_ptr<CheatBase>> cheats_list;
    mutable std::shared_mutex cheats_list_mutex;
};
} // namespace Cheats