Exemple #1
0
        public override void Write(FileStream input)
        {
            if (_offset < 0) //new
            {
                using (
                    FileStream readInput = new FileStream(_scFile.GetInfoFileName(), FileMode.Open, FileAccess.Read,
                                                          FileShare.ReadWrite))
                {
                    //Positionnement des curseurs
                    readInput.Seek(Math.Abs(_offset), SeekOrigin.Begin);
                    input.Seek(_scFile.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(_clipId), 0, 2);

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

                    //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 = _scFile.GetShapes().FindIndex(shape => shape.Id == BitConverter.ToInt16(id, 0));
                        if (index != -1)
                        {
                            input.Write(BitConverter.GetBytes(_shapes[cptShape].Id), 0, 2);
                            cptShape++;
                        }
                        else
                        {
                            input.Write(id, 0, 2);
                        }
                    }
                    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[] lenght = new byte[4];
                    while (true)
                    {
                        byte v26;
                        while (true)
                        {
                            while (true)
                            {
                                v26 = (byte)readInput.ReadByte();
                                input.WriteByte(v26);

                                //br.ReadInt32();
                                readInput.Read(lenght, 0, 4);
                                input.Write(lenght, 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 if (v26 == 31)
                            {
                                int    l    = Convert.ToInt32(lenght);
                                byte[] data = new byte[l];
                                readInput.Read(data, 0, l);
                                input.Write(data, 0, l);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (v26 == 0)
                        {
                            break;
                        }
                        Console.WriteLine("Unknown tag " + v26);
                    }
                }
                _offset = _scFile.GetEofOffset();
                _scFile.SetEofOffset(input.Position);
                input.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5);
            }
        }
Exemple #2
0
        public override void Write(FileStream input)
        {
            if (_offset < 0) //new
            {
                using (FileStream readInput = new FileStream(_scFile.GetInfoFileName(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    //Positionnement des curseurs
                    readInput.Seek(Math.Abs(_offset), SeekOrigin.Begin);
                    input.Seek(_scFile.GetEofOffset(), SeekOrigin.Begin);

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

                    input.WriteByte(dataType);
                    input.Write(dataLength, 0, 4);

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

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

                    if (dataType == 18)
                    {
                        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 || shapeType == 22)
                            {
                                Console.WriteLine("Managed shape type " + shapeType);
                                _chunks[chunkCounter].Write(input);
                                chunkCounter++;
                                readInput.Seek(BitConverter.ToInt32(length, 0), SeekOrigin.Current);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (shapeType == 0)
                        {
                            break;
                        }
                        Console.WriteLine("Unmanaged shape type " + shapeType);
                        for (int i = 0; i < BitConverter.ToInt32(length, 0); i++)
                        {
                            input.WriteByte((byte)readInput.ReadByte());
                        }
                    }
                }
                _offset = _scFile.GetEofOffset();
                _scFile.SetEofOffset(input.Position);
                input.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5);
            }
        }