-
Notifications
You must be signed in to change notification settings - Fork 1
/
hogreader.hpp
79 lines (65 loc) · 2.28 KB
/
hogreader.hpp
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
#ifndef HOG_READER_HPP_GUARD
#define HOG_READER_HPP_GUARD
//===----------------------------------------------------------------------===//
//
// The Descent map loader
//
// NAME : HogReader
// PURPOSE : Providing a decoder and wrapper for the Descent .HOG format.
// COPYRIGHT : (c) 2011 Sean Donnellan. All Rights Reserved.
// AUTHORS : Sean Donnellan ([email protected])
// DESCRIPTION : A decoder for the HOG file format that is used by Parallax
// Software in the computer game, Descent.
//
// The file format is as follows:
//
// - Magic number which is 3 bytes and corresponding to the
// string "DHF"
// - A series of files which are preceded by a short header,
// which describes the name of the file and the numer of bytes.
//
// | "DHF" - 3 bytes
// |---------------- Start of the first file
// | filename - 13 bytes
// | size - 4 bytes
// | data - the size of this part is by the size before it.
// |---------------- The next header/file comes straight after.
// | filename - 13 bytes
// | size - 4 bytes
// | data - the size of this part is by the size before it.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <vector>
#include <stdint.h>
class HogReaderIterator;
struct HogFileHeader
{
char name[13]; // Padded to 13 bytes with \0.
uint32_t size; // The filesize as N bytes.
};
// Warning: The above structure is padded on x86 so you can not just read in the
// whole thing.
class HogReader
{
public:
typedef HogReaderIterator iterator;
HogReader(const char* filename);
~HogReader();
bool IsValid() const;
// Returns true if the file was succesfully opened and the magic header is
// correct.
bool NextFile();
std::vector<uint8_t> CurrentFile();
// Returns a copy of the data for the current file after reading it.
const char* CurrentFileName() const;
unsigned int CurrentFileSize() const;
iterator begin();
iterator end();
private:
FILE* myFile;
uint8_t myHeader[3];
bool hasReadFile;
HogFileHeader myChildFile;
};
#endif