Beispiel #1
0
 public void ReadFromCDO(Stream stream)
 {
     X       = stream.ReadShort();
     Y       = stream.ReadShort();
     Z       = stream.ReadShort();
     Padding = stream.ReadUShort();
 }
Beispiel #2
0
        public override void Restore(Stream str)
        {
            base.Restore(str);

            if (str.ReadByte() == 0)
            {
                AcceptsFocus = str.ReadBool();
                SortIndex    = str.ReadInteger();
                IsCheckable  = str.ReadBool();
                SlotHint     = BinaryHelper.ReadString(str);

                short numberOfStates = str.ReadShort();

                if (numberOfStates > 0)
                {
                    for (int i = 0; i < numberOfStates; i++)
                    {
                        BlockState state = (BlockState)str.ReadShort();

                        SingleSlotBlockStateData ssbsd = new SingleSlotBlockStateData();
                        ssbsd.Restore(str);

                        stateData.Add(state, ssbsd);
                    }
                }
            }
        }
Beispiel #3
0
 public void ReadFromCDO(Stream stream)
 {
     X     = stream.ReadShort(); // these are probably in the wrong order
     Y     = stream.ReadShort();
     Z     = stream.ReadShort();
     Scale = stream.ReadUShort();
 }
Beispiel #4
0
        public override void FromRaw(Stream s, int mapVersion)
        {
            ElementId    = s.ReadUInt();
            Hue.Red      = (byte)s.ReadByte();
            Hue.Green    = (byte)s.ReadByte();
            Hue.Blue     = (byte)s.ReadByte();
            Shadow.Red   = (byte)s.ReadByte();
            Shadow.Green = (byte)s.ReadByte();
            Shadow.Blue  = (byte)s.ReadByte();

            if (mapVersion <= 4)
            {
                Offset.X      = (short)s.ReadByte();
                Offset.Y      = (short)s.ReadByte();
                PixelOffset.X = (short)(Offset.X * AtouinConstants.CellHalfWidth);
                PixelOffset.Y = (short)(Offset.Y * AtouinConstants.CellHalfHeight);
            }
            else
            {
                PixelOffset.X = s.ReadShort();
                PixelOffset.Y = s.ReadShort();
                Offset.X      = (short)(PixelOffset.X / AtouinConstants.CellHalfWidth);
                Offset.Y      = (short)(PixelOffset.Y / AtouinConstants.CellHalfHeight);
            }

            Altitude   = (byte)s.ReadByte();
            Identifier = s.ReadUInt();
        }
Beispiel #5
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt();
     Slot     = aStream.ReadShort();
     ItemID   = aStream.ReadShort();
     Damage   = aStream.ReadShort();
 }
Beispiel #6
0
        /// <summary>
        /// Creates a <see cref="JavaClass"/> instance from bytes.
        /// </summary>
        /// <param name="stream">The stream to create the class file from.</param>
        /// <returns>A new <see cref="JavaClass"/> instance.</returns>
        public static JavaClass Create(Stream stream)
        {
            Guard.NotNull(ref stream, nameof(stream));

            JavaClass result = new JavaClass();

            result.Magic             = stream.ReadInteger();
            result.MinorVersion      = stream.ReadShort();
            result.MajorVersion      = stream.ReadShort();
            result.ConstantPoolCount = stream.ReadShort();
            result.ConstantPool      = ReadConstants(stream, result.ConstantPoolCount);
            result.AccessFlags       = (JavaClassAccessFlags)stream.ReadShort();
            result.ThisClassIndex    = stream.ReadShort();
            result.SuperClassIndex   = stream.ReadShort();
            result.InterfacesCount   = stream.ReadShort();
            result.Interfaces        = stream.ReadShorts(result.InterfacesCount);
            result.FieldsCount       = stream.ReadShort();
            result.Fields            = ReadFields(stream, result.FieldsCount, result.ConstantPool);
            result.MethodsCount      = stream.ReadShort();
            result.Methods           = ReadMethods(stream, result.MethodsCount, result.ConstantPool);
            result.AttributesCount   = stream.ReadShort();
            result.Attributes        = JavaAttribute.ReadFromStream(stream, result.AttributesCount, result.ConstantPool);

            return(result);
        }
Beispiel #7
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt();
     VelX     = aStream.ReadShort();
     VelY     = aStream.ReadShort();
     VelZ     = aStream.ReadShort();
 }
