Beispiel #1
0
 public BSARecord(BSAFile archive, string name, BSAFileInfo fileInfo, BSAHashRecord hash)
 {
     Archive  = archive;
     Name     = name;
     FileInfo = fileInfo;
     Hash     = hash;
 }
		internal BSAArchive(string path)
		{
			BSAHeader4 header;
			br = new BinaryReader(File.OpenRead(path), System.Text.Encoding.Default);
			header = new BSAHeader4(br);
			if (header.bsaVersion != 0x68 && header.bsaVersion != 0x67) throw new BSALoadException();
			defaultCompressed = (header.archiveFlags & 4) > 0;
			SkipNames = (header.archiveFlags & 0x100) > 0 && header.bsaVersion == 0x68;
			files = new Dictionary<ulong, BSAArchive.BSAFileInfo>();

			//Read folder info
			BSAFolderInfo4[] folderInfo = new BSAFolderInfo4[header.folderCount];
			BSAFileInfo4[] fileInfo = new BSAFileInfo4[header.fileCount];
			fileNames = new string[header.fileCount];
			for (int i = 0; i < header.folderCount; i++) folderInfo[i] = new BSAFolderInfo4(br);
			int count = 0;
			for (uint i = 0; i < header.folderCount; i++)
			{
				folderInfo[i].path = new string(br.ReadChars(br.ReadByte() - 1));
				br.BaseStream.Position++;
				folderInfo[i].offset = count;
				for (int j = 0; j < folderInfo[i].count; j++) fileInfo[count + j] = new BSAFileInfo4(br);
				count += folderInfo[i].count;
			}
			for (uint i = 0; i < header.fileCount; i++)
			{
				fileInfo[i].path = "";
				char c;
				while ((c = br.ReadChar()) != '\0') fileInfo[i].path += c;
			}

			for (int i = 0; i < header.folderCount; i++)
			{
				for (int j = 0; j < folderInfo[i].count; j++)
				{
					BSAFileInfo4 fi4 = fileInfo[folderInfo[i].offset + j];
					string ext = Path.GetExtension(fi4.path);
					BSAFileInfo fi = new BSAFileInfo(this, (int)fi4.offset, fi4.size);
					string fpath = Path.Combine(folderInfo[i].path, Path.GetFileNameWithoutExtension(fi4.path));
					ulong hash = GenHash(fpath, ext);
					files[hash] = fi;
					fileNames[folderInfo[i].offset + j] = fpath + ext;
				}
			}

			Array.Sort<string>(fileNames);
		}
