Example #1
0
 public ButtonCondAction(SwfStream stream)
 {
     ushort size = stream.ReadUShort();
     mFlags = stream.ReadByte();
     mKey = stream.ReadByte();
     Actions = ActionRecord.ReadActions(stream, null);
 }
Example #2
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();

            int count = stream.ReadUShort() / 2;
            stream.Skip((count - 1) * 2);

            Glyphs = new FontGlyph[count];
            for (int i = 0; i < count; i++)
            {
                var subShapes = new Shape(ShapeInfo.ReadShape(stream, false, false, false, false), true).SubShapes;
                if (subShapes == null || subShapes.Length < 1) continue;

                var shape = subShapes[0];
                if (shape != null && shape.Fills.Count > 0)
                {
                    Glyphs[i] = new FontGlyph
                    {
                        GlyphPath = shape.Fills.Values.First().GetPath(),
                        ReferencePoint = new Vector2(shape.Shape.ReferencePoint.X, shape.Shape.ReferencePoint.Y) * EMSquareInv
                    };
                    Glyphs[i].GlyphPath.Scale(EMSquareInv);
                }
                else
                    Glyphs[i] = new FontGlyph { GlyphPath = new VGPath(), ReferencePoint = Vector2.Zero };
            }
        }
Example #3
0
        public static IEnumerable<ShapeRecord> ReadShape(SwfStream swf, bool hasAlpha, bool isExtended, bool hasStyle, bool extendedStyles)
        {
            ShapeState state = new ShapeState();

            swf.Align();
            if (hasStyle)
            {
                state.FillStyles = new FillStyleArray(swf, hasAlpha);
                state.LineStyles = new LineStyleArray(swf, hasAlpha, isExtended);
            }
            else
            {
                state.FillStyles = new FillStyleArray();
                state.LineStyles = new LineStyleArray();
            }

            state.FillBits = (int)swf.ReadBitUInt(4);
            state.LineBits = (int)swf.ReadBitUInt(4);

            ShapeRecord rec;

            while (true)
            {
                rec = new ShapeRecord(swf, hasAlpha, isExtended, extendedStyles, state);
                if (rec.Type == ShapeRecord.ShapeRecordType.EndOfShape)
                    break;

                yield return rec;
            }
        }
Example #4
0
        public ButtonRecord(SwfStream stream, Type defButtonType, out bool ok)
        {
            mFlags = stream.ReadByte();
            ok = (mFlags != 0);
            if (!ok)
                return;

            bool hasBlend = (mFlags & 0x20) != 0;
            bool hasFilters = (mFlags & 0x10) != 0;
            CharacterID = stream.ReadUShort();
            CharacterDepth = stream.ReadUShort();
            CharacterMatrix = stream.ReadMatrix();

            if (defButtonType == typeof(Tags.DefineButton2Tag))
            {
                CxForm = stream.ReadCxForm(true);
                Filters = hasFilters ? Filter.ReadFilterList(stream) : new Filter[0];
                Blending = hasBlend ? (BlendMode)stream.ReadByte() : BlendMode.Normal;
            }
            else
            {
                CxForm = VGCxForm.Identity;
                Filters = new Filter[0];
                Blending = BlendMode.Normal;
            }
        }
Example #5
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     CharacterID = stream.ReadUShort();
     Depth = stream.ReadUShort();
     Matrix = stream.ReadMatrix();
     CxForm = stream.TagPosition < length ? stream.ReadCxForm(false) : VGCxForm.Identity;
 }
Example #6
0
        protected override void DecompileBody(byte[] data)
        {
            SwfStream stream = data;

            Tag = stream.ReadShort();
            stream.ReadBytes(4);
            Data = stream.ReadToEnd();
        }
Example #7
0
 public GlowFilter(SwfStream stream)
 {
     GlowColor = stream.ReadRGBA();
     BlurX = stream.ReadFixed();
     BlurY = stream.ReadFixed();
     Strength = stream.ReadFixedHalf();
     mFlags = stream.ReadByte();
 }
Example #8
0
 public static Filter[] ReadFilterList(SwfStream stream)
 {
     byte count = stream.ReadByte();
     var filters = new Filter[count];
     for (; count > 0; count--)
         filters[filters.Length - count] = Read(stream);
     return filters;
 }
Example #9
0
        protected override byte[] CompileBody()
        {
            SwfStream stream = new SwfStream();

            stream.WriteShort(Tag);
            stream.WriteInt(0);
            stream.WriteBytes(Data);
            return(stream);
        }
