2018-05-21 08:46:03 -06:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-05-21 08:46:03 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2023-02-12 03:07:11 -07:00
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
class CPUThreadGuard;
|
|
|
|
}
|
|
|
|
|
2018-05-21 08:46:03 -06:00
|
|
|
namespace Common::Debug
|
|
|
|
{
|
|
|
|
struct MemoryPatch
|
|
|
|
{
|
|
|
|
enum class State
|
|
|
|
{
|
|
|
|
Enabled,
|
|
|
|
Disabled
|
|
|
|
};
|
|
|
|
|
2022-12-22 16:38:08 -07:00
|
|
|
enum class ApplyType
|
|
|
|
{
|
|
|
|
Once,
|
|
|
|
EachFrame
|
|
|
|
};
|
|
|
|
|
2018-06-19 19:21:52 -06:00
|
|
|
MemoryPatch(u32 address_, std::vector<u8> value_);
|
|
|
|
MemoryPatch(u32 address_, u32 value_);
|
2018-05-29 16:03:12 -06:00
|
|
|
|
|
|
|
u32 address;
|
|
|
|
std::vector<u8> value;
|
|
|
|
State is_enabled = State::Enabled;
|
2022-12-22 16:38:08 -07:00
|
|
|
ApplyType type = ApplyType::Once;
|
2018-05-21 08:46:03 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class MemoryPatches
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MemoryPatches();
|
|
|
|
virtual ~MemoryPatches();
|
|
|
|
|
2023-02-12 03:07:11 -07:00
|
|
|
void SetPatch(const Core::CPUThreadGuard& guard, u32 address, u32 value);
|
|
|
|
void SetPatch(const Core::CPUThreadGuard& guard, u32 address, std::vector<u8> value);
|
|
|
|
void SetFramePatch(const Core::CPUThreadGuard& guard, u32 address, u32 value);
|
|
|
|
void SetFramePatch(const Core::CPUThreadGuard& guard, u32 address, std::vector<u8> value);
|
2018-05-21 08:46:03 -06:00
|
|
|
const std::vector<MemoryPatch>& GetPatches() const;
|
2023-02-12 03:07:11 -07:00
|
|
|
void UnsetPatch(const Core::CPUThreadGuard& guard, u32 address);
|
|
|
|
void EnablePatch(const Core::CPUThreadGuard& guard, std::size_t index);
|
|
|
|
void DisablePatch(const Core::CPUThreadGuard& guard, std::size_t index);
|
2018-05-21 08:46:03 -06:00
|
|
|
bool HasEnabledPatch(u32 address) const;
|
2023-02-12 03:07:11 -07:00
|
|
|
void RemovePatch(const Core::CPUThreadGuard& guard, std::size_t index);
|
|
|
|
void ClearPatches(const Core::CPUThreadGuard& guard);
|
|
|
|
virtual void ApplyExistingPatch(const Core::CPUThreadGuard& guard, std::size_t index) = 0;
|
2018-05-21 08:46:03 -06:00
|
|
|
|
|
|
|
protected:
|
2023-02-12 03:07:11 -07:00
|
|
|
virtual void Patch(const Core::CPUThreadGuard& guard, std::size_t index) = 0;
|
2022-12-22 16:38:08 -07:00
|
|
|
virtual void UnPatch(std::size_t index) = 0;
|
2018-05-21 08:46:03 -06:00
|
|
|
|
|
|
|
std::vector<MemoryPatch> m_patches;
|
|
|
|
};
|
|
|
|
} // namespace Common::Debug
|