Beispiel #8
0
        public override void Restore(Stream str)
        {
            base.Restore(str);

            if (str.ReadByte() == 0)
            {
                IsUnpacked         = str.ReadBool();
                SecondaryEntryType = (PaletteEntryType)str.ReadShort();

                int numberOfItems = str.ReadInteger();

                if (numberOfItems > 0)
                {
                    for (int i = 0; i < numberOfItems; i++)
                    {
                        BlockState state = (BlockState)str.ReadShort();

                        SlotStyleData ssd = new SlotStyleData();
                        ssd.Restore(str);

                        Data.Add(state, ssd);
                    }
                }
            }
        }
		public static PlainTextExtension Read(Stream stream)
		{
			var blockSize = stream.ReadByte();
			if (blockSize != BlockSize)
			{
				throw new GifException("Plain text extension data format error");
			}

			var result = new PlainTextExtension
				{
					TextGridLeftPosition = stream.ReadShort(),
					TextGridTopPosition = stream.ReadShort(),
					TextGridWidth = stream.ReadShort(),
					TextGridHeight = stream.ReadShort(),
					CharacterCellWidth = (byte) stream.ReadByte(),
					CharacterCellHeight = (byte) stream.ReadByte(),
					TextForegroundColorIndex = (byte) stream.ReadByte(),
					TextBackgroundColorIndex = (byte) stream.ReadByte(),
					PlainTextData = new List<string>()
				};

			blockSize = stream.ReadByte();
			while (blockSize > 0)
			{
				var plainTextData = stream.ReadString(blockSize);
				result.PlainTextData.Add(plainTextData);

				blockSize = stream.ReadByte();
			}

			return result;
		}
 public static SVector3 ReadSVector3(
     this Stream stream, Endian endianness = Endian.BIG)
 {
     return(new SVector3(
                stream.ReadShort(endianness),
                stream.ReadShort(endianness),
                stream.ReadShort(endianness)));
 }
Beispiel #11
0
 public void ReadFromCAR(Stream stream)
 {
     X = stream.ReadShort();
     stream.ReadShort();   // unused Y, always 0
     Z = stream.ReadShort();
     Z = (short)(0 - Z);   // is this needed like with the main model verts?
     stream.Position += 2; // padding
 }
Beispiel #12
0
 public override void FromRaw(Stream s, int mapVersion)
 {
     SoundId = s.ReadInt();
     BaseVolume = s.ReadShort();
     FullVolumeDistance = s.ReadInt();
     NullVolumeDistance = s.ReadInt();
     MinDelayBetweenLoops = s.ReadShort();
     MaxDelayBetweenLoops = s.ReadShort();
 }
Beispiel #13
0
        /// <summary>
        /// Reads a method from the stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="constantPool">The constant pool used for finding the attribute names.</param>
        /// <returns>The method read from the stream.</returns>
        private static JavaMethod ReadMethod(Stream stream, JavaConstantPool constantPool)
        {
            JavaMethodAccessFlags flags = (JavaMethodAccessFlags)stream.ReadShort();
            ushort nameIndex            = stream.ReadShort();
            ushort descriptorIndex      = stream.ReadShort();
            ushort attributesCount      = stream.ReadShort();

            IJavaAttribute[] attributes = JavaAttribute.ReadFromStream(stream, attributesCount, constantPool);
            return(new JavaMethod(flags, nameIndex, descriptorIndex, attributesCount, attributes));
        }
 public override void FromRaw(Stream s, int fileVersion)
 {
     GfxId              = s.ReadInt();
     Height             = s.ReadByte();
     HorizontalSymmetry = s.ReadBoolean();
     Origin.X           = s.ReadShort();
     Origin.Y           = s.ReadShort();
     Size.X             = s.ReadShort();
     Size.Y             = s.ReadShort();
 }
