This repository has been archived by the owner on Nov 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
DrsFile.cpp
131 lines (100 loc) · 3.29 KB
/
DrsFile.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2011 <copyright holder> <email>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "genie/resource/DrsFile.h"
#include <string>
#include "genie/util/Logger.h"
//#include <file/BinaFile.h>
namespace genie
{
using std::string;
Logger& DrsFile::log = Logger::getLogger("freeaoe.DrsFile");
//------------------------------------------------------------------------------
DrsFile::DrsFile()
{
header_loaded_ = false;
}
//------------------------------------------------------------------------------
DrsFile::~DrsFile()
{
}
//------------------------------------------------------------------------------
SlpFilePtr DrsFile::getSlpFile(uint32_t id)
{
slp_map_[id]->readObject(*getIStream());
return slp_map_[id];
}
//------------------------------------------------------------------------------
void DrsFile::serializeObject(void)
{
loadHeader();
}
//------------------------------------------------------------------------------
std::string DrsFile::getSlpTableHeader(void) const
{
return " plsL";
}
//------------------------------------------------------------------------------
std::string DrsFile::getBinaryTableHeader(void) const
{
return "anibd";
}
//------------------------------------------------------------------------------
void DrsFile::loadHeader()
{
if (header_loaded_)
log.warn("Trying to load header again!");
else
{
string copy_right = readString(40);
string version = readString(4);
//File type
string file_type = readString(12);
num_of_tables_ = read<uint32_t>();
header_offset_ = read<uint32_t>();
// Load table data
for (uint32_t i = 0; i < num_of_tables_; i++)
{
table_types_.push_back(readString(8));
table_num_of_files_.push_back(read<uint32_t>());
}
// Load file headers
for (uint32_t i = 0; i < num_of_tables_; i++)
{
for (uint32_t j = 0; j < table_num_of_files_[i]; j++)
{
uint32_t id = read<uint32_t>();
uint32_t pos = read<uint32_t>();
/*uint32_t len =*/ read<uint32_t>();
if (table_types_[i].compare(getSlpTableHeader()) == 0)
{
SlpFilePtr slp(new SlpFile());
slp->setInitialReadPosition(pos);
slp_map_[id] = slp;
}
else
{
if (table_types_[i].compare(getBinaryTableHeader()) == 0)
{
// BinaFile *bina = new BinaFile(id, pos, len, file_.getIOStream());
// resource_manager_->addBinaFile(bina);
}
}
// else other TODO: Sounds
}
}
header_loaded_ = true;
}
}
}