redid set handling, again. did other stuff
[riven-wahrk.git] / src / mohawk.h
blobdfd1548d16cf25787cf0a1b157d8a21b57f2c97a
2 /*
4 * Riven-Wahrk - a reimplementation of the game Riven, by Cyan
5 * Copyright (C) 2009-2010 Tyler Genter <tylergenter@gmail.com>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef RIVEN_MOHAWK_H
23 #define RIVEN_MOHAWK_H
25 #include <string>
26 #include <map>
28 #include <stdint.h>
32 #include "common.h"
34 #include "system.h"
36 namespace riven {
38 class file_table_t {
40 uint8_t *table;
41 uint32_t count;
43 public:
44 file_table_t (uint8_t* tableIn);
46 uint32_t getSize (int index);
47 uint32_t getOffset (int index);
51 #define fileTypeShift(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))
53 class resource_t {
55 public:
56 static const uint32_t BLST = fileTypeShift ('B', 'L', 'S', 'T');
57 static const uint32_t CARD = fileTypeShift ('C', 'A', 'R', 'D');
58 static const uint32_t FLST = fileTypeShift ('F', 'L', 'S', 'T');
59 static const uint32_t HSPT = fileTypeShift ('H', 'S', 'P', 'T');
60 static const uint32_t MLST = fileTypeShift ('M', 'L', 'S', 'T');
61 static const uint32_t NAME = fileTypeShift ('N', 'A', 'M', 'E');
62 static const uint32_t PLST = fileTypeShift ('P', 'L', 'S', 'T');
63 static const uint32_t RMAP = fileTypeShift ('R', 'M', 'A', 'P');
64 static const uint32_t SFXE = fileTypeShift ('S', 'F', 'X', 'E');
65 static const uint32_t SLST = fileTypeShift ('S', 'L', 'S', 'T');
66 static const uint32_t VARS = fileTypeShift ('V', 'A', 'R', 'S');
67 static const uint32_t VERS = fileTypeShift ('V', 'E', 'R', 'S');
68 static const uint32_t ZIPS = fileTypeShift ('Z', 'I', 'P', 'S');
69 static const uint32_t tBMP = fileTypeShift ('t', 'B', 'M', 'P');
70 static const uint32_t tMOV = fileTypeShift ('t', 'M', 'O', 'V');
71 static const uint32_t tWAV = fileTypeShift ('t', 'W', 'A', 'V');
74 private:
76 uint8_t* resourceDir;
77 uint8_t* resourceTable;
78 uint32_t type;
79 int count;
81 public:
83 resource_t (uint8_t *resourceDirIn, uint32_t type);
84 int getFileIndex (int id);
88 // Represents a single *.mhk file.
90 class mohawk_t {
92 public:
94 mohawk_t (const std::string &fileName);
95 ~mohawk_t ();
97 // returns a pointer to the file specified.
98 // returns NULL if not found
99 uint8_t *get_file (uint32_t type, int id);
100 uint32_t get_file_loc (uint32_t type, int id);
101 int get_size (uint32_t type, int id);
103 std::string file_name;
105 private:
107 mmap_file_t *file_mmap;
108 uint8_t *file;
109 int handle;
110 uint8_t *resourceDir;
111 file_table_t *fileTable;
113 std::map<uint32_t,resource_t> resources;
115 void loadresource_t (uint32_t type);
121 #endif