コード例 #1
0
        public MovieClip(MovieClip mv)
        {
            m_vStorageObject = mv.GetStorageObject();
            m_vDataType      = mv.GetMovieClipDataType();
            m_vShapes        = new List <ScObject>();

            this.SetOffset(-Math.Abs(mv.GetOffset()));

            //Duplicate MovieClip
            using (FileStream input = new FileStream(m_vStorageObject.GetFileName(), FileMode.Open))
            {
                input.Seek(Math.Abs(mv.GetOffset()) + 5, SeekOrigin.Begin);
                using (var br = new BinaryReader(input))
                {
                    this.ParseData(br);
                }
            }

            //Set new clip id
            short maxMovieClipId = this.GetId();

            foreach (MovieClip clip in m_vStorageObject.GetMovieClips())
            {
                if (clip.GetId() > maxMovieClipId)
                {
                    maxMovieClipId = clip.GetId();
                }
            }
            maxMovieClipId++;
            this.SetId(maxMovieClipId);

            //Get max shape id
            short maxShapeId = 20000;//avoid collision with other objects in MovieClips

            foreach (Shape shape in m_vStorageObject.GetShapes())
            {
                if (shape.GetId() > maxShapeId)
                {
                    maxShapeId = shape.GetId();
                }
            }
            maxShapeId++;

            //Duplicate shapes associated to clip
            List <ScObject> newShapes = new List <ScObject>();

            foreach (Shape s in m_vShapes)
            {
                Shape newShape = new Shape(s);
                newShape.SetId(maxShapeId);
                maxShapeId++;
                newShapes.Add(newShape);
                m_vStorageObject.AddShape(newShape);//Add to global shapelist
                m_vStorageObject.AddChange(newShape);
            }
            this.m_vShapes = newShapes;
        }
コード例 #2
0
ファイル: MovieClip.cs プロジェクト: doio/Ultrapowa-SC-Editor
        public MovieClip(MovieClip mv)
        {
            m_vStorageObject = mv.GetStorageObject();
            m_vDataType = mv.GetMovieClipDataType();
            m_vShapes = new List<ScObject>();

            this.SetOffset(-Math.Abs(mv.GetOffset()));
            
            //Duplicate MovieClip
            using (FileStream input = new FileStream(m_vStorageObject.GetFileName(), FileMode.Open))
            {
                input.Seek(Math.Abs(mv.GetOffset()) + 5, SeekOrigin.Begin);
                using (var br = new BinaryReader(input))
                {
                    this.ParseData(br);
                }
            }

            //Set new clip id
            short maxMovieClipId = this.GetId();
            foreach(MovieClip clip in m_vStorageObject.GetMovieClips())
            {
                if (clip.GetId() > maxMovieClipId)
                    maxMovieClipId = clip.GetId();
            }
            maxMovieClipId++;
            this.SetId(maxMovieClipId);

            //Get max shape id
            short maxShapeId = 20000;//avoid collision with other objects in MovieClips
            foreach(Shape shape in m_vStorageObject.GetShapes())
            {
                if (shape.GetId() > maxShapeId)
                    maxShapeId = shape.GetId();
            }
            maxShapeId++;

            //Duplicate shapes associated to clip
            List<ScObject> newShapes = new List<ScObject>();
            foreach(Shape s in m_vShapes)
            {
                Shape newShape = new Shape(s);
                newShape.SetId(maxShapeId);
                maxShapeId++;
                newShapes.Add(newShape);
                m_vStorageObject.AddShape(newShape);//Add to global shapelist
                m_vStorageObject.AddChange(newShape);
            }
            this.m_vShapes = newShapes;
        }
