forked from nydrani/maplereverence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwzfile.hpp
113 lines (91 loc) · 3.04 KB
/
wzfile.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
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
#pragma once
#include <iostream>
#include <fstream>
#include <memory>
#include <vector>
#include "mapleaccessor.hpp"
class MapleEntry {
public:
MapleEntry(const std::string& name,
const uint32_t bytesize,
const int32_t checksum,
const uint32_t unknown,
const int offset)
: name(name), bytesize(bytesize), checksum(checksum),
unknown(unknown), headerOffset(offset), dataOffset(0) {}
virtual ~MapleEntry() {}
void setDataOffset(int);
int getDataOffset() const;
uint32_t getByteSize() const;
const std::string& getName() const;
virtual void extract(MapleAccessor&);
virtual void print() const;
private:
const std::string name;
const uint32_t bytesize;
const int32_t checksum;
const uint32_t unknown;
const int headerOffset;
int dataOffset;
};
class MapleFolder: public MapleEntry {
public:
MapleFolder(const std::string& name,
const uint32_t bytesize,
const int32_t checksum,
const uint32_t unknown,
const int offset)
: MapleEntry(name, bytesize, checksum, unknown, offset) {}
~MapleFolder() {}
void extract(MapleAccessor&);
void addEntry(std::unique_ptr<MapleEntry>);
void print() const;
const std::vector<std::unique_ptr<MapleEntry>>& getEntries() const;
private:
std::vector<std::unique_ptr<MapleEntry>> entries;
};
class BasicWZFile {
public:
BasicWZFile(const std::string& name) : name(name), accessor(name) {
readHeader();
std::ios::pos_type curPos = accessor.tell();
if (!sanityCheck()) {
std::string exception("Invalid header at offset: ");
exception += std::to_string(accessor.tell());
throw std::runtime_error(exception);
}
accessor.seek(curPos);
root = std::unique_ptr<MapleFolder>(new MapleFolder(name,
header.dataSize + header.headerSize, 0, 0,
accessor.tell()));
generateMapleEntries(root.get());
findDataOffsets(root.get());
}
~BasicWZFile() {}
void print() const;
void extract();
const std::string& getName() const;
private:
bool sanityCheck();
void readHeader();
void generateMapleEntries(MapleFolder* folder);
void findDataOffsets(MapleFolder* folder);
struct Header {
std::string fileIdentifier;
uint64_t dataSize;
uint32_t headerSize;
std::string fileDesc;
uint16_t version;
};
Header header;
const std::string name;
MapleAccessor accessor;
std::unique_ptr<MapleFolder> root;
};
class ListWZFile {
public:
ListWZFile(const std::string& name) : name(name) {}
~ListWZFile() {}
private:
const std::string name;
};