From 3dbdbec13bd5c8a32799eb53c686ec2d878858af Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 4 Dec 2006 00:19:58 +0000 Subject: [PATCH] * Added more documentation to Types.cs * Renamed LLUUID.GenerateUUID() to LLUUID.Random() * Optimized the type classes hashing functions * Fixed a bug where source packet data would be modified on big endian platforms when creating type classes * Normalized the ToString() output of the type classes git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@677 52acb1d6-8a22-11de-b505-999d5b087335 --- libsecondlife-cs/AssetSystem/AssetManager.cs | 6 +- libsecondlife-cs/Avatar.cs | 6 +- libsecondlife-cs/EstateTools.cs | 2 +- libsecondlife-cs/GroupManager.cs | 6 +- .../InventorySystem/InventoryImage.cs | 4 +- .../InventorySystem/InventoryItem.cs | 2 +- .../InventorySystem/InventoryManager.cs | 4 +- .../InventorySystem/InventoryNotecard.cs | 4 +- libsecondlife-cs/NetworkManager.cs | 2 +- libsecondlife-cs/Parcel.cs | 2 +- libsecondlife-cs/Types.cs | 371 +++++++++++------- libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs | 6 +- .../examples/slaccountant/frmSLAccountant.cs | 2 +- 13 files changed, 250 insertions(+), 167 deletions(-) diff --git a/libsecondlife-cs/AssetSystem/AssetManager.cs b/libsecondlife-cs/AssetSystem/AssetManager.cs index fb94d7be..4ae333e2 100644 --- a/libsecondlife-cs/AssetSystem/AssetManager.cs +++ b/libsecondlife-cs/AssetSystem/AssetManager.cs @@ -100,7 +100,7 @@ namespace libsecondlife.AssetSystem try { - curUploadRequest = new AssetRequestUpload(slClient, LLUUID.GenerateUUID(), asset); + curUploadRequest = new AssetRequestUpload(slClient, LLUUID.Random(), asset); LLUUID assetID = curUploadRequest.DoUpload(); if (asset.Type == Asset.ASSET_TYPE_IMAGE) @@ -121,7 +121,7 @@ namespace libsecondlife.AssetSystem /// public void GetInventoryAsset( InventoryItem item ) { - LLUUID TransferID = LLUUID.GenerateUUID(); + LLUUID TransferID = LLUUID.Random(); AssetRequestDownload request = new AssetRequestDownload(TransferID); request.Size = int.MaxValue; // Number of bytes expected @@ -159,7 +159,7 @@ namespace libsecondlife.AssetSystem /// public void GetInventoryAsset(Asset asset) { - LLUUID TransferID = LLUUID.GenerateUUID(); + LLUUID TransferID = LLUUID.Random(); AssetRequestDownload request = new AssetRequestDownload(TransferID); request.Size = int.MaxValue; // Number of bytes expected diff --git a/libsecondlife-cs/Avatar.cs b/libsecondlife-cs/Avatar.cs index 750d5fb7..d62af6a1 100644 --- a/libsecondlife-cs/Avatar.cs +++ b/libsecondlife-cs/Avatar.cs @@ -385,7 +385,7 @@ namespace libsecondlife /// public void InstantMessage(LLUUID target, string message) { - InstantMessage(FirstName + " " + LastName, LLUUID.GenerateUUID(), target, message, null, LLUUID.GenerateUUID()); + InstantMessage(FirstName + " " + LastName, LLUUID.Random(), target, message, null, LLUUID.Random()); } /// @@ -396,7 +396,7 @@ namespace libsecondlife /// public void InstantMessage(LLUUID target, string message, LLUUID IMSessionID) { - InstantMessage(FirstName + " " + LastName, LLUUID.GenerateUUID(), target, message, null, IMSessionID); + InstantMessage(FirstName + " " + LastName, LLUUID.Random(), target, message, null, IMSessionID); } /// @@ -409,7 +409,7 @@ namespace libsecondlife /// public void InstantMessage(string fromName, LLUUID sessionID, LLUUID target, string message, LLUUID[] conferenceIDs) { - InstantMessage(fromName, sessionID, target, message, conferenceIDs, LLUUID.GenerateUUID()); + InstantMessage(fromName, sessionID, target, message, conferenceIDs, LLUUID.Random()); } /// diff --git a/libsecondlife-cs/EstateTools.cs b/libsecondlife-cs/EstateTools.cs index 2e3eb356..3f5c54d6 100644 --- a/libsecondlife-cs/EstateTools.cs +++ b/libsecondlife-cs/EstateTools.cs @@ -53,7 +53,7 @@ namespace libsecondlife EstateOwnerMessagePacket estate = new EstateOwnerMessagePacket(); estate.AgentData.AgentID = Client.Network.AgentID; estate.AgentData.SessionID = Client.Network.SessionID; - estate.MethodData.Invoice = LLUUID.GenerateUUID(); + estate.MethodData.Invoice = LLUUID.Random(); estate.MethodData.Method = Helpers.StringToField("kick"); estate.ParamList = new EstateOwnerMessagePacket.ParamListBlock[2]; estate.ParamList[0].Parameter = Helpers.StringToField(Client.Network.AgentID.ToStringHyphenated()); diff --git a/libsecondlife-cs/GroupManager.cs b/libsecondlife-cs/GroupManager.cs index aaa1b580..706a5055 100644 --- a/libsecondlife-cs/GroupManager.cs +++ b/libsecondlife-cs/GroupManager.cs @@ -451,7 +451,7 @@ namespace libsecondlife /// public void BeginGetGroupMembers(LLUUID group, GroupMembersCallback gmc) { - LLUUID requestID = LLUUID.GenerateUUID(); + LLUUID requestID = LLUUID.Random(); lock (GroupMembersCaches) { @@ -477,7 +477,7 @@ namespace libsecondlife /// public void BeginGetGroupRoles(LLUUID group, GroupRolesCallback grc) { - LLUUID requestID = LLUUID.GenerateUUID(); + LLUUID requestID = LLUUID.Random(); lock (GroupRolesCaches) { @@ -503,7 +503,7 @@ namespace libsecondlife /// public void BeginGetGroupTitles(LLUUID group, GroupTitlesCallback gtc) { - LLUUID requestID = LLUUID.GenerateUUID(); + LLUUID requestID = LLUUID.Random(); GroupTitlesCallbacks[group] = gtc; diff --git a/libsecondlife-cs/InventorySystem/InventoryImage.cs b/libsecondlife-cs/InventorySystem/InventoryImage.cs index 54546b10..a3e11b37 100644 --- a/libsecondlife-cs/InventorySystem/InventoryImage.cs +++ b/libsecondlife-cs/InventorySystem/InventoryImage.cs @@ -33,7 +33,7 @@ namespace libsecondlife.InventorySystem set { - base._Asset = new AssetImage( LLUUID.GenerateUUID(), value ); + base._Asset = new AssetImage( LLUUID.Random(), value ); LLUUID TransactionID = base.iManager.AssetManager.UploadAsset( Asset ); base.SetAssetTransactionIDs( Asset.AssetID, TransactionID ); } @@ -86,7 +86,7 @@ namespace libsecondlife.InventorySystem } else { - _Asset = new AssetImage( LLUUID.GenerateUUID(), assetData ); + _Asset = new AssetImage( LLUUID.Random(), assetData ); _AssetID = _Asset.AssetID; } } diff --git a/libsecondlife-cs/InventorySystem/InventoryItem.cs b/libsecondlife-cs/InventorySystem/InventoryItem.cs index 054d501b..cf1efc68 100644 --- a/libsecondlife-cs/InventorySystem/InventoryItem.cs +++ b/libsecondlife-cs/InventorySystem/InventoryItem.cs @@ -440,7 +440,7 @@ namespace libsecondlife.InventorySystem } else { - _Asset = new Asset(LLUUID.GenerateUUID(), Type, assetData); + _Asset = new Asset(LLUUID.Random(), Type, assetData); _AssetID = _Asset.AssetID; } } diff --git a/libsecondlife-cs/InventorySystem/InventoryManager.cs b/libsecondlife-cs/InventorySystem/InventoryManager.cs index fdaba3a0..9fd156a0 100644 --- a/libsecondlife-cs/InventorySystem/InventoryManager.cs +++ b/libsecondlife-cs/InventorySystem/InventoryManager.cs @@ -192,7 +192,7 @@ namespace libsecondlife.InventorySystem internal InventoryFolder FolderCreate(String name, LLUUID parentid) { - InventoryFolder ifolder = new InventoryFolder(this, name, LLUUID.GenerateUUID(), parentid); + InventoryFolder ifolder = new InventoryFolder(this, name, LLUUID.Random(), parentid); ifolder._Type = -1; if (htFoldersByUUID.ContainsKey(ifolder.ParentID)) @@ -297,7 +297,7 @@ namespace libsecondlife.InventorySystem internal void ItemGiveTo(InventoryItem iitem, LLUUID ToAgentID) { - LLUUID MessageID = LLUUID.GenerateUUID(); + LLUUID MessageID = LLUUID.Random(); Packet packet = InvPacketHelper.GiveItemViaImprovedInstantMessage( MessageID diff --git a/libsecondlife-cs/InventorySystem/InventoryNotecard.cs b/libsecondlife-cs/InventorySystem/InventoryNotecard.cs index 7efb71e5..fa1090df 100644 --- a/libsecondlife-cs/InventorySystem/InventoryNotecard.cs +++ b/libsecondlife-cs/InventorySystem/InventoryNotecard.cs @@ -30,7 +30,7 @@ namespace libsecondlife.InventorySystem set { - base._Asset = new AssetNotecard( LLUUID.GenerateUUID(), value ); + base._Asset = new AssetNotecard( LLUUID.Random(), value ); LLUUID TransactionID = base.iManager.AssetManager.UploadAsset( Asset ); base.SetAssetTransactionIDs(Asset.AssetID, TransactionID); } @@ -97,7 +97,7 @@ namespace libsecondlife.InventorySystem } else { - _Asset = new AssetNotecard( LLUUID.GenerateUUID(), assetData ); + _Asset = new AssetNotecard( LLUUID.Random(), assetData ); _AssetID = _Asset.AssetID; } } diff --git a/libsecondlife-cs/NetworkManager.cs b/libsecondlife-cs/NetworkManager.cs index e5320941..eb09bfbb 100644 --- a/libsecondlife-cs/NetworkManager.cs +++ b/libsecondlife-cs/NetworkManager.cs @@ -29,10 +29,10 @@ using System.Timers; using System.Collections.Generic; using System.Net; using System.Net.Sockets; +using System.Globalization; using Nwc.XmlRpc; using Nii.JSON; using libsecondlife.Packets; -using System.Globalization; namespace libsecondlife { diff --git a/libsecondlife-cs/Parcel.cs b/libsecondlife-cs/Parcel.cs index 7c6e00ba..2c6c51f0 100644 --- a/libsecondlife-cs/Parcel.cs +++ b/libsecondlife-cs/Parcel.cs @@ -465,7 +465,7 @@ namespace libsecondlife query.QueryData.Auction = auction; query.QueryData.ForSale = forSale; query.QueryData.QueryFlags = 0; - query.QueryData.QueryID = LLUUID.GenerateUUID(); + query.QueryData.QueryID = LLUUID.Random(); query.QueryData.ReservedNewbie = reservedNewbie; Client.Network.SendPacket((Packet)query); diff --git a/libsecondlife-cs/Types.cs b/libsecondlife-cs/Types.cs index d9210826..9e9f14af 100644 --- a/libsecondlife-cs/Types.cs +++ b/libsecondlife-cs/Types.cs @@ -47,16 +47,18 @@ namespace libsecondlife } /// - /// + /// Default constructor /// public LLUUID() { } /// - /// + /// Constructor that takes a string UUID representation /// - /// + /// A string representation of a UUID, case + /// insensitive and can either be hyphenated or non-hyphenated + /// LLUUID("11f8aa9c-b071-4242-836b-13b7abe0d489") public LLUUID(string val) { if (val.Length == 36) val = val.Replace("-", ""); @@ -70,32 +72,22 @@ namespace libsecondlife } /// - /// + /// Constructor that takes a byte array containing a UUID /// - /// - /// + /// Byte array containing a 16 byte UUID + /// Beginning offset in the array public LLUUID(byte[] byteArray, int pos) { Array.Copy(byteArray, pos, data, 0, 16); } /// - /// + /// Returns the raw bytes for this UUID /// - /// - public LLUUID(bool randomize) - { - if (randomize) data = Guid.NewGuid().ToByteArray(); - else data = new byte[16]; - } - - /// - /// - /// - /// + /// A 16 byte array containing this UUID public byte[] GetBytes() { - return Data; + return data; } /// @@ -118,23 +110,26 @@ namespace libsecondlife /// /// /// - public static LLUUID GenerateUUID() + public static LLUUID Random() { return new LLUUID(Guid.NewGuid().ToByteArray(), 0); } /// - /// + /// Required implementation for XML serialization /// - /// + /// null public System.Xml.Schema.XmlSchema GetSchema() { return null; } + /// + /// Deserializes an XML UUID + /// + /// XmlReader containing the UUID to deserialize public void ReadXml(System.Xml.XmlReader reader) { - //reader.ReadStartElement("uuid"); string val = reader.ReadString(); if (val.Length == 36) val = val.Replace("-", ""); @@ -146,31 +141,40 @@ namespace libsecondlife data[i] = Convert.ToByte(val.Substring(i * 2, 2), 16); } - //reader.ReadEndElement(); //reader.MoveToContent(); } + /// + /// Serialize this UUID to XML + /// + /// XmlWriter to serialize to public void WriteXml(System.Xml.XmlWriter writer) { - //writer.WriteStartElement("uuid"); writer.WriteString(this.ToString()); - //writer.WriteEndElement(); } /// - /// + /// Return a hash code for this UUID, used by .NET for hash tables /// - /// + /// An integer composed of all the UUID bytes XORed together public override int GetHashCode() { - return ToString().GetHashCode(); + int hash = data[0]; + + for (int i = 1; i < 16; i++) + { + hash ^= data[i]; + } + + return hash; } /// - /// + /// Comparison function /// - /// - /// + /// An object to compare to this UUID + /// False if the object is not an LLUUID, true if it is and + /// byte for byte identical to this public override bool Equals(object o) { if (!(o is LLUUID)) return false; @@ -186,11 +190,11 @@ namespace libsecondlife } /// - /// + /// Equals operator /// - /// - /// - /// + /// First LLUUID for comparison + /// Second LLUUID for comparison + /// True if the UUIDs are byte for byte equal, otherwise false public static bool operator==(LLUUID lhs, LLUUID rhs) { // If both are null, or both are same instance, return true @@ -214,22 +218,22 @@ namespace libsecondlife } /// - /// + /// Not equals operator /// - /// - /// - /// + /// First LLUUID for comparison + /// Second LLUUID for comparison + /// True if the UUIDs are not equal, otherwise true public static bool operator!=(LLUUID lhs, LLUUID rhs) { return !(lhs == rhs); } /// - /// + /// XOR operator /// - /// - /// - /// + /// First LLUUID + /// Second LLUUID + /// A UUID that is a XOR combination of the two input UUIDs public static LLUUID operator ^(LLUUID lhs, LLUUID rhs) { LLUUID returnUUID = new LLUUID(); @@ -243,22 +247,25 @@ namespace libsecondlife } /// - /// + /// String typecasting operator /// - /// - /// + /// A UUID in string form. Case insensitive, + /// hyphenated or non-hyphenated + /// A UUID built from the string representation public static implicit operator LLUUID(string val) { return new LLUUID(val); } /// - /// + /// Get a string representation of this UUID /// - /// + /// A string representation of this UUID, lowercase and + /// without hyphens + /// 11f8aa9cb0714242836b13b7abe0d489 public override string ToString() { - string uuid = ""; + string uuid = String.Empty; for (int i = 0; i < 16; ++i) { @@ -269,12 +276,14 @@ namespace libsecondlife } /// - /// + /// Get a hyphenated string representation of this UUID /// - /// + /// A string representation of this UUID, lowercase and + /// with hyphens + /// 11f8aa9c-b071-4242-836b-13b7abe0d489 public string ToStringHyphenated() { - string uuid = ""; + string uuid = String.Empty; for (int i = 0; i < 16; ++i) { @@ -291,34 +300,35 @@ namespace libsecondlife /// /// An LLUUID with a value of all zeroes /// - public readonly static LLUUID Zero = new LLUUID(); + public static readonly LLUUID Zero = new LLUUID(); } /// - /// + /// A three-dimensional vector with floating-point values /// [XmlRoot("vector3")] public class LLVector3 { - /// + /// X value [XmlAttribute("x")] public float X; - /// + /// Y value [XmlAttribute("y")] public float Y; - /// + /// Z value [XmlAttribute("z")] public float Z; /// - /// + /// Default constructor, all values are set to 0.0 /// public LLVector3() { - X = Y = Z = 0.0F; + X = Y = Z = 0.0f; } /// - /// + /// Constructor, builds a single-precision vector from a + /// double-precision one /// - /// + /// A double-precision vector public LLVector3(LLVector3d vector) { X = (float)vector.X; @@ -327,30 +337,39 @@ namespace libsecondlife } /// - /// + /// Constructor, builds a vector from a byte array /// - /// - /// + /// Byte array containing a 12 byte vector + /// Beginning position in the byte array public LLVector3(byte[] byteArray, int pos) { - if(!BitConverter.IsLittleEndian) - { - Array.Reverse(byteArray, pos, 4); - Array.Reverse(byteArray, pos + 4, 4); - Array.Reverse(byteArray, pos + 8, 4); - } + if (!BitConverter.IsLittleEndian) + { + byte[] newArray = new byte[12]; + Array.Copy(byteArray, pos, newArray, 0, 12); - X = BitConverter.ToSingle(byteArray, pos); - Y = BitConverter.ToSingle(byteArray, pos + 4); - Z = BitConverter.ToSingle(byteArray, pos + 8); + Array.Reverse(newArray, 0, 4); + Array.Reverse(newArray, 4, 4); + Array.Reverse(newArray, 8, 4); + + X = BitConverter.ToSingle(newArray, 0); + Y = BitConverter.ToSingle(newArray, 4); + Z = BitConverter.ToSingle(newArray, 8); + } + else + { + X = BitConverter.ToSingle(byteArray, pos); + Y = BitConverter.ToSingle(byteArray, pos + 4); + Z = BitConverter.ToSingle(byteArray, pos + 8); + } } /// - /// + /// Constructor, builds a vector for individual float values /// - /// - /// - /// + /// X value + /// Y value + /// Z value public LLVector3(float x, float y, float z) { X = x; @@ -359,9 +378,9 @@ namespace libsecondlife } /// - /// + /// Returns the raw bytes for this vector /// - /// + /// A 12 byte array containing X, Y, and Z public byte[] GetBytes() { byte[] byteArray = new byte[12]; @@ -380,25 +399,22 @@ namespace libsecondlife } /// - /// + /// Get a formatted string representation of the vector /// - /// + /// A string representation of the vector, similar to the LSL + /// vector to string conversion in Second Life public override string ToString() { - return X.ToString() + " " + Y.ToString() + " " + Z.ToString(); + return "<" + X.ToString() + ", " + Y.ToString() + ", " + Z.ToString() + ">"; } /// - /// + /// A hash of the vector, used by .NET for hash tables /// - /// + /// The hashes of the individual components XORed together public override int GetHashCode() { - int x = (int)X; - int y = (int)Y; - int z = (int)Z; - - return (x ^ y ^ z); + return (X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode()); } /// @@ -482,24 +498,24 @@ namespace libsecondlife } /// - /// + /// A double-precision three-dimensional vector /// [XmlRoot("vector3d")] public class LLVector3d { - /// + /// X value [XmlAttribute("x")] public double X; - /// + /// Y value [XmlAttribute("y")] public double Y; - /// + /// Z value [XmlAttribute("z")] public double Z; /// - /// + /// Default constructor, sets all the values to 0.0 /// public LLVector3d() { - X = Y = Z = 0.0D; + X = Y = Z = 0.0d; } /// @@ -522,15 +538,25 @@ namespace libsecondlife /// public LLVector3d(byte[] byteArray, int pos) { - if(!BitConverter.IsLittleEndian) { - Array.Reverse(byteArray, pos, 8); - Array.Reverse(byteArray, pos + 8, 8); - Array.Reverse(byteArray, pos + 16, 8); - } + if (!BitConverter.IsLittleEndian) + { + byte[] newArray = new byte[24]; + Array.Copy(byteArray, pos, newArray, 0, 24); - X = BitConverter.ToDouble(byteArray, pos); - Y = BitConverter.ToDouble(byteArray, pos + 8); - Z = BitConverter.ToDouble(byteArray, pos + 16); + Array.Reverse(newArray, 0, 8); + Array.Reverse(newArray, 8, 8); + Array.Reverse(newArray, 16, 8); + + X = BitConverter.ToDouble(newArray, 0); + Y = BitConverter.ToDouble(newArray, 8); + Z = BitConverter.ToDouble(newArray, 16); + } + else + { + X = BitConverter.ToDouble(byteArray, pos); + Y = BitConverter.ToDouble(byteArray, pos + 8); + Z = BitConverter.ToDouble(byteArray, pos + 16); + } } /// @@ -545,7 +571,8 @@ namespace libsecondlife Array.Copy(BitConverter.GetBytes(Y), 0, byteArray, 8, 8); Array.Copy(BitConverter.GetBytes(Z), 0, byteArray, 16, 8); - if(!BitConverter.IsLittleEndian) { + if(!BitConverter.IsLittleEndian) + { Array.Reverse(byteArray, 0, 8); Array.Reverse(byteArray, 8, 8); Array.Reverse(byteArray, 16, 8); @@ -560,17 +587,17 @@ namespace libsecondlife /// public override string ToString() { - return X.ToString() + " " + Y.ToString() + " " + Z.ToString(); + return "<" + X.ToString() + ", " + Y.ToString() + ", " + Z.ToString() + ">"; } /// /// An LLVector3d with a value of 0,0,0 /// - public readonly static LLVector3d Zero = new LLVector3d(); + public static readonly LLVector3d Zero = new LLVector3d(); } /// - /// + /// A four-dimensional vector /// [XmlRoot("vector4")] public class LLVector4 @@ -599,17 +626,28 @@ namespace libsecondlife /// public LLVector4(byte[] byteArray, int pos) { - if(!BitConverter.IsLittleEndian) { - Array.Reverse(byteArray, pos, 4); - Array.Reverse(byteArray, pos + 4, 4); - Array.Reverse(byteArray, pos + 8, 4); - Array.Reverse(byteArray, pos + 12, 4); - } + if (!BitConverter.IsLittleEndian) + { + byte[] newArray = new byte[16]; + Array.Copy(byteArray, pos, newArray, 0, 16); - X = BitConverter.ToSingle(byteArray, pos); - Y = BitConverter.ToSingle(byteArray, pos + 4); - Z = BitConverter.ToSingle(byteArray, pos + 8); - S = BitConverter.ToSingle(byteArray, pos + 12); + Array.Reverse(newArray, 0, 4); + Array.Reverse(newArray, 4, 4); + Array.Reverse(newArray, 8, 4); + Array.Reverse(newArray, 12, 4); + + X = BitConverter.ToSingle(newArray, 0); + Y = BitConverter.ToSingle(newArray, 4); + Z = BitConverter.ToSingle(newArray, 8); + S = BitConverter.ToSingle(newArray, 12); + } + else + { + X = BitConverter.ToSingle(byteArray, pos); + Y = BitConverter.ToSingle(byteArray, pos + 4); + Z = BitConverter.ToSingle(byteArray, pos + 8); + S = BitConverter.ToSingle(byteArray, pos + 12); + } } /// @@ -641,7 +679,7 @@ namespace libsecondlife /// public override string ToString() { - return X.ToString() + " " + Y.ToString() + " " + Z.ToString() + " " + S.ToString(); + return "<" + X.ToString() + ", " + Y.ToString() + ", " + Z.ToString() + ", " + S.ToString() + ">"; } /// @@ -651,22 +689,22 @@ namespace libsecondlife } /// - /// + /// A quaternion, used for rotations /// [XmlRoot("quaternion")] public class LLQuaternion { - /// + /// X value [XmlAttribute("x")] public float X; - /// + /// Y value [XmlAttribute("y")] public float Y; - /// + /// Z value [XmlAttribute("z")] public float Z; - /// + /// W value [XmlAttribute("w")] public float W; /// - /// + /// Default constructor, initializes to no rotation (0,0,0,1) /// public LLQuaternion() { @@ -688,29 +726,48 @@ namespace libsecondlife { if (!BitConverter.IsLittleEndian) { - Array.Reverse(byteArray, pos, 4); - Array.Reverse(byteArray, pos + 4, 4); - Array.Reverse(byteArray, pos + 8, 4); - Array.Reverse(byteArray, pos + 12, 4); - } + byte[] newArray = new byte[16]; + Array.Copy(byteArray, pos, newArray, 0, 16); - X = BitConverter.ToSingle(byteArray, pos); - Y = BitConverter.ToSingle(byteArray, pos + 4); - Z = BitConverter.ToSingle(byteArray, pos + 8); - W = BitConverter.ToSingle(byteArray, pos + 12); + Array.Reverse(newArray, 0, 4); + Array.Reverse(newArray, 4, 4); + Array.Reverse(newArray, 8, 4); + Array.Reverse(newArray, 12, 4); + + X = BitConverter.ToSingle(newArray, 0); + Y = BitConverter.ToSingle(newArray, 4); + Z = BitConverter.ToSingle(newArray, 8); + W = BitConverter.ToSingle(newArray, 12); + } + else + { + X = BitConverter.ToSingle(byteArray, pos); + Y = BitConverter.ToSingle(byteArray, pos + 4); + Z = BitConverter.ToSingle(byteArray, pos + 8); + W = BitConverter.ToSingle(byteArray, pos + 12); + } } else { if (!BitConverter.IsLittleEndian) { - Array.Reverse(byteArray, pos, 4); - Array.Reverse(byteArray, pos + 4, 4); - Array.Reverse(byteArray, pos + 8, 4); - } + byte[] newArray = new byte[12]; + Array.Copy(byteArray, pos, newArray, 0, 12); - X = BitConverter.ToSingle(byteArray, pos); - Y = BitConverter.ToSingle(byteArray, pos + 4); - Z = BitConverter.ToSingle(byteArray, pos + 8); + Array.Reverse(newArray, 0, 4); + Array.Reverse(newArray, 4, 4); + Array.Reverse(newArray, 8, 4); + + X = BitConverter.ToSingle(newArray, 0); + Y = BitConverter.ToSingle(newArray, 4); + Z = BitConverter.ToSingle(newArray, 8); + } + else + { + X = BitConverter.ToSingle(byteArray, pos); + Y = BitConverter.ToSingle(byteArray, pos + 4); + Z = BitConverter.ToSingle(byteArray, pos + 8); + } float xyzsum = 1 - X * X - Y * Y - Z * Z; W = (xyzsum > 0) ? (float)Math.Sqrt(xyzsum) : 0; @@ -776,18 +833,26 @@ namespace libsecondlife } else { - throw new Exception("Quaternion <" + X + "," + Y + "," + Z + "," + W + "> normalized to zero"); + throw new Exception("Quaternion " + this.ToString() + " normalized to zero"); } return bytes; } + /// + /// + /// + /// public override int GetHashCode() { - float sum = X + Y + Z + W; - return sum.GetHashCode(); + return (X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode()); } + /// + /// + /// + /// + /// public override bool Equals(object o) { if (!(o is LLQuaternion)) return false; @@ -797,6 +862,12 @@ namespace libsecondlife return X == quaternion.X && Y == quaternion.Y && Z == quaternion.Z && W == quaternion.W; } + /// + /// + /// + /// + /// + /// public static bool operator ==(LLQuaternion lhs, LLQuaternion rhs) { // If both are null, or both are same instance, return true @@ -815,11 +886,23 @@ namespace libsecondlife return lhs.X == rhs.X && lhs.Y == rhs.Y && lhs.Z == rhs.Z && lhs.W == rhs.W; } + /// + /// + /// + /// + /// + /// public static bool operator !=(LLQuaternion lhs, LLQuaternion rhs) { return !(lhs == rhs); } + /// + /// + /// + /// + /// + /// public static LLQuaternion operator *(LLQuaternion lhs, LLQuaternion rhs) { LLQuaternion ret = new LLQuaternion(); diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs index db924b25..f3bd13b4 100644 --- a/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs +++ b/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs @@ -2,14 +2,14 @@ namespace Nwc.XmlRpc { using System; - /// Standard XML-RPC error codes. + /// Standard XML-RPC error codes public class XmlRpcErrorCodes { // -32400 ---> system error - /// + /// Transport error public const int TRANSPORT_ERROR = -32300; - /// + /// Transport error message public const String TRANSPORT_ERROR_MSG = "Transport Layer Error"; } } diff --git a/libsecondlife-cs/examples/slaccountant/frmSLAccountant.cs b/libsecondlife-cs/examples/slaccountant/frmSLAccountant.cs index f29fa271..857f4230 100644 --- a/libsecondlife-cs/examples/slaccountant/frmSLAccountant.cs +++ b/libsecondlife-cs/examples/slaccountant/frmSLAccountant.cs @@ -453,7 +453,7 @@ namespace SLAccountant query.AgentData.AgentID = client.Network.AgentID; query.AgentData.SessionID = client.Network.SessionID; query.QueryData.QueryFlags = 1; - query.QueryData.QueryID = LLUUID.GenerateUUID(); + query.QueryData.QueryID = LLUUID.Random(); query.QueryData.QueryStart = 0; query.QueryData.QueryText = Helpers.StringToField(txtFind.Text); query.Header.Reliable = true;