-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbsa_parser.h
More file actions
132 lines (112 loc) · 2.94 KB
/
bsa_parser.h
File metadata and controls
132 lines (112 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* TES4 data file library.
* (C) Dmitry 'MatrixS_Master' Solovyev, 2015-2019. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef BSA_PARSER_H_
#define BSA_PARSER_H_
#include <inttypes.h>
#include <vector>
#include <string>
#include <list>
#include <map>
#include "dt.h"
#ifdef TES4LIB_USE_VFS
#include "vfshelper.h"
#endif
namespace TES4 {
enum BSAArchiveFlags {
BSA_HASDIRNAMES = 0x01,
BSA_HASFILENAMES = 0x02,
BSA_COMPRESSED = 0x04,
BSA_INMEM = 0x08,
BSA_SNDMEM = 0x10,
BSA_HOLDOFF = 0x20,
BSA_XBOX = 0x40,
BSA_UNK1 = 0x80,
BSA_UNK2 = 0x100,
BSA_UNK3 = 0x200,
BSA_UNK4 = 0x300
};
enum BSAFileFlags {
BSA_MESHES = 0x01,
BSA_TEXTURES = 0x02,
BSA_MENUS = 0x04,
BSA_SOUNDS = 0x08,
BSA_VOICES = 0x10,
BSA_SHADERS = 0x20,
BSA_TREES = 0x40,
BSA_FONTS = 0x80,
BSA_MISC = 0x100
};
#define BSA_SIZEKLUDGE (1<<30)
struct BSAHeader {
char fileid[4];
uint32_t ver;
uint32_t off;
uint32_t aflags;
uint32_t dirs;
uint32_t files;
uint32_t totalFolderNames;
uint32_t totalFileNames;
uint32_t fflags;
};
struct BSADirInfo {
uint64_t hash;
uint32_t qty;
uint32_t off;
};
struct BSAFileInfo {
uint64_t hash;
uint32_t size;
uint32_t off;
};
struct BSAFile {
BSAFileInfo inf;
std::string name;
bool compress;
std::string cont;
};
struct BSADir {
BSADirInfo inf;
std::string name;
std::vector<BSAFile> files;
};
class BSA {
private:
BSAHeader hdr;
std::vector<BSADir> cont;
std::map<std::string,BSAFile*> fmap;
size_t filecnt = 0;
std::string filename;
bool error = true;
void remap();
public:
BSA(const char* fn, void* vfs = NULL);
virtual ~BSA() {}
static std::string lowercase(std::string in);
bool isFailed() { return error; }
std::string getBSAFileName() { return filename; }
size_t getNumFiles() { return filecnt; }
bool addSource(const char* fn, void* vfs = NULL);
std::vector<uint8_t> getFile(std::string fn, void* vfs = NULL);
};
}; //TES4
#endif /* BSA_PARSER_H_ */