From 80f30b36bb377cb4c2db26ff5a7f66d0c28ef8b8 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 5 Dec 2022 15:18:36 +0000 Subject: [PATCH] Track VP_OBJECT_DATA --- VpSharp/src/Entities/VirtualParadiseObject.cs | 4 ++++ .../Entities/VirtualParadiseObjectBuilder.cs | 20 ++++++++++++++++++- .../VirtualParadiseParticleEmitterObject.cs | 2 ++ .../src/Entities/VirtualParadisePathObject.cs | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/VpSharp/src/Entities/VirtualParadiseObject.cs b/VpSharp/src/Entities/VirtualParadiseObject.cs index c07f418..364b1f1 100644 --- a/VpSharp/src/Entities/VirtualParadiseObject.cs +++ b/VpSharp/src/Entities/VirtualParadiseObject.cs @@ -49,6 +49,8 @@ public abstract class VirtualParadiseObject : IEquatable /// The owner of this object. public VirtualParadiseUser Owner { get; internal set; } = null!; + internal byte[] Data { get; set; } = Array.Empty(); + private protected VirtualParadiseClient Client { get; } /// @@ -240,6 +242,7 @@ public abstract class VirtualParadiseObject : IEquatable Location = virtualParadiseObject.Location; ModificationTimestamp = virtualParadiseObject.ModificationTimestamp; Owner = virtualParadiseObject.Owner; + Data = virtualParadiseObject.Data; } /// @@ -272,5 +275,6 @@ public abstract class VirtualParadiseObject : IEquatable /// A span of bytes containing the object data. protected virtual void ExtractFromData(ReadOnlySpan data) { + Data = data.ToArray(); } } diff --git a/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs b/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs index e8923bc..eab00c0 100644 --- a/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs +++ b/VpSharp/src/Entities/VirtualParadiseObjectBuilder.cs @@ -1,6 +1,7 @@ -using System.Numerics; +using System.Numerics; using VpSharp.Extensions; using VpSharp.Internal; +using static VpSharp.Internal.NativeAttributes.DataAttribute; using static VpSharp.Internal.NativeAttributes.FloatAttribute; using static VpSharp.Internal.NativeAttributes.IntegerAttribute; using static VpSharp.Internal.NativeMethods; @@ -57,6 +58,8 @@ public abstract class VirtualParadiseObjectBuilder /// The rotation of the object, or to leave unchanged. public Optional Rotation { get; set; } + internal Optional> Data { get; set; } + private protected VirtualParadiseClient Client { get; } private protected ObjectBuilderMode Mode { get; } @@ -69,6 +72,21 @@ public abstract class VirtualParadiseObjectBuilder ApplyRotation(); ApplyModificationTimestamp(); ApplyOwner(); + ApplyData(); + } + + private void ApplyData() + { + nint handle = Client.NativeInstanceHandle; + if (Data.HasValue) + { + IReadOnlyList data = Data.Value!; + _ = vp_data_set(handle, ObjectData, data.Count, data.ToArray()); + } + else + { + _ = vp_data_set(handle, ObjectData, 0, Array.Empty()); + } } private void ApplyOwner() diff --git a/VpSharp/src/Entities/VirtualParadiseParticleEmitterObject.cs b/VpSharp/src/Entities/VirtualParadiseParticleEmitterObject.cs index f8572ec..d2d2090 100644 --- a/VpSharp/src/Entities/VirtualParadiseParticleEmitterObject.cs +++ b/VpSharp/src/Entities/VirtualParadiseParticleEmitterObject.cs @@ -239,6 +239,8 @@ public sealed class VirtualParadiseParticleEmitterObject : VirtualParadiseObject /// protected override void ExtractFromData(ReadOnlySpan data) { + base.ExtractFromData(data); + #pragma warning disable 612 const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; PropertyInfo[] properties = typeof(VirtualParadiseParticleEmitterObject).GetProperties(bindingFlags); diff --git a/VpSharp/src/Entities/VirtualParadisePathObject.cs b/VpSharp/src/Entities/VirtualParadisePathObject.cs index 29b58c5..76298fb 100644 --- a/VpSharp/src/Entities/VirtualParadisePathObject.cs +++ b/VpSharp/src/Entities/VirtualParadisePathObject.cs @@ -42,6 +42,8 @@ public sealed class VirtualParadisePathObject : VirtualParadiseObject /// protected override void ExtractFromData(ReadOnlySpan data) { + base.ExtractFromData(data); + Span chars = stackalloc char[data.Length]; Encoding.UTF8.GetChars(data, chars);