refactor(Tools): restyle tools with astyle (#3465)

This commit is contained in:
Kargatum
2020-10-06 16:31:28 +07:00
committed by GitHub
parent be09e03756
commit b00a86f6ab
51 changed files with 1004 additions and 936 deletions

View File

@@ -29,19 +29,19 @@
#include <fcntl.h>
#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
extern ArchiveSet gOpenArchives;
@@ -51,8 +51,8 @@ typedef struct
uint32 id;
} map_id;
map_id *map_ids;
uint16 *LiqType;
map_id* map_ids;
uint16* LiqType;
#define MAX_PATH_LENGTH 128
char output_path[MAX_PATH_LENGTH] = ".";
char input_path[MAX_PATH_LENGTH] = ".";
@@ -80,7 +80,8 @@ float CONF_flat_height_delta_limit = 0.005f; // If max - min less this value - s
float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - liquid surface is flat
// List MPQ for extract from
const char *CONF_mpq_list[]={
const char* CONF_mpq_list[] =
{
"common.MPQ",
"common-2.MPQ",
"lichking.MPQ",
@@ -108,11 +109,11 @@ void CreateDir( const std::string& Path )
}
int ret;
#ifdef _WIN32
#ifdef _WIN32
ret = _mkdir( Path.c_str());
#else
#else
ret = mkdir( Path.c_str(), 0777 );
#endif
#endif
if (ret != 0)
{
printf("Fatal Error: Could not create directory %s check your permissions", Path.c_str());
@@ -145,7 +146,7 @@ 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)
{
@@ -173,14 +174,14 @@ void HandleArgs(int argc, char * arg[])
break;
case 'f':
if(c + 1 < argc) // all ok
CONF_allow_float_to_int=atoi(arg[(c++) + 1])!=0;
CONF_allow_float_to_int = atoi(arg[(c++) + 1]) != 0;
else
Usage(arg[0]);
break;
case 'e':
if(c + 1 < argc) // all ok
{
CONF_extract=atoi(arg[(c++) + 1]);
CONF_extract = atoi(arg[(c++) + 1]);
if(!(CONF_extract > 0 && CONF_extract < 4))
Usage(arg[0]);
}
@@ -194,7 +195,7 @@ void HandleArgs(int argc, char * arg[])
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());
MPQFile m(filename.c_str());
@@ -209,14 +210,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)
@@ -357,16 +358,16 @@ float selectUInt16StepStore(float maxDiff)
uint16 area_ids[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];
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];
int16 flight_box_max[3][3];
int16 flight_box_min[3][3];
@@ -378,7 +379,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
if (!adt.loadFile(inputPath))
return false;
adt_MCIN *cells = adt.a_grid->getMCIN();
adt_MCIN* cells = adt.a_grid->getMCIN();
if (!cells)
{
printf("Can't find cells in '%s'\n", inputPath.c_str());
@@ -437,11 +438,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
//
// 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 = cells->getMCNK(i, j);
adt_MCNK* cell = cells->getMCNK(i, j);
if (!cell)
continue;
// Height values for triangles stored in order:
@@ -463,44 +464,44 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
// Set map height as grid height
for (int y = 0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*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;
int cx = j * ADT_CELL_SIZE + x;
V9[cy][cx] = cell->ypos;
}
}
for (int y = 0; y < ADT_CELL_SIZE; y++)
{
int cy = i*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;
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++)
{
int cy = i*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;
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++)
{
int cy = i*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;
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];
}
}
}
@@ -510,9 +511,9 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
//============================================
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;
@@ -521,7 +522,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
}
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;
@@ -532,8 +533,8 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
// 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++)
@@ -569,7 +570,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
if (hasFlightBox)
{
heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
@@ -589,7 +590,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
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;
step = selectUInt16StepStore(diff);
@@ -597,20 +598,20 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
}
// 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++)
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)
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++)
@@ -626,11 +627,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
{
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_MCNK *cell = cells->getMCNK(i, j);
adt_MCNK* cell = cells->getMCNK(i, j);
if (!cell)
continue;
adt_MCLQ *liquid = cell->getMCLQ();
adt_MCLQ* liquid = cell->getMCLQ();
int count = 0;
if (!liquid || cell->sizeMCLQ <= 8)
continue;
@@ -684,14 +685,14 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
}
// 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 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;
@@ -715,10 +716,18 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
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;
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, inputPath.c_str(), i, j);
break;
@@ -726,7 +735,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
// Dark water detect
if (LiqType[h->liquidType] == LIQUID_TYPE_OCEAN)
{
uint8 *lm = h2o->getLiquidLightMap(h);
uint8* lm = h2o->getLiquidLightMap(h);
if (!lm)
liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER;
}
@@ -734,14 +743,14 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
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
@@ -757,11 +766,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
//============================================
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_flags[y][x]!=type)
if (liquid_flags[y][x] != type)
{
fullType = true;
y = ADT_CELLS_PER_GRID;
@@ -785,9 +794,9 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
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])
{
@@ -830,7 +839,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
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
@@ -848,7 +857,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
{
for (int j = 0; j < ADT_CELLS_PER_GRID; ++j)
{
adt_MCNK * cell = cells->getMCNK(i,j);
adt_MCNK* cell = cells->getMCNK(i, j);
if (!cell)
continue;
holes[i][j] = cell->holes;
@@ -872,7 +881,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
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_ids, sizeof(area_ids), 1, output);
// Store height data
@@ -906,15 +915,15 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
if (map.liquidMapOffset)
{
fwrite(&liquidHeader, sizeof(liquidHeader), 1, output);
if (!(liquidHeader.flags&MAP_LIQUID_NO_TYPE))
if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
{
fwrite(liquid_entry, sizeof(liquid_entry), 1, output);
fwrite(liquid_flags, sizeof(liquid_flags), 1, output);
}
if (!(liquidHeader.flags&MAP_LIQUID_NO_HEIGHT))
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);
for (int y = 0; y < liquidHeader.height; y++)
fwrite(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX], sizeof(float), liquidHeader.width, output);
}
}
@@ -946,13 +955,13 @@ void ExtractMapsFromMpq(uint32 build)
printf("Convert map files\n");
for(uint32 z = 0; z < map_count; ++z)
{
printf("Extract %s (%d/%u) \n", map_ids[z].name, z+1, map_count);
printf("Extract %s (%d/%u) \n", map_ids[z].name, z + 1, map_count);
// Loadup map grid data
mpqMapName = acore::StringFormat("World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
WDT_file wdt;
if (!wdt.loadFile(mpqMapName, false))
{
// printf("Error loading %s map wdt data\n", map_ids[z].name);
// printf("Error loading %s map wdt data\n", map_ids[z].name);
continue;
}
@@ -967,7 +976,7 @@ void ExtractMapsFromMpq(uint32 build)
ConvertADT(mpqFileName, outputFileName, 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);
}
}
printf("\n");
@@ -976,7 +985,7 @@ void ExtractMapsFromMpq(uint32 build)
bool ExtractFile( char const* mpq_name, std::string const& filename )
{
FILE *output = fopen(filename.c_str(), "wb");
FILE* output = fopen(filename.c_str(), "wb");
if(!output)
{
printf("Can't create the output file '%s'\n", filename.c_str());
@@ -997,13 +1006,13 @@ void ExtractDBCFiles(int locale, bool basicLocale)
std::set<std::string> dbcfiles;
// get DBC file list
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
{
vector<string> files;
(*i)->GetFileListTo(files);
for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
dbcfiles.insert(*iter);
dbcfiles.insert(*iter);
}
std::string path = output_path;
@@ -1030,7 +1039,7 @@ void ExtractDBCFiles(int locale, bool basicLocale)
{
string filename = path;
filename += (iter->c_str() + strlen("DBFilesClient\\"));
if(FileExists(filename.c_str()))
continue;
@@ -1044,7 +1053,7 @@ void LoadLocaleMPQFiles(int const locale)
{
char filename[512];
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]);
new MPQArchive(filename);
for(int i = 1; i < 5; ++i)
@@ -1053,7 +1062,7 @@ void LoadLocaleMPQFiles(int const locale)
if(i > 1)
sprintf(ext, "-%i", i);
sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ", input_path, langs[locale], langs[locale], ext);
sprintf(filename, "%s/Data/%s/patch-%s%s.MPQ", input_path, langs[locale], langs[locale], ext);
if(FileExists(filename))
new MPQArchive(filename);
}
@@ -1062,7 +1071,7 @@ void LoadLocaleMPQFiles(int const locale)
void LoadCommonMPQFiles()
{
char filename[512];
int count = sizeof(CONF_mpq_list)/sizeof(char*);
int count = sizeof(CONF_mpq_list) / sizeof(char*);
for(int i = 0; i < count; ++i)
{
sprintf(filename, "%s/Data/%s", input_path, CONF_mpq_list[i]);
@@ -1073,11 +1082,11 @@ void LoadCommonMPQFiles()
inline void CloseMPQFiles()
{
for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close();
gOpenArchives.clear();
for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end(); ++j) (*j)->close();
gOpenArchives.clear();
}
int main(int argc, char * arg[])
int main(int argc, char* arg[])
{
printf("Map & DBC Extractor\n");
printf("===================\n\n");

View File

@@ -12,13 +12,13 @@
int holetab_h[4] = { 0x1111, 0x2222, 0x4444, 0x8888 };
int holetab_v[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 };
u_map_fcc MHDRMagic = { { 'R','D','H','M' } };
u_map_fcc MCINMagic = { { 'N','I','C','M' } };
u_map_fcc MH2OMagic = { { 'O','2','H','M' } };
u_map_fcc MCNKMagic = { { 'K','N','C','M' } };
u_map_fcc MCVTMagic = { { 'T','V','C','M' } };
u_map_fcc MCLQMagic = { { 'Q','L','C','M' } };
u_map_fcc MFBOMagic = { { 'O','B','F','M' } };
u_map_fcc MHDRMagic = { { 'R', 'D', 'H', 'M' } };
u_map_fcc MCINMagic = { { 'N', 'I', 'C', 'M' } };
u_map_fcc MH2OMagic = { { 'O', '2', 'H', 'M' } };
u_map_fcc MCNKMagic = { { 'K', 'N', 'C', 'M' } };
u_map_fcc MCVTMagic = { { 'T', 'V', 'C', 'M' } };
u_map_fcc MCLQMagic = { { 'Q', 'L', 'C', 'M' } };
u_map_fcc MFBOMagic = { { 'O', 'B', 'F', 'M' } };
bool isHole(int holes, int i, int j)
{
@@ -58,7 +58,7 @@ bool ADT_file::prepareLoadedData()
return false;
// Check and prepare MHDR
a_grid = (adt_MHDR *)(GetData()+8+version->size);
a_grid = (adt_MHDR*)(GetData() + 8 + version->size);
if (!a_grid->prepareLoadedData())
return false;
@@ -93,9 +93,9 @@ bool adt_MCIN::prepareLoadedData()
return false;
// Check cells data
for (int i=0; i<ADT_CELLS_PER_GRID;i++)
for (int j=0; j<ADT_CELLS_PER_GRID;j++)
if (cells[i][j].offsMCNK && !getMCNK(i,j)->prepareLoadedData())
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
if (cells[i][j].offsMCNK && !getMCNK(i, j)->prepareLoadedData())
return false;
return true;
@@ -107,8 +107,8 @@ bool adt_MH2O::prepareLoadedData()
return false;
// Check liquid data
// for (int i=0; i<ADT_CELLS_PER_GRID;i++)
// for (int j=0; j<ADT_CELLS_PER_GRID;j++)
// for (int i=0; i<ADT_CELLS_PER_GRID;i++)
// for (int j=0; j<ADT_CELLS_PER_GRID;j++)
return true;
}
@@ -133,7 +133,7 @@ bool adt_MCVT::prepareLoadedData()
if (fcc != MCVTMagic.fcc)
return false;
if (size != sizeof(adt_MCVT)-8)
if (size != sizeof(adt_MCVT) - 8)
return false;
return true;

View File

@@ -33,13 +33,14 @@ enum LiquidType
//
class adt_MCVT
{
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
public:
float height_map[(ADT_CELL_SIZE+1)*(ADT_CELL_SIZE+1)+ADT_CELL_SIZE*ADT_CELL_SIZE];
float height_map[(ADT_CELL_SIZE + 1) * (ADT_CELL_SIZE + 1) + ADT_CELL_SIZE * ADT_CELL_SIZE];
bool prepareLoadedData();
};
@@ -49,7 +50,8 @@ public:
//
class adt_MCLQ
{
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
@@ -57,10 +59,11 @@ public:
uint32 size;
float height1;
float height2;
struct liquid_data{
struct liquid_data
{
uint32 light;
float height;
} liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1];
} liquid[ADT_CELL_SIZE + 1][ADT_CELL_SIZE + 1];
// 1<<0 - ochen
// 1<<1 - lava/slime
@@ -78,7 +81,8 @@ public:
//
class adt_MCNK
{
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
@@ -118,16 +122,16 @@ public:
uint32 effectId;
bool prepareLoadedData();
adt_MCVT *getMCVT()
adt_MCVT* getMCVT()
{
if (offsMCVT)
return (adt_MCVT *)((uint8 *)this + offsMCVT);
return (adt_MCVT*)((uint8*)this + offsMCVT);
return 0;
}
adt_MCLQ *getMCLQ()
adt_MCLQ* getMCLQ()
{
if (offsMCLQ)
return (adt_MCLQ *)((uint8 *)this + offsMCLQ);
return (adt_MCLQ*)((uint8*)this + offsMCLQ);
return 0;
}
};
@@ -137,13 +141,15 @@ public:
//
class adt_MCIN
{
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
struct adt_CELLS{
struct adt_CELLS
{
uint32 offsMCNK;
uint32 size;
uint32 flags;
@@ -152,10 +158,10 @@ public:
bool prepareLoadedData();
// offset from begin file (used this-84)
adt_MCNK *getMCNK(int x, int y)
adt_MCNK* getMCNK(int x, int y)
{
if (cells[x][y].offsMCNK)
return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84);
return (adt_MCNK*)((uint8*)this + cells[x][y].offsMCNK - 84);
return 0;
}
};
@@ -163,7 +169,8 @@ public:
#define ADT_LIQUID_HEADER_FULL_LIGHT 0x01
#define ADT_LIQUID_HEADER_NO_HIGHT 0x02
struct adt_liquid_header{
struct adt_liquid_header
{
uint16 liquidType; // Index from LiquidType.dbc
uint16 formatFlags;
float heightLevel1;
@@ -182,13 +189,15 @@ struct adt_liquid_header{
class adt_MH2O
{
public:
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
struct adt_LIQUID{
struct adt_LIQUID
{
uint32 offsData1;
uint32 used;
uint32 offsData2;
@@ -196,52 +205,52 @@ public:
bool prepareLoadedData();
adt_liquid_header *getLiquidData(int x, int y)
adt_liquid_header* getLiquidData(int x, int y)
{
if (liquid[x][y].used && liquid[x][y].offsData1)
return (adt_liquid_header *)((uint8*)this + 8 + liquid[x][y].offsData1);
return (adt_liquid_header*)((uint8*)this + 8 + liquid[x][y].offsData1);
return 0;
}
float *getLiquidHeightMap(adt_liquid_header *h)
float* getLiquidHeightMap(adt_liquid_header* h)
{
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
return 0;
if (h->offsData2b)
return (float *)((uint8*)this + 8 + h->offsData2b);
return (float*)((uint8*)this + 8 + h->offsData2b);
return 0;
}
uint8 *getLiquidLightMap(adt_liquid_header *h)
uint8* getLiquidLightMap(adt_liquid_header* h)
{
if (h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT)
if (h->formatFlags & ADT_LIQUID_HEADER_FULL_LIGHT)
return 0;
if (h->offsData2b)
{
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
return (uint8 *)((uint8*)this + 8 + h->offsData2b);
return (uint8 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
return (uint8*)((uint8*)this + 8 + h->offsData2b);
return (uint8*)((uint8*)this + 8 + h->offsData2b + (h->width + 1) * (h->height + 1) * 4);
}
return 0;
}
uint32 *getLiquidFullLightMap(adt_liquid_header *h)
uint32* getLiquidFullLightMap(adt_liquid_header* h)
{
if (!(h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT))
if (!(h->formatFlags & ADT_LIQUID_HEADER_FULL_LIGHT))
return 0;
if (h->offsData2b)
{
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
return (uint32 *)((uint8*)this + 8 + h->offsData2b);
return (uint32 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
return (uint32*)((uint8*)this + 8 + h->offsData2b);
return (uint32*)((uint8*)this + 8 + h->offsData2b + (h->width + 1) * (h->height + 1) * 4);
}
return 0;
}
uint64 getLiquidShowMap(adt_liquid_header *h)
uint64 getLiquidShowMap(adt_liquid_header* h)
{
if (h->offsData2a)
return *((uint64 *)((uint8*)this + 8 + h->offsData2a));
return *((uint64*)((uint8*)this + 8 + h->offsData2a));
else
return 0xFFFFFFFFFFFFFFFFuLL;
}
@@ -274,7 +283,8 @@ public:
//
class adt_MHDR
{
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
@@ -317,14 +327,15 @@ public:
}
};
class ADT_file : public FileLoader{
class ADT_file : public FileLoader
{
public:
bool prepareLoadedData();
ADT_file();
~ADT_file();
void free();
adt_MHDR *a_grid;
adt_MHDR* a_grid;
};
#endif

View File

@@ -19,35 +19,35 @@ bool DBCFile::open()
{
MPQFile f(filename.c_str());
char header[4];
unsigned int na,nb,es,ss;
unsigned int na, nb, es, ss;
if(f.read(header,4)!=4) // Number of records
if(f.read(header, 4) != 4) // Number of records
return false;
if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
if(header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C')
return false;
if(f.read(&na,4)!=4) // Number of records
if(f.read(&na, 4) != 4) // Number of records
return false;
if(f.read(&nb,4)!=4) // Number of fields
if(f.read(&nb, 4) != 4) // Number of fields
return false;
if(f.read(&es,4)!=4) // Size of a record
if(f.read(&es, 4) != 4) // Size of a record
return false;
if(f.read(&ss,4)!=4) // String size
if(f.read(&ss, 4) != 4) // String size
return false;
recordSize = es;
recordCount = na;
fieldCount = nb;
stringSize = ss;
if(fieldCount*4 != recordSize)
if(fieldCount * 4 != recordSize)
return false;
data = new unsigned char[recordSize*recordCount+stringSize];
stringTable = data + recordSize*recordCount;
data = new unsigned char[recordSize * recordCount + stringSize];
stringTable = data + recordSize * recordCount;
size_t data_size = recordSize*recordCount+stringSize;
if(f.read(data,data_size)!=data_size)
size_t data_size = recordSize * recordCount + stringSize;
if(f.read(data, data_size) != data_size)
return false;
f.close();
return true;
@@ -60,7 +60,7 @@ DBCFile::~DBCFile()
DBCFile::Record DBCFile::getRecord(size_t id)
{
assert(data);
return Record(*this, data + id*recordSize);
return Record(*this, data + id * recordSize);
}
size_t DBCFile::getMaxId()

View File

@@ -12,7 +12,7 @@
class DBCFile
{
public:
DBCFile(const std::string &filename);
DBCFile(const std::string& filename);
~DBCFile();
// Open database. It must be openened before it can be used.
@@ -22,11 +22,11 @@ public:
class Exception
{
public:
Exception(const std::string &message): message(message)
Exception(const std::string& message): message(message)
{ }
virtual ~Exception()
{ }
const std::string &getMessage() {return message;}
const std::string& getMessage() {return message;}
private:
std::string message;
};
@@ -44,19 +44,19 @@ public:
float getFloat(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<float*>(offset+field*4);
return *reinterpret_cast<float*>(offset + field * 4);
}
unsigned int getUInt(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<unsigned int*>(offset+field*4);
return *reinterpret_cast<unsigned int*>(offset + field * 4);
}
int getInt(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<int*>(offset+field*4);
return *reinterpret_cast<int*>(offset + field * 4);
}
const char *getString(size_t field) const
const char* getString(size_t field) const
{
assert(field < file.fieldCount);
size_t stringOffset = getUInt(field);
@@ -64,9 +64,9 @@ public:
return reinterpret_cast<char*>(file.stringTable + stringOffset);
}
private:
Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
DBCFile &file;
unsigned char *offset;
Record(DBCFile& file, unsigned char* offset): file(file), offset(offset) {}
DBCFile& file;
unsigned char* offset;
friend class DBCFile;
friend class DBCFile::Iterator;
@@ -76,24 +76,26 @@ public:
class Iterator
{
public:
Iterator(DBCFile &file, unsigned char *offset):
Iterator(DBCFile& file, unsigned char* offset):
record(file, offset) {}
/// Advance (prefix only)
Iterator & operator++() {
Iterator& operator++()
{
record.offset += record.file.recordSize;
return *this;
}
/// Return address of current instance
Record const & operator*() const { return record; }
const Record* operator->() const {
Record const& operator*() const { return record; }
const Record* operator->() const
{
return &record;
}
/// Comparison
bool operator==(const Iterator &b) const
bool operator==(const Iterator& b) const
{
return record.offset == b.record.offset;
}
bool operator!=(const Iterator &b) const
bool operator!=(const Iterator& b) const
{
return record.offset != b.record.offset;
}
@@ -117,8 +119,8 @@ private:
size_t recordCount;
size_t fieldCount;
size_t stringSize;
unsigned char *data;
unsigned char *stringTable;
unsigned char* data;
unsigned char* stringTable;
};
#endif

View File

@@ -12,7 +12,7 @@
class MPQFile;
u_map_fcc MverMagic = { {'R','E','V','M'} };
u_map_fcc MverMagic = { {'R', 'E', 'V', 'M'} };
FileLoader::FileLoader()
{
@@ -54,7 +54,7 @@ bool FileLoader::loadFile(std::string const& fileName, bool log)
bool FileLoader::prepareLoadedData()
{
// Check version
version = (file_MVER *) data;
version = (file_MVER*) data;
if (version->fcc != MverMagic.fcc)
return false;
if (version->ver != FILE_FORMAT_VERSION)

View File

@@ -48,7 +48,8 @@ union u_map_fcc
//
struct file_MVER
{
union{
union
{
uint32 fcc;
char fcc_txt[4];
};
@@ -56,15 +57,16 @@ struct file_MVER
uint32 ver;
};
class FileLoader{
uint8 *data;
class FileLoader
{
uint8* data;
uint32 data_size;
public:
virtual bool prepareLoadedData();
uint8 *GetData() {return data;}
uint8* GetData() {return data;}
uint32 GetDataSize() {return data_size;}
file_MVER *version;
file_MVER* version;
FileLoader();
~FileLoader();
bool loadFile(std::string const& filename, bool log = true);

View File

@@ -14,8 +14,10 @@ MPQArchive::MPQArchive(const char* filename)
{
int result = libmpq__archive_open(&mpq_a, filename, -1);
printf("Opening %s\n", filename);
if(result) {
switch(result) {
if(result)
{
switch(result)
{
case LIBMPQ_ERROR_OPEN :
printf("Error opening archive '%s': Does file really exist?\n", filename);
break;
@@ -52,9 +54,9 @@ MPQFile::MPQFile(const char* filename):
pointer(0),
size(0)
{
for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
{
mpq_archive *mpq_a = (*i)->mpq_a;
mpq_archive* mpq_a = (*i)->mpq_a;
uint32_t filenum;
if(libmpq__file_number(mpq_a, filename, &filenum)) continue;
@@ -62,8 +64,9 @@ MPQFile::MPQFile(const char* filename):
libmpq__file_unpacked_size(mpq_a, filenum, &size);
// HACK: in patch.mpq some files don't want to open and give 1 for filesize
if (size<=1) {
// printf("warning: file %s has size %d; cannot read.\n", filename, size);
if (size <= 1)
{
// printf("warning: file %s has size %d; cannot read.\n", filename, size);
eof = true;
buffer = 0;
return;
@@ -85,7 +88,8 @@ size_t MPQFile::read(void* dest, size_t bytes)
if (eof) return 0;
size_t rpos = pointer + bytes;
if (rpos > size_t(size)) {
if (rpos > size_t(size))
{
bytes = size - pointer;
eof = true;
}

View File

@@ -21,29 +21,31 @@ class MPQArchive
{
public:
mpq_archive_s *mpq_a;
mpq_archive_s* mpq_a;
MPQArchive(const char* filename);
~MPQArchive() { close(); }
void close();
void GetFileListTo(vector<string>& filelist) {
void GetFileListTo(vector<string>& filelist)
{
uint32_t filenum;
if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
libmpq__off_t size, transferred;
libmpq__file_unpacked_size(mpq_a, filenum, &size);
char *buffer = new char[size+1];
char* buffer = new char[size + 1];
buffer[size] = '\0';
libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
char seps[] = "\n";
char *token;
char* token;
token = strtok( buffer, seps );
uint32 counter = 0;
while ((token != nullptr) && (counter < size)) {
while ((token != nullptr) && (counter < size))
{
//cout << token << endl;
token[strlen(token) - 1] = 0;
string s = token;
@@ -61,8 +63,8 @@ class MPQFile
{
//MPQHANDLE handle;
bool eof;
char *buffer;
libmpq__off_t pointer,size;
char* buffer;
libmpq__off_t pointer, size;
// disable copying
MPQFile(const MPQFile& /*f*/) {}
@@ -82,15 +84,15 @@ public:
void close();
};
inline void flipcc(char *fcc)
inline void flipcc(char* fcc)
{
char t;
t=fcc[0];
fcc[0]=fcc[3];
fcc[3]=t;
t=fcc[1];
fcc[1]=fcc[2];
fcc[2]=t;
t = fcc[0];
fcc[0] = fcc[3];
fcc[3] = t;
t = fcc[1];
fcc[1] = fcc[2];
fcc[2] = t;
}
#endif

View File

@@ -59,13 +59,13 @@ bool WDT_file::prepareLoadedData()
if (!FileLoader::prepareLoadedData())
return false;
mphd = (wdt_MPHD *)((uint8*)version+version->size+8);
mphd = (wdt_MPHD*)((uint8*)version + version->size + 8);
if (!mphd->prepareLoadedData())
return false;
main = (wdt_MAIN *)((uint8*)mphd + mphd->size+8);
main = (wdt_MAIN*)((uint8*)mphd + mphd->size + 8);
if (!main->prepareLoadedData())
return false;
wmo = (wdt_MWMO *)((uint8*)main+ main->size+8);
wmo = (wdt_MWMO*)((uint8*)main + main->size + 8);
if (!wmo->prepareLoadedData())
return false;
return true;

View File

@@ -13,8 +13,10 @@
//**************************************************************************************
#define WDT_MAP_SIZE 64
class wdt_MWMO{
union{
class wdt_MWMO
{
union
{
uint32 fcc;
char fcc_txt[4];
};
@@ -23,8 +25,10 @@ public:
bool prepareLoadedData();
};
class wdt_MPHD{
union{
class wdt_MPHD
{
union
{
uint32 fcc;
char fcc_txt[4];
};
@@ -42,15 +46,18 @@ public:
bool prepareLoadedData();
};
class wdt_MAIN{
union{
class wdt_MAIN
{
union
{
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
struct adtData{
struct adtData
{
uint32 exist;
uint32 data1;
} adt_list[64][64];
@@ -58,7 +65,8 @@ public:
bool prepareLoadedData();
};
class WDT_file : public FileLoader{
class WDT_file : public FileLoader
{
public:
bool prepareLoadedData();
@@ -66,9 +74,9 @@ public:
~WDT_file();
void free();
wdt_MPHD *mphd;
wdt_MAIN *main;
wdt_MWMO *wmo;
wdt_MPHD* mphd;
wdt_MAIN* main;
wdt_MWMO* wmo;
};
#endif