2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-05-30 23:35:03 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
2020-07-15 23:14:21 +00:00
|
|
|
#include <chrono>
|
2019-11-27 02:48:56 +00:00
|
|
|
#include <memory>
|
2019-05-30 23:35:03 +00:00
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/memory/dmnt_cheat_types.h"
|
|
|
|
#include "core/memory/dmnt_cheat_vm.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Core::Timing {
|
|
|
|
class CoreTiming;
|
|
|
|
struct EventType;
|
|
|
|
} // namespace Core::Timing
|
|
|
|
|
2020-03-31 19:10:44 +00:00
|
|
|
namespace Core::Memory {
|
2019-05-30 23:35:03 +00:00
|
|
|
|
|
|
|
class StandardVmCallbacks : public DmntCheatVm::Callbacks {
|
|
|
|
public:
|
2021-05-16 05:46:30 +00:00
|
|
|
StandardVmCallbacks(System& system_, const CheatProcessMetadata& metadata_);
|
2019-05-30 23:35:03 +00:00
|
|
|
~StandardVmCallbacks() override;
|
|
|
|
|
|
|
|
void MemoryRead(VAddr address, void* data, u64 size) override;
|
|
|
|
void MemoryWrite(VAddr address, const void* data, u64 size) override;
|
|
|
|
u64 HidKeysDown() override;
|
|
|
|
void DebugLog(u8 id, u64 value) override;
|
|
|
|
void CommandLog(std::string_view data) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
VAddr SanitizeAddress(VAddr address) const;
|
|
|
|
|
|
|
|
const CheatProcessMetadata& metadata;
|
2021-05-16 05:46:30 +00:00
|
|
|
System& system;
|
2019-05-30 23:35:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Intermediary class that parses a text file or other disk format for storing cheats into a
|
|
|
|
// CheatList object, that can be used for execution.
|
|
|
|
class CheatParser {
|
|
|
|
public:
|
|
|
|
virtual ~CheatParser();
|
|
|
|
|
2020-09-15 07:13:22 +00:00
|
|
|
[[nodiscard]] virtual std::vector<CheatEntry> Parse(std::string_view data) const = 0;
|
2019-05-30 23:35:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CheatParser implementation that parses text files
|
|
|
|
class TextCheatParser final : public CheatParser {
|
|
|
|
public:
|
|
|
|
~TextCheatParser() override;
|
|
|
|
|
2020-09-15 07:13:22 +00:00
|
|
|
[[nodiscard]] std::vector<CheatEntry> Parse(std::string_view data) const override;
|
2019-05-30 23:35:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Class that encapsulates a CheatList and manages its interaction with memory and CoreTiming
|
|
|
|
class CheatEngine final {
|
|
|
|
public:
|
2021-05-16 05:46:30 +00:00
|
|
|
CheatEngine(System& system_, std::vector<CheatEntry> cheats_,
|
|
|
|
const std::array<u8, 0x20>& build_id_);
|
2019-05-30 23:35:03 +00:00
|
|
|
~CheatEngine();
|
|
|
|
|
|
|
|
void Initialize();
|
|
|
|
void SetMainMemoryParameters(VAddr main_region_begin, u64 main_region_size);
|
|
|
|
|
2021-05-03 02:14:15 +00:00
|
|
|
void Reload(std::vector<CheatEntry> reload_cheats);
|
2019-05-30 23:35:03 +00:00
|
|
|
|
|
|
|
private:
|
2020-07-27 23:00:41 +00:00
|
|
|
void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
2019-05-30 23:35:03 +00:00
|
|
|
|
|
|
|
DmntCheatVm vm;
|
|
|
|
CheatProcessMetadata metadata;
|
|
|
|
|
|
|
|
std::vector<CheatEntry> cheats;
|
|
|
|
std::atomic_bool is_pending_reload{false};
|
|
|
|
|
2019-11-27 02:48:56 +00:00
|
|
|
std::shared_ptr<Core::Timing::EventType> event;
|
2019-05-30 23:35:03 +00:00
|
|
|
Core::Timing::CoreTiming& core_timing;
|
|
|
|
Core::System& system;
|
|
|
|
};
|
|
|
|
|
2020-03-31 19:10:44 +00:00
|
|
|
} // namespace Core::Memory
|