Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
134 строки · 3.6 Кб
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
#include "vmapexport.h"
21
#include "wdtfile.h"
22
#include "adtfile.h"
23
#include <cstdio>
24

25
char * wdtGetPlainName(char * FileName)
26
{
27
    char * szTemp;
28

29
    if((szTemp = strrchr(FileName, '\\')) != nullptr)
30
        FileName = szTemp + 1;
31
    return FileName;
32
}
33

34
extern HANDLE WorldMpq;
35

36
WDTFile::WDTFile(char* file_name, char* file_name1) : _file(WorldMpq, file_name)
37
{
38
    filename.append(file_name1,strlen(file_name1));
39
}
40

41
bool WDTFile::init(uint32 mapId)
42
{
43
    if (_file.isEof())
44
    {
45
        //printf("Can't find WDT file.\n");
46
        return false;
47
    }
48

49
    char fourcc[5];
50
    uint32 size;
51

52
    std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
53
    FILE *dirfile;
54
    dirfile = fopen(dirname.c_str(), "ab");
55
    if(!dirfile)
56
    {
57
        printf("Can't open dirfile!'%s'\n", dirname.c_str());
58
        return false;
59
    }
60

61
    while (!_file.isEof())
62
    {
63
        _file.read(fourcc,4);
64
        _file.read(&size, 4);
65

66
        flipcc(fourcc);
67
        fourcc[4] = 0;
68

69
        size_t nextpos = _file.getPos() + size;
70

71
        if (!strcmp(fourcc,"MAIN"))
72
        {
73
        }
74
        if (!strcmp(fourcc,"MWMO"))
75
        {
76
            // global map objects
77
            if (size)
78
            {
79
                char *buf = new char[size];
80
                _file.read(buf, size);
81
                char *p=buf;
82
                while (p < buf + size)
83
                {
84
                    std::string path(p);
85

86
                    char* s = wdtGetPlainName(p);
87
                    fixnamen(s, strlen(s));
88
                    fixname2(s, strlen(s));
89
                    p = p + strlen(p) + 1;
90
                    _wmoNames.push_back(s);
91

92
                    ExtractSingleWmo(path);
93
                }
94
                delete[] buf;
95
            }
96
        }
97
        else if (!strcmp(fourcc, "MODF"))
98
        {
99
            // global wmo instance data
100
            if (size)
101
            {
102
                uint32 mapObjectCount = size / sizeof(ADT::MODF);
103
                for (uint32 i = 0; i < mapObjectCount; ++i)
104
                {
105
                    ADT::MODF mapObjDef;
106
                    _file.read(&mapObjDef, sizeof(ADT::MODF));                    
107
                    MapObject::Extract(mapObjDef, _wmoNames[mapObjDef.Id].c_str(), mapId, 65, 65, dirfile);
108
                    Doodad::ExtractSet(WmoDoodads[_wmoNames[mapObjDef.Id]], mapObjDef, mapId, 65, 65, dirfile);
109
                }
110
            }
111
        }
112
        _file.seek((int)nextpos);
113
    }
114

115
    _file.close();
116
    fclose(dirfile);
117
    return true;
118
}
119

120
WDTFile::~WDTFile(void)
121
{
122
    _file.close();
123
}
124

125
ADTFile* WDTFile::GetMap(int x, int z)
126
{
127
    if(!(x>=0 && z >= 0 && x<64 && z<64))
128
        return nullptr;
129

130
    char name[512];
131

132
    sprintf(name,"World\\Maps\\%s\\%s_%d_%d_obj0.adt", filename.c_str(), filename.c_str(), x, z);
133
    return new ADTFile(name);
134
}
135

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

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

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

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