protected override BSAHeader ReadHeader()
 {
     using (Reader = ReaderFromMMF <BSAHeader>())
         try
         {
             return(_header = base.ReadHeader());
         }
         finally
         {
             _offset += Reader.BaseStream.Position;
         }
 }
Exemple #2
0
 public BSAFolderInfo(BinaryReader binary, BSAHeader header)
 {
     path   = null;
     offset = 0;
     hash   = binary.ReadUInt64();
     count  = binary.ReadUInt32();
     binary.ReadUInt32();
     if (header.bsaVersion == 0x69)
     {
         binary.ReadUInt64();
     }
 }
        private BSAArchive(string archivepath, LogFile theLog, bool verbose)
        {
            if (!File.Exists(archivepath))
            {
                theLog.WriteLog("Archive not found " + archivepath);
                return;
            }
            if (verbose)
            {
                theLog.WriteLog("Using " + archivepath);
            }
            BSAHeader header;
            name = archivepath.ToLower();
            FileInfo file = new FileInfo(archivepath);
            BinaryReader binary = new BinaryReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite), System.Text.Encoding.Default);
            header = new BSAHeader(binary);
            //theLog.WriteLog(archivepath + " version " + header.bsaVersion);
            if (header.bsaVersion != 0x67 && header.bsaVersion != 0x68)
            {
                theLog.WriteLog("Unknown BSA version " + archivepath);
                binary.Close();
                return;
            }
            if ((header.archiveFlags & 0x4) > 0)
            {
                defaultCompressed = true;
            }
            else
            {
                defaultCompressed = false;
            }
            if ((header.archiveFlags & 0x100) > 0)
            {
                defaultFlag9 = true;
            }
            else
            {
                defaultFlag9 = false;
            }
            //theLog.WriteLog(name + " is compressed? " + defaultCompressed + " flags " + header.archiveFlags);
            BSAFolderInfo[] folderInfo = new BSAFolderInfo[header.folderCount];
            BSAFileInfo[] fileInfo = new BSAFileInfo[header.fileCount];
            for (int index = 0; index < header.folderCount; index++)
            {
                folderInfo[index] = new BSAFolderInfo(binary);
            }
            int count = 0;
            for (uint index = 0; index < header.folderCount; index++)
            {
                byte b = binary.ReadByte();
                if (b > 0)
                {
                    folderInfo[index].path = new string(binary.ReadChars(b - 1));
                }
                else
                {
                    folderInfo[index].path = "";
                }
                binary.BaseStream.Position++;
                folderInfo[index].offset = count;
                for (int index2 = 0; index2 < folderInfo[index].count; index2++)
                {
                    fileInfo[count + index2] = new BSAFileInfo(binary, defaultCompressed);
                }
                count += folderInfo[index].count;
            }
            for (uint index = 0; index < header.fileCount; index++)
            {
                fileInfo[index].path = "";
                char c;
                while ((c = binary.ReadChar()) != '\0') fileInfo[index].path += c;
            }
            binary.Close();

            for (int index = 0; index < header.folderCount; index++)
            {
                for (int index2 = 0; index2 < folderInfo[index].count; index2++)
                {
                    BSAFileInfo bsaFileInfo = fileInfo[folderInfo[index].offset + index2];
                    BSAArchiveFileInfo bsaArchiveFileInfo = new BSAArchiveFileInfo(this, (int)bsaFileInfo.offset, bsaFileInfo.size);
                    string filepath = Path.Combine(folderInfo[index].path, bsaFileInfo.path);
                    //theLog.WriteLog(archivepath + " file = " + filepath + " off = " + bsaFileInfo.offset + " size = " + bsaFileInfo.size + " compressed = " + bsaArchiveFileInfo.compressed);
                    FileList[filepath.ToLower()] = bsaArchiveFileInfo;
                }
            }
            LoadedArchives.Add(this);
        }
