-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWADLoader.cpp
97 lines (73 loc) · 2.07 KB
/
WADLoader.cpp
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
#include "WADLoader.h"
#include <iostream>
#include "WADReader.h"
using namespace std;
WADLoader::WADLoader(string sWADFilePath) : m_WADData(NULL), m_sWADFilePath(sWADFilePath)
{
}
WADLoader::~WADLoader()
{
delete[] m_WADData;
m_WADData = NULL;
}
bool WADLoader::LoadWAD()
{
if (!OpenAndLoad())
{
return false;
}
if (!ReadDirectories())
{
return false;
}
return true;
}
bool WADLoader::OpenAndLoad()
{
cout << "Info: Loading WAD file: " << m_sWADFilePath << endl;
m_WADFile.open(m_sWADFilePath, ifstream::binary);
if (!m_WADFile.is_open())
{
cout << "Error: Failed to open WAD file" << m_sWADFilePath << endl;
return false;
}
m_WADFile.seekg(0, m_WADFile.end);
size_t length = m_WADFile.tellg();
if (m_WADData)
{
delete[] m_WADData;
m_WADData = NULL;
}
m_WADData = new uint8_t[length];
if (m_WADData == NULL)
{
cout << "Error: Failed alocate memory for WAD file of size " << length << endl;
return false;
}
m_WADFile.seekg(ifstream::beg);
m_WADFile.read((char *)m_WADData, length);
m_WADFile.close();
cout << "Info: Loading complete." << endl;
return true;
}
bool WADLoader::ReadDirectories()
{
WADReader reader;
Header header;
reader.ReadHeaderData(m_WADData, 0, header);
std::cout << header.WADType << std::endl;
std::cout << header.DirectoryCount << std::endl;
std::cout << header.DirectoryOffset << std::endl;
std::cout << std::endl << std::endl;
Directory directory;
for (unsigned int i = 0; i < header.DirectoryCount; ++i)
{
reader.ReadDirectoryData(m_WADData, header.DirectoryOffset + i * 16, directory);
m_WADDirectories.push_back(directory);
std::cout << directory.LumpOffset << std::endl;
std::cout << directory.LumpSize << std::endl;
std::cout << directory.LumpName << std::endl;
std::cout << std::endl;
}
return true;
}