Beispiel #15
0
        public void Restore(Stream str)
        {
            if (str.ReadByte() == 0)
            {
                short contentIDSize = str.ReadShort();

                if (contentIDSize > 0)
                {
                    ContentID = str.ReadBytes(contentIDSize);
                }
                else
                {
                    ContentID = null;
                }

                MediaType         = (MediaPrimitiveType)str.ReadShort();
                Delivery          = (MediaDelivery)str.ReadShort();
                FileName          = BinaryHelper.ReadString(str);
                DownloadSize      = str.ReadInteger();
                DownloadURL       = BinaryHelper.ReadString(str);
                MediaWidth        = str.ReadShort();
                MediaHeight       = str.ReadShort();
                ImageStripIndex   = str.ReadShort();
                ImageStripTotal   = str.ReadShort();
                DeviceGroup       = (DeviceGroup)str.ReadShort();
                VectorMediaFormat = (MediaFormat)str.ReadShort();
            }
        }
        public override void Restore(Stream str)
        {
            base.Restore(str);

            if (str.ReadByte() == 0)
            {
                SpecialTag        = str.ReadInteger();
                AcceptsFocus      = str.ReadBool();
                SortIndex         = str.ReadInteger();
                IsCheckable       = str.ReadBool();
                DeviceTextScaling = str.ReadBool();

                // static display data
                if (str.ReadByte() == 1)
                {
                    StaticDisplayData = new DisplayDataCollection();
                    StaticDisplayData.Restore(str);
                }
                else
                {
                    StaticDisplayData = null;
                }

                // slot hints
                int slotHintsCount = str.ReadInteger();

                if (slotHintsCount > 0)
                {
                    SlotHints = new string[slotHintsCount];

                    for (int i = 0; i < slotHintsCount; i++)
                    {
                        SlotHints[i] = BinaryHelper.ReadString(str);
                    }
                }
                else
                {
                    SlotHints = null;
                }

                // state data
                short statesCount = str.ReadShort();

                for (int i = 0; i < statesCount; i++)
                {
                    BlockState st = (BlockState)str.ReadShort();

                    AtomicBlockStateData stData = new AtomicBlockStateData();
                    stData.Restore(str);

                    stateData[st] = stData;
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Reads a number of exception table entries from a stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="count">The number of exception table entries.</param>
        /// <returns>Exception table.</returns>
        private static JavaExceptionTableEntry[] ReadExceptionTable(Stream stream, int count)
        {
            JavaExceptionTableEntry[] result = new JavaExceptionTableEntry[count];

            for (int i = 0; i < count; i++)
            {
                result[i] = new JavaExceptionTableEntry(stream.ReadShort(), stream.ReadShort(), stream.ReadShort(), stream.ReadShort());
            }

            return(result);
        }
Beispiel #18
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID   = aStream.ReadInt();
     ItemID     = aStream.ReadShort();
     Count      = aStream.ReadByte2();
     DamageData = aStream.ReadShort();
     X          = aStream.ReadInt();
     Y          = aStream.ReadInt();
     Z          = aStream.ReadInt();
     Rotation   = aStream.ReadByte2();
     Pitch      = aStream.ReadByte2();
     Roll       = aStream.ReadByte2();
 }
Beispiel #19
0
 public override void ReadFromStream(Stream aStream)
 {
     X         = aStream.ReadInt();
     Y         = aStream.ReadByte2();
     Z         = aStream.ReadInt();
     Direction = aStream.ReadFace();
     ItemID    = aStream.ReadShort();
     if (ItemID >= 0)
     {
         Amount = aStream.ReadByte2();
         Damage = aStream.ReadShort();
     }
 }
Beispiel #20
0
        /* Unpack a GMP into a Bitmap */
        public override Bitmap Unpack(ref Stream data)
        {
            try
            {
                /* Get and set image variables */
                int width      = data.ReadInt(0xC); // Width
                int height     = data.ReadInt(0x8); // Height
                short bitDepth = data.ReadShort(0x1E); // Bit Depth
                short colors   = data.ReadShort(0x1C); // Pallete Entries

                /* Throw an exception if this is not an 8-bit gmp (for now) */
                if (bitDepth != 8)
                    throw new Exception();

                /* Set up the image */
                Bitmap image = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
                BitmapData imageData = image.LockBits(
                    new Rectangle(0, 0, width, height),
                    ImageLockMode.WriteOnly, image.PixelFormat);

                /* Read the data from the GMP */
                unsafe
                {
                    /* Write the palette */
                    ColorPalette palette = image.Palette;
                    for (int i = 0; i < colors; i++)
                        palette.Entries[i] = Color.FromArgb(data.ReadByte(0x20 + (i * 0x4) + 0x2), data.ReadByte(0x20 + (i * 0x4) + 0x1), data.ReadByte(0x20 + (i * 0x4)));

                    image.Palette = palette;

                    /* Start getting the pixels from the source image */
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            byte* rowData = (byte*)imageData.Scan0 + (y * imageData.Stride);
                            rowData[x] = data.ReadByte(0x20 + (colors * 0x4) + (width * height) - ((y + 1) * width) + x);
                        }
                    }
                }

                /* Unlock the bits now. */
                image.UnlockBits(imageData);

                return image;
            }
            catch
            {
                return null;
            }
        }