Beispiel #3
0
        private BSAArchive(string path, bool populateAll)
        {
            _name = Path.GetFileNameWithoutExtension(path)?.ToLower();

            _br = new BinaryReader(File.OpenRead(path), Encoding.Default);
            var header = new BSAHeader4(_br);

            if (header.BSAVersion != 0x67 || !populateAll && !header.ContainsMeshes && !header.ContainsTextures)
            {
                _br.Close();
                return;
            }

            _defaultCompressed = (header.ArchiveFlags & 0x100) > 0;

            var folderInfo = new BSAFolderInfo4[header.FolderCount];
            var fileInfo   = new BSAFileInfo4[header.FileCount];

            for (int i = 0; i < header.FolderCount; i++)
            {
                folderInfo[i] = new BSAFolderInfo4(_br);
            }

            var count = 0;

            for (uint i = 0; i < header.FolderCount; i++)
            {
                folderInfo[i].Path = new string(_br.ReadChars(_br.ReadByte() - 1));
                _br.BaseStream.Position++;
                folderInfo[i].Offset = count;
                for (int j = 0; j < folderInfo[i].Count; j++)
                {
                    fileInfo[count + j] = new BSAFileInfo4(_br, _defaultCompressed);
                }

                count += folderInfo[i].Count;
            }

            for (uint i = 0; i < header.FileCount; i++)
            {
                fileInfo[i].Path = "";
                char c;
                while ((c = _br.ReadChar()) != '\0')
                {
                    fileInfo[i].Path += c;
                }
            }

            for (var i = 0; i < header.FolderCount; i++)
            {
                for (var j = 0; j < folderInfo[i].Count; j++)
                {
                    var fi4   = fileInfo[folderInfo[i].Offset + j];
                    var ext   = Path.GetExtension(fi4.Path);
                    var fi    = new BSAFileInfo(this, (int)fi4.Offset, fi4.Size);
                    var fPath = Path.Combine(folderInfo[i].Path, Path.GetFileNameWithoutExtension(fi4.Path));
                    var hash  = GenHash(fPath, ext);
                    if (ext == ".nif")
                    {
                        Meshes[hash] = fi;
                    }
                    else if (ext == ".dds")
                    {
                        Textures[hash] = fi;
                    }

                    All[hash] = fi;
                }
            }

            LoadedArchives.Add(this);
        }
        internal BSAArchive(string path)
        {
            BSAHeader4 header;

            br     = new BinaryReader(File.OpenRead(path), System.Text.Encoding.Default);
            header = new BSAHeader4(br);
            if (header.bsaVersion != 0x68 && header.bsaVersion != 0x67)
            {
                throw new BSALoadException();
            }
            defaultCompressed = (header.archiveFlags & 4) > 0;
            SkipNames         = (header.archiveFlags & 0x100) > 0 && header.bsaVersion == 0x68;
            files             = new Dictionary <ulong, BSAArchive.BSAFileInfo>();

            //Read folder info
            BSAFolderInfo4[] folderInfo = new BSAFolderInfo4[header.folderCount];
            BSAFileInfo4[]   fileInfo   = new BSAFileInfo4[header.fileCount];
            fileNames = new string[header.fileCount];
            for (int i = 0; i < header.folderCount; i++)
            {
                folderInfo[i] = new BSAFolderInfo4(br);
            }
            int count = 0;

            for (uint i = 0; i < header.folderCount; i++)
            {
                folderInfo[i].path = new string(br.ReadChars(br.ReadByte() - 1));
                br.BaseStream.Position++;
                folderInfo[i].offset = count;
                for (int j = 0; j < folderInfo[i].count; j++)
                {
                    fileInfo[count + j] = new BSAFileInfo4(br);
                }
                count += folderInfo[i].count;
            }
            for (uint i = 0; i < header.fileCount; i++)
            {
                fileInfo[i].path = "";
                char c;
                while ((c = br.ReadChar()) != '\0')
                {
                    fileInfo[i].path += c;
                }
            }

            for (int i = 0; i < header.folderCount; i++)
            {
                for (int j = 0; j < folderInfo[i].count; j++)
                {
                    BSAFileInfo4 fi4   = fileInfo[folderInfo[i].offset + j];
                    string       ext   = Path.GetExtension(fi4.path);
                    BSAFileInfo  fi    = new BSAFileInfo(this, (int)fi4.offset, fi4.size);
                    string       fpath = Path.Combine(folderInfo[i].path, Path.GetFileNameWithoutExtension(fi4.path));
                    ulong        hash  = GenHash(fpath, ext);
                    files[hash] = fi;
                    fileNames[folderInfo[i].offset + j] = fpath + ext;
                }
            }

            Array.Sort <string>(fileNames);
        }
        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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        private BSAArchive(string path)
        {
            BSAHeader4 header;

            br     = new BinaryReader(File.OpenRead(path), System.Text.Encoding.Default);
            header = new BSAHeader4(br);
            if (header.bsaVersion != 0x67 || (!header.ContainsMeshes && !header.ContainsTextures))
            {
                br.Close();
                return;
            }
            bool defaultCompressed = (header.archiveFlags & 0x100) > 0;

            //Read folder info
            BSAFolderInfo4[] folderInfo = new BSAFolderInfo4[header.folderCount];
            BSAFileInfo4[]   fileInfo   = new BSAFileInfo4[header.fileCount];
            for (int i = 0; i < header.folderCount; i++)
            {
                folderInfo[i] = new BSAFolderInfo4(br);
            }
            int count = 0;

            for (uint i = 0; i < header.folderCount; i++)
            {
                folderInfo[i].path = new string(br.ReadChars(br.ReadByte() - 1));
                br.BaseStream.Position++;
                folderInfo[i].offset = count;
                for (int j = 0; j < folderInfo[i].count; j++)
                {
                    fileInfo[count + j] = new BSAFileInfo4(br, defaultCompressed);
                }
                count += folderInfo[i].count;
            }
            for (uint i = 0; i < header.fileCount; i++)
            {
                fileInfo[i].path = "";
                char c;
                while ((c = br.ReadChar()) != '\0')
                {
                    fileInfo[i].path += c;
                }
            }

            for (int i = 0; i < header.folderCount; i++)
            {
                for (int j = 0; j < folderInfo[i].count; j++)
                {
                    BSAFileInfo4 fi4 = fileInfo[folderInfo[i].offset + j];
                    string       ext = Path.GetExtension(fi4.path);
                    if (ext != ".nif" && ext != ".dds")
                    {
                        continue;
                    }
                    BSAFileInfo fi    = new BSAFileInfo(br, (int)fi4.offset, fi4.size);
                    string      fpath = Path.Combine(folderInfo[i].path, Path.GetFileNameWithoutExtension(fi4.path));
                    ulong       hash  = GenHash(fpath, ext);
                    if (ext == ".nif")
                    {
                        Meshes[hash] = fi;
                        AvailableMeshes.Add(fpath);
                    }
                    else
                    {
                        Textures[hash] = fi;
                    }
                }
            }
            LoadedArchives.Add(this);
        }
