Example #1
0
        public int readblock(byte[] blockdata, int offset)
        {
            BitPack input = new BitPack(blockdata, offset);
            mLocation = input.UnpackInt();
            mLength = input.UnpackInt();
            mAccessTime = input.UnpackInt();
            mFileID = input.UnpackUUID();
            int filetype = input.UnpackShort();
            mAssetType = (AssetType)filetype;
            mSize = input.UnpackInt();
            offset += 34;

            Logger.Log(String.Format("Found header for {0} type {1} length {2} at {3}", mFileID, mAssetType, mSize, mLocation), Helpers.LogLevel.Info);

            return offset;
        }
            /// <summary>
            /// Decodes a byte[] array into a ParticleSystem Object
            /// </summary>
            /// <param name="data">ParticleSystem object</param>
            /// <param name="pos">Start position for BitPacker</param>
            public ParticleSystem(byte[] data, int pos)
            {
                // TODO: Not sure exactly how many bytes we need here, so partial
                // (truncated) data will cause an exception to be thrown
                if (data.Length > 0)
                {
                    BitPack pack = new BitPack(data, pos);

                    CRC = pack.UnpackUBits(32);
                    PartFlags = pack.UnpackUBits(32);
                    Pattern = (SourcePattern)pack.UnpackByte();
                    MaxAge = pack.UnpackFixed(false, 8, 8);
                    StartAge = pack.UnpackFixed(false, 8, 8);
                    InnerAngle = pack.UnpackFixed(false, 3, 5);
                    OuterAngle = pack.UnpackFixed(false, 3, 5);
                    BurstRate = pack.UnpackFixed(false, 8, 8);
                    BurstRadius = pack.UnpackFixed(false, 8, 8);
                    BurstSpeedMin = pack.UnpackFixed(false, 8, 8);
                    BurstSpeedMax = pack.UnpackFixed(false, 8, 8);
                    BurstPartCount = pack.UnpackByte();
                    float x = pack.UnpackFixed(true, 8, 7);
                    float y = pack.UnpackFixed(true, 8, 7);
                    float z = pack.UnpackFixed(true, 8, 7);
                    AngularVelocity = new Vector3(x, y, z);
                    x = pack.UnpackFixed(true, 8, 7);
                    y = pack.UnpackFixed(true, 8, 7);
                    z = pack.UnpackFixed(true, 8, 7);
                    PartAcceleration = new Vector3(x, y, z);
                    Texture = pack.UnpackUUID();
                    Target = pack.UnpackUUID();

                    PartDataFlags = (ParticleDataFlags)pack.UnpackUBits(32);
                    PartMaxAge = pack.UnpackFixed(false, 8, 8);
                    byte r = pack.UnpackByte();
                    byte g = pack.UnpackByte();
                    byte b = pack.UnpackByte();
                    byte a = pack.UnpackByte();
                    PartStartColor = new Color4(r, g, b, a);
                    r = pack.UnpackByte();
                    g = pack.UnpackByte();
                    b = pack.UnpackByte();
                    a = pack.UnpackByte();
                    PartEndColor = new Color4(r, g, b, a);
                    PartStartScaleX = pack.UnpackFixed(false, 3, 5);
                    PartStartScaleY = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleX = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleY = pack.UnpackFixed(false, 3, 5);
                }
                else
                {
                    CRC = PartFlags = 0;
                    Pattern = SourcePattern.None;
                    MaxAge = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                        BurstSpeedMax = 0.0f;
                    BurstPartCount = 0;
                    AngularVelocity = PartAcceleration = Vector3.Zero;
                    Texture = Target = UUID.Zero;
                    PartDataFlags = ParticleDataFlags.None;
                    PartMaxAge = 0.0f;
                    PartStartColor = PartEndColor = Color4.Black;
                    PartStartScaleX = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;
                }
            }
 void UnpackSystem(ref BitPack pack)
 {
     CRC = pack.UnpackUBits(32);
     PartFlags = pack.UnpackUBits(32);
     Pattern = (SourcePattern)pack.UnpackByte();
     MaxAge = pack.UnpackFixed(false, 8, 8);
     StartAge = pack.UnpackFixed(false, 8, 8);
     InnerAngle = pack.UnpackFixed(false, 3, 5);
     OuterAngle = pack.UnpackFixed(false, 3, 5);
     BurstRate = pack.UnpackFixed(false, 8, 8);
     BurstRadius = pack.UnpackFixed(false, 8, 8);
     BurstSpeedMin = pack.UnpackFixed(false, 8, 8);
     BurstSpeedMax = pack.UnpackFixed(false, 8, 8);
     BurstPartCount = pack.UnpackByte();
     float x = pack.UnpackFixed(true, 8, 7);
     float y = pack.UnpackFixed(true, 8, 7);
     float z = pack.UnpackFixed(true, 8, 7);
     AngularVelocity = new Vector3(x, y, z);
     x = pack.UnpackFixed(true, 8, 7);
     y = pack.UnpackFixed(true, 8, 7);
     z = pack.UnpackFixed(true, 8, 7);
     PartAcceleration = new Vector3(x, y, z);
     Texture = pack.UnpackUUID();
     Target = pack.UnpackUUID();
 }