Beispiel #21
0
        /// <summary>
        /// Reads this attributes from the stream.
        /// </summary>
        /// <param name="nameIndex">Index of the name.</param>
        /// <param name="length">The length.</param>
        /// <param name="stream">The stream.</param>
        /// <returns>The attribute from the stream.</returns>
        public static JavaAttributeBootstrapMethods ReadFromStream(ushort nameIndex, uint length, Stream stream)
        {
            ushort count = stream.ReadShort();

            JavaBootstrapMethod[] methods = new JavaBootstrapMethod[count];
            for (int i = 0; i < count; i++)
            {
                ushort reference     = stream.ReadShort();
                ushort argumentCount = stream.ReadShort();
                methods[i] = new JavaBootstrapMethod(reference, argumentCount, stream.ReadShorts(argumentCount));
            }

            return(new JavaAttributeBootstrapMethods(nameIndex, length, count, methods));
        }
        /// <summary>
        /// Reads this attribute from the stream.
        /// </summary>
        /// <param name="nameIndex">Index of the name.</param>
        /// <param name="length">The length.</param>
        /// <param name="stream">The stream.</param>
        /// <returns>The attribute from the stream.</returns>
        public static JavaAttributeMethodParameters ReadFromStream(ushort nameIndex, uint length, Stream stream)
        {
            Guard.NotNull(ref stream, nameof(stream));

            byte count = (byte)stream.ReadByte();

            JavaParameter[] parameters = new JavaParameter[count];
            for (int i = 0; i < count; i++)
            {
                parameters[i] = new JavaParameter(stream.ReadShort(), stream.ReadShort());
            }

            return(new JavaAttributeMethodParameters(nameIndex, length, count, parameters));
        }
        public override void Restore(Stream str)
        {
            base.Restore(str);

            if (str.ReadByte() == 0)
            {
                // background
                if (str.ReadBool())
                {
                    PaintStyle bg = new PaintStyle();
                    bg.Restore(str);

                    Background = bg;
                }
                else
                {
                    Background = null;
                }

                // other settings
                IsZoomEnabled      = str.ReadBool();
                IsScrollEnabled    = str.ReadBool();
                IsAnimationEnabled = str.ReadBool();
                ShowUserLocation   = str.ReadBool();
                Mode = (WaveMapMode)str.ReadShort();
            }
        }
Beispiel #24
0
        public static Layer FromRaw(Stream s, int mapVersion)
        {
            var layer = new Layer();

            if (mapVersion >= 9)
            {
                layer.Id = s.ReadByte();
            }
            else
            {
                layer.Id = s.ReadInt();
            }

            var cellsCount = s.ReadShort();

            if (cellsCount > 0)
            {
                for (int i = 0; i < cellsCount; i++)
                {
                    layer.Cells.Add(Cell.FromRaw(s, mapVersion));
                }
                var maxMapCellId = AtouinConstants.MapCellsCount - 1;
                var lastCell     = layer.Cells.Last();
                if (lastCell.Id < maxMapCellId)
                {
                    var endCell = new Cell
                    {
                        Id = (short)maxMapCellId
                    };
                    layer.Cells.Add(endCell);
                }
            }

            return(layer);
        }
Beispiel #25
0
        public ClaimsSetMetadata(byte[] data)
            : base(data)
        {
            ClaimSetSize = Stream.ReadInt();

            Stream.Seek(4);

            CompressionFormat        = (CompressionFormat)Stream.ReadInt();
            UncompressedClaimSetSize = Stream.ReadInt();
            ReservedType             = Stream.ReadShort();
            ReservedFieldSize        = Stream.ReadInt();

            Stream.Align(8);

            var size = Stream.ReadInt();

            if (size != ClaimSetSize)
            {
                throw new InvalidDataException($"Data length {size} doesn't match expected ClaimSetSize {ClaimSetSize}");
            }

            var claimSet = Stream.Read(ClaimSetSize);

            if (CompressionFormat != CompressionFormat.COMPRESSION_FORMAT_NONE)
            {
                claimSet = Compressions.Decompress(claimSet, UncompressedClaimSetSize, CompressionFormat);
            }

            ClaimsSet = new ClaimsSet(claimSet);

            ReservedField = Stream.Read(ReservedFieldSize);
        }
