2013-10-27 22:27:46 +01:00
|
|
|
/*
|
2016-01-01 00:34:25 +01:00
|
|
|
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
2013-10-27 22:27:46 +01:00
|
|
|
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#define _CRT_SECURE_NO_DEPRECATE
|
|
|
|
|
|
2014-10-19 14:02:08 +02:00
|
|
|
#include <cstdio>
|
2008-10-02 16:23:55 -05:00
|
|
|
#include <deque>
|
2015-11-24 02:08:52 +01:00
|
|
|
#include <fstream>
|
2014-10-19 14:02:08 +02:00
|
|
|
#include <set>
|
2009-01-23 11:41:43 -06:00
|
|
|
#include <cstdlib>
|
2013-08-06 12:49:37 +01:00
|
|
|
#include <cstring>
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2014-10-29 23:38:01 +01:00
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
#include "Common.h"
|
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
|
#undef PLATFORM_WINDOWS
|
|
|
|
|
#endif
|
2014-10-10 20:17:30 +02:00
|
|
|
#include "DBFilesClientList.h"
|
|
|
|
|
#include "CascLib.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "dbcfile.h"
|
2016-07-17 17:24:53 +02:00
|
|
|
#include "Banner.h"
|
2015-11-24 02:08:52 +01:00
|
|
|
#include "StringFormat.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2010-06-23 10:16:40 +02:00
|
|
|
#include "adt.h"
|
|
|
|
|
#include "wdt.h"
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2014-10-29 23:38:47 +01:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
const char* HumanReadableCASCError(int error)
|
|
|
|
|
{
|
|
|
|
|
switch (error)
|
|
|
|
|
{
|
|
|
|
|
case ERROR_SUCCESS: return "SUCCESS";
|
|
|
|
|
case ERROR_FILE_CORRUPT: return "FILE_CORRUPT";
|
|
|
|
|
case ERROR_CAN_NOT_COMPLETE: return "CAN_NOT_COMPLETE";
|
|
|
|
|
case ERROR_HANDLE_EOF: return "HANDLE_EOF";
|
|
|
|
|
case ERROR_NO_MORE_FILES: return "NO_MORE_FILES";
|
|
|
|
|
case ERROR_BAD_FORMAT: return "BAD_FORMAT";
|
|
|
|
|
case ERROR_INSUFFICIENT_BUFFER: return "INSUFFICIENT_BUFFER";
|
|
|
|
|
case ERROR_ALREADY_EXISTS: return "ALREADY_EXISTS";
|
|
|
|
|
case ERROR_DISK_FULL: return "DISK_FULL";
|
|
|
|
|
case ERROR_INVALID_PARAMETER: return "INVALID_PARAMETER";
|
|
|
|
|
case ERROR_NOT_SUPPORTED: return "NOT_SUPPORTED";
|
|
|
|
|
case ERROR_NOT_ENOUGH_MEMORY: return "NOT_ENOUGH_MEMORY";
|
|
|
|
|
case ERROR_INVALID_HANDLE: return "INVALID_HANDLE";
|
|
|
|
|
case ERROR_ACCESS_DENIED: return "ACCESS_DENIED";
|
|
|
|
|
case ERROR_FILE_NOT_FOUND: return "FILE_NOT_FOUND";
|
|
|
|
|
default: return "UNKNOWN";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
HANDLE CascStorage = NULL;
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2008-12-24 09:58:26 -06:00
|
|
|
typedef struct
|
|
|
|
|
{
|
2008-10-02 16:23:55 -05:00
|
|
|
char name[64];
|
2008-12-24 09:58:26 -06:00
|
|
|
uint32 id;
|
|
|
|
|
} map_id;
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2008-12-24 09:58:26 -06:00
|
|
|
map_id *map_ids;
|
|
|
|
|
uint16 *LiqType;
|
2015-01-24 21:28:00 +01:00
|
|
|
#define MAX_PATH_LENGTH 128
|
2015-08-31 00:03:53 +02:00
|
|
|
char output_path[MAX_PATH_LENGTH];
|
|
|
|
|
char input_path[MAX_PATH_LENGTH];
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2012-06-13 18:38:21 +02:00
|
|
|
// **************************************************
|
2009-03-09 18:06:19 -06:00
|
|
|
// Extractor options
|
2012-06-13 18:38:21 +02:00
|
|
|
// **************************************************
|
2008-10-02 16:23:55 -05:00
|
|
|
enum Extract
|
|
|
|
|
{
|
|
|
|
|
EXTRACT_MAP = 1,
|
|
|
|
|
EXTRACT_DBC = 2
|
|
|
|
|
};
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
// Select data for extract
|
|
|
|
|
int CONF_extract = EXTRACT_MAP | EXTRACT_DBC;
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
// This option allow limit minimum height to some value (Allow save some memory)
|
|
|
|
|
bool CONF_allow_height_limit = true;
|
|
|
|
|
float CONF_use_minHeight = -500.0f;
|
|
|
|
|
|
|
|
|
|
// This option allow use float to int conversion
|
2014-10-25 12:32:14 +02:00
|
|
|
bool CONF_allow_float_to_int = true;
|
2009-03-09 18:06:19 -06:00
|
|
|
float CONF_float_to_int8_limit = 2.0f; // Max accuracy = val/256
|
|
|
|
|
float CONF_float_to_int16_limit = 2048.0f; // Max accuracy = val/65536
|
|
|
|
|
float CONF_flat_height_delta_limit = 0.005f; // If max - min less this value - surface is flat
|
|
|
|
|
float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - liquid surface is flat
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
uint32 CONF_Locale = 0;
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
#define CASC_LOCALES_COUNT 17
|
2014-09-14 15:12:31 +01:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
char const* CascLocaleNames[CASC_LOCALES_COUNT] =
|
2013-05-28 17:37:10 +02:00
|
|
|
{
|
2014-12-26 12:59:02 +01:00
|
|
|
"none", "enUS",
|
|
|
|
|
"koKR", "unknown",
|
|
|
|
|
"frFR", "deDE",
|
|
|
|
|
"zhCN", "esES",
|
|
|
|
|
"zhTW", "enGB",
|
|
|
|
|
"enCN", "enTW",
|
|
|
|
|
"esMX", "ruRU",
|
|
|
|
|
"ptBR", "itIT",
|
|
|
|
|
"ptPT"
|
2012-02-20 19:12:05 +01:00
|
|
|
};
|
|
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
uint32 WowLocaleToCascLocaleFlags[12] =
|
|
|
|
|
{
|
|
|
|
|
CASC_LOCALE_ENUS | CASC_LOCALE_ENGB,
|
|
|
|
|
CASC_LOCALE_KOKR,
|
|
|
|
|
CASC_LOCALE_FRFR,
|
|
|
|
|
CASC_LOCALE_DEDE,
|
|
|
|
|
CASC_LOCALE_ZHCN,
|
|
|
|
|
CASC_LOCALE_ZHTW,
|
|
|
|
|
CASC_LOCALE_ESES,
|
|
|
|
|
CASC_LOCALE_ESMX,
|
|
|
|
|
CASC_LOCALE_RURU,
|
|
|
|
|
0,
|
|
|
|
|
CASC_LOCALE_PTBR | CASC_LOCALE_PTPT,
|
|
|
|
|
CASC_LOCALE_ITIT,
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
void CreateDir(boost::filesystem::path const& path)
|
2012-02-20 19:12:05 +01:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
if (fs::exists(path))
|
2015-08-31 00:03:53 +02:00
|
|
|
return;
|
2013-11-02 14:05:17 +01:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
if (!fs::create_directory(path))
|
|
|
|
|
throw new std::runtime_error("Unable to create directory" + path.string());
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
|
2013-05-28 17:37:10 +02:00
|
|
|
void Usage(char const* prg)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-03-09 18:06:19 -06:00
|
|
|
printf(
|
|
|
|
|
"Usage:\n"\
|
|
|
|
|
"%s -[var] [value]\n"\
|
2015-01-24 21:28:00 +01:00
|
|
|
"-i set input path (max %d characters)\n"\
|
|
|
|
|
"-o set output path (max %d characters)\n"\
|
2009-03-09 18:06:19 -06:00
|
|
|
"-e extract only MAP(1)/DBC(2) - standard: both(3)\n"\
|
|
|
|
|
"-f height stored as int (less map size but lost some accuracy) 1 by default\n"\
|
2015-08-31 00:03:53 +02:00
|
|
|
"-l dbc locale\n"\
|
2015-01-24 21:28:00 +01:00
|
|
|
"Example: %s -f 0 -i \"c:\\games\\game\"\n", prg, MAX_PATH_LENGTH - 1, MAX_PATH_LENGTH - 1, prg);
|
2008-10-02 16:23:55 -05:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 17:37:10 +02:00
|
|
|
void HandleArgs(int argc, char* arg[])
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2012-02-20 19:12:05 +01:00
|
|
|
for (int c = 1; c < argc; ++c)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2008-12-24 09:58:26 -06:00
|
|
|
// i - input path
|
|
|
|
|
// o - output path
|
|
|
|
|
// e - extract only MAP(1)/DBC(2) - standard both(3)
|
2009-03-09 18:06:19 -06:00
|
|
|
// f - use float to int conversion
|
|
|
|
|
// h - limit minimum height
|
2012-02-20 19:12:05 +01:00
|
|
|
// b - target client build
|
|
|
|
|
if (arg[c][0] != '-')
|
2008-10-02 16:23:55 -05:00
|
|
|
Usage(arg[0]);
|
|
|
|
|
|
2012-02-20 19:12:05 +01:00
|
|
|
switch (arg[c][1])
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
case 'i':
|
2015-01-24 21:28:00 +01:00
|
|
|
if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok
|
|
|
|
|
{
|
|
|
|
|
strncpy(input_path, arg[c++ + 1], MAX_PATH_LENGTH);
|
|
|
|
|
input_path[MAX_PATH_LENGTH - 1] = '\0';
|
|
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
else
|
|
|
|
|
Usage(arg[0]);
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
2015-01-24 21:28:00 +01:00
|
|
|
if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok
|
|
|
|
|
{
|
|
|
|
|
strncpy(output_path, arg[c++ + 1], MAX_PATH_LENGTH);
|
|
|
|
|
output_path[MAX_PATH_LENGTH - 1] = '\0';
|
|
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
else
|
|
|
|
|
Usage(arg[0]);
|
|
|
|
|
break;
|
2009-03-09 18:06:19 -06:00
|
|
|
case 'f':
|
2012-02-20 19:12:05 +01:00
|
|
|
if (c + 1 < argc) // all ok
|
|
|
|
|
CONF_allow_float_to_int = atoi(arg[c++ + 1])!=0;
|
2009-03-09 18:06:19 -06:00
|
|
|
else
|
|
|
|
|
Usage(arg[0]);
|
|
|
|
|
break;
|
2008-10-02 16:23:55 -05:00
|
|
|
case 'e':
|
2012-02-20 19:12:05 +01:00
|
|
|
if (c + 1 < argc) // all ok
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2012-02-20 19:12:05 +01:00
|
|
|
CONF_extract = atoi(arg[c++ + 1]);
|
|
|
|
|
if (!(CONF_extract > 0 && CONF_extract < 4))
|
2008-10-02 16:23:55 -05:00
|
|
|
Usage(arg[0]);
|
|
|
|
|
}
|
|
|
|
|
else
|
2010-06-09 17:20:06 +02:00
|
|
|
Usage(arg[0]);
|
|
|
|
|
break;
|
2014-10-10 20:17:30 +02:00
|
|
|
case 'l':
|
2012-02-20 19:12:05 +01:00
|
|
|
if (c + 1 < argc) // all ok
|
2014-10-10 20:17:30 +02:00
|
|
|
{
|
2015-08-31 00:03:53 +02:00
|
|
|
for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
|
|
|
|
|
if (!strcmp(arg[c + 1], localeNames[i]))
|
2014-10-10 20:17:30 +02:00
|
|
|
CONF_Locale = 1 << i;
|
|
|
|
|
++c;
|
|
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
else
|
|
|
|
|
Usage(arg[0]);
|
|
|
|
|
break;
|
2014-10-29 23:39:03 +01:00
|
|
|
case 'h':
|
|
|
|
|
Usage(arg[0]);
|
|
|
|
|
break;
|
2012-02-20 19:12:05 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-11 05:01:30 +02:00
|
|
|
uint32 ReadBuild(int locale)
|
|
|
|
|
{
|
|
|
|
|
// include build info file also
|
2015-11-24 02:08:52 +01:00
|
|
|
std::string filename = Trinity::StringFormat("component.wow-%s.txt", localeNames[locale]);
|
2010-06-11 05:01:30 +02:00
|
|
|
//printf("Read %s file... ", filename.c_str());
|
|
|
|
|
|
2012-02-20 19:12:05 +01:00
|
|
|
HANDLE dbcFile;
|
2014-10-10 20:17:30 +02:00
|
|
|
if (!CascOpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL, 0, &dbcFile))
|
2012-02-20 19:12:05 +01:00
|
|
|
{
|
2015-08-31 00:03:53 +02:00
|
|
|
printf("Locale %s not installed.\n", localeNames[locale]);
|
2014-10-10 20:17:30 +02:00
|
|
|
return 0;
|
2012-02-20 19:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char buff[512];
|
|
|
|
|
DWORD readBytes = 0;
|
2014-10-10 20:17:30 +02:00
|
|
|
CascReadFile(dbcFile, buff, 512, &readBytes);
|
2012-02-20 19:12:05 +01:00
|
|
|
if (!readBytes)
|
2010-06-11 05:01:30 +02:00
|
|
|
{
|
|
|
|
|
printf("Fatal error: Not found %s file!\n", filename.c_str());
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 14:53:30 +01:00
|
|
|
std::string text = std::string(buff, readBytes);
|
2014-10-10 20:17:30 +02:00
|
|
|
CascCloseFile(dbcFile);
|
2010-06-11 05:01:30 +02:00
|
|
|
|
|
|
|
|
size_t pos = text.find("version=\"");
|
|
|
|
|
size_t pos1 = pos + strlen("version=\"");
|
2012-02-20 19:12:05 +01:00
|
|
|
size_t pos2 = text.find("\"", pos1);
|
2010-06-11 05:01:30 +02:00
|
|
|
if (pos == text.npos || pos2 == text.npos || pos1 >= pos2)
|
|
|
|
|
{
|
|
|
|
|
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string build_str = text.substr(pos1,pos2-pos1);
|
|
|
|
|
|
|
|
|
|
int build = atoi(build_str.c_str());
|
|
|
|
|
if (build <= 0)
|
|
|
|
|
{
|
|
|
|
|
printf("Fatal error: Invalid %s file format!\n", filename.c_str());
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return build;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
uint32 ReadMapDBC()
|
|
|
|
|
{
|
|
|
|
|
printf("Read Map.dbc file... ");
|
2009-03-12 14:48:44 -06:00
|
|
|
|
2012-02-20 19:12:05 +01:00
|
|
|
HANDLE dbcFile;
|
2014-10-19 14:02:08 +02:00
|
|
|
if (!CascOpenFile(CascStorage, "DBFilesClient\\Map.dbc", CASC_LOCALE_NONE, 0, &dbcFile))
|
2012-02-20 19:12:05 +01:00
|
|
|
{
|
2014-10-29 23:38:47 +01:00
|
|
|
printf("Fatal error: Cannot find Map.dbc in archive! %s\n", HumanReadableCASCError(GetLastError()));
|
2012-02-20 19:12:05 +01:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBCFile dbc(dbcFile);
|
|
|
|
|
if (!dbc.open())
|
2009-03-12 14:48:44 -06:00
|
|
|
{
|
|
|
|
|
printf("Fatal error: Invalid Map.dbc file format!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2008-12-24 09:58:26 -06:00
|
|
|
size_t map_count = dbc.getRecordCount();
|
|
|
|
|
map_ids = new map_id[map_count];
|
|
|
|
|
for(uint32 x = 0; x < map_count; ++x)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2008-12-24 09:58:26 -06:00
|
|
|
map_ids[x].id = dbc.getRecord(x).getUInt(0);
|
2015-01-24 21:28:00 +01:00
|
|
|
|
|
|
|
|
const char* map_name = dbc.getRecord(x).getString(1);
|
|
|
|
|
size_t max_map_name_length = sizeof(map_ids[x].name);
|
|
|
|
|
if (strlen(map_name) >= max_map_name_length)
|
|
|
|
|
{
|
|
|
|
|
printf("Fatal error: Map name too long!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strncpy(map_ids[x].name, map_name, max_map_name_length);
|
|
|
|
|
map_ids[x].name[max_map_name_length - 1] = '\0';
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
CascCloseFile(dbcFile);
|
2015-11-24 02:08:52 +01:00
|
|
|
printf("Done! (" SZFMTD " maps loaded)\n", map_count);
|
2008-10-02 16:23:55 -05:00
|
|
|
return map_count;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-24 09:58:26 -06:00
|
|
|
void ReadLiquidTypeTableDBC()
|
|
|
|
|
{
|
|
|
|
|
printf("Read LiquidType.dbc file...");
|
2012-02-20 19:12:05 +01:00
|
|
|
HANDLE dbcFile;
|
2014-10-19 14:02:08 +02:00
|
|
|
if (!CascOpenFile(CascStorage, "DBFilesClient\\LiquidType.dbc", CASC_LOCALE_NONE, 0, &dbcFile))
|
2012-02-20 19:12:05 +01:00
|
|
|
{
|
2014-10-29 23:38:47 +01:00
|
|
|
printf("Fatal error: Cannot find LiquidType.dbc in archive! %s\n", HumanReadableCASCError(GetLastError()));
|
2012-02-20 19:12:05 +01:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBCFile dbc(dbcFile);
|
2009-03-12 14:48:44 -06:00
|
|
|
if(!dbc.open())
|
|
|
|
|
{
|
|
|
|
|
printf("Fatal error: Invalid LiquidType.dbc file format!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-30 08:01:02 +02:00
|
|
|
size_t liqTypeCount = dbc.getRecordCount();
|
|
|
|
|
size_t liqTypeMaxId = dbc.getMaxId();
|
|
|
|
|
LiqType = new uint16[liqTypeMaxId + 1];
|
|
|
|
|
memset(LiqType, 0xff, (liqTypeMaxId + 1) * sizeof(uint16));
|
2008-12-24 09:58:26 -06:00
|
|
|
|
2012-05-30 08:01:02 +02:00
|
|
|
for(uint32 x = 0; x < liqTypeCount; ++x)
|
2008-12-24 09:58:26 -06:00
|
|
|
LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
CascCloseFile(dbcFile);
|
2015-11-24 02:08:52 +01:00
|
|
|
printf("Done! (" SZFMTD " LiqTypes loaded)\n", liqTypeCount);
|
2008-12-24 09:58:26 -06:00
|
|
|
}
|
|
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
//
|
|
|
|
|
// Adt file convertor function and data
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Map file format data
|
2010-06-11 05:01:30 +02:00
|
|
|
static char const* MAP_MAGIC = "MAPS";
|
2016-02-10 21:25:28 +01:00
|
|
|
static char const* MAP_VERSION_MAGIC = "v1.8";
|
2010-06-11 05:01:30 +02:00
|
|
|
static char const* MAP_AREA_MAGIC = "AREA";
|
|
|
|
|
static char const* MAP_HEIGHT_MAGIC = "MHGT";
|
|
|
|
|
static char const* MAP_LIQUID_MAGIC = "MLIQ";
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2009-07-31 11:25:28 +08:00
|
|
|
struct map_fileheader
|
|
|
|
|
{
|
2009-03-09 18:06:19 -06:00
|
|
|
uint32 mapMagic;
|
|
|
|
|
uint32 versionMagic;
|
2010-06-11 05:01:30 +02:00
|
|
|
uint32 buildMagic;
|
2009-03-09 18:06:19 -06:00
|
|
|
uint32 areaMapOffset;
|
|
|
|
|
uint32 areaMapSize;
|
|
|
|
|
uint32 heightMapOffset;
|
|
|
|
|
uint32 heightMapSize;
|
|
|
|
|
uint32 liquidMapOffset;
|
|
|
|
|
uint32 liquidMapSize;
|
2012-04-09 15:52:00 +02:00
|
|
|
uint32 holesOffset;
|
|
|
|
|
uint32 holesSize;
|
2009-03-09 18:06:19 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define MAP_AREA_NO_AREA 0x0001
|
2009-07-31 11:25:28 +08:00
|
|
|
|
|
|
|
|
struct map_areaHeader
|
|
|
|
|
{
|
2009-03-09 18:06:19 -06:00
|
|
|
uint32 fourcc;
|
|
|
|
|
uint16 flags;
|
|
|
|
|
uint16 gridArea;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-09 00:14:58 +01:00
|
|
|
#define MAP_HEIGHT_NO_HEIGHT 0x0001
|
|
|
|
|
#define MAP_HEIGHT_AS_INT16 0x0002
|
|
|
|
|
#define MAP_HEIGHT_AS_INT8 0x0004
|
|
|
|
|
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS 0x0008
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2009-07-31 11:25:28 +08:00
|
|
|
struct map_heightHeader
|
|
|
|
|
{
|
2009-03-09 18:06:19 -06:00
|
|
|
uint32 fourcc;
|
|
|
|
|
uint32 flags;
|
|
|
|
|
float gridHeight;
|
|
|
|
|
float gridMaxHeight;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define MAP_LIQUID_TYPE_NO_WATER 0x00
|
|
|
|
|
#define MAP_LIQUID_TYPE_WATER 0x01
|
|
|
|
|
#define MAP_LIQUID_TYPE_OCEAN 0x02
|
|
|
|
|
#define MAP_LIQUID_TYPE_MAGMA 0x04
|
|
|
|
|
#define MAP_LIQUID_TYPE_SLIME 0x08
|
|
|
|
|
|
|
|
|
|
#define MAP_LIQUID_TYPE_DARK_WATER 0x10
|
|
|
|
|
#define MAP_LIQUID_TYPE_WMO_WATER 0x20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAP_LIQUID_NO_TYPE 0x0001
|
2009-07-31 11:25:28 +08:00
|
|
|
#define MAP_LIQUID_NO_HEIGHT 0x0002
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2009-07-31 11:25:28 +08:00
|
|
|
struct map_liquidHeader
|
|
|
|
|
{
|
2009-03-09 18:06:19 -06:00
|
|
|
uint32 fourcc;
|
|
|
|
|
uint16 flags;
|
|
|
|
|
uint16 liquidType;
|
|
|
|
|
uint8 offsetX;
|
|
|
|
|
uint8 offsetY;
|
|
|
|
|
uint8 width;
|
|
|
|
|
uint8 height;
|
|
|
|
|
float liquidLevel;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
float selectUInt8StepStore(float maxDiff)
|
|
|
|
|
{
|
|
|
|
|
return 255 / maxDiff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float selectUInt16StepStore(float maxDiff)
|
|
|
|
|
{
|
|
|
|
|
return 65535 / maxDiff;
|
|
|
|
|
}
|
|
|
|
|
// Temporary grid data store
|
2016-02-02 19:13:04 +01:00
|
|
|
uint16 area_ids[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
|
|
|
|
|
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
|
|
|
|
|
uint16 uint16_V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
|
|
|
|
|
uint16 uint16_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
|
|
|
|
|
uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
|
|
|
|
|
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
|
|
|
|
|
|
2012-05-30 08:01:02 +02:00
|
|
|
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
|
|
|
|
|
uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
|
2009-03-09 18:06:19 -06:00
|
|
|
bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE];
|
|
|
|
|
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
|
2014-10-19 14:02:08 +02:00
|
|
|
uint8 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8];
|
|
|
|
|
|
2016-02-10 21:25:28 +01:00
|
|
|
int16 flight_box_max[3][3];
|
|
|
|
|
int16 flight_box_min[3][3];
|
2016-02-09 00:14:58 +01:00
|
|
|
|
|
|
|
|
bool TransformToHighRes(uint16 lowResHoles, uint8 hiResHoles[8])
|
2014-10-19 14:02:08 +02:00
|
|
|
{
|
|
|
|
|
for (uint8 i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
for (uint8 j = 0; j < 8; j++)
|
|
|
|
|
{
|
|
|
|
|
int32 holeIdxL = (i / 2) * 4 + (j / 2);
|
2016-02-09 00:14:58 +01:00
|
|
|
if (((lowResHoles >> holeIdxL) & 1) == 1)
|
2014-10-19 14:02:08 +02:00
|
|
|
hiResHoles[i] |= (1 << j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *((uint64*)hiResHoles) != 0;
|
|
|
|
|
}
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int /*cell_y*/, int /*cell_x*/, uint32 build)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
ChunkedFile adt;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
if (!adt.loadFile(CascStorage, inputPath))
|
2009-03-09 18:06:19 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Prepare map header
|
|
|
|
|
map_fileheader map;
|
2015-11-24 02:08:52 +01:00
|
|
|
map.mapMagic = *reinterpret_cast<uint32 const*>(MAP_MAGIC);
|
|
|
|
|
map.versionMagic = *reinterpret_cast<uint32 const*>(MAP_VERSION_MAGIC);
|
2010-06-11 05:01:30 +02:00
|
|
|
map.buildMagic = build;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
// Get area flags data
|
2016-02-02 19:13:04 +01:00
|
|
|
memset(area_ids, 0, sizeof(area_ids));
|
2014-10-10 20:17:30 +02:00
|
|
|
memset(V9, 0, sizeof(V9));
|
|
|
|
|
memset(V8, 0, sizeof(V8));
|
|
|
|
|
|
|
|
|
|
memset(liquid_show, 0, sizeof(liquid_show));
|
|
|
|
|
memset(liquid_flags, 0, sizeof(liquid_flags));
|
|
|
|
|
memset(liquid_entry, 0, sizeof(liquid_entry));
|
|
|
|
|
|
|
|
|
|
memset(holes, 0, sizeof(holes));
|
|
|
|
|
|
|
|
|
|
bool hasHoles = false;
|
2016-02-09 00:14:58 +01:00
|
|
|
bool hasFlightBox = false;
|
2014-10-10 20:17:30 +02:00
|
|
|
|
|
|
|
|
for (std::multimap<std::string, FileChunk*>::const_iterator itr = adt.chunks.lower_bound("MCNK"); itr != adt.chunks.upper_bound("MCNK"); ++itr)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
adt_MCNK* mcnk = itr->second->As<adt_MCNK>();
|
|
|
|
|
|
|
|
|
|
// Area data
|
2016-02-02 19:13:04 +01:00
|
|
|
area_ids[mcnk->iy][mcnk->ix] = mcnk->areaid;
|
2014-10-10 20:17:30 +02:00
|
|
|
|
|
|
|
|
// Height
|
|
|
|
|
// Height values for triangles stored in order:
|
|
|
|
|
// 1 2 3 4 5 6 7 8 9
|
|
|
|
|
// 10 11 12 13 14 15 16 17
|
|
|
|
|
// 18 19 20 21 22 23 24 25 26
|
|
|
|
|
// 27 28 29 30 31 32 33 34
|
|
|
|
|
// . . . . . . . .
|
|
|
|
|
// For better get height values merge it to V9 and V8 map
|
|
|
|
|
// V9 height map:
|
|
|
|
|
// 1 2 3 4 5 6 7 8 9
|
|
|
|
|
// 18 19 20 21 22 23 24 25 26
|
|
|
|
|
// . . . . . . . .
|
|
|
|
|
// V8 height map:
|
|
|
|
|
// 10 11 12 13 14 15 16 17
|
|
|
|
|
// 27 28 29 30 31 32 33 34
|
|
|
|
|
// . . . . . . . .
|
|
|
|
|
|
|
|
|
|
// Set map height as grid height
|
|
|
|
|
for (int y = 0; y <= ADT_CELL_SIZE; y++)
|
|
|
|
|
{
|
|
|
|
|
int cy = mcnk->iy * ADT_CELL_SIZE + y;
|
|
|
|
|
for (int x = 0; x <= ADT_CELL_SIZE; x++)
|
|
|
|
|
{
|
|
|
|
|
int cx = mcnk->ix * ADT_CELL_SIZE + x;
|
|
|
|
|
V9[cy][cx] = mcnk->ypos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < ADT_CELL_SIZE; y++)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
int cy = mcnk->iy * ADT_CELL_SIZE + y;
|
|
|
|
|
for (int x = 0; x < ADT_CELL_SIZE; x++)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
int cx = mcnk->ix * ADT_CELL_SIZE + x;
|
|
|
|
|
V8[cy][cx] = mcnk->ypos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get custom height
|
|
|
|
|
if (FileChunk* chunk = itr->second->GetSubChunk("MCVT"))
|
|
|
|
|
{
|
|
|
|
|
adt_MCVT* mcvt = chunk->As<adt_MCVT>();
|
|
|
|
|
// get V9 height map
|
|
|
|
|
for (int y = 0; y <= ADT_CELL_SIZE; y++)
|
|
|
|
|
{
|
|
|
|
|
int cy = mcnk->iy * ADT_CELL_SIZE + y;
|
|
|
|
|
for (int x = 0; x <= ADT_CELL_SIZE; x++)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
int cx = mcnk->ix * ADT_CELL_SIZE + x;
|
|
|
|
|
V9[cy][cx] += mcvt->height_map[y*(ADT_CELL_SIZE * 2 + 1) + x];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// get V8 height map
|
|
|
|
|
for (int y = 0; y < ADT_CELL_SIZE; y++)
|
|
|
|
|
{
|
|
|
|
|
int cy = mcnk->iy * ADT_CELL_SIZE + y;
|
|
|
|
|
for (int x = 0; x < ADT_CELL_SIZE; x++)
|
|
|
|
|
{
|
|
|
|
|
int cx = mcnk->ix * ADT_CELL_SIZE + x;
|
|
|
|
|
V8[cy][cx] += mcvt->height_map[y*(ADT_CELL_SIZE * 2 + 1) + ADT_CELL_SIZE + 1 + x];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Liquid data
|
|
|
|
|
if (mcnk->sizeMCLQ > 8)
|
|
|
|
|
{
|
|
|
|
|
if (FileChunk* chunk = itr->second->GetSubChunk("MCLQ"))
|
|
|
|
|
{
|
|
|
|
|
adt_MCLQ* liquid = chunk->As<adt_MCLQ>();
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (int y = 0; y < ADT_CELL_SIZE; ++y)
|
|
|
|
|
{
|
|
|
|
|
int cy = mcnk->iy * ADT_CELL_SIZE + y;
|
|
|
|
|
for (int x = 0; x < ADT_CELL_SIZE; ++x)
|
|
|
|
|
{
|
|
|
|
|
int cx = mcnk->ix * ADT_CELL_SIZE + x;
|
|
|
|
|
if (liquid->flags[y][x] != 0x0F)
|
|
|
|
|
{
|
|
|
|
|
liquid_show[cy][cx] = true;
|
|
|
|
|
if (liquid->flags[y][x] & (1 << 7))
|
|
|
|
|
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_DARK_WATER;
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32 c_flag = mcnk->flags;
|
|
|
|
|
if (c_flag & (1 << 2))
|
|
|
|
|
{
|
|
|
|
|
liquid_entry[mcnk->iy][mcnk->ix] = 1;
|
|
|
|
|
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_WATER; // water
|
|
|
|
|
}
|
|
|
|
|
if (c_flag & (1 << 3))
|
|
|
|
|
{
|
|
|
|
|
liquid_entry[mcnk->iy][mcnk->ix] = 2;
|
|
|
|
|
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_OCEAN; // ocean
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
2014-10-10 20:17:30 +02:00
|
|
|
if (c_flag & (1 << 4))
|
|
|
|
|
{
|
|
|
|
|
liquid_entry[mcnk->iy][mcnk->ix] = 3;
|
|
|
|
|
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_MAGMA; // magma/slime
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!count && liquid_flags[mcnk->iy][mcnk->ix])
|
|
|
|
|
fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
|
2012-02-21 21:12:00 +01:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
for (int y = 0; y <= ADT_CELL_SIZE; ++y)
|
|
|
|
|
{
|
|
|
|
|
int cy = mcnk->iy * ADT_CELL_SIZE + y;
|
|
|
|
|
for (int x = 0; x <= ADT_CELL_SIZE; ++x)
|
|
|
|
|
{
|
|
|
|
|
int cx = mcnk->ix * ADT_CELL_SIZE + x;
|
|
|
|
|
liquid_height[cy][cx] = liquid->liquid[y][x].height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hole data
|
|
|
|
|
if (!(mcnk->flags & 0x10000))
|
|
|
|
|
{
|
|
|
|
|
if (uint16 hole = mcnk->holes)
|
2014-10-19 14:02:08 +02:00
|
|
|
if (TransformToHighRes(hole, holes[mcnk->iy][mcnk->ix]))
|
|
|
|
|
hasHoles = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memcpy(holes[mcnk->iy][mcnk->ix], mcnk->union_5_3_0.HighResHoles, sizeof(uint64));
|
|
|
|
|
if (*((uint64*)holes[mcnk->iy][mcnk->ix]) != 0)
|
2014-10-10 20:17:30 +02:00
|
|
|
hasHoles = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get liquid map for grid (in WOTLK used MH2O chunk)
|
|
|
|
|
if (FileChunk* chunk = adt.GetChunk("MH2O"))
|
|
|
|
|
{
|
|
|
|
|
adt_MH2O* h2o = chunk->As<adt_MH2O>();
|
|
|
|
|
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
|
|
|
|
|
{
|
|
|
|
|
adt_liquid_header *h = h2o->getLiquidData(i, j);
|
|
|
|
|
if (!h)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
uint64 show = h2o->getLiquidShowMap(h);
|
|
|
|
|
for (int y = 0; y < h->height; y++)
|
|
|
|
|
{
|
|
|
|
|
int cy = i * ADT_CELL_SIZE + y + h->yOffset;
|
|
|
|
|
for (int x = 0; x < h->width; x++)
|
|
|
|
|
{
|
|
|
|
|
int cx = j * ADT_CELL_SIZE + x + h->xOffset;
|
|
|
|
|
if (show & 1)
|
|
|
|
|
{
|
|
|
|
|
liquid_show[cy][cx] = true;
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
show >>= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
liquid_entry[i][j] = h->liquidType;
|
|
|
|
|
switch (LiqType[h->liquidType])
|
|
|
|
|
{
|
|
|
|
|
case LIQUID_TYPE_WATER: liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; break;
|
|
|
|
|
case LIQUID_TYPE_OCEAN: liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; break;
|
|
|
|
|
case LIQUID_TYPE_MAGMA: liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; break;
|
|
|
|
|
case LIQUID_TYPE_SLIME: liquid_flags[i][j] |= MAP_LIQUID_TYPE_SLIME; break;
|
|
|
|
|
default:
|
2015-11-24 02:08:52 +01:00
|
|
|
printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->liquidType, inputPath.c_str(), i, j);
|
2014-10-10 20:17:30 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Dark water detect
|
|
|
|
|
if (LiqType[h->liquidType] == LIQUID_TYPE_OCEAN)
|
|
|
|
|
{
|
|
|
|
|
uint8* lm = h2o->getLiquidLightMap(h);
|
|
|
|
|
if (!lm)
|
|
|
|
|
liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!count && liquid_flags[i][j])
|
|
|
|
|
printf("Wrong liquid detect in MH2O chunk");
|
|
|
|
|
|
|
|
|
|
float* height = h2o->getLiquidHeightMap(h);
|
|
|
|
|
int pos = 0;
|
|
|
|
|
for (int y = 0; y <= h->height; y++)
|
|
|
|
|
{
|
|
|
|
|
int cy = i * ADT_CELL_SIZE + y + h->yOffset;
|
|
|
|
|
for (int x = 0; x <= h->width; x++)
|
|
|
|
|
{
|
|
|
|
|
int cx = j * ADT_CELL_SIZE + x + h->xOffset;
|
|
|
|
|
|
|
|
|
|
if (height)
|
|
|
|
|
liquid_height[cy][cx] = height[pos];
|
|
|
|
|
else
|
|
|
|
|
liquid_height[cy][cx] = h->heightLevel1;
|
2012-02-21 21:12:00 +01:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
}
|
2012-02-21 21:12:00 +01:00
|
|
|
|
2016-02-09 00:14:58 +01:00
|
|
|
if (FileChunk* chunk = adt.GetChunk("MFBO"))
|
|
|
|
|
{
|
2016-02-10 22:11:04 +01:00
|
|
|
adt_MFBO* mfbo = chunk->As<adt_MFBO>();
|
2016-02-10 21:25:28 +01:00
|
|
|
memcpy(flight_box_max, &mfbo->max, sizeof(flight_box_max));
|
|
|
|
|
memcpy(flight_box_min, &mfbo->min, sizeof(flight_box_min));
|
2016-02-09 00:14:58 +01:00
|
|
|
hasFlightBox = true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
//============================================
|
|
|
|
|
// Try pack area data
|
|
|
|
|
//============================================
|
|
|
|
|
bool fullAreaData = false;
|
2016-02-02 19:13:04 +01:00
|
|
|
uint32 areaId = area_ids[0][0];
|
|
|
|
|
for (int y = 0; y < ADT_CELLS_PER_GRID; ++y)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2016-02-02 19:13:04 +01:00
|
|
|
for (int x = 0; x < ADT_CELLS_PER_GRID; ++x)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2016-02-02 19:13:04 +01:00
|
|
|
if (area_ids[y][x] != areaId)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
|
|
|
|
fullAreaData = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map.areaMapOffset = sizeof(map);
|
|
|
|
|
map.areaMapSize = sizeof(map_areaHeader);
|
|
|
|
|
|
|
|
|
|
map_areaHeader areaHeader;
|
2015-11-24 02:08:52 +01:00
|
|
|
areaHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_AREA_MAGIC);
|
2009-03-09 18:06:19 -06:00
|
|
|
areaHeader.flags = 0;
|
|
|
|
|
if (fullAreaData)
|
|
|
|
|
{
|
|
|
|
|
areaHeader.gridArea = 0;
|
2016-02-02 19:13:04 +01:00
|
|
|
map.areaMapSize += sizeof(area_ids);
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
areaHeader.flags |= MAP_AREA_NO_AREA;
|
2016-02-02 19:13:04 +01:00
|
|
|
areaHeader.gridArea = static_cast<uint16>(areaId);
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//============================================
|
|
|
|
|
// Try pack height data
|
|
|
|
|
//============================================
|
|
|
|
|
float maxHeight = -20000;
|
|
|
|
|
float minHeight = 20000;
|
|
|
|
|
for (int y=0; y<ADT_GRID_SIZE; y++)
|
|
|
|
|
{
|
|
|
|
|
for(int x=0;x<ADT_GRID_SIZE;x++)
|
|
|
|
|
{
|
|
|
|
|
float h = V8[y][x];
|
|
|
|
|
if (maxHeight < h) maxHeight = h;
|
|
|
|
|
if (minHeight > h) minHeight = h;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int y=0; y<=ADT_GRID_SIZE; y++)
|
|
|
|
|
{
|
|
|
|
|
for(int x=0;x<=ADT_GRID_SIZE;x++)
|
|
|
|
|
{
|
|
|
|
|
float h = V9[y][x];
|
|
|
|
|
if (maxHeight < h) maxHeight = h;
|
|
|
|
|
if (minHeight > h) minHeight = h;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for allow limit minimum height (not store height in deep ochean - allow save some memory)
|
|
|
|
|
if (CONF_allow_height_limit && minHeight < CONF_use_minHeight)
|
|
|
|
|
{
|
|
|
|
|
for (int y=0; y<ADT_GRID_SIZE; y++)
|
|
|
|
|
for(int x=0;x<ADT_GRID_SIZE;x++)
|
|
|
|
|
if (V8[y][x] < CONF_use_minHeight)
|
|
|
|
|
V8[y][x] = CONF_use_minHeight;
|
|
|
|
|
for (int y=0; y<=ADT_GRID_SIZE; y++)
|
|
|
|
|
for(int x=0;x<=ADT_GRID_SIZE;x++)
|
|
|
|
|
if (V9[y][x] < CONF_use_minHeight)
|
|
|
|
|
V9[y][x] = CONF_use_minHeight;
|
|
|
|
|
if (minHeight < CONF_use_minHeight)
|
|
|
|
|
minHeight = CONF_use_minHeight;
|
|
|
|
|
if (maxHeight < CONF_use_minHeight)
|
|
|
|
|
maxHeight = CONF_use_minHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map.heightMapOffset = map.areaMapOffset + map.areaMapSize;
|
|
|
|
|
map.heightMapSize = sizeof(map_heightHeader);
|
|
|
|
|
|
|
|
|
|
map_heightHeader heightHeader;
|
2015-11-24 02:08:52 +01:00
|
|
|
heightHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_HEIGHT_MAGIC);
|
2009-03-09 18:06:19 -06:00
|
|
|
heightHeader.flags = 0;
|
|
|
|
|
heightHeader.gridHeight = minHeight;
|
|
|
|
|
heightHeader.gridMaxHeight = maxHeight;
|
|
|
|
|
|
|
|
|
|
if (maxHeight == minHeight)
|
2009-07-31 11:25:28 +08:00
|
|
|
heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
// Not need store if flat surface
|
|
|
|
|
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
|
2009-07-31 11:25:28 +08:00
|
|
|
heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2016-02-09 00:14:58 +01:00
|
|
|
if (hasFlightBox)
|
|
|
|
|
{
|
|
|
|
|
heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
|
|
|
|
|
map.heightMapSize += sizeof(flight_box_max) + sizeof(flight_box_min);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
// Try store as packed in uint16 or uint8 values
|
2009-07-31 11:25:28 +08:00
|
|
|
if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2012-06-13 18:38:21 +02:00
|
|
|
float step = 0;
|
2009-03-09 18:06:19 -06:00
|
|
|
// Try Store as uint values
|
|
|
|
|
if (CONF_allow_float_to_int)
|
|
|
|
|
{
|
|
|
|
|
float diff = maxHeight - minHeight;
|
|
|
|
|
if (diff < CONF_float_to_int8_limit) // As uint8 (max accuracy = CONF_float_to_int8_limit/256)
|
|
|
|
|
{
|
|
|
|
|
heightHeader.flags|=MAP_HEIGHT_AS_INT8;
|
|
|
|
|
step = selectUInt8StepStore(diff);
|
|
|
|
|
}
|
|
|
|
|
else if (diff<CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536)
|
|
|
|
|
{
|
|
|
|
|
heightHeader.flags|=MAP_HEIGHT_AS_INT16;
|
|
|
|
|
step = selectUInt16StepStore(diff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pack it to int values if need
|
|
|
|
|
if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
|
|
|
|
|
{
|
|
|
|
|
for (int y=0; y<ADT_GRID_SIZE; y++)
|
|
|
|
|
for(int x=0;x<ADT_GRID_SIZE;x++)
|
|
|
|
|
uint8_V8[y][x] = uint8((V8[y][x] - minHeight) * step + 0.5f);
|
|
|
|
|
for (int y=0; y<=ADT_GRID_SIZE; y++)
|
|
|
|
|
for(int x=0;x<=ADT_GRID_SIZE;x++)
|
|
|
|
|
uint8_V9[y][x] = uint8((V9[y][x] - minHeight) * step + 0.5f);
|
|
|
|
|
map.heightMapSize+= sizeof(uint8_V9) + sizeof(uint8_V8);
|
|
|
|
|
}
|
|
|
|
|
else if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
|
|
|
|
|
{
|
|
|
|
|
for (int y=0; y<ADT_GRID_SIZE; y++)
|
|
|
|
|
for(int x=0;x<ADT_GRID_SIZE;x++)
|
|
|
|
|
uint16_V8[y][x] = uint16((V8[y][x] - minHeight) * step + 0.5f);
|
|
|
|
|
for (int y=0; y<=ADT_GRID_SIZE; y++)
|
|
|
|
|
for(int x=0;x<=ADT_GRID_SIZE;x++)
|
|
|
|
|
uint16_V9[y][x] = uint16((V9[y][x] - minHeight) * step + 0.5f);
|
|
|
|
|
map.heightMapSize+= sizeof(uint16_V9) + sizeof(uint16_V8);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
map.heightMapSize+= sizeof(V9) + sizeof(V8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//============================================
|
|
|
|
|
// Pack liquid data
|
|
|
|
|
//============================================
|
2012-05-30 08:01:02 +02:00
|
|
|
uint8 type = liquid_flags[0][0];
|
2009-03-09 18:06:19 -06:00
|
|
|
bool fullType = false;
|
2012-05-30 08:01:02 +02:00
|
|
|
for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2012-05-30 08:01:02 +02:00
|
|
|
for (int x = 0; x < ADT_CELLS_PER_GRID; x++)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2012-05-30 08:01:02 +02:00
|
|
|
if (liquid_flags[y][x] != type)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
|
|
|
|
fullType = true;
|
|
|
|
|
y = ADT_CELLS_PER_GRID;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map_liquidHeader liquidHeader;
|
|
|
|
|
|
|
|
|
|
// no water data (if all grid have 0 liquid type)
|
|
|
|
|
if (type == 0 && !fullType)
|
|
|
|
|
{
|
|
|
|
|
// No liquid data
|
|
|
|
|
map.liquidMapOffset = 0;
|
|
|
|
|
map.liquidMapSize = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int minX = 255, minY = 255;
|
|
|
|
|
int maxX = 0, maxY = 0;
|
|
|
|
|
maxHeight = -20000;
|
|
|
|
|
minHeight = 20000;
|
|
|
|
|
for (int y=0; y<ADT_GRID_SIZE; y++)
|
|
|
|
|
{
|
|
|
|
|
for(int x=0; x<ADT_GRID_SIZE; x++)
|
|
|
|
|
{
|
|
|
|
|
if (liquid_show[y][x])
|
|
|
|
|
{
|
|
|
|
|
if (minX > x) minX = x;
|
|
|
|
|
if (maxX < x) maxX = x;
|
|
|
|
|
if (minY > y) minY = y;
|
|
|
|
|
if (maxY < y) maxY = y;
|
|
|
|
|
float h = liquid_height[y][x];
|
|
|
|
|
if (maxHeight < h) maxHeight = h;
|
|
|
|
|
if (minHeight > h) minHeight = h;
|
|
|
|
|
}
|
2009-03-10 15:33:54 -06:00
|
|
|
else
|
|
|
|
|
liquid_height[y][x] = CONF_use_minHeight;
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
map.liquidMapOffset = map.heightMapOffset + map.heightMapSize;
|
|
|
|
|
map.liquidMapSize = sizeof(map_liquidHeader);
|
2015-11-24 02:08:52 +01:00
|
|
|
liquidHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_LIQUID_MAGIC);
|
2009-03-09 18:06:19 -06:00
|
|
|
liquidHeader.flags = 0;
|
|
|
|
|
liquidHeader.liquidType = 0;
|
|
|
|
|
liquidHeader.offsetX = minX;
|
|
|
|
|
liquidHeader.offsetY = minY;
|
2012-05-30 08:01:02 +02:00
|
|
|
liquidHeader.width = maxX - minX + 1 + 1;
|
|
|
|
|
liquidHeader.height = maxY - minY + 1 + 1;
|
2009-03-09 18:06:19 -06:00
|
|
|
liquidHeader.liquidLevel = minHeight;
|
|
|
|
|
|
|
|
|
|
if (maxHeight == minHeight)
|
2009-07-31 11:25:28 +08:00
|
|
|
liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
// Not need store if flat surface
|
|
|
|
|
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_liquid_delta_limit)
|
2009-07-31 11:25:28 +08:00
|
|
|
liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
if (!fullType)
|
2009-07-31 11:25:28 +08:00
|
|
|
liquidHeader.flags |= MAP_LIQUID_NO_TYPE;
|
2009-03-09 18:06:19 -06:00
|
|
|
|
2009-07-31 11:25:28 +08:00
|
|
|
if (liquidHeader.flags & MAP_LIQUID_NO_TYPE)
|
2009-03-09 18:06:19 -06:00
|
|
|
liquidHeader.liquidType = type;
|
|
|
|
|
else
|
2012-05-30 08:01:02 +02:00
|
|
|
map.liquidMapSize += sizeof(liquid_entry) + sizeof(liquid_flags);
|
2010-08-08 19:45:53 +02:00
|
|
|
|
2009-07-31 11:25:28 +08:00
|
|
|
if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
|
|
|
|
|
map.liquidMapSize += sizeof(float)*liquidHeader.width*liquidHeader.height;
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
|
2012-04-09 15:52:00 +02:00
|
|
|
if (map.liquidMapOffset)
|
|
|
|
|
map.holesOffset = map.liquidMapOffset + map.liquidMapSize;
|
|
|
|
|
else
|
|
|
|
|
map.holesOffset = map.heightMapOffset + map.heightMapSize;
|
|
|
|
|
|
2012-08-22 18:00:58 -05:00
|
|
|
if (hasHoles)
|
|
|
|
|
map.holesSize = sizeof(holes);
|
|
|
|
|
else
|
|
|
|
|
map.holesSize = 0;
|
2012-04-09 15:52:00 +02:00
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
// Ok all data prepared - store it
|
2015-11-24 02:08:52 +01:00
|
|
|
std::ofstream outFile(outputPath, std::ofstream::out | std::ofstream::binary);
|
|
|
|
|
if (!outFile)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
printf("Can't create the output file '%s'\n", outputPath.c_str());
|
2009-03-09 18:06:19 -06:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-24 02:08:52 +01:00
|
|
|
|
|
|
|
|
outFile.write(reinterpret_cast<const char*>(&map), sizeof(map));
|
2009-03-09 18:06:19 -06:00
|
|
|
// Store area data
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(&areaHeader), sizeof(areaHeader));
|
2016-02-02 19:13:04 +01:00
|
|
|
if (!(areaHeader.flags & MAP_AREA_NO_AREA))
|
|
|
|
|
outFile.write(reinterpret_cast<const char*>(area_ids), sizeof(area_ids));
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
// Store height data
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(&heightHeader), sizeof(heightHeader));
|
2009-07-31 11:25:28 +08:00
|
|
|
if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2009-07-31 11:25:28 +08:00
|
|
|
if (heightHeader.flags & MAP_HEIGHT_AS_INT16)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(uint16_V9), sizeof(uint16_V9));
|
|
|
|
|
outFile.write(reinterpret_cast<const char*>(uint16_V8), sizeof(uint16_V8));
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
2009-07-31 11:25:28 +08:00
|
|
|
else if (heightHeader.flags & MAP_HEIGHT_AS_INT8)
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(uint8_V9), sizeof(uint8_V9));
|
|
|
|
|
outFile.write(reinterpret_cast<const char*>(uint8_V8), sizeof(uint8_V8));
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(V9), sizeof(V9));
|
|
|
|
|
outFile.write(reinterpret_cast<const char*>(V8), sizeof(V8));
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-09 00:14:58 +01:00
|
|
|
if (heightHeader.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
|
|
|
|
|
{
|
|
|
|
|
outFile.write(reinterpret_cast<char*>(flight_box_max), sizeof(flight_box_max));
|
|
|
|
|
outFile.write(reinterpret_cast<char*>(flight_box_min), sizeof(flight_box_min));
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
// Store liquid data if need
|
|
|
|
|
if (map.liquidMapOffset)
|
|
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(&liquidHeader), sizeof(liquidHeader));
|
2012-05-30 08:01:02 +02:00
|
|
|
if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
|
|
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(liquid_entry), sizeof(liquid_entry));
|
|
|
|
|
outFile.write(reinterpret_cast<const char*>(liquid_flags), sizeof(liquid_flags));
|
2012-05-30 08:01:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
|
2009-03-09 18:06:19 -06:00
|
|
|
{
|
2012-05-30 08:01:02 +02:00
|
|
|
for (int y = 0; y < liquidHeader.height; y++)
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width);
|
2009-03-09 18:06:19 -06:00
|
|
|
}
|
|
|
|
|
}
|
2012-08-22 18:00:58 -05:00
|
|
|
|
2012-04-09 15:52:00 +02:00
|
|
|
// store hole data
|
2012-08-22 18:00:58 -05:00
|
|
|
if (hasHoles)
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.write(reinterpret_cast<const char*>(holes), map.holesSize);
|
2012-04-09 15:52:00 +02:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
outFile.close();
|
2009-03-09 18:06:19 -06:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-19 14:02:08 +02:00
|
|
|
void ExtractWmos(ChunkedFile& file, std::set<std::string>& wmoList)
|
|
|
|
|
{
|
|
|
|
|
if (FileChunk* chunk = file.GetChunk("MWMO"))
|
|
|
|
|
{
|
|
|
|
|
file_MWMO* wmo = chunk->As<file_MWMO>();
|
|
|
|
|
if (wmo->size)
|
|
|
|
|
{
|
|
|
|
|
char* fileName = wmo->FileList;
|
|
|
|
|
while (fileName < wmo->FileList + wmo->size)
|
|
|
|
|
{
|
|
|
|
|
wmoList.insert(fileName);
|
|
|
|
|
fileName += strlen(fileName) + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
void ExtractMaps(uint32 build)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
std::string storagePath;
|
|
|
|
|
std::string outputFileName;
|
2008-10-02 16:23:55 -05:00
|
|
|
|
|
|
|
|
printf("Extracting maps...\n");
|
|
|
|
|
|
|
|
|
|
uint32 map_count = ReadMapDBC();
|
|
|
|
|
|
2008-12-24 09:58:26 -06:00
|
|
|
ReadLiquidTypeTableDBC();
|
2008-10-02 16:23:55 -05:00
|
|
|
|
|
|
|
|
std::string path = output_path;
|
|
|
|
|
path += "/maps/";
|
|
|
|
|
CreateDir(path);
|
|
|
|
|
|
2014-10-19 14:02:08 +02:00
|
|
|
std::set<std::string> wmoList;
|
|
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
printf("Convert map files\n");
|
2012-02-20 19:12:05 +01:00
|
|
|
for (uint32 z = 0; z < map_count; ++z)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2012-08-30 19:07:59 +01:00
|
|
|
printf("Extract %s (%d/%u) \n", map_ids[z].name, z+1, map_count);
|
2009-03-09 18:06:19 -06:00
|
|
|
// Loadup map grid data
|
2015-11-24 02:08:52 +01:00
|
|
|
storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
|
2014-10-10 20:17:30 +02:00
|
|
|
ChunkedFile wdt;
|
|
|
|
|
if (!wdt.loadFile(CascStorage, storagePath, false))
|
2009-03-09 18:06:19 -06:00
|
|
|
continue;
|
|
|
|
|
|
2014-10-19 14:02:08 +02:00
|
|
|
ExtractWmos(wdt, wmoList);
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
FileChunk* chunk = wdt.GetChunk("MAIN");
|
2012-02-20 19:12:05 +01:00
|
|
|
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2012-02-20 19:12:05 +01:00
|
|
|
for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
if (!(chunk->As<wdt_MAIN>()->adt_list[y][x].flag & 0x1))
|
2009-03-09 18:06:19 -06:00
|
|
|
continue;
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
|
|
|
|
|
outputFileName = Trinity::StringFormat("%s/maps/%04u_%02u_%02u.map", output_path, map_ids[z].id, y, x);
|
|
|
|
|
ConvertADT(storagePath, outputFileName, y, x, build);
|
2014-10-19 14:02:08 +02:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s_%u_%u_obj0.adt", map_ids[z].name, map_ids[z].name, x, y);
|
2014-10-19 14:02:08 +02:00
|
|
|
ChunkedFile adtObj;
|
|
|
|
|
if (adtObj.loadFile(CascStorage, storagePath, false))
|
|
|
|
|
ExtractWmos(adtObj, wmoList);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2008-12-24 09:58:26 -06:00
|
|
|
// draw progress bar
|
2009-03-09 18:06:19 -06:00
|
|
|
printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2014-10-19 14:02:08 +02:00
|
|
|
if (!wmoList.empty())
|
|
|
|
|
{
|
|
|
|
|
if (FILE* wmoListFile = fopen("wmo_list.txt", "w"))
|
|
|
|
|
{
|
|
|
|
|
for (std::string const& wmo : wmoList)
|
|
|
|
|
fprintf(wmoListFile, "%s\n", wmo.c_str());
|
|
|
|
|
|
|
|
|
|
fclose(wmoListFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-25 21:48:17 +02:00
|
|
|
printf("\n");
|
2014-10-10 20:17:30 +02:00
|
|
|
delete[] map_ids;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
bool ExtractFile(HANDLE fileInArchive, std::string filename)
|
2010-06-11 05:01:30 +02:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
FILE* output = fopen(filename.c_str(), "wb");
|
2015-08-31 00:03:53 +02:00
|
|
|
if (!output)
|
2010-06-11 05:01:30 +02:00
|
|
|
{
|
2015-11-24 02:08:52 +01:00
|
|
|
printf("Can't create the output file '%s'\n", filename.c_str());
|
2010-06-11 05:01:30 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
|
|
|
|
char buffer[0x10000];
|
|
|
|
|
DWORD readBytes = 1;
|
|
|
|
|
|
|
|
|
|
while (readBytes > 0)
|
|
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
CascReadFile(fileInArchive, buffer, sizeof(buffer), &readBytes);
|
2012-02-20 19:12:05 +01:00
|
|
|
if (readBytes > 0)
|
|
|
|
|
fwrite(buffer, 1, readBytes, output);
|
|
|
|
|
}
|
2010-06-11 05:01:30 +02:00
|
|
|
|
|
|
|
|
fclose(output);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
void ExtractDBFilesClient(int l)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
printf("Extracting dbc/db2 files...\n");
|
2013-11-08 10:29:51 +01:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
std::string outputPath = output_path;
|
|
|
|
|
outputPath += "/dbc/";
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
CreateDir(outputPath);
|
2015-08-31 00:03:53 +02:00
|
|
|
outputPath += localeNames[l];
|
2014-10-10 20:17:30 +02:00
|
|
|
outputPath += "/";
|
|
|
|
|
CreateDir(outputPath);
|
2012-02-21 21:29:19 +01:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
printf("locale %s output path %s\n", localeNames[l], outputPath.c_str());
|
|
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
uint32 index = 0;
|
2012-02-21 21:29:19 +01:00
|
|
|
uint32 count = 0;
|
2014-10-10 20:17:30 +02:00
|
|
|
char const* fileName = DBFilesClientList[index];
|
|
|
|
|
HANDLE dbcFile;
|
|
|
|
|
while (fileName)
|
2012-02-21 21:29:19 +01:00
|
|
|
{
|
2015-01-17 20:35:16 +01:00
|
|
|
std::string filename = fileName;
|
2015-08-31 00:03:53 +02:00
|
|
|
if (CascOpenFile(CascStorage, (filename = (filename + ".db2")).c_str(), WowLocaleToCascLocaleFlags[l], 0, &dbcFile) ||
|
|
|
|
|
CascOpenFile(CascStorage, (filename = (filename.substr(0, filename.length() - 4) + ".dbc")).c_str(), WowLocaleToCascLocaleFlags[l], 0, &dbcFile))
|
2012-02-21 21:29:19 +01:00
|
|
|
{
|
2014-05-14 19:49:59 +02:00
|
|
|
filename = outputPath + filename.substr(filename.rfind('\\') + 1);
|
2012-02-21 22:39:53 +01:00
|
|
|
|
2015-11-24 02:08:52 +01:00
|
|
|
if (!boost::filesystem::exists(filename))
|
|
|
|
|
if (ExtractFile(dbcFile, filename))
|
2014-10-10 20:17:30 +02:00
|
|
|
++count;
|
2012-02-21 21:29:19 +01:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
CascCloseFile(dbcFile);
|
2012-02-20 19:12:05 +01:00
|
|
|
}
|
|
|
|
|
else
|
2015-08-31 00:03:53 +02:00
|
|
|
printf("Unable to open file %s in the archive for locale %s: %s\n", fileName, localeNames[l], HumanReadableCASCError(GetLastError()));
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
fileName = DBFilesClientList[++index];
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
printf("Extracted %u files\n\n", count);
|
2008-11-06 08:20:26 -06:00
|
|
|
}
|
2008-12-24 15:49:38 -06:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
bool OpenCascStorage(int locale)
|
2008-11-06 08:20:26 -06:00
|
|
|
{
|
2015-02-08 16:56:43 +01:00
|
|
|
try
|
2012-02-20 19:12:05 +01:00
|
|
|
{
|
2015-02-08 16:56:43 +01:00
|
|
|
boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
|
2015-08-31 00:03:53 +02:00
|
|
|
if (!CascOpenStorage(storage_dir.string().c_str(), WowLocaleToCascLocaleFlags[locale], &CascStorage))
|
2015-02-08 16:56:43 +01:00
|
|
|
{
|
2015-08-31 00:03:53 +02:00
|
|
|
printf("error opening casc storage '%s' locale %s: %s\n", storage_dir.string().c_str(), localeNames[locale], HumanReadableCASCError(GetLastError()));
|
2015-02-08 16:56:43 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-08-31 00:03:53 +02:00
|
|
|
printf("opened casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]);
|
2015-02-08 16:56:43 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (boost::filesystem::filesystem_error& error)
|
|
|
|
|
{
|
|
|
|
|
printf("error opening casc storage : %s\n", error.what());
|
2014-10-10 20:17:30 +02:00
|
|
|
return false;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2008-11-06 08:20:26 -06:00
|
|
|
}
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
int main(int argc, char * arg[])
|
|
|
|
|
{
|
2016-07-17 17:24:53 +02:00
|
|
|
Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr);
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
boost::filesystem::path current(boost::filesystem::current_path());
|
|
|
|
|
strcpy(input_path, current.string().c_str());
|
|
|
|
|
strcpy(output_path, current.string().c_str());
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
HandleArgs(argc, arg);
|
|
|
|
|
|
2008-11-06 08:20:26 -06:00
|
|
|
int FirstLocale = -1;
|
2010-06-11 05:01:30 +02:00
|
|
|
uint32 build = 0;
|
2008-12-24 15:49:38 -06:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
for (int i = 0; i < TOTAL_LOCALES; ++i)
|
2008-11-06 08:20:26 -06:00
|
|
|
{
|
2014-10-10 20:17:30 +02:00
|
|
|
if (CONF_Locale && !(CONF_Locale & (1 << i)))
|
2012-02-21 21:12:00 +01:00
|
|
|
continue;
|
2008-12-24 15:49:38 -06:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
if (i == LOCALE_none)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!OpenCascStorage(i))
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-02-21 21:12:00 +01:00
|
|
|
if ((CONF_extract & EXTRACT_DBC) == 0)
|
|
|
|
|
{
|
|
|
|
|
FirstLocale = i;
|
|
|
|
|
build = ReadBuild(i);
|
2014-10-10 20:17:30 +02:00
|
|
|
if (!build)
|
2015-08-31 00:03:53 +02:00
|
|
|
{
|
|
|
|
|
CascCloseStorage(CascStorage);
|
2014-10-10 20:17:30 +02:00
|
|
|
continue;
|
2015-08-31 00:03:53 +02:00
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2014-10-10 20:17:30 +02:00
|
|
|
printf("Detected client build: %u\n\n", build);
|
2012-02-21 21:12:00 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2012-02-21 21:12:00 +01:00
|
|
|
//Extract DBC files
|
|
|
|
|
uint32 tempBuild = ReadBuild(i);
|
2014-10-10 20:17:30 +02:00
|
|
|
if (!tempBuild)
|
2015-08-31 00:03:53 +02:00
|
|
|
{
|
|
|
|
|
CascCloseStorage(CascStorage);
|
2012-02-21 21:12:00 +01:00
|
|
|
continue;
|
2015-08-31 00:03:53 +02:00
|
|
|
}
|
2012-02-20 19:12:05 +01:00
|
|
|
|
2015-08-31 00:03:53 +02:00
|
|
|
printf("Detected client build %u for locale %s\n\n", tempBuild, localeNames[i]);
|
2014-10-10 20:17:30 +02:00
|
|
|
ExtractDBFilesClient(i);
|
2015-08-31 00:03:53 +02:00
|
|
|
CascCloseStorage(CascStorage);
|
2008-12-12 11:21:28 -06:00
|
|
|
|
2012-02-21 21:12:00 +01:00
|
|
|
if (FirstLocale < 0)
|
|
|
|
|
{
|
|
|
|
|
FirstLocale = i;
|
|
|
|
|
build = tempBuild;
|
2008-11-06 08:20:26 -06:00
|
|
|
}
|
|
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
|
2012-02-20 19:12:05 +01:00
|
|
|
if (FirstLocale < 0)
|
2008-11-06 08:20:26 -06:00
|
|
|
{
|
|
|
|
|
printf("No locales detected\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-12-24 15:49:38 -06:00
|
|
|
|
2009-03-09 18:06:19 -06:00
|
|
|
if (CONF_extract & EXTRACT_MAP)
|
2008-11-06 08:20:26 -06:00
|
|
|
{
|
2015-11-19 03:11:47 +08:00
|
|
|
OpenCascStorage(FirstLocale);
|
2014-10-10 20:17:30 +02:00
|
|
|
ExtractMaps(build);
|
2015-08-31 00:03:53 +02:00
|
|
|
CascCloseStorage(CascStorage);
|
2008-11-06 08:20:26 -06:00
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|