Exemple #4
0
        private BSAArchive(string archivepath, LogFile theLog, bool verbose)
        {
            if (!File.Exists(archivepath))
            {
                theLog.WriteLog("Archive not found " + archivepath);
                return;
            }
            if (verbose)
            {
                theLog.WriteLog("Using " + archivepath);
            }
            BSAHeader header;

            name = archivepath.ToLower(CultureInfo.InvariantCulture);
            FileInfo     file   = new FileInfo(archivepath);
            BinaryReader binary = new BinaryReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite), System.Text.Encoding.Default);

            header = new BSAHeader(binary);
            if (header.bsaType == "GNRL")
            {
                if (header.bsaVersion != 0x01)
                {
                    theLog.WriteLog("Unknown BA2 version " + header.bsaVersion + " " + archivepath);
                    binary.Close();
                    return;
                }
                binary.BaseStream.Seek(24, SeekOrigin.Begin);
                BA2FileInfo[] fileInfo = new BA2FileInfo[header.fileCount];
                for (int index = 0; index < header.fileCount; index++)
                {
                    fileInfo[index] = new BA2FileInfo(binary);
                }
                binary.BaseStream.Seek((Int64)header.nameTableOffset, SeekOrigin.Begin);
                for (int index = 0; index < header.fileCount; index++)
                {
                    UInt16 size = binary.ReadUInt16();
                    fileInfo[index].path = new string(binary.ReadChars(size));
                    BSAArchiveFileInfo bsaArchiveFileInfo = new BSAArchiveFileInfo(this, fileInfo[index].offset, fileInfo[index].zsize, fileInfo[index].size);
                    //theLog.WriteLog("name=" + this.name + " file=" + fileInfo[index].path + " ext=" + fileInfo[index].ext + "< off=" + fileInfo[index].offset + " zsize=" + fileInfo[index].zsize + " size=" + fileInfo[index].size +  " compressed=" + fileInfo[index].compressed);
                    FileList[fileInfo[index].path.ToLower(CultureInfo.InvariantCulture)] = bsaArchiveFileInfo;
                }
            }
            if (header.bsaType == "BSA")
            {
                if (header.bsaVersion != 0x67 && header.bsaVersion != 0x68 && header.bsaVersion != 0x69)
                {
                    theLog.WriteLog("Unknown BSA version " + header.bsaVersion + " " + archivepath);
                    binary.Close();
                    return;
                }
                // LZ4?
                if (header.bsaVersion == 0x69)
                {
                    compressionType = true;
                }
                else
                {
                    compressionType = false;
                }
                if ((header.archiveFlags & 0x4) > 0)
                {
                    defaultCompressed = true;
                }
                else
                {
                    defaultCompressed = false;
                }
                if ((header.archiveFlags & 0x100) > 0)
                {
                    defaultFlag9 = true;
                }
                else
                {
                    defaultFlag9 = false;
                }
                //theLog.WriteLog(name + " is compressed? " + defaultCompressed + " flags " + header.archiveFlags);
                BSAFolderInfo[] folderInfo = new BSAFolderInfo[header.folderCount];
                BSAFileInfo[]   fileInfo   = new BSAFileInfo[header.fileCount];
                for (int index = 0; index < header.folderCount; index++)
                {
                    folderInfo[index] = new BSAFolderInfo(binary, header);
                }
                ulong count = 0;
                for (uint index = 0; index < header.folderCount; index++)
                {
                    byte b = binary.ReadByte();
                    if (b > 0)
                    {
                        folderInfo[index].path = new string(binary.ReadChars(b - 1));
                    }
                    else
                    {
                        folderInfo[index].path = "";
                    }
                    binary.BaseStream.Position++;
                    folderInfo[index].offset = count;
                    for (ulong index2 = 0; index2 < folderInfo[index].count; index2++)
                    {
                        fileInfo[count + index2] = new BSAFileInfo(binary, defaultCompressed);
                    }
                    count += folderInfo[index].count;
                }
                for (uint index = 0; index < header.fileCount; index++)
                {
                    fileInfo[index].path = "";
                    char c;
                    while ((c = binary.ReadChar()) != '\0')
                    {
                        fileInfo[index].path += c;
                    }
                }
                binary.Close();

                for (int index = 0; index < header.folderCount; index++)
                {
                    for (ulong index2 = 0; index2 < folderInfo[index].count; index2++)
                    {
                        BSAFileInfo        bsaFileInfo        = fileInfo[folderInfo[index].offset + index2];
                        BSAArchiveFileInfo bsaArchiveFileInfo = new BSAArchiveFileInfo(this, bsaFileInfo.offset, bsaFileInfo.size, 0);
                        string             filepath           = Path.Combine(folderInfo[index].path, bsaFileInfo.path);
                        //theLog.WriteLog(archivepath + " file = " + filepath + " off = " + bsaFileInfo.offset + " size = " + bsaFileInfo.size + " compressed = " + bsaArchiveFileInfo.compressed);
                        FileList[filepath.ToLower(CultureInfo.InvariantCulture)] = bsaArchiveFileInfo;
                    }
                }
            }
            LoadedArchives.Add(this);
        }