Beispiel #26
0
        protected void ResignPackage(Stream kv, int headerStart, int size, int toSignLoc)
        {
            var rsaParameters = GetRSAParameters(kv);

            // read the certificate
            kv.Position = 0x9B8 + (kv.Length == 0x4000 ? 0x10 : 0);
            Certificate.PublicKeyCertificateSize = kv.ReadShort();
            kv.Read(Certificate.OwnerConsoleId, 0, 5);
            Certificate.OwnerConsolePartNumber = kv.ReadWString(0x11);
            Certificate.OwnerConsoleType       = (ConsoleType)(kv.ReadUInt() & 3);
            Certificate.DateGeneration         = kv.ReadWString(8);
            Certificate.PublicExponent         = kv.ReadUInt();
            kv.Read(Certificate.PublicModulus, 0, 128);
            kv.Read(Certificate.CertificateSignature, 0, 256);

            ConsoleId = Certificate.OwnerConsoleId.ToHex();

            HeaderHash = HashBlock(headerStart, ((HeaderSize + 0xFFF) & 0xF000) - headerStart);

            var rsaEncryptor = new RSACryptoServiceProvider();
            var rsaSigFormat = new RSAPKCS1SignatureFormatter(rsaEncryptor);

            rsaEncryptor.ImportParameters(rsaParameters);
            rsaSigFormat.SetHashAlgorithm("SHA1");
            var signature = rsaSigFormat.CreateSignature(HashBlock(toSignLoc, size));

            Array.Reverse(signature);

            Certificate.Signature = signature;
        }
Beispiel #27
0
        public static Cell FromRaw(Stream s, int mapVersion)
        {
            var cell = new Cell();

            cell.Id = s.ReadShort();
            var elementsCount = s.ReadShort();

            for (int i = 0; i < elementsCount; i++)
            {
                var element = BasicElement.FromType((ElementType)s.ReadByte());
                element.FromRaw(s, mapVersion);
                cell.Elements.Add(element);
            }

            return(cell);
        }
Beispiel #28
0
 public PacClientInfo(byte[] data)
     : base(data)
 {
     ClientId   = Stream.ReadFiletime();
     NameLength = Stream.ReadShort();
     Name       = Encoding.Unicode.GetString(Stream.Read(NameLength));
 }
Beispiel #29
0
 public virtual void Restore(Stream str)
 {
     if (str.ReadByte() == 0)
     {
         EntryType = (PaletteEntryType)str.ReadShort();
     }
 }
        public void Restore(Stream str)
        {
            if (str.ReadByte() == 0)
            {
                if (str.ReadByte() == 1)
                {
                    Font = str.ReadShort();
                }
                else
                {
                    Font = null;
                }

                if (str.ReadByte() == 1)
                {
                    PaintStyle fg = new PaintStyle();
                    fg.Restore(str);

                    Foreground = fg;
                }
                else
                {
                    Foreground = null;
                }

                if (str.ReadByte() == 1)
                {
                    PaintStyle fg = new PaintStyle();
                    fg.Restore(str);

                    Background = fg;
                }
                else
                {
                    Background = null;
                }

                if (str.ReadByte() == 1)
                {
                    SlotIndex = str.ReadShort();
                }
                else
                {
                    SlotIndex = null;
                }
            }
        }
