Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
109 строк · 3.0 Кб
1
/*
2
 * Copyright (C) 2011-2016 Project SkyFire <http://www.projectskyfire.org/>
3
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
4
 * Copyright (C) 2005-2016 MaNGOS <http://getmangos.com/>
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License as published by the
8
 * Free Software Foundation; either version 3 of the License, or (at your
9
 * option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
 * more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along
17
 * with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#define _CRT_SECURE_NO_DEPRECATE
21

22
#include "dbcfile.h"
23

24
DBCFile::DBCFile(HANDLE file) :
25
    _file(file), _data(NULL), _stringTable(NULL)
26
{
27
}
28

29
bool DBCFile::open()
30
{
31
    char header[4];
32
    unsigned int na, nb, es, ss;
33

34
    DWORD readBytes = 0;
35
    SFileReadFile(_file, header, 4, &readBytes, NULL);
36
    if (readBytes != 4)                                         // Number of records
37
        return false;
38

39
    if (header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
40
        return false;
41

42
    SFileReadFile(_file, &na, 4, &readBytes, NULL);
43
    if (readBytes != 4)                                         // Number of records
44
        return false;
45

46
    SFileReadFile(_file, &nb, 4, &readBytes, NULL);
47
    if (readBytes != 4)                                         // Number of fields
48
        return false;
49

50
    SFileReadFile(_file, &es, 4, &readBytes, NULL);
51
    if (readBytes != 4)                                         // Size of a record
52
        return false;
53

54
    SFileReadFile(_file, &ss, 4, &readBytes, NULL);
55
    if (readBytes != 4)                                         // String size
56
        return false;
57

58
    _recordSize = es;
59
    _recordCount = na;
60
    _fieldCount = nb;
61
    _stringSize = ss;
62
    if (_fieldCount * 4 != _recordSize)
63
        return false;
64

65
    _data = new unsigned char[_recordSize * _recordCount + _stringSize];
66
    _stringTable = _data + _recordSize*_recordCount;
67

68
    size_t data_size = _recordSize * _recordCount + _stringSize;
69
    SFileReadFile(_file, _data, data_size, &readBytes, NULL);
70
    if (readBytes != data_size)
71
        return false;
72

73
    return true;
74
}
75

76
DBCFile::~DBCFile()
77
{
78
    delete [] _data;
79
}
80

81
DBCFile::Record DBCFile::getRecord(size_t id)
82
{
83
    assert(_data);
84
    return Record(*this, _data + id*_recordSize);
85
}
86

87
size_t DBCFile::getMaxId()
88
{
89
    assert(_data);
90

91
    size_t maxId = 0;
92
    for(size_t i = 0; i < getRecordCount(); ++i)
93
        if (maxId < getRecord(i).getUInt(0))
94
            maxId = getRecord(i).getUInt(0);
95

96
    return maxId;
97
}
98

99
DBCFile::Iterator DBCFile::begin()
100
{
101
    assert(_data);
102
    return Iterator(*this, _data);
103
}
104

105
DBCFile::Iterator DBCFile::end()
106
{
107
    assert(_data);
108
    return Iterator(*this, _stringTable);
109
}
110

111

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.