Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
144 строки · 4.1 Кб
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 "model.h"
21
#include "dbcfile.h"
22
#include "adtfile.h"
23
#include "vmapexport.h"
24
#include "VMapDefinitions.h"
25
#include <algorithm>
26
#include <stdio.h>
27

28
bool ExtractSingleModel(std::string& fname)
29
{
30
    if (fname.length() < 4)
31
        return false;    
32

33
    std::string extension = fname.substr(fname.length() - 4, 4);
34
    if (extension == ".mdx" || extension == ".MDX" || extension == ".mdl" || extension == ".MDL")
35
    {
36
        // replace .mdx -> .m2
37
        fname.erase(fname.length()-2,2);
38
        fname.append("2");
39
    }    
40

41
    std::string originalName = fname;
42

43
    char* name = GetPlainName((char*)fname.c_str());
44
    FixNameCase(name, strlen(name));
45
    FixNameSpaces(name, strlen(name));
46

47
    std::string output(szWorkDirWmo);
48
    output += "/";
49
    output += name;
50

51
    if (FileExists(output.c_str()))
52
        return true;
53

54
    Model mdl(originalName);
55
    if (!mdl.open())
56
        return false;
57

58
    return mdl.ConvertToVMAPModel(output.c_str());
59
}
60

61
extern HANDLE LocaleMpq;
62

63
void ExtractGameobjectModels(char* input_path)
64
{
65
    HANDLE localeFile;
66
    char localMPQ[512];
67

68
    sprintf(localMPQ, "%smisc.MPQ", input_path);
69
    if (FileExists(localMPQ) == false)
70
    {   // Use misc.mpq
71
        printf(localMPQ, "%s/Data/%s/locale-%s.MPQ", input_path);
72
    }
73

74
    if (!SFileOpenArchive(localMPQ, 0, MPQ_OPEN_READ_ONLY, &localeFile))
75
    {
76
        exit(1);
77
    }
78

79
    printf("Extracting GameObject models...");
80
    DBCFile dbc(localeFile, "DBFilesClient\\GameObjectDisplayInfo.dbc");
81
    if (!dbc.open())
82
    {
83
        printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
84
        exit(1);
85
    }
86

87
    std::string basepath = szWorkDirWmo;
88
    basepath += "/";
89
    std::string path;
90

91
    std::string modelListPath = basepath + "temp_gameobject_models";
92
    FILE* model_list = fopen(modelListPath.c_str(), "wb");
93
    if (!model_list)
94
    {
95
        printf("Fatal error: Could not open file %s\n", modelListPath.c_str());
96
        return;
97
    }
98

99
    fwrite(VMAP::RAW_VMAP_MAGIC, 1, 8, model_list);
100

101
    for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
102
    {
103
        path = it->getString(1);
104

105
        if (path.length() < 4)
106
            continue;
107

108
        FixNameCase((char*)path.c_str(), path.size());
109
        char * name = GetPlainName((char*)path.c_str());
110
        FixNameSpaces(name, strlen(name));
111

112
        char * ch_ext = GetExtension(name);
113
        if (!ch_ext)
114
            continue;
115

116
        strToLower(ch_ext);
117

118
        bool result = false;
119
        uint8 isWmo = 0;
120
        if (!strcmp(ch_ext, ".wmo"))
121
        {
122
            isWmo = 1;
123
            result = ExtractSingleWmo(path);
124
        }
125
        else if (!strcmp(ch_ext, ".mdl"))   // TODO: extract .mdl files, if needed
126
            continue;
127
        else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
128
            result = ExtractSingleModel(path);
129

130
        if (result)
131
        {
132
            uint32 displayId = it->getUInt(0);
133
            uint32 path_length = strlen(name);
134
            fwrite(&displayId, sizeof(uint32), 1, model_list);
135
            fwrite(&isWmo, sizeof(uint8), 1, model_list);
136
            fwrite(&path_length, sizeof(uint32), 1, model_list);
137
            fwrite(name, sizeof(char), path_length, model_list);
138
        }
139
    }
140

141
    fclose(model_list);
142

143
    printf("Done!\n");
144
}
145

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

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

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

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