Example #10
0
        protected override void DecompileBody(byte[] data)
        {
            SwfStream stream = data;

            Flags   = (DoAbcTagFlags)stream.ReadInt();
            Name    = stream.ReadString();
            AbcData = new Abc();
            AbcData.Decompile(stream.ReadToEnd());
        }
Example #11
0
        public LineStyleArray(SwfStream swf, bool hasAlpha, bool isExtended)
        {
            int count = swf.ReadByte();
            if (count == 0xFF) count = swf.ReadUShort();

            Styles = new LineStyle[count];
            for (int i = 0; i < count; i++)
                Styles[i] = new LineStyle(swf, hasAlpha, isExtended, i + 1);
        }
Example #12
0
        public FillStyleArray(SwfStream swf, bool hasAlpha)
        {
            int count = swf.ReadByte();
            if (count == 0xFF) count = swf.ReadUShort();

            Styles = new FillStyle[count];
            for (int i = 0; i < count; i++)
                Styles[i] = new FillStyle(swf, hasAlpha, i + 1);
        }
Example #13
0
        public ClipActionRecord(SwfStream stream)
        {
            EventFlags = stream.ReadClipEventFlags();
            if (EventFlags == ClipEventFlags.None) return;

            uint size = stream.ReadUInt();
            if ((EventFlags & ClipEventFlags.KeyPress) != 0) KeyCode = new KeyCode(stream.ReadByte());

            Actions = ActionRecord.ReadActions(stream, size);
        }
Example #14
0
        public GradientInfo(SwfStream swf, bool hasAlpha)
        {
            swf.Align();
            PadMode = (Padding)swf.ReadBitUInt(2);
            InterpolationMode = (Interpolation)swf.ReadBitUInt(2);
            GradientStops = new GradRecord[swf.ReadBitUInt(4)];

            for (int i = 0; i < GradientStops.Length; i++)
                GradientStops[i] = new GradRecord(swf, hasAlpha);
        }
Example #15
0
 public DropShadowFilter(SwfStream stream)
 {
     DropShadowColor = stream.ReadRGBA();
     BlurX = stream.ReadFixed();
     BlurY = stream.ReadFixed();
     Angle = stream.ReadFixed();
     Distance = stream.ReadFixed();
     Strength = stream.ReadFixedHalf();
     mFlags = stream.ReadByte();
 }
Example #16
0
 public BevelFilter(SwfStream stream)
 {
     ShadowColor = stream.ReadRGBA();
     HighlightColor = stream.ReadRGBA();
     BlurX = stream.ReadFixed();
     BlurY = stream.ReadFixed();
     Angle = stream.ReadFixed();
     Distance = stream.ReadFixed();
     Strength = stream.ReadFixedHalf();
     mFlags = stream.ReadByte();
 }
Example #17
0
        protected override byte[] CompileBody()
        {
            SwfStream stream = new SwfStream();

            stream.WriteInt((int)Flags);
            stream.WriteString(Name);
            byte[] abcData = AbcData.Compile();
            stream.WriteBytes(abcData);
            byte[] result = stream;
            return(result);
        }
Example #18
0
        public GradientGlowBevelFilter(SwfStream stream, bool bevel)
        {
            mId = bevel ? ID.GradientBevel : ID.GradientGlow;

            byte numColors = stream.ReadByte();
            GlowColors = stream.ReadRGBAArray(numColors);
            GlowRatios = stream.ReadByteArray(numColors);
            BlurX = stream.ReadFixed();
            BlurY = stream.ReadFixed();
            Strength = stream.ReadFixedHalf();
            mFlags = stream.ReadByte();
        }