Beispiel #31
0
        /// <summary>
        /// Reads an attribute from the given stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="constantPool">The constant pool used for finding the attribute names.</param>
        /// <returns>The attribute read from the stream.</returns>
        private static IJavaAttribute ReadAttribute(Stream stream, JavaConstantPool constantPool)
        {
            ushort nameIndex = stream.ReadShort();
            uint   length    = stream.ReadInteger();
            string name      = ((JavaConstantUtf8)constantPool[nameIndex]).Value;

            // TODO Implement commented cases.
            switch (name)
            {
            case "ConstantValue":
                return(new JavaAttributeConstantValue(nameIndex, length, stream.ReadShort()));

            case "Code":
                return(JavaAttributeCode.ReadFromStream(stream, constantPool, nameIndex, length));

            // case "StackMapTable":
            case "Exceptions":
                ushort exceptionCount = stream.ReadShort();
                return(new JavaAttributeExceptions(nameIndex, length, exceptionCount, stream.ReadShorts(exceptionCount)));

            case "BootstrapMethods":
                return(JavaAttributeBootstrapMethods.ReadFromStream(nameIndex, length, stream));

            // case "InnerClasses":
            // case "EnclosingMethods":
            // case "Synthetic":
            // case "Signature":
            // case "RuntimeVisibleAnnotations":
            // case "RuntimeInvisibleAnnotations":
            // case "RuntimeVisibleParameterAnnotations":
            // case "RuntimeInvisibleParameterAnnotations":
            // case "RuntimeVisibleTypeAnnotations":
            // case "RuntimeInvisibleTypeAnnotations":
            // case "AnnotationDefault":
            case "MethodParameters":
                return(JavaAttributeMethodParameters.ReadFromStream(nameIndex, length, stream));

            // case "Module":
            // case "ModulePackages":
            // case "ModuleMainClass":
            // case "NestHost":
            // case "NestMembers":
            default:
                return(new JavaAttributeUnknown(nameIndex, length, stream.ReadBytes(length)));
            }
        }
Beispiel #32
0
        public static Fixture FromRaw(Stream s)
        {
            var fixture = new Fixture();

            fixture.Id          = s.ReadInt();
            fixture.Offset.X    = s.ReadShort();
            fixture.Offset.Y    = s.ReadShort();
            fixture.Rotation    = s.ReadShort();
            fixture.Scale.X     = s.ReadShort();
            fixture.Scale.Y     = s.ReadShort();
            fixture.Color.Red   = (byte)s.ReadByte();
            fixture.Color.Green = (byte)s.ReadByte();
            fixture.Color.Blue  = (byte)s.ReadByte();
            fixture.Color.Alpha = (byte)s.ReadByte();

            return(fixture);
        }
		public static ImageDescriptor Read(Stream stream)
		{
			var result = new ImageDescriptor
				{
					ImageLeftPosition = stream.ReadShort(),
					ImageTopPosition = stream.ReadShort(),
					ImageWidth = stream.ReadShort(),
					ImageHeight = stream.ReadShort(),
					PackedFields = (byte) stream.ReadByte()
				};

			result.LocalColorTableFlag = ((result.PackedFields & 0x80) >> 7) == 1;
			result.InterlaceFlag = ((result.PackedFields & 0x40) >> 6) == 1;
			result.SortFlag = ((result.PackedFields & 0x20) >> 5) == 1;
			result.LocalColorTableSize = (2 << (result.PackedFields & 0x07));

			return result;
		}
		public static LogicalScreenDescriptor Read(Stream stream)
		{
			var result = new LogicalScreenDescriptor
				{
					LogicalScreenWidth = stream.ReadShort(),
					LogicalScreenHeight = stream.ReadShort(),
					PackedFields = (byte) stream.ReadByte()
				};

			result.GlobalColorTableFlag = ((result.PackedFields & 0x80) >> 7) == 1;
			result.ColorResolution = (byte) ((result.PackedFields & 0x60) >> 5);
			result.SortFlag = (byte) (result.PackedFields & 0x10) >> 4;
			result.GlobalColorTableSize = 2 << (result.PackedFields & 0x07);
			result.BackgroundColorIndex = (byte) stream.ReadByte();
			result.PixelAspectRatio = (byte) stream.ReadByte();

			return result;
		}
		public static GraphicControlExtension Read(Stream stream)
		{
			var blockSize = stream.ReadByte();
			if (blockSize != BlockSize)
			{
				throw new GifException("Graphic control extension data format error");
			}

			var result = new GraphicControlExtension
				{
					PackedFields = (byte) stream.ReadByte()
				};

			result.TransparentColorFlag = (result.PackedFields & 0x01) == 1;
			result.DisposalMethod = (result.PackedFields & 0x1C) >> 2;
			result.DelayTime = stream.ReadShort();
			result.TransparentColorIndex = (byte) stream.ReadByte();
			stream.ReadByte();

			return result;
		}
