Ejemplo n.º 1
0
        private byte[] Decompress(BinaryReader Reader, Far3Entry Entry)
        {
            //Unknown part of the header, not needed for decompression.
            //NOTE: This header is part of the actual filedata if file isn't compressed.
            Reader.ReadBytes(9);

            //Read the compression header
            uint   Filesize      = Reader.ReadUInt32();
            ushort CompressionID = Reader.ReadUInt16();

            if (CompressionID == 0xFB10)
            {
                byte[] Dummy            = Reader.ReadBytes(3);
                uint   DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]);

                Decompresser Dec = new Decompresser();
                Dec.CompressedSize   = Filesize;
                Dec.DecompressedSize = DecompressedSize;

                return(Dec.Decompress(Reader.ReadBytes((int)Filesize)));
            }
            else //The entry wasn't compressed...
            {
                Reader.BaseStream.Seek((Reader.BaseStream.Position - 15), SeekOrigin.Begin);
                return(Reader.ReadBytes((int)Entry.DecompressedFileSize));
            }
        }
Ejemplo n.º 2
0
        private byte[] Decompress(BinaryReader Reader, Far3Entry Entry)
        {
            //Unknown part of the header, not needed for decompression.
            //NOTE: This header is part of the actual filedata if file isn't compressed.
            Reader.ReadBytes(9);

            //Read the compression header
            uint Filesize = Reader.ReadUInt32();
            ushort CompressionID = Reader.ReadUInt16();

            if (CompressionID == 0xFB10)
            {
                byte[] Dummy = Reader.ReadBytes(3);
                uint DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]);

                Decompresser Dec = new Decompresser();
                Dec.CompressedSize = Filesize;
                Dec.DecompressedSize = DecompressedSize;

                return Dec.Decompress(Reader.ReadBytes((int)Filesize));
            }
            else //The entry wasn't compressed...
            {
                Reader.BaseStream.Seek((Reader.BaseStream.Position - 15), SeekOrigin.Begin);
                return Reader.ReadBytes((int)Entry.DecompressedFileSize);
            }
        }
Ejemplo n.º 3
0
        private void OpenDatArchive(string Path)
        {
            BinaryReader Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            BinaryWriter Logger = new BinaryWriter(File.Create("Entries log.txt"));

            string Header  = Encoding.ASCII.GetString(Reader.ReadBytes(8));
            uint   Version = Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 3))
            {
                MessageBox.Show("Archive wasn't a valid FAR V.3 archive!");
                return;
            }

            uint ManifestOffset = Reader.ReadUInt32();

            m_ManifestOffset = ManifestOffset;

            Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);

            LstFiles.Items.Clear();

            uint NumFiles = Reader.ReadUInt32();

            LstFiles.Items.Add("Number of files: " + NumFiles.ToString());
            LstFiles.Items.Add("");

            for (int i = 0; i < NumFiles; i++)
            {
                Far3Entry Entry = new Far3Entry();
                Entry.DecompressedFileSize = Reader.ReadUInt32();
                Logger.Write("DecompressedFilesize: " + Entry.DecompressedFileSize + "\r\n");
                byte[] Dummy = Reader.ReadBytes(3);
                Entry.CompressedFileSize = (uint)((Dummy[0] << 0) | (Dummy[1] << 8) | (Dummy[2]) << 16);
                Logger.Write("CompressedFilesize: " + Entry.CompressedFileSize + "\r\n");
                //Entry.CompressedFileSize = Convert.ToUInt32(Reader.ReadBytes(3));
                Entry.DataType = Reader.ReadByte();
                Logger.Write("DataType: " + Entry.DataType + "\r\n");
                //Entry.CompressedSpecifics = Reader.ReadUInt16();
                //Entry.PowerValue = Reader.ReadByte();
                //Entry.Unknown = Reader.ReadByte();
                Entry.DataOffset = Reader.ReadUInt32();
                Logger.Write("DataOffset: " + Entry.DataOffset + "\r\n");
                //Entry.Unknown2 = Reader.ReadUInt16();
                Entry.Compressed = Reader.ReadByte();
                Logger.Write("Compressed: " + Entry.Compressed + "\r\n");
                Entry.AccessNumber = Reader.ReadByte();
                Logger.Write("AccessNumber: " + Entry.AccessNumber + "\r\n");
                Entry.FilenameLength = Reader.ReadUInt16();
                Logger.Write("FilenameLength: " + Entry.FilenameLength + "\r\n");
                Entry.TypeID = Reader.ReadUInt32();
                Logger.Write("TypeID: " + Entry.TypeID + "\r\n");
                Entry.FileID = Reader.ReadUInt32();
                Logger.Write("FileID: " + Entry.FileID + "\r\n");
                Entry.Filename = Encoding.ASCII.GetString(Reader.ReadBytes(Entry.FilenameLength));
                Logger.Write("Filename: " + Entry.Filename + "\r\n");
                Logger.Write("\r\n");

                m_Far3Entries.Add(Entry);
                LstFiles.Items.Add(Entry.Filename + ", " + string.Format("{0:X}", Entry.FileID));
            }

            Logger.Flush();

            Reader.Close();
            Logger.Close();
        }
