diff --git a/LibreMetaverse.Types/Color4.cs b/LibreMetaverse.Types/Color4.cs index 0b7dd8e0..f98e16d6 100644 --- a/LibreMetaverse.Types/Color4.cs +++ b/LibreMetaverse.Types/Color4.cs @@ -26,6 +26,7 @@ using System; using System.Runtime.InteropServices; +using ProtoBuf; namespace OpenMetaverse { @@ -33,16 +34,21 @@ namespace OpenMetaverse /// An 8-bit color structure including an alpha channel /// [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Color4 : IComparable, IEquatable { /// Red + [ProtoMember(1)] public float R; /// Green + [ProtoMember(2)] public float G; /// Blue + [ProtoMember(3)] public float B; /// Alpha + [ProtoMember(4)] public float A; #region Constructors diff --git a/LibreMetaverse.Types/LibreMetaverse.Types.csproj b/LibreMetaverse.Types/LibreMetaverse.Types.csproj index f34673ff..247cd4af 100644 --- a/LibreMetaverse.Types/LibreMetaverse.Types.csproj +++ b/LibreMetaverse.Types/LibreMetaverse.Types.csproj @@ -130,6 +130,9 @@ + + + diff --git a/LibreMetaverse.Types/Quaternion.cs b/LibreMetaverse.Types/Quaternion.cs index 34ff2b4f..4bdeecb3 100644 --- a/LibreMetaverse.Types/Quaternion.cs +++ b/LibreMetaverse.Types/Quaternion.cs @@ -27,23 +27,29 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Quaternion : IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; /// Z value + [ProtoMember(3)] public float Z; /// W value + [ProtoMember(4)] public float W; #region Constructors diff --git a/LibreMetaverse.Types/UUID.cs b/LibreMetaverse.Types/UUID.cs index 98e516d5..4b5fcf9d 100644 --- a/LibreMetaverse.Types/UUID.cs +++ b/LibreMetaverse.Types/UUID.cs @@ -26,6 +26,7 @@ using System; using System.Security.Cryptography; +using ProtoBuf; namespace OpenMetaverse { @@ -34,9 +35,11 @@ namespace OpenMetaverse /// Life networking protocol /// [Serializable] + [ProtoContract] public struct UUID : IComparable, IEquatable { /// The System.Guid object this struct wraps around + [ProtoMember(1)] public Guid Guid { get; set; } #region Constructors diff --git a/LibreMetaverse.Types/Vector2.cs b/LibreMetaverse.Types/Vector2.cs index e3138516..77fe0d3e 100644 --- a/LibreMetaverse.Types/Vector2.cs +++ b/LibreMetaverse.Types/Vector2.cs @@ -27,6 +27,7 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { @@ -34,12 +35,15 @@ namespace OpenMetaverse /// A two-dimensional vector with floating-point values /// [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Vector2 : IComparable, IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; #region Constructors diff --git a/LibreMetaverse.Types/Vector3.cs b/LibreMetaverse.Types/Vector3.cs index b4655170..ebfc0e5f 100644 --- a/LibreMetaverse.Types/Vector3.cs +++ b/LibreMetaverse.Types/Vector3.cs @@ -27,6 +27,7 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { @@ -34,16 +35,20 @@ namespace OpenMetaverse /// A three-dimensional vector with floating-point values /// [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Vector3 : IComparable, IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; /// Z value + [ProtoMember(3)] public float Z; #region Constructors diff --git a/LibreMetaverse.Types/Vector3d.cs b/LibreMetaverse.Types/Vector3d.cs index 0f71dabe..6d9dee98 100644 --- a/LibreMetaverse.Types/Vector3d.cs +++ b/LibreMetaverse.Types/Vector3d.cs @@ -27,6 +27,7 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { @@ -34,14 +35,18 @@ namespace OpenMetaverse /// A three-dimensional vector with doubleing-point values /// [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Vector3d : IComparable, IEquatable { /// X value + [ProtoMember(1)] public double X; /// Y value + [ProtoMember(2)] public double Y; /// Z value + [ProtoMember(3)] public double Z; #region Constructors diff --git a/LibreMetaverse.Types/Vector4.cs b/LibreMetaverse.Types/Vector4.cs index 3ed77218..88714d30 100644 --- a/LibreMetaverse.Types/Vector4.cs +++ b/LibreMetaverse.Types/Vector4.cs @@ -27,20 +27,26 @@ using System; using System.Runtime.InteropServices; using System.Globalization; +using ProtoBuf; namespace OpenMetaverse { [Serializable] + [ProtoContract] [StructLayout(LayoutKind.Sequential)] public struct Vector4 : IComparable, IEquatable { /// X value + [ProtoMember(1)] public float X; /// Y value + [ProtoMember(2)] public float Y; /// Z value + [ProtoMember(3)] public float Z; /// W value + [ProtoMember(4)] public float W; #region Constructors diff --git a/LibreMetaverse/Inventory.cs b/LibreMetaverse/Inventory.cs index 7d100013..ba942b4c 100644 --- a/LibreMetaverse/Inventory.cs +++ b/LibreMetaverse/Inventory.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.Serialization.Formatters.Binary; +using ProtoBuf; namespace OpenMetaverse { @@ -342,13 +342,12 @@ namespace OpenMetaverse { using (Stream stream = File.Open(filename, FileMode.Create)) { - BinaryFormatter bformatter = new BinaryFormatter(); lock (Items) { - Logger.Log("Caching " + Items.Count.ToString() + " inventory items to " + filename, Helpers.LogLevel.Info); + Logger.Log($"Caching {Items.Count} inventory items to {filename}", Helpers.LogLevel.Info); foreach (KeyValuePair kvp in Items) { - bformatter.Serialize(stream, kvp.Value); + Serializer.Serialize(stream, kvp.Value); } } } @@ -376,10 +375,9 @@ namespace OpenMetaverse using (Stream stream = File.Open(filename, FileMode.Open)) { - BinaryFormatter bformatter = new BinaryFormatter(); while (stream.Position < stream.Length) { - var node = (InventoryNode)bformatter.Deserialize(stream); + var node = Serializer.Deserialize(stream); nodes.Add(node); item_count++; } diff --git a/LibreMetaverse/InventoryBase.cs b/LibreMetaverse/InventoryBase.cs index a7c8c529..75465612 100644 --- a/LibreMetaverse/InventoryBase.cs +++ b/LibreMetaverse/InventoryBase.cs @@ -1,15 +1,44 @@ -using System; -using System.Collections.Generic; +/* + * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021, Sjofn LLC. + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; using System.Runtime.Serialization; -using System.Text; using OpenMetaverse.StructuredData; +using ProtoBuf; namespace OpenMetaverse { /// /// Base Class for Inventory Items /// - [Serializable()] + [Serializable] + [ProtoContract(ImplicitFields = ImplicitFields.AllFields)] + [ProtoInclude(20, typeof(InventoryItem))] + [ProtoInclude(21, typeof(InventoryFolder))] public abstract class InventoryBase : ISerializable { /// of item/folder @@ -69,7 +98,7 @@ namespace OpenMetaverse } /// - /// Determine whether the specified object is equal to the current object + /// Determine whether the specified object is equal to the current object /// /// InventoryBase object to compare against /// true if objects are the same @@ -79,7 +108,7 @@ namespace OpenMetaverse } /// - /// Determine whether the specified object is equal to the current object + /// Determine whether the specified object is equal to the current object /// /// InventoryBase object to compare against /// true if objects are the same @@ -102,14 +131,27 @@ namespace OpenMetaverse /// An Item in Inventory /// [Serializable] + [ProtoContract(SkipConstructor = true, ImplicitFields = ImplicitFields.AllFields)] + [ProtoInclude(20, typeof(InventoryTexture))] + [ProtoInclude(21, typeof(InventorySound))] + [ProtoInclude(22, typeof(InventoryCallingCard))] + [ProtoInclude(23, typeof(InventoryLandmark))] + [ProtoInclude(24, typeof(InventoryObject))] + [ProtoInclude(25, typeof(InventoryNotecard))] + [ProtoInclude(26, typeof(InventoryCategory))] + [ProtoInclude(27, typeof(InventoryLSL))] + [ProtoInclude(28, typeof(InventorySnapshot))] + [ProtoInclude(29, typeof(InventoryAttachment))] + [ProtoInclude(30, typeof(InventoryWearable))] + [ProtoInclude(31, typeof(InventoryAnimation))] + [ProtoInclude(32, typeof(InventoryGesture))] public class InventoryItem : InventoryBase { public override string ToString() { - return AssetType + " " + AssetUUID + " (" + InventoryType + " " + UUID + ") '" + Name + "'/'" + - Description + "' " + Permissions; + return $"{AssetType} {AssetUUID} ({InventoryType} {UUID}) '{Name}'/'{Description}' {Permissions}"; } - /// The of this item + /// The of this item public UUID AssetUUID; /// The combined of this item public Permissions Permissions; @@ -117,11 +159,11 @@ namespace OpenMetaverse public AssetType AssetType; /// The type of item from the enum public InventoryType InventoryType; - /// The of the creator of this item + /// The of the creator of this item public UUID CreatorID; /// A Description of this item public string Description; - /// The s this item is set to or owned by + /// The s this item is set to or owned by public UUID GroupID; /// If true, item is owned by a group public bool GroupOwned; @@ -129,20 +171,20 @@ namespace OpenMetaverse public int SalePrice; /// The type of sale from the enum public SaleType SaleType; - /// Combined flags from + /// Combined flags from public uint Flags; /// Time and date this inventory item was created, stored as /// UTC (Coordinated Universal Time) public DateTime CreationDate; /// Used to update the AssetID in requests sent to the server public UUID TransactionID; - /// The of the previous owner of the item + /// The of the previous owner of the item public UUID LastOwnerID; /// /// Construct a new InventoryItem object /// - /// The of the item + /// The of the item public InventoryItem(UUID itemID) : base(itemID) { } @@ -245,9 +287,9 @@ namespace OpenMetaverse } /// - /// Determine whether the specified object is equal to the current object + /// Determine whether the specified object is equal to the current object /// - /// The object to compare against + /// The object to compare against /// true if objects are the same public bool Equals(InventoryItem o) { @@ -348,14 +390,15 @@ namespace OpenMetaverse /// InventoryTexture Class representing a graphical image /// /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryTexture : InventoryItem { /// /// Construct an InventoryTexture object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryTexture(UUID itemID) : base(itemID) { @@ -376,14 +419,15 @@ namespace OpenMetaverse /// /// InventorySound Class representing a playable sound /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventorySound : InventoryItem { /// /// Construct an InventorySound object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventorySound(UUID itemID) : base(itemID) { @@ -404,14 +448,15 @@ namespace OpenMetaverse /// /// InventoryCallingCard Class, contains information on another avatar /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryCallingCard : InventoryItem { /// /// Construct an InventoryCallingCard object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryCallingCard(UUID itemID) : base(itemID) { @@ -432,14 +477,15 @@ namespace OpenMetaverse /// /// InventoryLandmark Class, contains details on a specific location /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryLandmark : InventoryItem { /// /// Construct an InventoryLandmark object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryLandmark(UUID itemID) : base(itemID) { @@ -474,14 +520,15 @@ namespace OpenMetaverse /// /// InventoryObject Class contains details on a primitive or coalesced set of primitives /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryObject : InventoryItem { /// /// Construct an InventoryObject object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryObject(UUID itemID) : base(itemID) { @@ -520,14 +567,15 @@ namespace OpenMetaverse /// /// InventoryNotecard Class, contains details on an encoded text document /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryNotecard : InventoryItem { /// /// Construct an InventoryNotecard object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryNotecard(UUID itemID) : base(itemID) { @@ -549,14 +597,15 @@ namespace OpenMetaverse /// InventoryCategory Class /// /// TODO: Is this even used for anything? - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryCategory : InventoryItem { /// /// Construct an InventoryCategory object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryCategory(UUID itemID) : base(itemID) { @@ -577,14 +626,15 @@ namespace OpenMetaverse /// /// InventoryLSL Class, represents a Linden Scripting Language object /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryLSL : InventoryItem { /// /// Construct an InventoryLSL object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryLSL(UUID itemID) : base(itemID) { @@ -605,7 +655,8 @@ namespace OpenMetaverse /// /// InventorySnapshot Class, an image taken with the viewer /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventorySnapshot : InventoryItem { /// @@ -633,14 +684,15 @@ namespace OpenMetaverse /// /// InventoryAttachment Class, contains details on an attachable object /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryAttachment : InventoryItem { /// /// Construct an InventoryAttachment object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryAttachment(UUID itemID) : base(itemID) { @@ -670,14 +722,15 @@ namespace OpenMetaverse /// /// InventoryWearable Class, details on a clothing item or body part /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryWearable : InventoryItem { /// /// Construct an InventoryWearable object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryWearable(UUID itemID) : base(itemID) { InventoryType = InventoryType.Wearable; } /// @@ -703,14 +756,15 @@ namespace OpenMetaverse /// /// InventoryAnimation Class, A bvh encoded object which animates an avatar /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryAnimation : InventoryItem { /// /// Construct an InventoryAnimation object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryAnimation(UUID itemID) : base(itemID) { @@ -731,14 +785,15 @@ namespace OpenMetaverse /// /// InventoryGesture Class, details on a series of animations, sounds, and actions /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true)] public class InventoryGesture : InventoryItem { /// /// Construct an InventoryGesture object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryGesture(UUID itemID) : base(itemID) { @@ -760,7 +815,8 @@ namespace OpenMetaverse /// A folder contains s and has certain attributes specific /// to itself /// - [Serializable()] + [Serializable] + [ProtoContract(SkipConstructor = true, ImplicitFields = ImplicitFields.AllFields)] public class InventoryFolder : InventoryBase { /// The Preferred for a folder. diff --git a/LibreMetaverse/InventoryNode.cs b/LibreMetaverse/InventoryNode.cs index 69161219..7a630cec 100644 --- a/LibreMetaverse/InventoryNode.cs +++ b/LibreMetaverse/InventoryNode.cs @@ -27,10 +27,12 @@ using System; using System.Runtime.Serialization; +using ProtoBuf; namespace OpenMetaverse { [Serializable] + [ProtoContract(ImplicitFields = ImplicitFields.AllFields)] public class InventoryNode : ISerializable { private InventoryBase data; @@ -39,9 +41,9 @@ namespace OpenMetaverse private InventoryNodeDictionary nodes; private bool needsUpdate = true; [NonSerialized] + [ProtoIgnore] private object tag; - /// public InventoryBase Data { get => data; @@ -55,24 +57,31 @@ namespace OpenMetaverse set => tag = value; } - /// public InventoryNode Parent { get => parent; set => parent = value; } - /// public UUID ParentID => parentID; - /// public InventoryNodeDictionary Nodes { get => nodes ?? (nodes = new InventoryNodeDictionary(this)); set => nodes = value; } - public System.DateTime ModifyTime + /// + /// For inventory folder nodes specifies weather the folder needs to be + /// refreshed from the server + /// + public bool NeedsUpdate + { + get => needsUpdate; + set => needsUpdate = value; + } + + public DateTime ModifyTime { get { @@ -98,16 +107,6 @@ namespace OpenMetaverse Nodes.Sort(); } - /// - /// For inventory folder nodes specifies weather the folder needs to be - /// refreshed from the server - /// - public bool NeedsUpdate - { - get => needsUpdate; - set => needsUpdate = value; - } - public InventoryNode() { } diff --git a/LibreMetaverse/InventoryNodeDictionary.cs b/LibreMetaverse/InventoryNodeDictionary.cs index b18e4945..efce2434 100644 --- a/LibreMetaverse/InventoryNodeDictionary.cs +++ b/LibreMetaverse/InventoryNodeDictionary.cs @@ -26,9 +26,11 @@ using System; using System.Collections.Generic; +using ProtoBuf; namespace OpenMetaverse { + [ProtoContract(SkipConstructor = true, ImplicitFields = ImplicitFields.AllFields)] public class InventoryNodeDictionary: IComparer { protected readonly SortedDictionary SDictionary; diff --git a/LibreMetaverse/LibreMetaverse.csproj b/LibreMetaverse/LibreMetaverse.csproj index 4b90dbee..b91db50b 100644 --- a/LibreMetaverse/LibreMetaverse.csproj +++ b/LibreMetaverse/LibreMetaverse.csproj @@ -13,7 +13,6 @@ Library LibreMetaverse true - true netstandard2.0;netstandard2.1;net5.0 AnyCPU;x64;x86 @@ -128,6 +127,7 @@ + diff --git a/LibreMetaverse/Permissions.cs b/LibreMetaverse/Permissions.cs index ab2cf652..d53f75b4 100644 --- a/LibreMetaverse/Permissions.cs +++ b/LibreMetaverse/Permissions.cs @@ -26,6 +26,7 @@ using System; using OpenMetaverse.StructuredData; +using ProtoBuf; namespace OpenMetaverse { @@ -70,7 +71,8 @@ namespace OpenMetaverse /// /// /// - [Serializable()] + [Serializable] + [ProtoContract(ImplicitFields = ImplicitFields.AllFields)] public struct Permissions { public PermissionMask BaseMask; diff --git a/LibreMetaverse/TerrainCompressor.cs b/LibreMetaverse/TerrainCompressor.cs index 43ffd4ae..576ce0b6 100644 --- a/LibreMetaverse/TerrainCompressor.cs +++ b/LibreMetaverse/TerrainCompressor.cs @@ -26,10 +26,12 @@ using System; using OpenMetaverse.Packets; +using ProtoBuf; namespace OpenMetaverse { [Serializable] + [ProtoContract] public class TerrainPatch { #region Enums and Structs @@ -77,10 +79,13 @@ namespace OpenMetaverse #endregion Enums and Structs /// X position of this patch + [ProtoMember(1)] public int X; /// Y position of this patch + [ProtoMember(2)] public int Y; /// A 16x16 array of floats holding decompressed layer data + [ProtoMember(3)] public float[] Data; }