using Qrakhen.Qamp.Core.Values.Objects; using System.Runtime.InteropServices; using Qrakhen.Qamp.Core.Collections; namespace Qrakhen.Qamp.Core.Values; [StructLayout(LayoutKind.Sequential, Size = sizeof(ulong))] public readonly struct Ptr { private static readonly StackRegister _register = new(0x10); [Serialized] public readonly Address Address; //private readonly IntPtr _pointer; //public IntPtr Pointer => _pointer; public Obj? Value { get { if (_register.TryGet(Address, out Obj obj)) return obj; return null; //if (_pointer == IntPtr.Zero) // throw new ObjectDisposedException(nameof(Ptr)); //return (Obj)GCHandle.FromIntPtr(_pointer).Target!; } } public Ptr(Obj obj) { //_pointer = GCHandle.ToIntPtr(GCHandle.Alloc(obj, GCHandleType.Normal)); Address = _register.Add(obj); } public override string ToString() => $"0x{Value}"; }