Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
dbcfile.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#define _CRT_SECURE_NO_DEPRECATE
7
8
#include "
dbcfile.h
"
9
10
DBCFile::DBCFile
(HANDLE mpq,
const
char
* filename) :
11
_mpq
(mpq),
_filename
(filename),
_file
(NULL),
_recordSize
(0),
_recordCount
(0),
12
_fieldCount
(0),
_stringSize
(0),
_data
(NULL),
_stringTable
(NULL)
13
{
14
}
15
16
bool
DBCFile::open
()
17
{
18
if
(!SFileOpenFileEx(
_mpq
,
_filename
, SFILE_OPEN_FROM_MPQ, &
_file
))
19
return
false
;
20
21
char
header[4];
22
unsigned
int
na, nb, es, ss;
23
24
DWORD readBytes = 0;
25
SFileReadFile(
_file
, header, 4, &readBytes, NULL);
26
if
(readBytes != 4)
// Number of records
27
return
false
;
28
29
if
(header[0] !=
'W'
|| header[1] !=
'D'
|| header[2] !=
'B'
|| header[3] !=
'C'
)
30
return
false
;
31
32
readBytes = 0;
33
SFileReadFile(
_file
, &na, 4, &readBytes, NULL);
34
if
(readBytes != 4)
// Number of records
35
return
false
;
36
37
readBytes = 0;
38
SFileReadFile(
_file
, &nb, 4, &readBytes, NULL);
39
if
(readBytes != 4)
// Number of fields
40
return
false
;
41
42
readBytes = 0;
43
SFileReadFile(
_file
, &es, 4, &readBytes, NULL);
44
if
(readBytes != 4)
// Size of a record
45
return
false
;
46
47
readBytes = 0;
48
SFileReadFile(
_file
, &ss, 4, &readBytes, NULL);
49
if
(readBytes != 4)
// String size
50
return
false
;
51
52
_recordSize
= es;
53
_recordCount
= na;
54
_fieldCount
= nb;
55
_stringSize
= ss;
56
if
(
_fieldCount
* 4 !=
_recordSize
)
57
return
false
;
58
59
_data
=
new
unsigned
char
[
_recordSize
*
_recordCount
+
_stringSize
];
60
_stringTable
=
_data
+
_recordSize
*
_recordCount
;
61
62
size_t
data_size =
_recordSize
*
_recordCount
+
_stringSize
;
63
readBytes = 0;
64
SFileReadFile(
_file
,
_data
, data_size, &readBytes, NULL);
65
if
(readBytes != data_size)
66
return
false
;
67
68
return
true
;
69
}
70
71
DBCFile::~DBCFile
()
72
{
73
delete
[]
_data
;
74
if
(
_file
!= NULL)
75
SFileCloseFile(
_file
);
76
}
77
78
DBCFile::Record
DBCFile::getRecord
(
size_t
id
)
79
{
80
assert(
_data
);
81
return
Record
(*
this
,
_data
+
id
*
_recordSize
);
82
}
83
84
size_t
DBCFile::getMaxId
()
85
{
86
assert(
_data
);
87
88
size_t
maxId = 0;
89
for
(
size_t
i = 0; i <
getRecordCount
(); ++i)
90
if
(maxId <
getRecord
(i).getUInt(0))
91
maxId =
getRecord
(i).
getUInt
(0);
92
93
return
maxId;
94
}
95
96
DBCFile::Iterator
DBCFile::begin
()
97
{
98
assert(
_data
);
99
return
Iterator
(*
this
,
_data
);
100
}
101
102
DBCFile::Iterator
DBCFile::end
()
103
{
104
assert(
_data
);
105
return
Iterator
(*
this
,
_stringTable
);
106
}
107
DBCFile::Iterator
Definition
dbcfile.h:82
DBCFile::Record
Definition
dbcfile.h:41
DBCFile::Record::getUInt
unsigned int getUInt(size_t field) const
Definition
dbcfile.h:49
DBCFile::_stringSize
size_t _stringSize
Definition
dbcfile.h:130
DBCFile::_mpq
HANDLE _mpq
Definition
dbcfile.h:136
DBCFile::getRecord
Record getRecord(size_t id)
Definition
dbcfile.cpp:68
DBCFile::~DBCFile
~DBCFile()
Definition
dbcfile.cpp:63
DBCFile::_stringTable
unsigned char * _stringTable
Definition
dbcfile.h:132
DBCFile::_data
unsigned char * _data
Definition
dbcfile.h:131
DBCFile::end
Iterator end()
Get begin iterator over records.
Definition
dbcfile.cpp:92
DBCFile::_recordSize
size_t _recordSize
Definition
dbcfile.h:127
DBCFile::getMaxId
size_t getMaxId()
Definition
dbcfile.cpp:74
DBCFile::begin
Iterator begin()
Get begin iterator over records.
Definition
dbcfile.cpp:86
DBCFile::_fieldCount
size_t _fieldCount
Definition
dbcfile.h:129
DBCFile::_recordCount
size_t _recordCount
Definition
dbcfile.h:128
DBCFile::open
virtual bool open()
Definition
dbcfile.cpp:16
DBCFile::_file
HANDLE _file
Definition
dbcfile.h:126
DBCFile::getRecordCount
size_t getRecordCount() const
Trivial.
Definition
dbcfile.h:121
DBCFile::_filename
const char * _filename
Definition
dbcfile.h:137
DBCFile::DBCFile
DBCFile(HANDLE file)
Definition
dbcfile.cpp:10
dbcfile.h
src
tools
vmap4_extractor
dbcfile.cpp
Generated on
for Project SkyFire Core by
1.17.0