コード例 #3
0
        public override void ParseData(BinaryReader br)
        {
            Debug.WriteLine("MovieClip data type: " + m_vDataType);

            /*StringBuilder hex = new StringBuilder(data.Length * 2);
             * foreach (byte b in data)
             *  hex.AppendFormat("{0:x2}", b);
             * Debug.WriteLine(hex.ToString());*/

            m_vClipId = br.ReadInt16();
            br.ReadByte();//a1 + 34
            m_vFrameCount = br.ReadInt16();
            if (m_vDataType == 14)
            {
            }
            else
            {
                int     cnt1 = br.ReadInt32();
                short[] sa1  = new short[cnt1 * 3];
                for (int i = 0; i < cnt1; i++)
                {
                    sa1[3 * i]     = br.ReadInt16();
                    sa1[3 * i + 1] = br.ReadInt16();
                    sa1[3 * i + 2] = br.ReadInt16();
                }
            }
            int cnt2 = br.ReadInt16();

            short[] sa2 = new short[cnt2];//a1 + 8
            for (int i = 0; i < cnt2; i++)
            {
                sa2[i] = br.ReadInt16();
                int index = m_vStorageObject.GetShapes().FindIndex(shape => shape.GetId() == sa2[i]);
                if (index != -1)
                {
                    m_vShapes.Add(m_vStorageObject.GetShapes()[index]);
                }
            }
            if (m_vDataType == 12)
            {
                br.ReadBytes(cnt2);//a1 + 12
            }
            //read ascii
            for (int i = 0; i < cnt2; i++)
            {
                byte stringLength = br.ReadByte();
                if (stringLength < 255)
                {
                    br.ReadBytes(stringLength);
                }
            }

            byte v26;

            while (true)
            {
                while (true)
                {
                    while (true)
                    {
                        v26 = br.ReadByte();
                        br.ReadInt32();
                        if (v26 != 5)
                        {
                            break;
                        }
                    }
                    if (v26 == 11)
                    {
                        short frameId         = br.ReadInt16();
                        byte  frameNameLength = br.ReadByte();
                        if (frameNameLength < 255)
                        {
                            br.ReadBytes(frameNameLength);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (v26 == 0)
                {
                    break;
                }
                Debug.WriteLine("Unknown tag " + v26.ToString());
            }
        }
コード例 #4
0
        public override void Save(FileStream input)
        {
            input.Seek(0, SeekOrigin.Begin);
            byte[] file = new byte[input.Length];
            input.Read(file, 0, file.Length);

            int cursor = (int)m_vStorageObject.GetStartExportsOffset();

            input.Seek(m_vStorageObject.GetStartExportsOffset(), SeekOrigin.Begin);

            ushort exportCount = BitConverter.ToUInt16(file, cursor);

            input.Write(BitConverter.GetBytes((ushort)(exportCount + 1)), 0, 2);
            cursor += 2;

            input.Seek(exportCount * 2, SeekOrigin.Current);
            cursor += exportCount * 2;
            input.Write(BitConverter.GetBytes(m_vExportId), 0, 2);

            for (int i = 0; i < exportCount; i++)
            {
                byte nameLength = file[cursor];
                cursor++;
                byte[] exportName = new byte[nameLength];
                Array.Copy(file, cursor, exportName, 0, nameLength);
                input.WriteByte(nameLength);
                input.Write(exportName, 0, nameLength);
                cursor += nameLength;
            }

            input.WriteByte((byte)m_vExportName.Length);
            input.Write(Encoding.UTF8.GetBytes(m_vExportName), 0, (byte)m_vExportName.Length);

            while (cursor < file.Length)
            {
                input.WriteByte(file[cursor]);
                cursor++;
            }

            //refresh all offsets
            foreach (Texture t in m_vStorageObject.GetTextures())
            {
                long offset = t.GetOffset();
                if (offset > 0)
                {
                    offset += 2 + 1 + m_vExportName.Length;
                }
                else
                {
                    offset = offset - 2 - 1 - m_vExportName.Length;
                }
                t.SetOffset(offset);
            }
            foreach (Shape s in m_vStorageObject.GetShapes())
            {
                long offset = s.GetOffset();
                if (offset > 0)
                {
                    offset += 2 + 1 + m_vExportName.Length;
                }
                else
                {
                    offset = offset - 2 - 1 - m_vExportName.Length;
                }
                s.SetOffset(offset);
                foreach (ShapeChunk sc in s.GetChunks())
                {
                    long chunkOffset = sc.GetOffset();
                    if (chunkOffset > 0)
                    {
                        chunkOffset += 2 + 1 + m_vExportName.Length;
                    }
                    else
                    {
                        chunkOffset = chunkOffset - 2 - 1 - m_vExportName.Length;
                    }
                    sc.SetOffset(chunkOffset);
                }
            }
            foreach (MovieClip mc in m_vStorageObject.GetMovieClips())
            {
                long offset = mc.GetOffset();
                if (offset > 0)
                {
                    offset += 2 + 1 + m_vExportName.Length;
                }
                else
                {
                    offset = offset - 2 - 1 - m_vExportName.Length;
                }
                mc.SetOffset(offset);
            }
            m_vStorageObject.SetEofOffset(m_vStorageObject.GetEofOffset() + 2 + 1 + m_vExportName.Length);
            //ne pas oublier eofoffset
        }