Beispiel #9
0
    internal BSAArchive(string path)
    {
      br = new BinaryReader(File.OpenRead(path), Encoding.Default);
      var header = new BSAHeader4(br);
      if (header.bsaVersion != 0x68 && header.bsaVersion != 0x67)
      {
        throw new BSALoadException();
      }
      defaultCompressed = (header.archiveFlags & 4) > 0;
      SkipNames = (header.archiveFlags & 0x100) > 0 && header.bsaVersion == 0x68;
      files = new HashTable();

      //Read folder info
      var folderInfo = new BSAFolderInfo4[header.folderCount];
      var fileInfo = new BSAFileInfo4[header.fileCount];
      FileNames = new string[header.fileCount];
      for (var i = 0; i < header.folderCount; i++)
      {
        folderInfo[i] = new BSAFolderInfo4(br);
      }
      var count = 0;
      for (uint i = 0; i < header.folderCount; i++)
      {
        folderInfo[i].path = new string(br.ReadChars(br.ReadByte() - 1));
        br.BaseStream.Position++;
        folderInfo[i].offset = count;
        for (var j = 0; j < folderInfo[i].count; j++)
        {
          fileInfo[count + j] = new BSAFileInfo4(br);
        }
        count += folderInfo[i].count;
      }
      for (uint i = 0; i < header.fileCount; i++)
      {
        fileInfo[i].path = "";
        char c;
        while ((c = br.ReadChar()) != '\0')
        {
          fileInfo[i].path += c;
        }
      }

      for (var i = 0; i < header.folderCount; i++)
      {
        for (var j = 0; j < folderInfo[i].count; j++)
        {
          var fi4 = fileInfo[folderInfo[i].offset + j];
          var ext = Path.GetExtension(fi4.path);
          var fi = new BSAFileInfo(this, (int) fi4.offset, fi4.size);
          var fpath = Path.Combine(folderInfo[i].path, Path.GetFileNameWithoutExtension(fi4.path));
          var hash = GenHash(fpath, ext);
          files[hash] = fi;
          FileNames[folderInfo[i].offset + j] = fpath + ext;
        }
      }

      Array.Sort(FileNames);
    }