public static new BoundingBoxGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader)
        {
            var data = new BoundingBoxGraphicalElementData(instance, id);

            data.Gfx = reader.ReadInt();
            data.Height = reader.ReadUInt();
            data.HorizontalSymmetry = reader.ReadBoolean();
            data.Origin = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());
            data.Size = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());

            return data;
        }
Ejemplo n.º 2
0
        public static DlmFixture ReadFromStream(DlmMap map, BigEndianReader reader)
        {
            var fixture = new DlmFixture(map);

            fixture.FixtureId = reader.ReadInt();
            fixture.Offset = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());
            fixture.Rotation = reader.ReadShort();
            fixture.ScaleX = reader.ReadShort();
            fixture.ScaleY = reader.ReadShort();
            fixture.Hue = reader.ReadByte() << 16 | reader.ReadByte() << 8 | reader.ReadByte();
            fixture.Alpha = reader.ReadByte();

            return fixture;
        }
Ejemplo n.º 3
0
        public static DlmCell ReadFromStream(DlmLayer layer, BigEndianReader reader)
        {
            var cell = new DlmCell(layer);

            cell.Id = reader.ReadShort();
            cell.Elements = new DlmBasicElement[reader.ReadShort()];

            for (int i = 0; i < cell.Elements.Length; i++)
            {
                DlmBasicElement element =
                    DlmBasicElement.ReadFromStream(cell, reader);
                cell.Elements[i] = element;
            }

            return cell;
        }
        public static ParticlesGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader)
        {
            var data = new ParticlesGraphicalElementData(instance, id);

            data.ScriptId = reader.ReadShort();

            return data;
        }
        public static new AnimatedGraphicalElementData ReadFromStream(EleInstance instance, int id, BigEndianReader reader)
        {
            var data = new AnimatedGraphicalElementData(instance, id);

            data.Gfx = reader.ReadInt();
            data.Height = reader.ReadUInt();
            data.HorizontalSymmetry = reader.ReadBoolean();
            data.Origin = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());
            data.Size = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());

            if (instance.Version == 4)
            {
                data.MinDelay = reader.ReadUInt();
                data.MaxDelay = reader.ReadUInt();
            }

            return data;
        }
        public static new DlmGraphicalElement ReadFromStream(DlmCell cell, BigEndianReader reader)
        {
            var element = new DlmGraphicalElement(cell);

            element.m_elementId = reader.ReadUInt();
            element.m_hue = new ColorMultiplicator(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), false);
            element.m_shadow = new ColorMultiplicator(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), false);

            if (cell.Layer.Map.Version <= 4)
            {
                element.m_offset.X = reader.ReadByte();
                element.m_offset.Y = reader.ReadByte();
                element.m_pixelOffset.X = (int) (element.m_offset.X * CELL_HALF_WIDTH);
                element.m_pixelOffset.Y = (int) (element.m_offset.Y * CELL_HALF_HEIGHT);
            }
            else
            {
                element.m_pixelOffset.X = reader.ReadShort();
                element.m_pixelOffset.Y = reader.ReadShort();
                element.m_offset.X = (int)( element.m_pixelOffset.X / CELL_HALF_WIDTH );
                element.m_offset.Y = (int)( element.m_pixelOffset.Y / CELL_HALF_HEIGHT );
            }

            element.m_altitude = reader.ReadByte();
            element.m_identifier = reader.ReadUInt();

            element.CalculateFinalTeint();

            return element;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Build or continue building the message. Returns true if the resulted message is valid and ready to be parsed
        /// </summary>
        public bool Build(BigEndianReader reader)
        {
            if (IsValid)
                return true;

            if (reader.BytesAvailable >= 2 && !Header.HasValue)
            {
                Header = reader.ReadShort();
            }

            if (LengthBytesCount.HasValue &&
                reader.BytesAvailable >= LengthBytesCount && !Length.HasValue)
            {
                if (LengthBytesCount < 0 || LengthBytesCount > 3)
                    throw new Exception("Malformated Message Header, invalid bytes number to read message length (inferior to 0 or superior to 3)");

                Length = 0;

                // 3..0 or 2..0 or 1..0
                for (int i = LengthBytesCount.Value - 1; i >= 0; i--)
                {
                    Length |= reader.ReadByte() << (i * 8);
                }
            }

            // first case : no data read
            if (Data == null && Length.HasValue)
            {
                if (Length == 0)
                    Data = new byte[0];

                // enough bytes in the buffer to build a complete message
                if (reader.BytesAvailable >= Length)
                {
                    Data = reader.ReadBytes(Length.Value);
                }
                // not enough bytes, so we read what we can
                else if (Length > reader.BytesAvailable)
                {
                    Data = reader.ReadBytes((int) reader.BytesAvailable);
                }
            }
            //second case : the message was split and it missed some bytes
            if (Data != null && Length.HasValue && Data.Length < Length)
            {
                int bytesToRead = 0;

                // still miss some bytes ...
                if (Data.Length + reader.BytesAvailable < Length)
                    bytesToRead = (int)reader.BytesAvailable;

                // there is enough bytes in the buffer to complete the message :)
                else if(Data.Length + reader.BytesAvailable >= Length)
                    bytesToRead = Length.Value - Data.Length;

                if(bytesToRead != 0)
                {
                    int oldLength = Data.Length;
                    Array.Resize(ref m_data, (int)( Data.Length + bytesToRead ));
                    Array.Copy(reader.ReadBytes(bytesToRead), 0, Data, oldLength, bytesToRead);
                }
            }

            return IsValid;
        }