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   = (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);
            }
        }
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 = 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 #3
0
        public override void Write(FileStream input)
        {
            input.Seek(0, SeekOrigin.Begin);
            byte[] file = new byte[input.Length];
            input.Read(file, 0, file.Length);

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

            input.Seek(_scFile.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(_exportId), 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)_exportName.Length);
            input.Write(Encoding.UTF8.GetBytes(_exportName), 0, (byte)_exportName.Length);

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

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