using System.Text; namespace WhiteMagic; /// /// A pointer-relative view over a . Obtained through the /// high-level facade indexer, it provides read/write/string operations with optional /// offsets relative to a base address. /// public sealed class RemotePointer { private readonly MemoryBase _memory; /// The base address of this view. public IntPtr BaseAddress { get; } internal RemotePointer(MemoryBase memory, IntPtr baseAddress) { _memory = memory; BaseAddress = baseAddress; } /// Reads a value of type at BaseAddress + offset. public T Read(nint offset = 0) where T : struct { return _memory.Read(BaseAddress + offset); } /// Writes at BaseAddress + offset. public bool Write(T value, nint offset = 0) where T : struct { return _memory.Write(BaseAddress + offset, value); } /// Reads a null-terminated string at BaseAddress + offset. public string ReadString(Encoding encoding, int maxLength = 512, nint offset = 0) { return _memory.ReadString(BaseAddress + offset, encoding, maxLength); } /// Writes a null-terminated string at BaseAddress + offset. public bool WriteString(string value, Encoding encoding, nint offset = 0) { return _memory.WriteString(BaseAddress + offset, value, encoding); } /// Returns a new with the offset added. public RemotePointer this[nint offset] => new RemotePointer(_memory, BaseAddress + offset); }