Example #19
0
        public ShapeRecord(SwfStream swf, bool hasAlpha, bool isExtended, bool extendedStyles, ShapeState state)
        {
            int f0 = 0, f1 = 0, l = 0;

            mFlags = swf.ReadBitUInt(6);

            Type = ConvertType(mFlags);
            switch (Type)
            {
                case ShapeRecordType.StyleChange:
                    {
                        if (NewMoveTo)
                        {
                            int bits = (int)swf.ReadBitUInt(5);
                            MoveDeltaX = swf.ReadBitInt(bits);
                            MoveDeltaY = swf.ReadBitInt(bits);
                        }
                        if (NewFillStyle0) f0 = ((int)swf.ReadBitUInt(state.FillBits));
                        if (NewFillStyle1) f1 = ((int)swf.ReadBitUInt(state.FillBits));
                        if (NewLineStyle) l = ((int)swf.ReadBitUInt(state.LineBits));
                        if (NewStyles && extendedStyles)
                        {
                            state.FillStyles = new FillStyleArray(swf, hasAlpha);
                            state.LineStyles = new LineStyleArray(swf, hasAlpha, isExtended);
                            state.FillBits = (int)swf.ReadBitUInt(4);
                            state.LineBits = (int)swf.ReadBitUInt(4);
                        }
                        if (NewFillStyle0) FillStyle0 = state.GetFill(f0);
                        if (NewFillStyle1) FillStyle1 = state.GetFill(f1);
                        if (NewLineStyle) LineStyle = state.GetLine(l);
                    }
                    break;
                case ShapeRecordType.StraightEdge:
                    {
                        int bits = 2 + (int)(mFlags & 0x0F);
                        bool general = swf.ReadBit();
                        bool vert = general || swf.ReadBit();
                        DrawDeltaX = (general || !vert) ? swf.ReadBitInt(bits) : 0;
                        DrawDeltaY = (general ||  vert) ? swf.ReadBitInt(bits) : 0;
                    }
                    break;
                case ShapeRecordType.CurvedEdge:
                    {
                        int bits = 2 + (int)(mFlags & 0x0F);
                        DrawControlX = swf.ReadBitInt(bits);
                        DrawControlY = swf.ReadBitInt(bits);
                        DrawDeltaX = swf.ReadBitInt(bits);
                        DrawDeltaY = swf.ReadBitInt(bits);
                    }
                    break;
            }
        }
Example #20
0
        public ConvolutionFilter(SwfStream stream)
        {
            Width = stream.ReadByte();
            Height = stream.ReadByte();
            Divisor = stream.ReadSingle();
            Bias = stream.ReadSingle();
            Matrix = stream.ReadSingleArray(Width * Height);
            DefaultColor = stream.ReadRGBA();

            byte flags = stream.ReadByte();
            Clamp = (flags & 0x02) != 0;
            PreserveAlpha = (flags & 0x01) != 0;
        }
Example #21
0
        public override void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            ShapeBounds = stream.ReadRectangle();
            EdgeBounds = stream.ReadRectangle();

            byte res = stream.ReadByte();
            UsesFillWindingRule = version >= 10 && (res & 4) != 0;
            UsesNonScalingStrokes = (res & 2) != 0;
            UsesScalingStrokes = (res & 1) != 0;

            Shape = new Shape(ShapeInfo.ReadShape(stream, true, true, true, true), false);
        }
Example #22
0
        protected override void DecompileBody(byte[] data)
        {
            SwfStream stream = data;
            short     count  = stream.ReadShort();

            TagArray  = new short[count];
            NameArray = new string[count];
            for (int i = 0; i < count; i++)
            {
                TagArray[i]  = stream.ReadShort();
                NameArray[i] = stream.ReadString();
            }
        }
Example #23
0
        public TextRecord(SwfStream stream, bool hasAlpha, int glyphBits, int advanceBits)
        {
            _flags = stream.ReadByte();
            if (EndRecord) return;

            if (HasFont) FontId = stream.ReadUShort();
            if (HasColor) Color = hasAlpha ? stream.ReadRGBA() : stream.ReadRGB();
            if (HasXOffset) XOffset = stream.ReadShort();
            if (HasYOffset) YOffset = stream.ReadShort();
            if (HasFont) FontSize = stream.ReadUShort();

            byte count = stream.ReadByte();
            Glyphs = new GlyphEntry[count];
            for (int i = 0; i < count; i++)
                Glyphs[i] = new GlyphEntry(stream, glyphBits, advanceBits);
        }
Example #24
0
        protected override byte[] CompileBody()
        {
            SwfStream stream = new SwfStream();

            if (TagArray.Length != NameArray.Length)
            {
                throw new Exception("Names length and Tags length are not equal in SymbolClassTag");
            }

            stream.WriteShort((short)TagArray.Length);
            for (int i = 0; i < TagArray.Length; i++)
            {
                stream.WriteShort(TagArray[i]);
                stream.WriteString(NameArray[i]);
            }
            return(stream);
        }
