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 file) :
11
_file
(file),
_recordSize
(0),
_recordCount
(0),
_fieldCount
(0),
12
_stringSize
(0),
_data
(NULL),
_stringTable
(NULL)
13
{
14
}
15
16
bool
DBCFile::open
()
17
{
18
char
header[4];
19
unsigned
int
na, nb, es, ss;
20
21
DWORD readBytes = 0;
22
SFileReadFile(
_file
, header, 4, &readBytes, NULL);
23
if
(readBytes != 4)
// Number of records
24
return
false
;
25
26
if
(header[0] !=
'W'
|| header[1] !=
'D'
|| header[2] !=
'B'
|| header[3] !=
'C'
)
27
return
false
;
28
29
SFileReadFile(
_file
, &na, 4, &readBytes, NULL);
30
if
(readBytes != 4)
// Number of records
31
return
false
;
32
33
SFileReadFile(
_file
, &nb, 4, &readBytes, NULL);
34
if
(readBytes != 4)
// Number of fields
35
return
false
;
36
37
SFileReadFile(
_file
, &es, 4, &readBytes, NULL);
38
if
(readBytes != 4)
// Size of a record
39
return
false
;
40
41
SFileReadFile(
_file
, &ss, 4, &readBytes, NULL);
42
if
(readBytes != 4)
// String size
43
return
false
;
44
45
_recordSize
= es;
46
_recordCount
= na;
47
_fieldCount
= nb;
48
_stringSize
= ss;
49
if
(
_fieldCount
* 4 !=
_recordSize
)
50
return
false
;
51
52
_data
=
new
unsigned
char
[
_recordSize
*
_recordCount
+
_stringSize
];
53
_stringTable
=
_data
+
_recordSize
*
_recordCount
;
54
55
size_t
data_size =
_recordSize
*
_recordCount
+
_stringSize
;
56
SFileReadFile(
_file
,
_data
, data_size, &readBytes, NULL);
57
if
(readBytes != data_size)
58
return
false
;
59
60
return
true
;
61
}
62
63
DBCFile::~DBCFile
()
64
{
65
delete
[]
_data
;
66
}
67
68
DBCFile::Record
DBCFile::getRecord
(
size_t
id
)
69
{
70
assert(
_data
);
71
return
Record
(*
this
,
_data
+
id
*
_recordSize
);
72
}
73
74
size_t
DBCFile::getMaxId
()
75
{
76
assert(
_data
);
77
78
size_t
maxId = 0;
79
for
(
size_t
i = 0; i <
getRecordCount
(); ++i)
80
if
(maxId <
getRecord
(i).getUInt(0))
81
maxId =
getRecord
(i).
getUInt
(0);
82
83
return
maxId;
84
}
85
86
DBCFile::Iterator
DBCFile::begin
()
87
{
88
assert(
_data
);
89
return
Iterator
(*
this
,
_data
);
90
}
91
92
DBCFile::Iterator
DBCFile::end
()
93
{
94
assert(
_data
);
95
return
Iterator
(*
this
,
_stringTable
);
96
}
97
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::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::DBCFile
DBCFile(HANDLE file)
Definition
dbcfile.cpp:10
dbcfile.h
src
tools
map_extractor
dbcfile.cpp
Generated on
for Project SkyFire Core by
1.17.0