コード例 #1
0
ファイル: BSA.cs プロジェクト: erri120/OMOD-Framework
        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;

            //Read folder info
            var folderInfo = new BSAFolderInfo4[header.folderCount];
            var fileInfo   = new BSAFileInfo4[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, 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);
        }
コード例 #2
0
ファイル: BSAArchive.cs プロジェクト: vjmira/fomm
        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);
        }