From fde3508fc1a5cd72410e80aa9d452b73f5ba5496 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 4 Dec 2022 17:42:13 +0000 Subject: [PATCH] Lock handle when extracting object --- VpSharp/src/VirtualParadiseClient.Objects.cs | 48 ++++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/VpSharp/src/VirtualParadiseClient.Objects.cs b/VpSharp/src/VirtualParadiseClient.Objects.cs index 2f9fabd..aac7315 100644 --- a/VpSharp/src/VirtualParadiseClient.Objects.cs +++ b/VpSharp/src/VirtualParadiseClient.Objects.cs @@ -144,29 +144,37 @@ public sealed partial class VirtualParadiseClient private async Task ExtractObjectAsync(nint sender) { - var type = (ObjectType)vp_int(sender, IntegerAttribute.ObjectType); - int id = vp_int(sender, IntegerAttribute.ObjectId); - int owner = vp_int(sender, IntegerAttribute.ObjectUserId); - - double x = vp_double(sender, FloatAttribute.ObjectX); - double y = vp_double(sender, FloatAttribute.ObjectY); - double z = vp_double(sender, FloatAttribute.ObjectZ); - var position = new Vector3d(x, y, z); - - float rotX = vp_float(sender, FloatAttribute.ObjectRotationX); - float rotY = vp_float(sender, FloatAttribute.ObjectRotationY); - float rotZ = vp_float(sender, FloatAttribute.ObjectRotationZ); - float angle = vp_float(sender, FloatAttribute.ObjectRotationAngle); + ObjectType type; + int id; + int owner; Quaternion rotation; + Vector3d position; - if (double.IsPositiveInfinity(angle)) + lock (Lock) { - rotation = Quaternion.CreateFromYawPitchRoll(rotY, rotX, rotZ); - } - else - { - var axis = new Vector3(rotX, rotY, rotZ); - rotation = Quaternion.CreateFromAxisAngle(axis, angle); + type = (ObjectType)vp_int(sender, IntegerAttribute.ObjectType); + id = vp_int(sender, IntegerAttribute.ObjectId); + owner = vp_int(sender, IntegerAttribute.ObjectUserId); + + double x = vp_double(sender, FloatAttribute.ObjectX); + double y = vp_double(sender, FloatAttribute.ObjectY); + double z = vp_double(sender, FloatAttribute.ObjectZ); + position = new Vector3d(x, y, z); + + float rotX = vp_float(sender, FloatAttribute.ObjectRotationX); + float rotY = vp_float(sender, FloatAttribute.ObjectRotationY); + float rotZ = vp_float(sender, FloatAttribute.ObjectRotationZ); + float angle = vp_float(sender, FloatAttribute.ObjectRotationAngle); + + if (double.IsPositiveInfinity(angle)) + { + rotation = Quaternion.CreateFromYawPitchRoll(rotY, rotX, rotZ); + } + else + { + var axis = new Vector3(rotX, rotY, rotZ); + rotation = Quaternion.CreateFromAxisAngle(axis, angle); + } } VirtualParadiseObject virtualParadiseObject = type switch