TrinityCore
Loading...
Searching...
No Matches
dbcfile.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include "
dbcfile.h
"
19
#include "
mpq_libmpq.h
"
20
21
DBCFile::DBCFile
(
const
std::string& filename):
22
filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr)
23
{
24
25
}
26
27
bool
DBCFile::open
()
28
{
29
MPQFile
f(
filename
.c_str());
30
char
header[4];
31
unsigned
int
na,nb,es,ss;
32
33
if
(f.
read
(header,4)!=4)
// Number of records
34
return
false
;
35
36
if
(header[0]!=
'W'
|| header[1]!=
'D'
|| header[2]!=
'B'
|| header[3]!=
'C'
)
37
return
false
;
38
39
if
(f.
read
(&na,4)!=4)
// Number of records
40
return
false
;
41
if
(f.
read
(&nb,4)!=4)
// Number of fields
42
return
false
;
43
if
(f.
read
(&es,4)!=4)
// Size of a record
44
return
false
;
45
if
(f.
read
(&ss,4)!=4)
// String size
46
return
false
;
47
48
recordSize
= es;
49
recordCount
= na;
50
fieldCount
= nb;
51
stringSize
= ss;
52
if
(
fieldCount
*4 !=
recordSize
)
53
return
false
;
54
55
data
=
new
unsigned
char
[
recordSize
*
recordCount
+
stringSize
];
56
stringTable
=
data
+
recordSize
*
recordCount
;
57
58
size_t
data_size =
recordSize
*
recordCount
+
stringSize
;
59
if
(f.
read
(
data
,data_size)!=data_size)
60
return
false
;
61
f.
close
();
62
return
true
;
63
}
64
DBCFile::~DBCFile
()
65
{
66
delete
[]
data
;
67
}
68
69
DBCFile::Record
DBCFile::getRecord
(
size_t
id
)
70
{
71
assert(
data
);
72
return
Record
(*
this
,
data
+
id
*
recordSize
);
73
}
74
75
size_t
DBCFile::getMaxId
()
76
{
77
assert(
data
);
78
79
size_t
maxId = 0;
80
for
(
size_t
i = 0; i <
getRecordCount
(); ++i)
81
{
82
if
(maxId <
getRecord
(i).
getUInt
(0))
83
maxId =
getRecord
(i).
getUInt
(0);
84
}
85
return
maxId;
86
}
87
88
DBCFile::Iterator
DBCFile::begin
()
89
{
90
assert(
data
);
91
return
Iterator
(*
this
,
data
);
92
}
93
DBCFile::Iterator
DBCFile::end
()
94
{
95
assert(
data
);
96
return
Iterator
(*
this
,
stringTable
);
97
}
DBCFile::Iterator
Definition
dbcfile.h:90
DBCFile::Record
Definition
dbcfile.h:53
DBCFile::Record::getUInt
unsigned int getUInt(size_t field) const
Definition
dbcfile.h:60
DBCFile::DBCFile
DBCFile(const std::string &filename)
Definition
dbcfile.cpp:21
DBCFile::fieldCount
size_t fieldCount
Definition
dbcfile.h:130
DBCFile::data
unsigned char * data
Definition
dbcfile.h:132
DBCFile::stringSize
size_t stringSize
Definition
dbcfile.h:131
DBCFile::recordCount
size_t recordCount
Definition
dbcfile.h:129
DBCFile::getRecord
Record getRecord(size_t id)
Definition
dbcfile.cpp:69
DBCFile::~DBCFile
~DBCFile()
Definition
dbcfile.cpp:64
DBCFile::filename
std::string filename
Definition
dbcfile.h:127
DBCFile::end
Iterator end()
Get begin iterator over records.
Definition
dbcfile.cpp:93
DBCFile::getMaxId
size_t getMaxId()
Definition
dbcfile.cpp:75
DBCFile::begin
Iterator begin()
Get begin iterator over records.
Definition
dbcfile.cpp:88
DBCFile::open
bool open()
Definition
dbcfile.cpp:27
DBCFile::getRecordCount
size_t getRecordCount() const
Trivial.
Definition
dbcfile.h:123
DBCFile::stringTable
unsigned char * stringTable
Definition
dbcfile.h:133
DBCFile::recordSize
size_t recordSize
Definition
dbcfile.h:128
MPQFile
Definition
mpq_libmpq.h:73
MPQFile::read
size_t read(void *dest, size_t bytes)
Definition
mpq_libmpq.cpp:100
MPQFile::close
void close()
Definition
mpq_libmpq.cpp:129
mpq_libmpq.h
dbcfile.h
tools
map_extractor
dbcfile.cpp
Generated on Sun May 10 2026 02:30:26 for TrinityCore by
1.9.8