-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatreader.cpp
More file actions
52 lines (42 loc) · 1.17 KB
/
Datreader.cpp
File metadata and controls
52 lines (42 loc) · 1.17 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
#include "Datreader.h"
void Datreader::LoadOffsets()
{
int retval;
DATOffset offset;
uint16_t lowestOffset = 0xFFFFFFFF;
do
{
retval = fread(&offset.length, 2, 1, pFile);
retval = fread(&offset.position, 4, 1, pFile);
offsets.push_back(offset);
if (offset.length != 0)
{
if (offset.length < lowestOffset)
{
lowestOffset = offset.length;
}
}
} while (ftell(pFile) <= lowestOffset && retval > 0);
}
void Datreader::GetFiles(std::string filename)
{
std::ifstream dat;
dat.open(filename, std::ios::binary);
for (int i = 0; i < offsets.size(); i++) {
DATOffset offset = offsets[i];
char* buff = new char[offset.length];
dat.seekg(offset.position);
dat.read(buff, offset.length);
data.push_back(DatConent(buff, offset.length));
}
}
Datreader::Datreader(std::string filename)
{
pFile = fopen(filename.c_str(), "rb");
LoadOffsets();
GetFiles(filename);
}
DatConent Datreader::operator[](int index)
{
return data[index];
}