コード例 #1
0
        static SwfSymbolData LoadSymbol(
            string swf_path, string symbol_name, SwfLibrary library, List <SwfTagBase> tags)
        {
            var warnings = new HashSet <string>();
            var disp_lst = new SwfDisplayList();
            var executer = new SwfContextExecuter(library, 0, warning_msg => {
                warnings.Add(warning_msg);
            });
            var symbol_frames = new List <SwfFrameData>();

            while (executer.NextFrame(tags, disp_lst))
            {
                _progressBar.UpdateProgress(
                    string.Format("swf symbols loading ({0})", symbol_name),
                    (float)(executer.CurrentTag + 1) / tags.Count);
                symbol_frames.Add(LoadSymbolFrameData(library, disp_lst, warning_msg => {
                    warnings.Add(warning_msg);
                }));
            }
            foreach (var warning in warnings)
            {
                Debug.LogWarningFormat(
                    AssetDatabase.LoadMainAssetAtPath(swf_path),
                    "<b>[FlashTools]</b> {0}\nSwf path: {1}",
                    warning, swf_path);
            }
            return(new SwfSymbolData {
                Name = symbol_name,
                Frames = symbol_frames
            });
        }
コード例 #2
0
        // ---------------------------------------------------------------------
        //
        // LoadBitmaps
        //
        // ---------------------------------------------------------------------

        static List <SwfBitmapData> LoadBitmaps(SwfLibrary library)
        {
            return(library.Defines
                   .Where(p => p.Value.Type == SwfLibraryDefineType.Bitmap)
                   .ToDictionary(p => p.Key, p => p.Value as SwfLibraryBitmapDefine)
                   .Select(p => ConvertBitmap(p.Key, p.Value))
                   .ToList());
        }
コード例 #3
0
        static void AddShapeInstanceToFrame(
            SwfLibrary library,
            SwfDisplayShapeInstance inst,
            Matrix4x4 inst_matrix,
            SwfBlendModeData inst_blend_mode,
            SwfColorTransData inst_color_transform,
            ushort parent_masked,
            ushort parent_mask,
            List <SwfInstanceData> parent_masks,
            List <SwfInstanceData> self_masks,
            SwfFrameData frame)
        {
            var shape_def = library.FindDefine <SwfLibraryShapeDefine>(inst.Id);

            if (shape_def != null)
            {
                for (var i = 0; i < shape_def.Bitmaps.Length; ++i)
                {
                    var bitmap_id     = shape_def.Bitmaps[i];
                    var bitmap_matrix = i < shape_def.Matrices.Length ? shape_def.Matrices[i] : SwfMatrix.identity;
                    var bitmap_def    = library.FindDefine <SwfLibraryBitmapDefine>(bitmap_id);
                    if (bitmap_def != null)
                    {
                        var frame_inst_type =
                            (parent_mask > 0 || inst.ClipDepth > 0)
                                                                ? SwfInstanceData.Types.Mask
                                                                : (parent_masked > 0 || self_masks.Count > 0)
                                                                        ? SwfInstanceData.Types.Masked
                                                                        : SwfInstanceData.Types.Group;
                        var frame_inst_clip_depth =
                            (parent_mask > 0)
                                                                ? parent_mask
                                                                : (inst.ClipDepth > 0)
                                                                        ? inst.ClipDepth
                                                                        : parent_masked + self_masks.Count;
                        frame.Instances.Add(new SwfInstanceData {
                            Type       = frame_inst_type,
                            ClipDepth  = (ushort)frame_inst_clip_depth,
                            Bitmap     = bitmap_id,
                            Matrix     = SwfMatrixData.FromUMatrix(inst_matrix * bitmap_matrix.ToUMatrix()),
                            BlendMode  = inst_blend_mode,
                            ColorTrans = inst_color_transform
                        });
                        if (parent_mask > 0)
                        {
                            parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
                        }
                        else if (inst.ClipDepth > 0)
                        {
                            self_masks.Add(frame.Instances[frame.Instances.Count - 1]);
                        }
                    }
                }
            }
        }
コード例 #4
0
        static SwfAssetData LoadSwfAssetData(string swf_path)
        {
            var library = new SwfLibrary();
            var decoder = new SwfDecoder(swf_path, progress => {
                _progressBar.UpdateProgress("swf decoding", progress);
            });

            return(new SwfAssetData {
                FrameRate = decoder.UncompressedHeader.FrameRate,
                Symbols = LoadSymbols(swf_path, library, decoder),
                Bitmaps = LoadBitmaps(library)
            });
        }
