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);
		}
Example #2
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);
        }
Example #3
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);
        }
        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);
        }
Example #5
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);
    }