Beispiel #36
0
 public override void ReadFromStream(Stream aStream)
 {
     X = aStream.ReadInt ();
     Y = aStream.ReadByte2 ();
     Z = aStream.ReadInt ();
     Direction = aStream.ReadFace ();
     ItemID = aStream.ReadShort ();
     if (ItemID >= 0) {
         Amount = aStream.ReadByte2 ();
         Damage = aStream.ReadShort ();
     }
 }
Beispiel #37
0
 protected void ReadKeepAlive(Stream stream) {
     KeepAlive = stream.ReadShort();
     length += 2;
 }
        private static Exception CreateExceptionFromError(Stream stream)
        {
            ErrorCodes code = (ErrorCodes) stream.ReadInt();
            string msg = stream.ReadString();

            switch (code)
            {
                case ErrorCodes.Unavailable:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadShort();
                        int required = stream.ReadInt();
                        int alive = stream.ReadInt();
                        return new UnavailableException(msg, cl, required, alive);
                    }

                case ErrorCodes.WriteTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        string writeType = stream.ReadString();
                        return new WriteTimeOutException(msg, cl, received, blockFor, writeType);
                    }

                case ErrorCodes.ReadTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        bool dataPresent = 0 != stream.ReadByte();
                        return new ReadTimeOutException(msg, cl, received, blockFor, dataPresent);
                    }

                case ErrorCodes.Syntax:
                    return new SyntaxException(msg);

                case ErrorCodes.Unauthorized:
                    return new UnauthorizedException(msg);

                case ErrorCodes.Invalid:
                    return new InvalidException(msg);

                case ErrorCodes.AlreadyExists:
                    {
                        string keyspace = stream.ReadString();
                        string table = stream.ReadString();
                        return new AlreadyExistsException(msg, keyspace, table);
                    }

                case ErrorCodes.Unprepared:
                    {
                        byte[] unknownId = stream.ReadShortBytes();
                        return new UnpreparedException(msg, unknownId);
                    }

                default:
                    return new CassandraException(code, msg);
            }
        }
Beispiel #39
0
 protected void ReadMessageIdentifier(Stream stream) {
     MessageIdentifier = stream.ReadShort();
     length += 2;
 }
Beispiel #40
0
 public override void ReadFromStream(Stream aStream)
 {
     SlotID = aStream.ReadShort ();
 }
Beispiel #41
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt ();
     PlayerName = aStream.ReadString16 ();
     X = aStream.ReadInt ();
     Y = aStream.ReadInt ();
     Z = aStream.ReadInt ();
     Rotation = aStream.ReadByte2 ();
     Pitch = aStream.ReadByte2 ();
     CurrentItem = aStream.ReadShort ();
 }
Beispiel #42
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt ();
     VelX = aStream.ReadShort ();
     VelY = aStream.ReadShort ();
     VelZ = aStream.ReadShort ();
 }
Beispiel #43
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt ();
     Slot = aStream.ReadShort ();
     ItemID = aStream.ReadShort ();
     Damage = aStream.ReadShort ();
 }
Beispiel #44
0
 public override void ReadFromStream(Stream aStream)
 {
     Health = aStream.ReadShort ();
 }
Beispiel #45
0
        internal int DecodeParamI4(Stream reader)
        {
            switch (this.flags & OpcodeFlags.OperandType) {
            case OpcodeFlags.NoOperand:
                throw new Exception ("no param");
            case OpcodeFlags.OperandSize1:
                return reader.ReadByte ();
            case OpcodeFlags.OperandSize2:
                return reader.ReadShort ();
            case OpcodeFlags.OperandSize4:
                return reader.ReadInt ();
            case OpcodeFlags.OperandSize8:
                throw new Exception ("param of size 8");

            case OpcodeFlags.OperandSwitch:
                throw new Exception ("variable length param");
            default:
                throw new Exception ("invalid opcode type " + this.flags);
            }
        }
Beispiel #46
0
 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt ();
     ItemID = aStream.ReadShort ();
     Count = aStream.ReadByte2 ();
     DamageData = aStream.ReadShort ();
     X = aStream.ReadInt ();
     Y = aStream.ReadInt ();
     Z = aStream.ReadInt ();
     Rotation = aStream.ReadByte2 ();
     Pitch = aStream.ReadByte2 ();
     Roll = aStream.ReadByte2 ();
 }