Ejemplo n.º 4
0
        private void OpenDatArchive(string Path)
        {
            BinaryReader Reader = new BinaryReader(File.Open(Path, FileMode.Open));

            BinaryWriter Logger = new BinaryWriter(File.Create("Entries log.txt"));

            string Header = Encoding.ASCII.GetString(Reader.ReadBytes(8));
            uint Version = Reader.ReadUInt32();

            if ((Header != "FAR!byAZ") || (Version != 3))
            {
                MessageBox.Show("Archive wasn't a valid FAR V.3 archive!");
                return;
            }

            uint ManifestOffset = Reader.ReadUInt32();
            m_ManifestOffset = ManifestOffset;

            Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin);

            LstFiles.Items.Clear();

            uint NumFiles = Reader.ReadUInt32();
            LstFiles.Items.Add("Number of files: " + NumFiles.ToString());
            LstFiles.Items.Add("");

            for (int i = 0; i < NumFiles; i++)
            {
                Far3Entry Entry = new Far3Entry();
                Entry.DecompressedFileSize = Reader.ReadUInt32();
                Logger.Write("DecompressedFilesize: " + Entry.DecompressedFileSize + "\r\n");
                byte[] Dummy = Reader.ReadBytes(3);
                Entry.CompressedFileSize = (uint)((Dummy[0] << 0) | (Dummy[1] << 8) | (Dummy[2]) << 16);
                Logger.Write("CompressedFilesize: " + Entry.CompressedFileSize + "\r\n");
                //Entry.CompressedFileSize = Convert.ToUInt32(Reader.ReadBytes(3));
                Entry.DataType = Reader.ReadByte();
                Logger.Write("DataType: " + Entry.DataType + "\r\n");
                //Entry.CompressedSpecifics = Reader.ReadUInt16();
                //Entry.PowerValue = Reader.ReadByte();
                //Entry.Unknown = Reader.ReadByte();
                Entry.DataOffset = Reader.ReadUInt32();
                Logger.Write("DataOffset: " + Entry.DataOffset + "\r\n");
                //Entry.Unknown2 = Reader.ReadUInt16();
                Entry.Compressed = Reader.ReadByte();
                Logger.Write("Compressed: " + Entry.Compressed + "\r\n");
                Entry.AccessNumber = Reader.ReadByte();
                Logger.Write("AccessNumber: " + Entry.AccessNumber + "\r\n");
                Entry.FilenameLength = Reader.ReadUInt16();
                Logger.Write("FilenameLength: " + Entry.FilenameLength + "\r\n");
                Entry.TypeID = Reader.ReadUInt32();
                Logger.Write("TypeID: " + Entry.TypeID + "\r\n");
                Entry.FileID = Reader.ReadUInt32();
                Logger.Write("FileID: " + Entry.FileID + "\r\n");
                Entry.Filename = Encoding.ASCII.GetString(Reader.ReadBytes(Entry.FilenameLength));
                Logger.Write("Filename: " + Entry.Filename + "\r\n");
                Logger.Write("\r\n");

                m_Far3Entries.Add(Entry);
                LstFiles.Items.Add(Entry.Filename + ", " + string.Format("{0:X}", Entry.FileID));
            }

            Logger.Flush();

            Reader.Close();
            Logger.Close();
        }
Ejemplo n.º 5
0
        private byte[] Decompress(BinaryReader Reader, Far3Entry Entry)
        {
            Reader.ReadBytes(9); //Unknown part of the header, not needed for decompression.

            //Read the compression header
            uint Filesize = Reader.ReadUInt32();
            ushort CompressionID = Reader.ReadUInt16();

            if (CompressionID == 0xFB10)
            {
                byte[] Dummy = Reader.ReadBytes(3);
                uint DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]);

                /*return Uncompress(Reader.ReadBytes((int)Entry.CompressedFileSize), DecompressedSize, 0,
                    (int)Entry.CompressedFileSize, GameType.SimCity4);*/

                Decompresser Dec = new Decompresser();
                Dec.CompressedSize = Filesize;
                Dec.DecompressedSize = DecompressedSize;

                return Dec.Decompress(Reader.ReadBytes((int)Filesize));
            }
            else //The entry wasn't compressed...
            {
                MessageBox.Show("CompressionID didn't match!");
                Reader.BaseStream.Seek((Reader.BaseStream.Position - 6), SeekOrigin.Begin);
                return Reader.ReadBytes((int)Entry.DecompressedFileSize/*Entry.CalculateFileSize()*/);
            }
        }