Example #25
0
        protected void Load(SwfStream stream, uint length, bool hasDeblock)
        {
            CharacterID = stream.ReadUShort();
            uint alpha = stream.ReadUInt();
            Deblock = hasDeblock ? (ushort?)stream.ReadUShort() : null;
            byte[] data = stream.ReadByteArray(length - 6);

            ImageData = new byte[alpha];
            Array.Copy(data, 0, ImageData, 0, (int)alpha);
            Format = BitmapUtils.DetectFormat(ImageData);
            if (Format == BitmapFormat.Jpeg)
                ImageData = BitmapUtils.RepairJpegMarkers(ImageData);

            CompressedAlpha = new byte[data.Length - alpha];
            if (CompressedAlpha.Length > 0)
                Array.Copy(data, (int)alpha, CompressedAlpha, 0, CompressedAlpha.Length);
        }
Example #26
0
 public static Filter Read(SwfStream stream)
 {
     ID id = (ID)stream.ReadByte();
     switch (id)
     {
         case ID.DropShadow: return new DropShadowFilter(stream);
         case ID.Blur: return new BlurFilter(stream);
         case ID.Glow: return new GlowFilter(stream);
         case ID.Bevel: return new BevelFilter(stream);
         case ID.GradientGlow: return new GradientGlowBevelFilter(stream, false);
         case ID.Convolution: return new ConvolutionFilter(stream);
         case ID.ColorMatrix: return new ColorMatrixFilter(stream);
         case ID.GradientBevel: return new GradientGlowBevelFilter(stream, true);
         default:
             throw new SwfCorruptedException("Unknown filter found!");
     }
 }
Example #27
0
        public LineStyle(SwfStream swf, bool hasAlpha, bool isExtended, int index)
        {
            Index = index;

            if (isExtended)
            {
                Width = swf.ReadUShort();
                StartCapStyle = ReadCap(swf);
                JoinStyle = ReadJoin(swf);
                HasFill = swf.ReadBit();
                NoHScale = swf.ReadBit();
                NoVScale = swf.ReadBit();
                PixelHinting = swf.ReadBit();

                swf.ReadBitUInt(5); // Reserved

                NoClose = swf.ReadBit();
                EndCapStyle = ReadCap(swf);

                if (JoinStyle == VGLineJoin.Miter)
                    MiterLimit = swf.ReadFixedHalf();

                if (HasFill)
                    Fill = new FillStyle(swf, hasAlpha, -1);
                else
                    Color = swf.ReadRGBA();
            }
            else
            {
                Width = swf.ReadUShort();
                Color = hasAlpha ? swf.ReadRGBA() : swf.ReadRGB();

                StartCapStyle = VGLineCap.Round;
                EndCapStyle = VGLineCap.Round;
                JoinStyle = VGLineJoin.Round;
                HasFill = false;
                NoHScale = false;
                NoVScale = false;
                PixelHinting = false;
                NoClose = false;
                MiterLimit = 1m;
                Fill = null;
            }

            if (Width < 1) Width = 1;
        }
Example #28
0
        public ClipActions(SwfStream stream)
        {
            stream.ReadUShort();
            AllEvents = stream.ReadClipEventFlags();

            var records = new List<ClipActionRecord>();
            ClipActionRecord current;

            while(true)
            {
                current = new ClipActionRecord(stream);
                if (current.EventFlags == ClipEventFlags.None)
                    break;
                records.Add(current);
            }

            Records = records.ToArray();
        }
Example #29
0
        public byte[] Compile()
        {
            SwfStream stream = new SwfStream();

            byte[] body = CompileBody();
            if (body.Length >= 63)
            {
                stream.WriteShort((short)((Code << 6) | 63));
                stream.WriteInt(body.Length);
            }
            else
            {
                stream.WriteShort((short)((Code << 6) | body.Length));
            }

            stream.WriteBytes(body);

            return(stream);
        }