コード例 #5
0
        // ---------------------------------------------------------------------
        //
        // LoadBitmaps
        //
        // ---------------------------------------------------------------------

        static List <SwfBitmapData> LoadBitmaps(SwfLibrary library)
        {
            return(library.Defines
                   .Where(p => p.Value.Type == SwfLibraryDefineType.Bitmap)
                   .ToDictionary(p => p.Key, p => p.Value as SwfLibraryBitmapDefine)
                   .Select(p => new SwfBitmapData {
                Id = p.Key,
                ARGB32 = p.Value.ARGB32,
                Redirect = p.Value.Redirect,
                RealWidth = p.Value.Width,
                RealHeight = p.Value.Height
            })
                   .ToList());
        }
コード例 #6
0
        static void AddBitmapInstanceToFrame(
            SwfLibrary library,
            SwfDisplayBitmapInstance inst,
            Matrix4x4 inst_matrix,
            SwfBlendModeData inst_blend_mode,
            SwfColorTransData inst_color_transform,
            ushort parent_masked,
            ushort parent_mask,
            List <SwfInstanceData> parent_masks,
            List <SwfInstanceData> self_masks,
            SwfFrameData frame)
        {
            var bitmap_def = library.FindDefine <SwfLibraryBitmapDefine>(inst.Id);

            if (bitmap_def != null)
            {
                var frame_inst_type =
                    (parent_mask > 0 || inst.ClipDepth > 0)
                                                ? SwfInstanceData.Types.Mask
                                                : (parent_masked > 0 || self_masks.Count > 0)
                                                        ? SwfInstanceData.Types.Masked
                                                        : SwfInstanceData.Types.Group;
                var frame_inst_clip_depth =
                    (parent_mask > 0)
                                                ? parent_mask
                                                : (inst.ClipDepth > 0)
                                                        ? inst.ClipDepth
                                                        : parent_masked + self_masks.Count;
                frame.Instances.Add(new SwfInstanceData {
                    Type       = frame_inst_type,
                    ClipDepth  = (ushort)frame_inst_clip_depth,
                    Bitmap     = inst.Id,
                    Matrix     = SwfMatrixData.FromUMatrix(inst_matrix * Matrix4x4.Scale(new Vector3(20, 20, 1))),
                    BlendMode  = inst_blend_mode,
                    ColorTrans = inst_color_transform
                });
                if (parent_mask > 0)
                {
                    parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
                }
                else if (inst.ClipDepth > 0)
                {
                    self_masks.Add(frame.Instances[frame.Instances.Count - 1]);
                }
            }
        }
コード例 #7
0
        // ---------------------------------------------------------------------
        //
        // LoadSymbols
        //
        // ---------------------------------------------------------------------

        static List <SwfSymbolData> LoadSymbols(
            string swf_path, SwfLibrary library, SwfDecoder decoder)
        {
            var symbols = new List <SwfSymbolData>();

            symbols.Add(LoadSymbol(swf_path, "_Stage_", library, decoder.Tags));
            var sprite_defs = library.Defines.Values
                              .OfType <SwfLibrarySpriteDefine>()
                              .Where(p => !string.IsNullOrEmpty(p.ExportName))
                              .ToList();

            for (var i = 0; i < sprite_defs.Count; ++i)
            {
                var def  = sprite_defs[i];
                var name = def.ExportName;
                var tags = def.ControlTags.Tags;
                symbols.Add(LoadSymbol(swf_path, name, library, tags));
            }
            return(symbols);
        }
コード例 #8
0
        static SwfFrameData LoadSymbolFrameData(
            SwfLibrary library, SwfDisplayList display_list)
        {
            var frame = new SwfFrameData {
                Anchor = display_list.FrameAnchors.Count > 0
                                        ? display_list.FrameAnchors[0]
                                        : string.Empty,
                Labels = new List <string>(display_list.FrameLabels)
            };

            return(AddDisplayListToFrame(
                       library,
                       display_list,
                       Matrix4x4.identity,
                       SwfBlendModeData.identity,
                       SwfColorTransData.identity,
                       0,
                       0,
                       null,
                       frame));
        }
コード例 #9
0
        static SwfSymbolData LoadSymbol(
            string symbol_name, SwfLibrary library, List <SwfTagBase> tags)
        {
            var disp_lst = new SwfDisplayList();
            var executer = new SwfContextExecuter(library, 0, warning_msg => {
                Debug.LogWarningFormat("<b>[FlashTools]</b> {0}", warning_msg);
            });
            var symbol_frames = new List <SwfFrameData>();

            while (executer.NextFrame(tags, disp_lst))
            {
                _progressBar.UpdateProgress(
                    string.Format("swf symbols loading ({0})", symbol_name),
                    (float)(executer.CurrentTag + 1) / tags.Count);
                symbol_frames.Add(LoadSymbolFrameData(library, disp_lst));
            }
            return(new SwfSymbolData {
                Name = symbol_name,
                Frames = symbol_frames
            });
        }
