Ejemplo n.º 1
0
 public override void Save(FileStream input)
 {
     if (m_vOffset < 0)//new
     {
         //Get info
         input.Seek(Math.Abs(m_vOffset), SeekOrigin.Begin);
         byte[] dataType = new byte[1];
         input.Read(dataType, 0, 1);
         byte[] dataLength = new byte[4];
         input.Read(dataLength, 0, 4);
         //Then write
         input.Seek(m_vStorageObject.GetEofOffset(), SeekOrigin.Begin);
         input.Write(dataType, 0, 1);
         input.Write(dataLength, 0, 4);
         input.WriteByte(m_vImageType);
         m_vImage.WriteImage(input);
         m_vOffset = m_vStorageObject.GetEofOffset();
         m_vStorageObject.SetEofOffset(input.Position);
         input.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5);
     }
     else//existing
     {
         input.Seek(m_vOffset + 5, SeekOrigin.Current);
         input.WriteByte(m_vImageType);
         m_vImage.WriteImage(input);
     }
 }
Ejemplo n.º 2
0
        public override void Save(FileStream input)
        {
            if (m_vOffset < 0)//new
            {
                using (FileStream readInput = new FileStream(m_vStorageObject.GetFileName(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    //Positionnement des curseurs
                    readInput.Seek(Math.Abs(m_vOffset), SeekOrigin.Begin);
                    input.Seek(m_vStorageObject.GetEofOffset(), SeekOrigin.Begin);

                    //type and length
                    byte[] dataType = new byte[1];
                    readInput.Read(dataType, 0, 1);
                    byte[] dataLength = new byte[4];
                    readInput.Read(dataLength, 0, 4);
                    input.Write(dataType, 0, 1);
                    input.Write(dataLength, 0, 4);

                    //movieclip
                    readInput.Seek(2, SeekOrigin.Current);
                    input.Write(BitConverter.GetBytes(m_vClipId), 0, 2);

                    input.WriteByte((byte)readInput.ReadByte());
                    readInput.Seek(2, SeekOrigin.Current);
                    input.Write(BitConverter.GetBytes(m_vFrameCount), 0, 2);

                    if (m_vDataType == 14)
                    {
                    }
                    else
                    {
                        //int cnt1 = br.ReadInt32();
                        byte[] cnt1 = new byte[4];
                        readInput.Read(cnt1, 0, 4);
                        input.Write(cnt1, 0, 4);

                        for (int i = 0; i < BitConverter.ToInt32(cnt1, 0); i++)
                        {
                            byte[] uk1 = new byte[2];
                            readInput.Read(uk1, 0, 2);
                            input.Write(uk1, 0, 2);

                            byte[] uk2 = new byte[2];
                            readInput.Read(uk2, 0, 2);
                            input.Write(uk2, 0, 2);

                            byte[] uk3 = new byte[2];
                            readInput.Read(uk3, 0, 2);
                            input.Write(uk3, 0, 2);
                        }
                    }
                    //int cnt2 = br.ReadInt16();
                    byte[] cnt2 = new byte[2];
                    readInput.Read(cnt2, 0, 2);
                    input.Write(cnt2, 0, 2);

                    int cptShape = 0;
                    for (int i = 0; i < BitConverter.ToInt16(cnt2, 0); i++)
                    {
                        byte[] id = new byte[2];
                        readInput.Read(id, 0, 2);

                        int index = m_vStorageObject.GetShapes().FindIndex(shape => shape.GetId() == BitConverter.ToInt16(id, 0));
                        if (index != -1)
                        {
                            input.Write(BitConverter.GetBytes(m_vShapes[cptShape].GetId()), 0, 2);
                            cptShape++;
                        }
                        else
                        {
                            input.Write(id, 0, 2);
                        }
                    }
                    if (m_vDataType == 12)
                    {
                        for (int i = 0; i < BitConverter.ToInt16(cnt2, 0); i++)
                        {
                            input.WriteByte((byte)readInput.ReadByte());
                        }
                    }

                    //read ascii
                    for (int i = 0; i < BitConverter.ToInt16(cnt2, 0); i++)
                    {
                        byte stringLength = (byte)readInput.ReadByte();
                        input.WriteByte(stringLength);
                        if (stringLength < 255)
                        {
                            for (int j = 0; j < stringLength; j++)
                            {
                                input.WriteByte((byte)readInput.ReadByte());
                            }
                        }
                    }

                    byte v26;
                    while (true)
                    {
                        while (true)
                        {
                            while (true)
                            {
                                v26 = (byte)readInput.ReadByte();
                                input.WriteByte(v26);

                                //br.ReadInt32();
                                byte[] uk4 = new byte[4];
                                readInput.Read(uk4, 0, 4);
                                input.Write(uk4, 0, 4);

                                if (v26 != 5)
                                {
                                    break;
                                }
                            }
                            if (v26 == 11)
                            {
                                //short frameId = br.ReadInt16();
                                byte[] frameId = new byte[2];
                                readInput.Read(frameId, 0, 2);
                                input.Write(frameId, 0, 2);

                                byte frameNameLength = (byte)readInput.ReadByte();
                                input.WriteByte(frameNameLength);

                                if (frameNameLength < 255)
                                {
                                    for (int i = 0; i < frameNameLength; i++)
                                    {
                                        input.WriteByte((byte)readInput.ReadByte());
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (v26 == 0)
                        {
                            break;
                        }
                        Debug.WriteLine("Unknown tag " + v26.ToString());
                    }
                }
                m_vOffset = m_vStorageObject.GetEofOffset();
                m_vStorageObject.SetEofOffset(input.Position);
                input.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5);
            }
        }
Ejemplo n.º 3
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
        }
Ejemplo n.º 4
0
        public override void Save(FileStream input)
        {
            if (m_vOffset < 0)//new
            {
                using (FileStream readInput = new FileStream(m_vStorageObject.GetFileName(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    //Positionnement des curseurs
                    readInput.Seek(Math.Abs(m_vOffset), SeekOrigin.Begin);
                    input.Seek(m_vStorageObject.GetEofOffset(), SeekOrigin.Begin);

                    //type and length
                    byte[] dataType = new byte[1];
                    readInput.Read(dataType, 0, 1);
                    byte[] dataLength = new byte[4];
                    readInput.Read(dataLength, 0, 4);
                    input.Write(dataType, 0, 1);
                    input.Write(dataLength, 0, 4);

                    //shape
                    readInput.Seek(2, SeekOrigin.Current);
                    input.Write(BitConverter.GetBytes(m_vShapeId), 0, 2);

                    byte[] unknown1 = new byte[2];
                    readInput.Read(unknown1, 0, 2);//0100
                    input.Write(unknown1, 0, 2);

                    byte[] unknown2 = new byte[2];
                    readInput.Read(unknown2, 0, 2);//0400
                    input.Write(unknown2, 0, 2);

                    int chunkCounter = 0;
                    while (true)
                    {
                        byte   shapeType;
                        byte[] length = new byte[4];
                        while (true)
                        {
                            shapeType = (byte)readInput.ReadByte();//11
                            input.WriteByte(shapeType);

                            readInput.Read(length, 0, 4);//32000000
                            input.Write(length, 0, 4);

                            if (shapeType == 17)
                            {
                                m_vChunks[chunkCounter].Save(input);
                                chunkCounter++;
                                readInput.Seek(BitConverter.ToInt32(length, 0), SeekOrigin.Current);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (shapeType == 0)
                        {
                            break;
                        }
                        Log("Unmanaged shape type " + shapeType);
                        for (int i = 0; i < BitConverter.ToInt32(length, 0); i++)
                        {
                            input.WriteByte((byte)readInput.ReadByte());
                        }
                    }
                }
                m_vOffset = m_vStorageObject.GetEofOffset();
                m_vStorageObject.SetEofOffset(input.Position);
                input.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5);
            }
        }