예제 #1
0
        public ReadError Open(string filename)
        {
            if (!File.Exists(filename))
            {
                return(ReadError.FileDoesntExist);
            }

            directories = new List <FO1Dir>();
            fileStream  = File.OpenRead(filename);
            var r = new BinaryBigEndian(fileStream);

            dirCount = r.ReadInt32();
            unknown  = r.ReadInt32();
            unknown2 = r.ReadInt32();
            unknown3 = r.ReadInt32();

            if (unknown != 0x5E && unknown2 != 0)
            {
                return(ReadError.NotValidMasterDat);
            }
            for (var i = 0; i < dirCount; i++)
            {
                directories.Add(new FO1Dir()
                {
                    name = ReadString(r)
                });
            }

            for (var i = 0; i < dirCount; i++)
            {
                var dir = directories[i];
                dir.fileCount = r.ReadInt32();
                r.ReadInt32(); // unknown4
                r.ReadInt32(); // unknown5
                r.ReadInt32(); // unknown6
                for (var y = 0; y < dir.fileCount; y++)
                {
                    var name       = ReadString(r);
                    var packed     = r.ReadInt32() == 0x40;
                    var offset     = r.ReadInt32();
                    var size       = r.ReadInt32();
                    var sizePacked = r.ReadInt32();
                    dir.files.Add(new FO1File
                    {
                        packed     = packed,
                        name       = name,
                        fullPath   = dir.name + "\\" + name,
                        offset     = offset,
                        size       = size,
                        packedSize = sizePacked
                    });
                }
            }

            //this.memStream = new MemoryStream();
            this.fileStream.Position = 0;
            //this.fileStream.CopyTo(this.memStream);

            return(ReadError.Success);
        }
예제 #2
0
        public byte[] getBytes(FileStream stream) //MemoryStream
        {
            var r = new BinaryBigEndian(stream);

            r.BaseStream.Seek(offset, SeekOrigin.Begin);
            return(r.ReadBytes(size));
        }
예제 #3
0
파일: dat.cs 프로젝트: rotators/Fo1in2
        public byte[] getCompressedBytes(FileStream stream)
        {
            // Create a new stream so that we are thread safe.
            var             s = new MemoryStream();
            BinaryBigEndian r;

            stream.Seek(offset, SeekOrigin.Begin);
            // Copy packedSize amount of bytes from the original dat stream to our new memory stream.
            for (int i = 0; i < packedSize; i++)
            {
                s.WriteByte((byte)stream.ReadByte());
            }

            r = new BinaryBigEndian(s);
            r.BaseStream.Seek(0, SeekOrigin.Begin);

            var LZSS  = new FO1LZSS(r, size);
            var bytes = LZSS.Decompress();

            s.Dispose();
            r.Dispose();

            GC.Collect();

            return(bytes);
        }
예제 #4
0
        private string ReadString(BinaryBigEndian r)
        {
            var len = r.ReadByte();

            return(Encoding.ASCII.GetString(r.ReadBytes(len)));
        }
예제 #5
0
        byte FL;      // Flags indicating the compression status of up to 8 next characters.

        public FO1LZSS(BinaryBigEndian stream, int uncompressedSize)
        {
            this.uncompressedSize = uncompressedSize;
            this.stream           = stream;
        }