mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-30 03:10:19 +00:00
69665063a9
add per-cheat runtime toggles (thread-safe). add master code handling (master code cannot be disabled, as noted in Atmosphere's implementation). add configurable global / per-game initial states for cheat entries. remove fixed opcode limits and do some fixes to text parsing / file loading. do not run debug log while cheat logging is not enabled, to reduce performance impacts. update the `Using Cheats` document to reflect the changes. - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4334 Reviewed-by: lizzie <lizzie@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: John <john@eden-emu.dev>
105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#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 Kernel {
|
|
class KProcess;
|
|
}
|
|
|
|
namespace Core::Timing {
|
|
class CoreTiming;
|
|
struct EventType;
|
|
} // namespace Core::Timing
|
|
|
|
namespace Core::Memory {
|
|
|
|
class StandardVmCallbacks : public DmntCheatVm::Callbacks {
|
|
public:
|
|
StandardVmCallbacks(System& system_, const CheatProcessMetadata& metadata_);
|
|
~StandardVmCallbacks() override;
|
|
|
|
void MemoryReadUnsafe(VAddr address, void* data, u64 size) override;
|
|
void MemoryWriteUnsafe(VAddr address, const void* data, u64 size) override;
|
|
u64 HidKeysDown() override;
|
|
void PauseProcess() override;
|
|
void ResumeProcess() override;
|
|
void DebugLog(u8 id, u64 value) override;
|
|
void CommandLog(std::string_view data) override;
|
|
[[nodiscard]] bool IsCommandLogEnabled() const override;
|
|
|
|
private:
|
|
bool IsAddressInRange(VAddr address) const;
|
|
|
|
Kernel::KProcess* GetProcess() const;
|
|
|
|
const CheatProcessMetadata& metadata;
|
|
Core::System& system;
|
|
mutable Kernel::KProcess* cached_process{};
|
|
mutable u64 cached_process_id{};
|
|
};
|
|
|
|
// 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();
|
|
|
|
[[nodiscard]] virtual std::vector<CheatEntry> Parse(std::string_view data) const = 0;
|
|
};
|
|
|
|
// CheatParser implementation that parses text files
|
|
class TextCheatParser final : public CheatParser {
|
|
public:
|
|
~TextCheatParser() override;
|
|
|
|
[[nodiscard]] std::vector<CheatEntry> Parse(std::string_view data) const override;
|
|
};
|
|
|
|
// Class that encapsulates a CheatList and manages its interaction with memory and CoreTiming
|
|
class CheatEngine final {
|
|
public:
|
|
CheatEngine(System& system_, std::vector<CheatEntry> cheats_,
|
|
const std::array<u8, 0x20>& build_id_);
|
|
~CheatEngine();
|
|
|
|
void Initialize();
|
|
void SetMainMemoryParameters(VAddr main_region_begin, u64 main_region_size);
|
|
|
|
void Reload(std::vector<CheatEntry> reload_cheats);
|
|
[[nodiscard]] std::vector<RuntimeCheatInfo> GetCheats() const;
|
|
bool SetCheatEnabled(u32 cheat_id, bool enabled);
|
|
|
|
private:
|
|
void FrameCallback(std::chrono::nanoseconds ns_late);
|
|
|
|
DmntCheatVm vm;
|
|
CheatProcessMetadata metadata;
|
|
|
|
std::vector<CheatEntry> cheats;
|
|
mutable std::mutex cheats_mutex;
|
|
std::atomic_bool is_pending_reload{false};
|
|
|
|
std::shared_ptr<Core::Timing::EventType> event;
|
|
Core::Timing::CoreTiming& core_timing;
|
|
Core::System& system;
|
|
};
|
|
|
|
} // namespace Core::Memory
|