From c0f1d4093ac68aceb98dfa3a2a3e746999cde78f Mon Sep 17 00:00:00 2001 From: Cinder Date: Fri, 4 Oct 2019 08:46:12 -0500 Subject: [PATCH] Pull some PacketDecoder changes from Ubit OMV --- LibreMetaverse/ObjectManager.cs | 4 +- LibreMetaverse/PacketDecoder.cs | 165 ++++++++++++++++++++++++++++---- 2 files changed, 148 insertions(+), 21 deletions(-) diff --git a/LibreMetaverse/ObjectManager.cs b/LibreMetaverse/ObjectManager.cs index f14dab6b..0458e1df 100644 --- a/LibreMetaverse/ObjectManager.cs +++ b/LibreMetaverse/ObjectManager.cs @@ -81,7 +81,9 @@ namespace OpenMetaverse /// Whether the object has a name value pairs string HasNameValues = 0x100, /// Whether the object has a Media URL set - MediaURL = 0x200 + MediaURL = 0x200, + /// Whether the object has, you guessed it, new particles + HasParticlesNew = 0x400 } /// diff --git a/LibreMetaverse/PacketDecoder.cs b/LibreMetaverse/PacketDecoder.cs index 2c7ebc45..aaa516bb 100644 --- a/LibreMetaverse/PacketDecoder.cs +++ b/LibreMetaverse/PacketDecoder.cs @@ -335,7 +335,11 @@ namespace OpenMetaverse.Packets "(" + point + ")", "AttachmentPoint"); - // TODO: CRC + //CRC + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "CRC", + Utils.BytesToUInt(block, i), + "UInt"); i += 4; // Material @@ -483,7 +487,12 @@ namespace OpenMetaverse.Packets // Extra parameters TODO: Primitive prim = new Primitive(); - i += prim.SetExtraParamsFromBytes(block, i); + int extrapLen = prim.SetExtraParamsFromBytes(block, i); + i += extrapLen; + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "ExtraParams[]", + extrapLen, + "byte[]"); //Sound data if ((flags & CompressedFlags.HasSound) != 0) @@ -538,7 +547,7 @@ namespace OpenMetaverse.Packets nameValues[j] = nv; } } - DecodeNameValue("NameValues", nameValues); + result.AppendLine(DecodeNameValue("NameValues", nameValues)); } } @@ -658,6 +667,17 @@ namespace OpenMetaverse.Packets result.AppendLine(a); } + if ((flags & CompressedFlags.HasParticlesNew) != 0) + { + Primitive.ParticleSystem p = new Primitive.ParticleSystem(block, i); + result.AppendLine(DecodeObjectParticleSystem("ParticleSystemNEW", p)); + i += 94; + if ((p.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.DataGlow) != 0) + i += 2; + if ((p.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.DataBlend) != 0) + i += 2; + } + return result.ToString(); } @@ -669,18 +689,96 @@ namespace OpenMetaverse.Packets return String.Format("{0,30}: {1,2} {2,-38} [{3}]", fieldName + " (Tree Species)", fieldData, - "(" + (Tree)(byte)fieldData + ")", + //"(" + (Tree)(byte)fieldData + ")", + "(" + (Tree)data[0] + ")", fieldData.GetType().Name); } - else if (data.Length == 60) + else if (data.Length == 76) { /* TODO: these are likely useful packed fields, * need to unpack them */ - return Utils.BytesToHexString((byte[])fieldData, String.Format("{0,30}", fieldName)); + Vector4 col = Vector4.Zero; + Vector3 offset = Vector3.Zero; + Vector3 vel = Vector3.Zero; + Vector3 acc = Vector3.Zero; + Quaternion q = Quaternion.Identity; + Vector3 angvel = Vector3.Zero; + + col.FromBytes(data, 0); + offset.FromBytes(data, 16); + vel.FromBytes(data, 28); + acc.FromBytes(data, 40); + q.FromBytes(data, 52, true); + angvel.FromBytes(data, 64); + + StringBuilder result = new StringBuilder(); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "ColisionPlane", + col, + "Vector4"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Offset", + offset, + "Vector3"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Velocity", + vel, + "Vector3"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Acceleration", + acc, + "Vector3"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "rotation", + q, + "Quaternion"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Omega", + angvel, + "Vector3"); + return result.ToString(); + } + else if (data.Length == 60) + { + /* TODO: these are likely useful packed fields, need to unpack them */ + Vector3 offset = Vector3.Zero; + Vector3 vel = Vector3.Zero; + Vector3 acc = Vector3.Zero; + Quaternion q = Quaternion.Identity; + Vector3 angvel = Vector3.Zero; + + offset.FromBytes(data, 0); + vel.FromBytes(data, 12); + acc.FromBytes(data, 24); + q.FromBytes(data, 36, true); + angvel.FromBytes(data, 48); + + StringBuilder result = new StringBuilder(); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Offset", + offset, + "Vector3"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Velocity", + vel, + "Vector3"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Acceleration", + acc, + "Vector3"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "rotation", + q, + "Quaternion"); + result.AppendFormat("{0,30}: {1,-40} [{2}]" + Environment.NewLine, + "Omega", + angvel, + "Vector3"); + return result.ToString(); } else { - return Utils.BytesToHexString((byte[])fieldData, String.Format("{0,30}", fieldName)); + return Utils.BytesToHexString((byte[])fieldData, $"{fieldName, 30}"); } } @@ -688,8 +786,8 @@ namespace OpenMetaverse.Packets { StringBuilder result = new StringBuilder(); Primitive.TextureAnimation TextureAnim; - if (fieldData is Primitive.TextureAnimation) - TextureAnim = (Primitive.TextureAnimation)fieldData; + if (fieldData is Primitive.TextureAnimation data) + TextureAnim = data; else TextureAnim = new Primitive.TextureAnimation((byte[])fieldData, 0); @@ -716,23 +814,27 @@ namespace OpenMetaverse.Packets private static string DecodeNameValue(string fieldName, object fieldData) { - string nameValue = Utils.BytesToString((byte[])fieldData); NameValue[] nameValues = null; - if (nameValue.Length > 0) + if (fieldData is NameValue[]) + nameValues = fieldData as NameValue[]; + else { - string[] lines = nameValue.Split('\n'); - nameValues = new NameValue[lines.Length]; - - for (int i = 0; i < lines.Length; i++) + string nameValue = Utils.BytesToString((byte[])fieldData); + if (nameValue.Length > 0) { - if (!String.IsNullOrEmpty(lines[i])) + string[] lines = nameValue.Split('\n'); + nameValues = new NameValue[lines.Length]; + + for (int i = 0; i < lines.Length; i++) { - NameValue nv = new NameValue(lines[i]); - nameValues[i] = nv; + if (!String.IsNullOrEmpty(lines[i])) + { + NameValue nv = new NameValue(lines[i]); + nameValues[i] = nv; + } } } } - StringBuilder result = new StringBuilder(); result.AppendFormat("{0,30}", " " + Environment.NewLine); if (nameValues != null) @@ -759,6 +861,9 @@ namespace OpenMetaverse.Packets Primitive.FlexibleData Flexible = null; Primitive.LightData Light = null; Primitive.SculptData Sculpt = null; + Primitive.SculptData Mesh = null; + uint meshFlags = 0; + bool hasmeshFlags = false; byte extraParamCount = data[i++]; @@ -776,7 +881,13 @@ namespace OpenMetaverse.Packets Light = new Primitive.LightData(data, i); else if (type == ExtraParamType.Sculpt) Sculpt = new Primitive.SculptData(data, i); - + else if (type == ExtraParamType.Mesh) + Mesh = new Primitive.SculptData(data, i); + else if ((byte)type == 0x70) + { + hasmeshFlags = true; + meshFlags = Utils.BytesToUInt(data, i); + } i += (int)paramLength; //totalLength += (int)paramLength + 6; } @@ -797,6 +908,13 @@ namespace OpenMetaverse.Packets result.AppendFormat("{0,30}", "" + Environment.NewLine); } + if (Mesh != null) + { + result.AppendFormat("{0,30}", "" + Environment.NewLine); + GenericTypeDecoder(Mesh, ref result); + result.AppendFormat("{0,30}", "" + Environment.NewLine); + } + if (Light != null) { result.AppendFormat("{0,30}", "" + Environment.NewLine); @@ -804,6 +922,13 @@ namespace OpenMetaverse.Packets result.AppendFormat("{0,30}", "" + Environment.NewLine); } + if (hasmeshFlags) + { + result.AppendFormat("{0,30}", "" + Environment.NewLine); + result.AppendFormat("{0,30}", meshFlags.ToString() + Environment.NewLine); + result.AppendFormat("{0,30}", "" + Environment.NewLine); + } + result.AppendFormat("{0,30}", ""); return result.ToString(); }