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
#undef min
21
#undef max
22
23
#include <cstdio>
24
25
DBCFile::DBCFile
(
const
std::string& filename):
26
filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr)
27
{
28
29
}
30
31
bool
DBCFile::open
()
32
{
33
MPQFile
f(
filename
.c_str());
34
35
// Need some error checking, otherwise an unhandled exception error occurs
36
// if people screw with the data path.
37
if
(f.isEof() ==
true
)
38
return
false
;
39
40
unsigned
char
header[4];
41
unsigned
int
na,nb,es,ss;
42
43
f.read(header,4);
// File Header
44
45
if
(header[0]!=
'W'
|| header[1]!=
'D'
|| header[2]!=
'B'
|| header[3] !=
'C'
)
46
{
47
f.close();
48
data
=
nullptr
;
49
printf(
"Critical Error: An error occured while trying to read the DBCFile %s."
,
filename
.c_str());
50
return
false
;
51
}
52
53
//assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
54
55
f.read(&na,4);
// Number of records
56
f.read(&nb,4);
// Number of fields
57
f.read(&es,4);
// Size of a record
58
f.read(&ss,4);
// String size
59
60
recordSize
= es;
61
recordCount
= na;
62
fieldCount
= nb;
63
stringSize
= ss;
64
//assert(fieldCount*4 == recordSize);
65
assert(
fieldCount
*4 >=
recordSize
);
66
67
data
=
new
unsigned
char
[
recordSize
*
recordCount
+
stringSize
];
68
stringTable
=
data
+
recordSize
*
recordCount
;
69
f.read(
data
,
recordSize
*
recordCount
+
stringSize
);
70
f.close();
71
return
true
;
72
}
73
74
DBCFile::~DBCFile
()
75
{
76
delete
[]
data
;
77
}
78
79
DBCFile::Record
DBCFile::getRecord
(
size_t
id
)
80
{
81
assert(
data
);
82
return
Record(*
this
,
data
+
id
*
recordSize
);
83
}
84
85
DBCFile::Iterator
DBCFile::begin
()
86
{
87
assert(
data
);
88
return
Iterator(*
this
,
data
);
89
}
90
91
DBCFile::Iterator
DBCFile::end
()
92
{
93
assert(
data
);
94
return
Iterator(*
this
,
stringTable
);
95
}
DBCFile::Iterator
Definition
dbcfile.h:90
DBCFile::Record
Definition
dbcfile.h:53
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::begin
Iterator begin()
Get begin iterator over records.
Definition
dbcfile.cpp:88
DBCFile::open
bool open()
Definition
dbcfile.cpp:27
DBCFile::stringTable
unsigned char * stringTable
Definition
dbcfile.h:133
DBCFile::recordSize
size_t recordSize
Definition
dbcfile.h:128
MPQFile
Definition
mpq_libmpq.h:73
mpq_libmpq.h
dbcfile.h
tools
vmap4_extractor
dbcfile.cpp
Generated on Sun May 10 2026 02:30:26 for TrinityCore by
1.9.8