コード例 #10
0
        static void AddSpriteInstanceToFrame(
            SwfLibrary library,
            SwfDisplaySpriteInstance inst,
            Matrix4x4 inst_matrix,
            SwfBlendModeData inst_blend_mode,
            SwfColorTransData inst_color_transform,
            ushort parent_masked,
            ushort parent_mask,
            List <SwfInstanceData> parent_masks,
            List <SwfInstanceData> self_masks,
            SwfFrameData frame,
            System.Action <string> warning_log)
        {
            var sprite_def = library.FindDefine <SwfLibrarySpriteDefine>(inst.Id);

            if (sprite_def != null)
            {
                AddDisplayListToFrame(
                    library,
                    inst.DisplayList,
                    inst_matrix,
                    inst_blend_mode,
                    inst_color_transform,
                    (ushort)(parent_masked + self_masks.Count),
                    (ushort)(parent_mask > 0
                                                ? parent_mask
                                                : (inst.ClipDepth > 0
                                                        ? inst.ClipDepth
                                                        : (ushort)0)),
                    parent_mask > 0
                                                ? parent_masks
                                                : (inst.ClipDepth > 0
                                                        ? self_masks
                                                        : null),
                    frame,
                    warning_log);
            }
        }
コード例 #11
0
ファイル: DisassemblerPlain.cs プロジェクト: wl3780/as3c
        protected override void FormatAbc(SwfLibrary.Abc.Abc46 abc)
        {
            base.FormatAbc(abc);

            MethodBodyInfo methodBody;
            AVM2Command command;

            int n = abc.MethodBodies.Count;

            for (int i = 0; i < n; ++i)
            {
                methodBody = (MethodBodyInfo)abc.MethodBodies[i];

                FormatBody(methodBody);

                byte[] code = methodBody.Code;

                uint j = 0;
                int m = code.Length;
                uint k;

                while (j < m)
                {
                    k = j;
                    command = Translator.ToCommand(code[j++]);

                    if (null == command)
                    {
                        throw new Exception("Unknown opcode detected.");
                    }

                    j += command.ReadParameters(code, j);

                    FormatCommand(k, command);
                }
            }
        }
コード例 #12
0
        static SwfFrameData AddDisplayListToFrame(
            SwfLibrary library,
            SwfDisplayList display_list,
            Matrix4x4 parent_matrix,
            SwfBlendModeData parent_blend_mode,
            SwfColorTransData parent_color_transform,
            ushort parent_masked,
            ushort parent_mask,
            List <SwfInstanceData> parent_masks,
            SwfFrameData frame,
            System.Action <string> warning_log)
        {
            if (warning_log != null)
            {
                var inst_filter_types = display_list.Instances.Values
                                        .Where(p => p.Visible && p.FilterList.Filters.Count > 0)
                                        .SelectMany(p => p.FilterList.Filters)
                                        .Select(p => p.Type)
                                        .Distinct();
                foreach (var filter_type in inst_filter_types)
                {
                    warning_log(string.Format(
                                    "Unsupported filter type '{0}'",
                                    filter_type));
                }
            }
            var self_masks = new List <SwfInstanceData>();

            foreach (var inst in display_list.Instances.Values.Where(p => p.Visible))
            {
                CheckSelfMasks(self_masks, inst.Depth, frame);
                var child_matrix          = parent_matrix * inst.Matrix.ToUMatrix();
                var child_blend_mode      = parent_blend_mode * inst.BlendMode.ToBlendModeData(warning_log);
                var child_color_transform = parent_color_transform * inst.ColorTransform.ToColorTransData();
                switch (inst.Type)
                {
                case SwfDisplayInstanceType.Shape:
                    AddShapeInstanceToFrame(
                        library,
                        inst as SwfDisplayShapeInstance,
                        child_matrix,
                        child_blend_mode,
                        child_color_transform,
                        parent_masked,
                        parent_mask,
                        parent_masks,
                        self_masks,
                        frame);
                    break;

                case SwfDisplayInstanceType.Bitmap:
                    AddBitmapInstanceToFrame(
                        library,
                        inst as SwfDisplayBitmapInstance,
                        child_matrix,
                        child_blend_mode,
                        child_color_transform,
                        parent_masked,
                        parent_mask,
                        parent_masks,
                        self_masks,
                        frame);
                    break;

                case SwfDisplayInstanceType.Sprite:
                    AddSpriteInstanceToFrame(
                        library,
                        inst as SwfDisplaySpriteInstance,
                        child_matrix,
                        child_blend_mode,
                        child_color_transform,
                        parent_masked,
                        parent_mask,
                        parent_masks,
                        self_masks,
                        frame,
                        warning_log);
                    break;

                default:
                    throw new UnityException(string.Format(
                                                 "unsupported SwfDisplayInstanceType: {0}", inst.Type));
                }
            }
            CheckSelfMasks(self_masks, ushort.MaxValue, frame);
            return(frame);
        }
コード例 #13
0
ファイル: DisassemblerPlain.cs プロジェクト: wl3780/as3c
 protected void FormatBody(SwfLibrary.Abc.MethodBodyInfo methodBody)
 {
     _output.Add("\r\n");
 }