aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Tamper/Pointer.cs
blob: c961e1a7debab0154b375b6cc9fe76beb6e3fd35 (plain) (blame)
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
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Tamper.Operations;
using System.Runtime.CompilerServices;

namespace Ryujinx.HLE.HOS.Tamper
{
    class Pointer : IOperand
    {
        private readonly IOperand _position;
        private readonly ITamperedProcess _process;

        public Pointer(IOperand position, ITamperedProcess process)
        {
            _position = position;
            _process = process;
        }

        public T Get<T>() where T : unmanaged
        {
            return _process.ReadMemory<T>(_position.Get<ulong>());
        }

        public void Set<T>(T value) where T : unmanaged
        {
            ulong position = _position.Get<ulong>();

            Logger.Debug?.Print(LogClass.TamperMachine, $"0x{position:X16}@{Unsafe.SizeOf<T>()}: {value:X}");

            _process.WriteMemory(position, value);
        }
    }
}