Example #30
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            FontID = stream.ReadUShort();
            Name = stream.ReadString(stream.ReadByte());
            Flags = (FontFlags)stream.ReadByte();
            ReadLangCode(stream);

            uint count = (uint)(length - stream.TagPosition);
            if ((Flags & FontFlags.WideCodes) != 0)
            {
                count /= 2;
                Characters = stream.ReadCharArray((int)count);
            }
            else
            {
                Characters = new char[count];
                for (int i = 0; i < count; i++)
                    Characters[i] = (char)stream.ReadByte();
            }
        }
        public void Load(SwfStream stream, uint length, byte version)
        {
            uint numScenes = stream.ReadEncodedUInt();
            var scenes = new Dictionary<string, ushort>((int)numScenes);
            for (uint i = 0; i < numScenes; i++)
            {
                ushort frame = (ushort)stream.ReadEncodedUInt();
                scenes.Add(stream.ReadString(), frame);
            }

            uint numLabels = stream.ReadEncodedUInt();
            var labels = new Dictionary<string, ushort>((int)numScenes);
            for (uint i = 0; i < numScenes; i++)
            {
                ushort label = (ushort)stream.ReadEncodedUInt();
                labels.Add(stream.ReadString(), label);
            }

            Scenes = scenes;
            FrameLabels = labels;
        }
Example #32
0
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            Bounds = stream.ReadRectangle();
            Matrix = stream.ReadMatrix();

            if (CharacterID == 347)
            { }

            byte gBits = stream.ReadByte();
            byte aBits = stream.ReadByte();

            List<TextRecord> recs = new List<TextRecord>();
            while (true)
            {
                var rec = new TextRecord(stream, HasAlpha, gBits, aBits);
                if (rec.EndRecord) break;
                recs.Add(rec);
            }
            TextRecords = recs.ToArray();
        }
Example #33
0
        protected bool Load(SwfStream stream, uint length, bool hasAlpha)
        {
            CharacterID = stream.ReadUShort();

            byte format = stream.ReadByte();
            Width = stream.ReadUShort();
            Height = stream.ReadUShort();
            byte table = (format == 3) ? stream.ReadByte() : (byte)0;
            byte[] compressed = stream.ReadByteArray(length - stream.TagPosition);
            byte[] data;
            var inflater = new Inflater();
            inflater.SetInput(compressed);

            if (format == 3)
            {
                int rem = Width % 4;
                data = new byte[((rem == 0) ? Width : (Width + 4 - rem)) * Height * 4];
                if (inflater.Inflate(data) != data.Length)
                    throw new SwfCorruptedException("Bitmap data are not valid ZLIB stream!");
                Pixels = BitmapUtils.UnpackIndexed(data, Width, Height, table, hasAlpha);
            }
            else if (format == 4 && !hasAlpha)
            {
                data = new byte[(Width + Width & 0x01) * Height * 2];
                if (inflater.Inflate(data) != data.Length)
                    throw new SwfCorruptedException("Bitmap data are not valid ZLIB stream!");
                Pixels = BitmapUtils.UnpackPIX15(data, Width, Height);
            }
            else if (format == 5)
            {
                data = new byte[Width * Height * 4];
                if (inflater.Inflate(data) != data.Length)
                    return true;
                Pixels = BitmapUtils.UnpackPIX24(data, Width, Height, hasAlpha);
            }
            else
                throw new SwfCorruptedException("Invalid lossless bitmap format found!");

            return true;
        }
Example #34
0
        public void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            FrameCount = stream.ReadUShort();

            List<ISwfControlTag> tags = new List<ISwfControlTag>(256);
            ISwfTag tag;

            do
            {
                tag = stream.ReadTag();
                if (tag == null)
                    continue;

                CheckTagValidity(tag);

                if (tag is EndTag)
                    break;
                else
                    tags.Add((ISwfControlTag)tag);
            } while (true);

            Tags = tags.ToArray();
        }
Example #35
0
        public void Load(SwfStream stream, uint length, byte version)
        {
            long end = length + stream.TagPosition;

            CharacterID = stream.ReadUShort();
            TrackAsMenu = (stream.ReadByte() & 0x01) != 0;
            ushort actionOffset = stream.ReadUShort();

            var type = GetType();
            var parts = new List<ButtonRecord>();
            bool ok;
            while (true)
            {
                var part = new ButtonRecord(stream, type, out ok);
                if (!ok) break;
                parts.Add(part);
            }
            Parts = parts.ToArray();

            var actions = new List<ButtonCondAction>();
            while (stream.TagPosition < end)
                actions.Add(new ButtonCondAction(stream));
            Actions = actions.ToArray();
        }
Example #36
0
 public void Load(SwfStream stream, uint length, byte version)
 {
     Actions = ActionRecord.ReadActions(stream, null);
 }
Example #37
0
 public virtual void ReadLangCode(SwfStream stream)
 {
     LanguageCode = SwfLanguage.None;
 }