Rebase resync

This commit is contained in:
Antz 2020-02-17 09:19:44 +00:00
parent a0797532e8
commit 1997c1e903
3106 changed files with 11118 additions and 627576 deletions

View file

@ -38,20 +38,24 @@
#include "loadlib/wdt.h"
#include <fcntl.h>
#ifndef WIN32
#include <unistd.h>
#endif
#if defined( __GNUC__ )
#define _open open
#define _close close
#ifndef O_BINARY
#define O_BINARY 0
#endif
#define _open open
#define _close close
#ifndef O_BINARY
#define O_BINARY 0
#endif
#else
#include <io.h>
#include <io.h>
#endif
#ifdef O_LARGEFILE
#define OPEN_FLAGS (O_RDONLY | O_BINARY | O_LARGEFILE)
#define OPEN_FLAGS (O_RDONLY | O_BINARY | O_LARGEFILE)
#else
#define OPEN_FLAGS (O_RDONLY | O_BINARY)
#define OPEN_FLAGS (O_RDONLY | O_BINARY)
#endif
typedef struct
@ -60,9 +64,9 @@ typedef struct
uint32 id;
} map_id;
map_id *map_ids;
uint16 *areas;
uint16 *LiqType;
map_id* map_ids;
uint16* areas;
uint16* LiqType;
char output_path[128] = ".";
char input_path[128] = ".";
uint32 maxAreaId = 0;
@ -98,19 +102,19 @@ static char* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "z
#define EXPANSION_COUNT 3
#define WORLD_COUNT 2
void CreateDir( const std::string& Path )
void CreateDir(const std::string& Path)
{
#ifdef WIN32
_mkdir( Path.c_str());
#else
mkdir( Path.c_str(), 0777 );
#endif
#ifdef WIN32
_mkdir(Path.c_str());
#else
mkdir(Path.c_str(), 0777);
#endif
}
bool FileExists( const char* FileName )
bool FileExists(const char* FileName)
{
int fp = _open(FileName, OPEN_FLAGS);
if(fp != -1)
if (fp != -1)
{
_close(fp);
return true;
@ -134,50 +138,50 @@ void Usage(char* prg)
exit(1);
}
void HandleArgs(int argc, char * arg[])
void HandleArgs(int argc, char* arg[])
{
for(int c = 1; c < argc; ++c)
for (int c = 1; c < argc; ++c)
{
// i - input path
// o - output path
// e - extract only MAP(1)/DBC(2) - standard both(3)
// f - use float to int conversion
// h - limit minimum height
if(arg[c][0] != '-')
if (arg[c][0] != '-')
Usage(arg[0]);
switch(arg[c][1])
switch (arg[c][1])
{
case 'i':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
strcpy(input_path, arg[(c++) + 1]);
else
Usage(arg[0]);
break;
case 'o':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
strcpy(output_path, arg[(c++) + 1]);
else
Usage(arg[0]);
break;
case 'f':
if(c + 1 < argc) // all ok
CONF_allow_float_to_int=atoi(arg[(c++) + 1])!=0;
if (c + 1 < argc) // all ok
CONF_allow_float_to_int = atoi(arg[(c++) + 1]) != 0;
else
Usage(arg[0]);
break;
case 'e':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
{
CONF_extract=atoi(arg[(c++) + 1]);
if(!(CONF_extract > 0 && CONF_extract < 4))
CONF_extract = atoi(arg[(c++) + 1]);
if (!(CONF_extract > 0 && CONF_extract < 4))
Usage(arg[0]);
}
else
Usage(arg[0]);
break;
case 'b':
if(c + 1 < argc) // all ok
if (c + 1 < argc) // all ok
{
CONF_max_build = atoi(arg[(c++) + 1]);
if (CONF_max_build < MIN_SUPPORTED_BUILD)
@ -228,7 +232,7 @@ void AppendDB2FileListTo(HANDLE mpqHandle, std::set<std::string>& filelist)
uint32 ReadBuild(int locale)
{
// include build info file also
std::string filename = std::string("component.wow-")+langs[locale]+".txt";
std::string filename = std::string("component.wow-") + langs[locale] + ".txt";
//printf("Read %s file... ", filename.c_str());
HANDLE fileHandle;
@ -254,14 +258,14 @@ uint32 ReadBuild(int locale)
size_t pos = text.find("version=\"");
size_t pos1 = pos + strlen("version=\"");
size_t pos2 = text.find("\"",pos1);
size_t pos2 = text.find("\"", pos1);
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);
std::string build_str = text.substr(pos1, pos2 - pos1);
int build = atoi(build_str.c_str());
if (build <= 0)
@ -297,7 +301,7 @@ uint32 ReadMapDBC(int const locale)
}
DBCFile dbc(dbcFile);
if(!dbc.open())
if (!dbc.open())
{
printf("Fatal error: Invalid Map.dbc file format!\n");
exit(1);
@ -305,7 +309,7 @@ uint32 ReadMapDBC(int const locale)
size_t map_count = dbc.getRecordCount();
map_ids = new map_id[map_count];
for(uint32 x = 0; x < map_count; ++x)
for (uint32 x = 0; x < map_count; ++x)
{
map_ids[x].id = dbc.getRecord(x).getUInt(0);
strcpy(map_ids[x].name, dbc.getRecord(x).getString(1));
@ -333,7 +337,7 @@ void ReadAreaTableDBC(int const locale)
DBCFile dbc(dbcFile);
if(!dbc.open())
if (!dbc.open())
{
printf("Fatal error: Invalid AreaTable.dbc file format!\n");
exit(1);
@ -344,7 +348,7 @@ void ReadAreaTableDBC(int const locale)
areas = new uint16[maxid + 1];
memset(areas, 0xff, (maxid + 1) * sizeof(uint16));
for(uint32 x = 0; x < area_count; ++x)
for (uint32 x = 0; x < area_count; ++x)
areas[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
maxAreaId = dbc.getMaxId();
@ -370,7 +374,7 @@ void ReadLiquidTypeTableDBC(int const locale)
}
DBCFile dbc(dbcFile);
if(!dbc.open())
if (!dbc.open())
{
printf("Fatal error: Invalid LiquidType.dbc file format!\n");
exit(1);
@ -381,7 +385,7 @@ void ReadLiquidTypeTableDBC(int const locale)
LiqType = new uint16[LiqType_maxid + 1];
memset(LiqType, 0xff, (LiqType_maxid + 1) * sizeof(uint16));
for(uint32 x = 0; x < LiqType_count; ++x)
for (uint32 x = 0; x < LiqType_count; ++x)
LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
printf("Done! (%lu LiqTypes loaded)\n", LiqType_count);
@ -393,7 +397,7 @@ void ReadLiquidTypeTableDBC(int const locale)
// Map file format data
static char const* MAP_MAGIC = "MAPS";
static char const* MAP_VERSION_MAGIC = "v1.2";
static char const* MAP_VERSION_MAGIC = "c1.3";
static char const* MAP_AREA_MAGIC = "AREA";
static char const* MAP_HEIGHT_MAGIC = "MHGT";
static char const* MAP_LIQUID_MAGIC = "MLIQ";
@ -443,7 +447,6 @@ struct map_heightHeader
#define MAP_LIQUID_TYPE_DARK_WATER 0x10
#define MAP_LIQUID_TYPE_WMO_WATER 0x20
#define MAP_LIQUID_NO_TYPE 0x0001
#define MAP_LIQUID_NO_HEIGHT 0x0002
@ -472,17 +475,18 @@ float selectUInt16StepStore(float maxDiff)
uint16 area_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
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];
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];
uint8 uint8_V9[ADT_GRID_SIZE + 1][ADT_GRID_SIZE + 1];
uint8 liquid_type[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE];
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
float liquid_height[ADT_GRID_SIZE + 1][ADT_GRID_SIZE + 1];
bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32 build)
bool ConvertADT(char* filename, char* filename2, int cell_y, int cell_x, uint32 build)
{
ADT_file adt;
@ -490,7 +494,8 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
return false;
memset(liquid_show, 0, sizeof(liquid_show));
memset(liquid_type, 0, sizeof(liquid_type));
memset(liquid_flags, 0, sizeof(liquid_flags));
memset(liquid_entry, 0, sizeof(liquid_entry));
// Prepare map header
map_fileheader map;
@ -499,15 +504,15 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
map.buildMagic = build;
// Get area flags data
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_MCNK * cell = adt.cells[i][j];
adt_MCNK* cell = adt.cells[i][j];
uint32 areaid = cell->areaid;
if(areaid && areaid <= maxAreaId)
if (areaid && areaid <= maxAreaId)
{
if(areas[areaid] != 0xffff)
if (areas[areaid] != 0xffff)
{
area_flags[i][j] = areas[areaid];
continue;
@ -522,11 +527,11 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
//============================================
bool fullAreaData = false;
uint32 areaflag = area_flags[0][0];
for (int y=0;y<ADT_CELLS_PER_GRID;y++)
for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
{
for(int x=0;x<ADT_CELLS_PER_GRID;x++)
for (int x = 0; x < ADT_CELLS_PER_GRID; x++)
{
if(area_flags[y][x]!=areaflag)
if (area_flags[y][x] != areaflag)
{
fullAreaData = true;
break;
@ -543,7 +548,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
if (fullAreaData)
{
areaHeader.gridArea = 0;
map.areaMapSize+=sizeof(area_flags);
map.areaMapSize += sizeof(area_flags);
}
else
{
@ -554,11 +559,11 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
//
// Get Height map from grid
//
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_MCNK * cell = adt.cells[i][j];
adt_MCNK* cell = adt.cells[i][j];
if (!cell)
continue;
// Height values for triangles stored in order:
@ -578,46 +583,46 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
// . . . . . . . .
// Set map height as grid height
for (int y=0; y <= ADT_CELL_SIZE; y++)
for (int y = 0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x <= ADT_CELL_SIZE; x++)
int cy = i * ADT_CELL_SIZE + y;
for (int x = 0; x <= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V9[cy][cx]=cell->ypos;
int cx = j * ADT_CELL_SIZE + x;
V9[cy][cx] = cell->ypos;
}
}
for (int y=0; y < ADT_CELL_SIZE; y++)
for (int y = 0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
int cy = i * ADT_CELL_SIZE + y;
for (int x = 0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V8[cy][cx]=cell->ypos;
int cx = j * ADT_CELL_SIZE + x;
V8[cy][cx] = cell->ypos;
}
}
// Get custom height
adt_MCVT *v = cell->getMCVT();
adt_MCVT* v = cell->getMCVT();
if (!v)
continue;
// get V9 height map
for (int y=0; y <= ADT_CELL_SIZE; y++)
for (int y = 0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x <= ADT_CELL_SIZE; x++)
int cy = i * ADT_CELL_SIZE + y;
for (int x = 0; x <= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V9[cy][cx]+=v->height_map[y*(ADT_CELL_SIZE*2+1)+x];
int cx = j * ADT_CELL_SIZE + x;
V9[cy][cx] += v->height_map[y * (ADT_CELL_SIZE * 2 + 1) + x];
}
}
// get V8 height map
for (int y=0; y < ADT_CELL_SIZE; y++)
for (int y = 0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
int cy = i * ADT_CELL_SIZE + y;
for (int x = 0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V8[cy][cx]+=v->height_map[y*(ADT_CELL_SIZE*2+1)+ADT_CELL_SIZE+1+x];
int cx = j * ADT_CELL_SIZE + x;
V8[cy][cx] += v->height_map[y * (ADT_CELL_SIZE * 2 + 1) + ADT_CELL_SIZE + 1 + x];
}
}
}
@ -627,18 +632,18 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
//============================================
float maxHeight = -20000;
float minHeight = 20000;
for (int y=0; y<ADT_GRID_SIZE; y++)
for (int y = 0; y < ADT_GRID_SIZE; y++)
{
for(int x=0;x<ADT_GRID_SIZE;x++)
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 y = 0; y <= ADT_GRID_SIZE; y++)
{
for(int x=0;x<=ADT_GRID_SIZE;x++)
for (int x = 0; x <= ADT_GRID_SIZE; x++)
{
float h = V9[y][x];
if (maxHeight < h) maxHeight = h;
@ -649,12 +654,12 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
// 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++)
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++)
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)
@ -689,100 +694,162 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
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;
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)
else if (diff < CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536)
{
heightHeader.flags|=MAP_HEIGHT_AS_INT16;
heightHeader.flags |= MAP_HEIGHT_AS_INT16;
step = selectUInt16StepStore(diff);
}
}
// Pack it to int values if need
if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
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++)
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++)
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);
map.heightMapSize += sizeof(uint8_V9) + sizeof(uint8_V8);
}
else if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
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++)
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++)
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);
map.heightMapSize += sizeof(uint16_V9) + sizeof(uint16_V8);
}
else
map.heightMapSize+= sizeof(V9) + sizeof(V8);
map.heightMapSize += sizeof(V9) + sizeof(V8);
}
// Get from MCLQ chunk (old)
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
{
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_MCNK* cell = adt.cells[i][j];
if (!cell)
continue;
adt_MCLQ* liquid = cell->getMCLQ();
int count = 0;
if (!liquid || cell->sizeMCLQ <= 8)
continue;
for (int y = 0; y < ADT_CELL_SIZE; y++)
{
int cy = i * ADT_CELL_SIZE + y;
for (int x = 0; x < ADT_CELL_SIZE; x++)
{
int cx = j * ADT_CELL_SIZE + x;
if (liquid->flags[y][x] != 0x0F)
{
liquid_show[cy][cx] = true;
if (liquid->flags[y][x] & (1 << 7))
liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER;
++count;
}
}
}
uint32 c_flag = cell->flags;
if (c_flag & (1 << 2))
{
liquid_entry[i][j] = 1;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; // water
}
if (c_flag & (1 << 3))
{
liquid_entry[i][j] = 2;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; // ocean
}
if (c_flag & (1 << 4))
{
liquid_entry[i][j] = 3;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; // magma/slime
}
if (!count && liquid_flags[i][j])
fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
for (int y = 0; y <= ADT_CELL_SIZE; y++)
{
int cy = i * ADT_CELL_SIZE + y;
for (int x = 0; x <= ADT_CELL_SIZE; x++)
{
int cx = j * ADT_CELL_SIZE + x;
liquid_height[cy][cx] = liquid->liquid[y][x].height;
}
}
}
}
// Get liquid map for grid (in WOTLK used MH2O chunk)
adt_MH2O * h2o = adt.a_grid->getMH2O();
adt_MH2O* h2o = adt.a_grid->getMH2O();
if (h2o)
{
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_liquid_header *h = h2o->getLiquidData(i,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++)
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 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;
int cx = j * ADT_CELL_SIZE + x + h->xOffset;
if (show & 1)
{
liquid_show[cy][cx] = true;
++count;
}
show>>=1;
show >>= 1;
}
}
uint32 type = LiqType[h->liquidType];
switch (type)
liquid_entry[i][j] = h->liquidType;
switch (LiqType[h->liquidType])
{
case LIQUID_TYPE_WATER: liquid_type[i][j] |= MAP_LIQUID_TYPE_WATER; break;
case LIQUID_TYPE_OCEAN: liquid_type[i][j] |= MAP_LIQUID_TYPE_OCEAN; break;
case LIQUID_TYPE_MAGMA: liquid_type[i][j] |= MAP_LIQUID_TYPE_MAGMA; break;
case LIQUID_TYPE_SLIME: liquid_type[i][j] |= MAP_LIQUID_TYPE_SLIME; break;
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:
printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->liquidType, filename, i, j);
break;
}
// Dark water detect
if (type == LIQUID_TYPE_OCEAN)
if (LiqType[h->liquidType] == LIQUID_TYPE_OCEAN)
{
uint8 *lm = h2o->getLiquidLightMap(h);
uint8* lm = h2o->getLiquidLightMap(h);
if (!lm)
liquid_type[i][j]|=MAP_LIQUID_TYPE_DARK_WATER;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER;
}
if (!count && liquid_type[i][j])
if (!count && liquid_flags[i][j])
printf("Wrong liquid detect in MH2O chunk");
float *height = h2o->getLiquidHeightMap(h);
float* height = h2o->getLiquidHeightMap(h);
int pos = 0;
for (int y=0; y<=h->height;y++)
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 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;
int cx = j * ADT_CELL_SIZE + x + h->xOffset;
if (height)
liquid_height[cy][cx] = height[pos];
else
@ -793,72 +860,16 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
}
}
}
else
{
// Get from MCLQ chunk (old)
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
{
adt_MCNK *cell = adt.cells[i][j];
if (!cell)
continue;
adt_MCLQ *liquid = cell->getMCLQ();
int count = 0;
if (!liquid || cell->sizeMCLQ <= 8)
continue;
for (int y=0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
if (liquid->flags[y][x] != 0x0F)
{
liquid_show[cy][cx] = true;
if (liquid->flags[y][x]&(1<<7))
liquid_type[i][j]|=MAP_LIQUID_TYPE_DARK_WATER;
++count;
}
}
}
uint32 c_flag = cell->flags;
if(c_flag & (1<<2))
liquid_type[i][j]|=MAP_LIQUID_TYPE_WATER; // water
if(c_flag & (1<<3))
liquid_type[i][j]|=MAP_LIQUID_TYPE_OCEAN; // ochean
if(c_flag & (1<<4))
liquid_type[i][j]|=MAP_LIQUID_TYPE_MAGMA; // magma/slime
if (!count && liquid_type[i][j])
printf("Wrong liquid detect in MCLQ chunk");
for (int y=0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x<= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
liquid_height[cy][cx] = liquid->liquid[y][x].height;
}
}
}
}
}
//============================================
// Pack liquid data
//============================================
uint8 type = liquid_type[0][0];
uint8 type = liquid_flags[0][0];
bool fullType = false;
for (int y=0;y<ADT_CELLS_PER_GRID;y++)
for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
{
for(int x=0;x<ADT_CELLS_PER_GRID;x++)
for (int x = 0; x < ADT_CELLS_PER_GRID; x++)
{
if (liquid_type[y][x]!=type)
if (liquid_flags[y][x] != type)
{
fullType = true;
y = ADT_CELLS_PER_GRID;
@ -882,9 +893,9 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
int maxX = 0, maxY = 0;
maxHeight = -20000;
minHeight = 20000;
for (int y=0; y<ADT_GRID_SIZE; y++)
for (int y = 0; y < ADT_GRID_SIZE; y++)
{
for(int x=0; x<ADT_GRID_SIZE; x++)
for (int x = 0; x < ADT_GRID_SIZE; x++)
{
if (liquid_show[y][x])
{
@ -924,16 +935,16 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
if (liquidHeader.flags & MAP_LIQUID_NO_TYPE)
liquidHeader.liquidType = type;
else
map.liquidMapSize+=sizeof(liquid_type);
map.liquidMapSize += sizeof(liquid_entry) + sizeof(liquid_flags);
if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
map.liquidMapSize += sizeof(float)*liquidHeader.width*liquidHeader.height;
map.liquidMapSize += sizeof(float) * liquidHeader.width * liquidHeader.height;
}
// map hole info
uint16 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
if(map.liquidMapOffset)
if (map.liquidMapOffset)
map.holesOffset = map.liquidMapOffset + map.liquidMapSize;
else
map.holesOffset = map.heightMapOffset + map.heightMapSize;
@ -941,20 +952,20 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
map.holesSize = sizeof(holes);
memset(holes, 0, map.holesSize);
for(int i = 0; i < ADT_CELLS_PER_GRID; ++i)
for (int i = 0; i < ADT_CELLS_PER_GRID; ++i)
{
for(int j = 0; j < ADT_CELLS_PER_GRID; ++j)
for (int j = 0; j < ADT_CELLS_PER_GRID; ++j)
{
adt_MCNK * cell = adt.cells[i][j];
if(!cell)
adt_MCNK* cell = adt.cells[i][j];
if (!cell)
continue;
holes[i][j] = cell->holes;
}
}
// Ok all data prepared - store it
FILE *output=fopen(filename2, "wb");
if(!output)
FILE* output = fopen(filename2, "wb");
if (!output)
{
printf("Can't create the output file '%s'\n", filename2);
return false;
@ -962,7 +973,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
fwrite(&map, sizeof(map), 1, output);
// Store area data
fwrite(&areaHeader, sizeof(areaHeader), 1, output);
if (!(areaHeader.flags&MAP_AREA_NO_AREA))
if (!(areaHeader.flags & MAP_AREA_NO_AREA))
fwrite(area_flags, sizeof(area_flags), 1, output);
// Store height data
@ -990,12 +1001,15 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32
if (map.liquidMapOffset)
{
fwrite(&liquidHeader, sizeof(liquidHeader), 1, output);
if (!(liquidHeader.flags&MAP_LIQUID_NO_TYPE))
fwrite(liquid_type, sizeof(liquid_type), 1, output);
if (!(liquidHeader.flags&MAP_LIQUID_NO_HEIGHT))
if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
{
for (int y=0; y<liquidHeader.height;y++)
fwrite(&liquid_height[y+liquidHeader.offsetY][liquidHeader.offsetX], sizeof(float), liquidHeader.width, output);
fwrite(liquid_entry, sizeof(liquid_entry), 1, output);
fwrite(liquid_flags, sizeof(liquid_flags), 1, output);
}
if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
{
for (int y = 0; y < liquidHeader.height; y++)
fwrite(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX], sizeof(float), liquidHeader.width, output);
}
}
@ -1025,18 +1039,18 @@ void ExtractMapsFromMpq(uint32 build, const int locale)
CreateDir(path);
printf("Convert map files\n");
for(uint32 z = 0; z < map_count; ++z)
for (uint32 z = 0; z < map_count; ++z)
{
printf("Extract %s (%d/%d) \n", map_ids[z].name, z+1, map_count);
printf("Extract %s (%d/%d) \n", map_ids[z].name, z + 1, map_count);
// Loadup map grid data
sprintf(mpq_map_name, "World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
WDT_file wdt;
if (!wdt.loadFile(mpq_map_name, false))
continue;
for(uint32 y = 0; y < WDT_MAP_SIZE; ++y)
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
{
for(uint32 x = 0; x < WDT_MAP_SIZE; ++x)
for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
{
if (!wdt.main->adt_list[y][x].exist)
continue;
@ -1046,7 +1060,7 @@ void ExtractMapsFromMpq(uint32 build, const int locale)
ConvertADT(mpq_filename, output_filename, y, x, build);
}
// draw progress bar
printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
printf("Processing........................%d%%\r", (100 * (y + 1)) / WDT_MAP_SIZE);
}
}
delete [] areas;
@ -1061,7 +1075,7 @@ void ExtractDBCFiles(int locale, bool basicLocale)
// get DBC file list
ArchiveSetBounds archives = GetArchivesBounds();
for(ArchiveSet::const_iterator i = archives.first; i != archives.second;++i)
for (ArchiveSet::const_iterator i = archives.first; i != archives.second; ++i)
{
AppendDBCFileListTo(*i, dbcfiles);
AppendDB2FileListTo(*i, dbcfiles);
@ -1098,30 +1112,30 @@ void ExtractDBCFiles(int locale, bool basicLocale)
printf("Extracted %u DBC/DB2 files\n\n", count);
}
typedef std::pair<std::string /*full_filename*/, char const* /*locale_prefix*/> UpdatesPair;
typedef std::map<int /*build*/, UpdatesPair> Updates;
typedef std::pair < std::string /*full_filename*/, char const* /*locale_prefix*/ > UpdatesPair;
typedef std::map < int /*build*/, UpdatesPair > Updates;
void AppendPatchMPQFilesToList(char const* subdir, char const* suffix, char const* section, Updates& updates)
{
char dirname[512];
if (subdir)
sprintf(dirname,"%s/Data/%s", input_path, subdir);
sprintf(dirname, "%s/Data/%s", input_path, subdir);
else
sprintf(dirname,"%s/Data", input_path);
sprintf(dirname, "%s/Data", input_path);
char scanname[512];
if (suffix)
sprintf(scanname,"wow-update-%s-%%u.MPQ", suffix);
sprintf(scanname, "wow-update-%s-%%u.MPQ", suffix);
else
sprintf(scanname,"wow-update-%%u.MPQ");
sprintf(scanname, "wow-update-%%u.MPQ");
#ifdef WIN32
char maskname[512];
if (suffix)
sprintf(maskname,"%s/wow-update-%s-*.MPQ", dirname, suffix);
sprintf(maskname, "%s/wow-update-%s-*.MPQ", dirname, suffix);
else
sprintf(maskname,"%s/wow-update-*.MPQ", dirname);
sprintf(maskname, "%s/wow-update-*.MPQ", dirname);
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(maskname, &ffd);
@ -1144,10 +1158,10 @@ void AppendPatchMPQFilesToList(char const* subdir, char const* suffix, char cons
#else
if (DIR *dp = opendir(dirname))
if (DIR* dp = opendir(dirname))
{
int ubuild = 0;
dirent *dirp;
dirent* dirp;
while ((dirp = readdir(dp)) != NULL)
if (sscanf(dirp->d_name, scanname, &ubuild) == 1 && (!CONF_max_build || ubuild <= CONF_max_build))
updates[ubuild] = UpdatesPair(dirp->d_name, section);
@ -1163,7 +1177,7 @@ void LoadLocaleMPQFiles(int const locale)
char filename[512];
// first base old version of dbc files
sprintf(filename,"%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]);
sprintf(filename, "%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]);
HANDLE localeMpqHandle;
@ -1183,9 +1197,9 @@ void LoadLocaleMPQFiles(int const locale)
for (Updates::const_iterator itr = updates.begin(); itr != updates.end(); ++itr)
{
if (!itr->second.second)
sprintf(filename,"%s/Data/%s/%s", input_path, langs[locale], itr->second.first.c_str());
sprintf(filename, "%s/Data/%s/%s", input_path, langs[locale], itr->second.first.c_str());
else
sprintf(filename,"%s/Data/%s", input_path, itr->second.first.c_str());
sprintf(filename, "%s/Data/%s", input_path, itr->second.first.c_str());
//if (!OpenArchive(filename))
if (!SFileOpenPatchArchive(localeMpqHandle, filename, itr->second.second ? itr->second.second : "", 0))
@ -1232,7 +1246,7 @@ void LoadBaseMPQFiles()
for (Updates::const_iterator itr = updates.begin(); itr != updates.end(); ++itr)
{
sprintf(filename,"%s/Data/%s", input_path, itr->second.first.c_str());
sprintf(filename, "%s/Data/%s", input_path, itr->second.first.c_str());
printf("%s\n", filename);
@ -1244,7 +1258,7 @@ void LoadBaseMPQFiles()
}
}
int main(int argc, char * arg[])
int main(int argc, char* arg[])
{
printf("Map & DBC Extractor\n");
printf("===================\n\n");
@ -1265,7 +1279,7 @@ int main(int argc, char * arg[])
//Open MPQs
LoadLocaleMPQFiles(i);
if((CONF_extract & EXTRACT_DBC) == 0)
if ((CONF_extract & EXTRACT_DBC) == 0)
{
FirstLocale = i;
build = ReadBuild(FirstLocale);
@ -1274,7 +1288,7 @@ int main(int argc, char * arg[])
}
//Extract DBC files
if(FirstLocale < 0)
if (FirstLocale < 0)
{
FirstLocale = i;
build = ReadBuild(FirstLocale);
@ -1289,7 +1303,7 @@ int main(int argc, char * arg[])
}
}
if(FirstLocale < 0)
if (FirstLocale < 0)
{
printf("No locales detected\n");
return 0;