Exemple #1
0
        public static List <byte[]> GetRawAbcFiles(Stream input)
        {
            var swf = new SwfMovie();

            swf.Load(input, SwfTagDecodeOptions.Fast);
            return(swf.GetRawAbcFiles());
        }
Exemple #2
0
        public SwfSprite ImportSprite(SwfMovie from, SwfSprite sprite)
        {
            var mysprite = GetImportedTag(sprite) as SwfSprite;

            if (mysprite != null)
            {
                return(mysprite);
            }

            mysprite = new SwfSprite {
                FrameCount = sprite.FrameCount
            };

            _spriteStack.Push(mysprite);
            foreach (var tag in sprite.Tags)
            {
                Import(from, tag);
            }
            _spriteStack.Pop();

            mysprite.CharacterId = NewCharacterID();
            AddImport(sprite, mysprite);

            return(mysprite);
        }
Exemple #3
0
        public static void DumpSwf(string path)
        {
            var swf = new SwfMovie(path);

            swf.LinkAssets();
            DumpSwf(swf, path);
        }
Exemple #4
0
        public static void DumpSwc(string path)
        {
            var lib = path.ExtractSwfLibrary();
            var swf = new SwfMovie(lib);

            swf.LinkAssets();
            DumpSwf(swf, path);
        }
Exemple #5
0
        public void ImportCharacter(SwfMovie from, ref ushort id)
        {
            var c = from.GetCharacter(id);

            if (c == null)
            {
                throw UnableToImportChar(id);
            }
            c = Import(from, c as SwfTag) as ISwfCharacter;
            if (c == null)
            {
                throw UnableToImportChar(id);
            }
            id = c.CharacterId;
        }
Exemple #6
0
        public SwfTag Import(SwfMovie from, SwfTag tag)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }

            var mytag = GetImportedTag(tag);

            if (mytag != null)
            {
                Debug.Assert(Tags.Contains(mytag));
                return(mytag);
            }

            if (tag.TagCode == SwfTagCode.DefineSprite)
            {
                var sprite = tag as SwfSprite;
                if (sprite == null)
                {
                    throw new InvalidOperationException();
                }
                return(ImportSprite(from, sprite));
            }

            mytag = tag.Clone();
            mytag.ImportDependencies(from, this);

            var obj = mytag as ISwfCharacter;

            if (obj != null)
            {
                obj.CharacterId = NewCharacterID();
            }

            AddImport(tag, mytag);

            return(mytag);
        }
Exemple #7
0
        private static void DumpSwf(SwfMovie swf, string path)
        {
            swf.Dump(path + ".xml");
            if (!SwfOnly)
            {
                string dir = GetAbcDumpDir(path);
                foreach (var abc in swf.GetAbcFiles())
                {
                    Directory.CreateDirectory(dir);
                    //abc.DumpDirectory(dir);
                    string name = abc.Name.Replace('/', '.').Replace('\\', '.');
                    abc.DumpXml(Path.Combine(dir, name.ReplaceInvalidFileNameChars() + ".xml"));
                }

                if (DumpImages)
                {
                    SaveImages(swf, path + ".images");
                }
            }
        }
Exemple #8
0
        public static void SaveImages(SwfMovie swf, string dir)
        {
            foreach (var tag in swf.Tags)
            {
                var c = tag as ISwfImageCharacter;
                if (c != null)
                {
                    var img = c.Image;
                    if (img != null)
                    {
                        Directory.CreateDirectory(dir);

                        string name = "";
                        name += c.CharacterId;
                        if (img.IsIndexed())
                        {
                            name += "_indexed";
                        }
                        if (!string.IsNullOrEmpty(c.Name))
                        {
                            name += "_";
                            name += c.Name;
                        }

                        try
                        {
                            ImageExtensions.Save(img, Path.Combine(dir, name + ".png"));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Unable to save image. Exception:\n{0}", e);
                        }
                    }
                }
            }
        }