Exemple #5
0
        private BSAArchive(string archivepath, LogFile theLog, bool verbose)
        {
            if (!File.Exists(archivepath))
            {
                theLog.WriteLog("Archive not found " + archivepath);
                return;
            }
            if (verbose)
            {
                theLog.WriteLog("Using " + archivepath);
            }
            BSAHeader header;

            name = archivepath.ToLower();
            FileInfo     file   = new FileInfo(archivepath);
            BinaryReader binary = new BinaryReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite), System.Text.Encoding.Default);

            header = new BSAHeader(binary);
            //theLog.WriteLog(archivepath + " version " + header.bsaVersion);
            if (header.bsaVersion != 0x67 && header.bsaVersion != 0x68)
            {
                theLog.WriteLog("Unknown BSA version " + archivepath);
                binary.Close();
                return;
            }
            if ((header.archiveFlags & 0x4) > 0)
            {
                defaultCompressed = true;
            }
            else
            {
                defaultCompressed = false;
            }
            if ((header.archiveFlags & 0x100) > 0)
            {
                defaultFlag9 = true;
            }
            else
            {
                defaultFlag9 = false;
            }
            //theLog.WriteLog(name + " is compressed? " + defaultCompressed + " flags " + header.archiveFlags);
            BSAFolderInfo[] folderInfo = new BSAFolderInfo[header.folderCount];
            BSAFileInfo[]   fileInfo   = new BSAFileInfo[header.fileCount];
            for (int index = 0; index < header.folderCount; index++)
            {
                folderInfo[index] = new BSAFolderInfo(binary);
            }
            int count = 0;

            for (uint index = 0; index < header.folderCount; index++)
            {
                byte b = binary.ReadByte();
                if (b > 0)
                {
                    folderInfo[index].path = new string(binary.ReadChars(b - 1));
                }
                else
                {
                    folderInfo[index].path = "";
                }
                binary.BaseStream.Position++;
                folderInfo[index].offset = count;
                for (int index2 = 0; index2 < folderInfo[index].count; index2++)
                {
                    fileInfo[count + index2] = new BSAFileInfo(binary, defaultCompressed);
                }
                count += folderInfo[index].count;
            }
            for (uint index = 0; index < header.fileCount; index++)
            {
                fileInfo[index].path = "";
                char c;
                while ((c = binary.ReadChar()) != '\0')
                {
                    fileInfo[index].path += c;
                }
            }
            binary.Close();

            for (int index = 0; index < header.folderCount; index++)
            {
                for (int index2 = 0; index2 < folderInfo[index].count; index2++)
                {
                    BSAFileInfo        bsaFileInfo        = fileInfo[folderInfo[index].offset + index2];
                    BSAArchiveFileInfo bsaArchiveFileInfo = new BSAArchiveFileInfo(this, (int)bsaFileInfo.offset, bsaFileInfo.size);
                    string             filepath           = Path.Combine(folderInfo[index].path, bsaFileInfo.path);
                    //theLog.WriteLog(archivepath + " file = " + filepath + " off = " + bsaFileInfo.offset + " size = " + bsaFileInfo.size + " compressed = " + bsaArchiveFileInfo.compressed);
                    FileList[filepath.ToLower()] = bsaArchiveFileInfo;
                }
            }
            LoadedArchives.Add(this);
        }