TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
System.cpp File Reference
#include <cstdio>
#include <deque>
#include <fstream>
#include <set>
#include <cstdlib>
#include <cstring>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include "Common.h"
#include "DBFilesClientList.h"
#include "CascLib.h"
#include "dbcfile.h"
#include "StringFormat.h"
#include "adt.h"
#include "wdt.h"
+ Include dependency graph for System.cpp:

Classes

struct  map_id
 
struct  map_fileheader
 
struct  map_areaHeader
 
struct  map_heightHeader
 
struct  map_liquidHeader
 

Macros

#define _CRT_SECURE_NO_DEPRECATE
 
#define MAX_PATH_LENGTH   128
 
#define CASC_LOCALES_COUNT   17
 
#define MAP_AREA_NO_AREA   0x0001
 
#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
 
#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
 
#define MAP_LIQUID_NO_HEIGHT   0x0002
 

Enumerations

enum  Extract { EXTRACT_MAP = 1, EXTRACT_DBC = 2 }
 

Functions

void CreateDir (boost::filesystem::path const &path)
 
void Usage (char const *prg)
 
void HandleArgs (int argc, char *arg[])
 
uint32 ReadBuild (int locale)
 
uint32 ReadMapDBC ()
 
void ReadLiquidTypeTableDBC ()
 
float selectUInt8StepStore (float maxDiff)
 
float selectUInt16StepStore (float maxDiff)
 
bool TransformToHighRes (uint16 lowResHoles, uint8 hiResHoles[8])
 
bool ConvertADT (std::string const &inputPath, std::string const &outputPath, int, int, uint32 build)
 
void ExtractWmos (ChunkedFile &file, std::set< std::string > &wmoList)
 
void ExtractMaps (uint32 build)
 
bool ExtractFile (HANDLE fileInArchive, std::string filename)
 
void ExtractDBFilesClient (int l)
 
bool OpenCascStorage (int locale)
 
int main (int argc, char *arg[])
 

Variables

HANDLE CascStorage = NULL
 
map_idmap_ids
 
uint16LiqType
 
char output_path [MAX_PATH_LENGTH]
 
char input_path [MAX_PATH_LENGTH]
 
int CONF_extract = EXTRACT_MAP | EXTRACT_DBC
 
bool CONF_allow_height_limit = true
 
float CONF_use_minHeight = -500.0f
 
bool CONF_allow_float_to_int = true
 
float CONF_float_to_int8_limit = 2.0f
 
float CONF_float_to_int16_limit = 2048.0f
 
float CONF_flat_height_delta_limit = 0.005f
 
float CONF_flat_liquid_delta_limit = 0.001f
 
uint32 CONF_Locale = 0
 
char constCascLocaleNames [CASC_LOCALES_COUNT]
 
uint32 WowLocaleToCascLocaleFlags [12]
 
static char constMAP_MAGIC = "MAPS"
 
static char constMAP_VERSION_MAGIC = "v1.8"
 
static char constMAP_AREA_MAGIC = "AREA"
 
static char constMAP_HEIGHT_MAGIC = "MHGT"
 
static char constMAP_LIQUID_MAGIC = "MLIQ"
 
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]
 
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]
 
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]
 
uint8 holes [ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8]
 
int16 flight_box_max [3][3]
 
int16 flight_box_min [3][3]
 

Macro Definition Documentation

#define _CRT_SECURE_NO_DEPRECATE
#define CASC_LOCALES_COUNT   17
#define MAP_AREA_NO_AREA   0x0001
#define MAP_HEIGHT_AS_INT16   0x0002
#define MAP_HEIGHT_AS_INT8   0x0004
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS   0x0008
#define MAP_HEIGHT_NO_HEIGHT   0x0001
#define MAP_LIQUID_NO_HEIGHT   0x0002
#define MAP_LIQUID_NO_TYPE   0x0001
#define MAP_LIQUID_TYPE_DARK_WATER   0x10
#define MAP_LIQUID_TYPE_MAGMA   0x04
#define MAP_LIQUID_TYPE_NO_WATER   0x00
#define MAP_LIQUID_TYPE_OCEAN   0x02
#define MAP_LIQUID_TYPE_SLIME   0x08
#define MAP_LIQUID_TYPE_WATER   0x01
#define MAP_LIQUID_TYPE_WMO_WATER   0x20
#define MAX_PATH_LENGTH   128

Enumeration Type Documentation

enum Extract
Enumerator
EXTRACT_MAP 
EXTRACT_DBC 
87 {
88  EXTRACT_MAP = 1,
89  EXTRACT_DBC = 2
90 };
Definition: System.cpp:88
Definition: System.cpp:89

Function Documentation

bool ConvertADT ( std::string const inputPath,
std::string const outputPath,
int  ,
int  ,
uint32  build 
)
465 {
466  ChunkedFile adt;
467 
468  if (!adt.loadFile(CascStorage, inputPath))
469  return false;
470 
471  // Prepare map header
472  map_fileheader map;
473  map.mapMagic = *reinterpret_cast<uint32 const*>(MAP_MAGIC);
474  map.versionMagic = *reinterpret_cast<uint32 const*>(MAP_VERSION_MAGIC);
475  map.buildMagic = build;
476 
477  // Get area flags data
478  memset(area_ids, 0, sizeof(area_ids));
479  memset(V9, 0, sizeof(V9));
480  memset(V8, 0, sizeof(V8));
481 
482  memset(liquid_show, 0, sizeof(liquid_show));
483  memset(liquid_flags, 0, sizeof(liquid_flags));
484  memset(liquid_entry, 0, sizeof(liquid_entry));
485 
486  memset(holes, 0, sizeof(holes));
487 
488  bool hasHoles = false;
489  bool hasFlightBox = false;
490 
491  for (std::multimap<std::string, FileChunk*>::const_iterator itr = adt.chunks.lower_bound("MCNK"); itr != adt.chunks.upper_bound("MCNK"); ++itr)
492  {
493  adt_MCNK* mcnk = itr->second->As<adt_MCNK>();
494 
495  // Area data
496  area_ids[mcnk->iy][mcnk->ix] = mcnk->areaid;
497 
498  // Height
499  // Height values for triangles stored in order:
500  // 1 2 3 4 5 6 7 8 9
501  // 10 11 12 13 14 15 16 17
502  // 18 19 20 21 22 23 24 25 26
503  // 27 28 29 30 31 32 33 34
504  // . . . . . . . .
505  // For better get height values merge it to V9 and V8 map
506  // V9 height map:
507  // 1 2 3 4 5 6 7 8 9
508  // 18 19 20 21 22 23 24 25 26
509  // . . . . . . . .
510  // V8 height map:
511  // 10 11 12 13 14 15 16 17
512  // 27 28 29 30 31 32 33 34
513  // . . . . . . . .
514 
515  // Set map height as grid height
516  for (int y = 0; y <= ADT_CELL_SIZE; y++)
517  {
518  int cy = mcnk->iy * ADT_CELL_SIZE + y;
519  for (int x = 0; x <= ADT_CELL_SIZE; x++)
520  {
521  int cx = mcnk->ix * ADT_CELL_SIZE + x;
522  V9[cy][cx] = mcnk->ypos;
523  }
524  }
525 
526  for (int y = 0; y < ADT_CELL_SIZE; y++)
527  {
528  int cy = mcnk->iy * ADT_CELL_SIZE + y;
529  for (int x = 0; x < ADT_CELL_SIZE; x++)
530  {
531  int cx = mcnk->ix * ADT_CELL_SIZE + x;
532  V8[cy][cx] = mcnk->ypos;
533  }
534  }
535 
536  // Get custom height
537  if (FileChunk* chunk = itr->second->GetSubChunk("MCVT"))
538  {
539  adt_MCVT* mcvt = chunk->As<adt_MCVT>();
540  // get V9 height map
541  for (int y = 0; y <= ADT_CELL_SIZE; y++)
542  {
543  int cy = mcnk->iy * ADT_CELL_SIZE + y;
544  for (int x = 0; x <= ADT_CELL_SIZE; x++)
545  {
546  int cx = mcnk->ix * ADT_CELL_SIZE + x;
547  V9[cy][cx] += mcvt->height_map[y*(ADT_CELL_SIZE * 2 + 1) + x];
548  }
549  }
550  // get V8 height map
551  for (int y = 0; y < ADT_CELL_SIZE; y++)
552  {
553  int cy = mcnk->iy * ADT_CELL_SIZE + y;
554  for (int x = 0; x < ADT_CELL_SIZE; x++)
555  {
556  int cx = mcnk->ix * ADT_CELL_SIZE + x;
557  V8[cy][cx] += mcvt->height_map[y*(ADT_CELL_SIZE * 2 + 1) + ADT_CELL_SIZE + 1 + x];
558  }
559  }
560  }
561 
562  // Liquid data
563  if (mcnk->sizeMCLQ > 8)
564  {
565  if (FileChunk* chunk = itr->second->GetSubChunk("MCLQ"))
566  {
567  adt_MCLQ* liquid = chunk->As<adt_MCLQ>();
568  int count = 0;
569  for (int y = 0; y < ADT_CELL_SIZE; ++y)
570  {
571  int cy = mcnk->iy * ADT_CELL_SIZE + y;
572  for (int x = 0; x < ADT_CELL_SIZE; ++x)
573  {
574  int cx = mcnk->ix * ADT_CELL_SIZE + x;
575  if (liquid->flags[y][x] != 0x0F)
576  {
577  liquid_show[cy][cx] = true;
578  if (liquid->flags[y][x] & (1 << 7))
579  liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_DARK_WATER;
580  ++count;
581  }
582  }
583  }
584 
585  uint32 c_flag = mcnk->flags;
586  if (c_flag & (1 << 2))
587  {
588  liquid_entry[mcnk->iy][mcnk->ix] = 1;
589  liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_WATER; // water
590  }
591  if (c_flag & (1 << 3))
592  {
593  liquid_entry[mcnk->iy][mcnk->ix] = 2;
594  liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_OCEAN; // ocean
595  }
596  if (c_flag & (1 << 4))
597  {
598  liquid_entry[mcnk->iy][mcnk->ix] = 3;
599  liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_MAGMA; // magma/slime
600  }
601 
602  if (!count && liquid_flags[mcnk->iy][mcnk->ix])
603  fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
604 
605  for (int y = 0; y <= ADT_CELL_SIZE; ++y)
606  {
607  int cy = mcnk->iy * ADT_CELL_SIZE + y;
608  for (int x = 0; x <= ADT_CELL_SIZE; ++x)
609  {
610  int cx = mcnk->ix * ADT_CELL_SIZE + x;
611  liquid_height[cy][cx] = liquid->liquid[y][x].height;
612  }
613  }
614  }
615  }
616 
617  // Hole data
618  if (!(mcnk->flags & 0x10000))
619  {
620  if (uint16 hole = mcnk->holes)
621  if (TransformToHighRes(hole, holes[mcnk->iy][mcnk->ix]))
622  hasHoles = true;
623  }
624  else
625  {
626  memcpy(holes[mcnk->iy][mcnk->ix], mcnk->union_5_3_0.HighResHoles, sizeof(uint64));
627  if (*((uint64*)holes[mcnk->iy][mcnk->ix]) != 0)
628  hasHoles = true;
629  }
630  }
631 
632  // Get liquid map for grid (in WOTLK used MH2O chunk)
633  if (FileChunk* chunk = adt.GetChunk("MH2O"))
634  {
635  adt_MH2O* h2o = chunk->As<adt_MH2O>();
636  for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
637  {
638  for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
639  {
640  adt_liquid_header *h = h2o->getLiquidData(i, j);
641  if (!h)
642  continue;
643 
644  int count = 0;
645  uint64 show = h2o->getLiquidShowMap(h);
646  for (int y = 0; y < h->height; y++)
647  {
648  int cy = i * ADT_CELL_SIZE + y + h->yOffset;
649  for (int x = 0; x < h->width; x++)
650  {
651  int cx = j * ADT_CELL_SIZE + x + h->xOffset;
652  if (show & 1)
653  {
654  liquid_show[cy][cx] = true;
655  ++count;
656  }
657  show >>= 1;
658  }
659  }
660 
661  liquid_entry[i][j] = h->liquidType;
662  switch (LiqType[h->liquidType])
663  {
668  default:
669  printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->liquidType, inputPath.c_str(), i, j);
670  break;
671  }
672  // Dark water detect
674  {
675  uint8* lm = h2o->getLiquidLightMap(h);
676  if (!lm)
678  }
679 
680  if (!count && liquid_flags[i][j])
681  printf("Wrong liquid detect in MH2O chunk");
682 
683  float* height = h2o->getLiquidHeightMap(h);
684  int pos = 0;
685  for (int y = 0; y <= h->height; y++)
686  {
687  int cy = i * ADT_CELL_SIZE + y + h->yOffset;
688  for (int x = 0; x <= h->width; x++)
689  {
690  int cx = j * ADT_CELL_SIZE + x + h->xOffset;
691 
692  if (height)
693  liquid_height[cy][cx] = height[pos];
694  else
695  liquid_height[cy][cx] = h->heightLevel1;
696 
697  pos++;
698  }
699  }
700  }
701  }
702  }
703 
704  if (FileChunk* chunk = adt.GetChunk("MFBO"))
705  {
706  adt_MFBO* mfbo = chunk->As<adt_MFBO>();
707  memcpy(flight_box_max, &mfbo->max, sizeof(flight_box_max));
708  memcpy(flight_box_min, &mfbo->min, sizeof(flight_box_min));
709  hasFlightBox = true;
710  }
711 
712  //============================================
713  // Try pack area data
714  //============================================
715  bool fullAreaData = false;
716  uint32 areaId = area_ids[0][0];
717  for (int y = 0; y < ADT_CELLS_PER_GRID; ++y)
718  {
719  for (int x = 0; x < ADT_CELLS_PER_GRID; ++x)
720  {
721  if (area_ids[y][x] != areaId)
722  {
723  fullAreaData = true;
724  break;
725  }
726  }
727  }
728 
729  map.areaMapOffset = sizeof(map);
730  map.areaMapSize = sizeof(map_areaHeader);
731 
732  map_areaHeader areaHeader;
733  areaHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_AREA_MAGIC);
734  areaHeader.flags = 0;
735  if (fullAreaData)
736  {
737  areaHeader.gridArea = 0;
738  map.areaMapSize += sizeof(area_ids);
739  }
740  else
741  {
742  areaHeader.flags |= MAP_AREA_NO_AREA;
743  areaHeader.gridArea = static_cast<uint16>(areaId);
744  }
745 
746  //============================================
747  // Try pack height data
748  //============================================
749  float maxHeight = -20000;
750  float minHeight = 20000;
751  for (int y=0; y<ADT_GRID_SIZE; y++)
752  {
753  for(int x=0;x<ADT_GRID_SIZE;x++)
754  {
755  float h = V8[y][x];
756  if (maxHeight < h) maxHeight = h;
757  if (minHeight > h) minHeight = h;
758  }
759  }
760  for (int y=0; y<=ADT_GRID_SIZE; y++)
761  {
762  for(int x=0;x<=ADT_GRID_SIZE;x++)
763  {
764  float h = V9[y][x];
765  if (maxHeight < h) maxHeight = h;
766  if (minHeight > h) minHeight = h;
767  }
768  }
769 
770  // Check for allow limit minimum height (not store height in deep ochean - allow save some memory)
771  if (CONF_allow_height_limit && minHeight < CONF_use_minHeight)
772  {
773  for (int y=0; y<ADT_GRID_SIZE; y++)
774  for(int x=0;x<ADT_GRID_SIZE;x++)
775  if (V8[y][x] < CONF_use_minHeight)
776  V8[y][x] = CONF_use_minHeight;
777  for (int y=0; y<=ADT_GRID_SIZE; y++)
778  for(int x=0;x<=ADT_GRID_SIZE;x++)
779  if (V9[y][x] < CONF_use_minHeight)
780  V9[y][x] = CONF_use_minHeight;
781  if (minHeight < CONF_use_minHeight)
782  minHeight = CONF_use_minHeight;
783  if (maxHeight < CONF_use_minHeight)
784  maxHeight = CONF_use_minHeight;
785  }
786 
787  map.heightMapOffset = map.areaMapOffset + map.areaMapSize;
788  map.heightMapSize = sizeof(map_heightHeader);
789 
790  map_heightHeader heightHeader;
791  heightHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_HEIGHT_MAGIC);
792  heightHeader.flags = 0;
793  heightHeader.gridHeight = minHeight;
794  heightHeader.gridMaxHeight = maxHeight;
795 
796  if (maxHeight == minHeight)
797  heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
798 
799  // Not need store if flat surface
800  if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
801  heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
802 
803  if (hasFlightBox)
804  {
805  heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
806  map.heightMapSize += sizeof(flight_box_max) + sizeof(flight_box_min);
807  }
808 
809  // Try store as packed in uint16 or uint8 values
810  if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
811  {
812  float step = 0;
813  // Try Store as uint values
815  {
816  float diff = maxHeight - minHeight;
817  if (diff < CONF_float_to_int8_limit) // As uint8 (max accuracy = CONF_float_to_int8_limit/256)
818  {
819  heightHeader.flags|=MAP_HEIGHT_AS_INT8;
820  step = selectUInt8StepStore(diff);
821  }
822  else if (diff<CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536)
823  {
824  heightHeader.flags|=MAP_HEIGHT_AS_INT16;
825  step = selectUInt16StepStore(diff);
826  }
827  }
828 
829  // Pack it to int values if need
830  if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
831  {
832  for (int y=0; y<ADT_GRID_SIZE; y++)
833  for(int x=0;x<ADT_GRID_SIZE;x++)
834  uint8_V8[y][x] = uint8((V8[y][x] - minHeight) * step + 0.5f);
835  for (int y=0; y<=ADT_GRID_SIZE; y++)
836  for(int x=0;x<=ADT_GRID_SIZE;x++)
837  uint8_V9[y][x] = uint8((V9[y][x] - minHeight) * step + 0.5f);
838  map.heightMapSize+= sizeof(uint8_V9) + sizeof(uint8_V8);
839  }
840  else if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
841  {
842  for (int y=0; y<ADT_GRID_SIZE; y++)
843  for(int x=0;x<ADT_GRID_SIZE;x++)
844  uint16_V8[y][x] = uint16((V8[y][x] - minHeight) * step + 0.5f);
845  for (int y=0; y<=ADT_GRID_SIZE; y++)
846  for(int x=0;x<=ADT_GRID_SIZE;x++)
847  uint16_V9[y][x] = uint16((V9[y][x] - minHeight) * step + 0.5f);
848  map.heightMapSize+= sizeof(uint16_V9) + sizeof(uint16_V8);
849  }
850  else
851  map.heightMapSize+= sizeof(V9) + sizeof(V8);
852  }
853 
854  //============================================
855  // Pack liquid data
856  //============================================
857  uint8 type = liquid_flags[0][0];
858  bool fullType = false;
859  for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
860  {
861  for (int x = 0; x < ADT_CELLS_PER_GRID; x++)
862  {
863  if (liquid_flags[y][x] != type)
864  {
865  fullType = true;
866  y = ADT_CELLS_PER_GRID;
867  break;
868  }
869  }
870  }
871 
872  map_liquidHeader liquidHeader;
873 
874  // no water data (if all grid have 0 liquid type)
875  if (type == 0 && !fullType)
876  {
877  // No liquid data
878  map.liquidMapOffset = 0;
879  map.liquidMapSize = 0;
880  }
881  else
882  {
883  int minX = 255, minY = 255;
884  int maxX = 0, maxY = 0;
885  maxHeight = -20000;
886  minHeight = 20000;
887  for (int y=0; y<ADT_GRID_SIZE; y++)
888  {
889  for(int x=0; x<ADT_GRID_SIZE; x++)
890  {
891  if (liquid_show[y][x])
892  {
893  if (minX > x) minX = x;
894  if (maxX < x) maxX = x;
895  if (minY > y) minY = y;
896  if (maxY < y) maxY = y;
897  float h = liquid_height[y][x];
898  if (maxHeight < h) maxHeight = h;
899  if (minHeight > h) minHeight = h;
900  }
901  else
903  }
904  }
906  map.liquidMapSize = sizeof(map_liquidHeader);
907  liquidHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_LIQUID_MAGIC);
908  liquidHeader.flags = 0;
909  liquidHeader.liquidType = 0;
910  liquidHeader.offsetX = minX;
911  liquidHeader.offsetY = minY;
912  liquidHeader.width = maxX - minX + 1 + 1;
913  liquidHeader.height = maxY - minY + 1 + 1;
914  liquidHeader.liquidLevel = minHeight;
915 
916  if (maxHeight == minHeight)
917  liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
918 
919  // Not need store if flat surface
920  if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_liquid_delta_limit)
921  liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
922 
923  if (!fullType)
924  liquidHeader.flags |= MAP_LIQUID_NO_TYPE;
925 
926  if (liquidHeader.flags & MAP_LIQUID_NO_TYPE)
927  liquidHeader.liquidType = type;
928  else
929  map.liquidMapSize += sizeof(liquid_entry) + sizeof(liquid_flags);
930 
931  if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
932  map.liquidMapSize += sizeof(float)*liquidHeader.width*liquidHeader.height;
933  }
934 
935  if (map.liquidMapOffset)
936  map.holesOffset = map.liquidMapOffset + map.liquidMapSize;
937  else
938  map.holesOffset = map.heightMapOffset + map.heightMapSize;
939 
940  if (hasHoles)
941  map.holesSize = sizeof(holes);
942  else
943  map.holesSize = 0;
944 
945  // Ok all data prepared - store it
946  std::ofstream outFile(outputPath, std::ofstream::out | std::ofstream::binary);
947  if (!outFile)
948  {
949  printf("Can't create the output file '%s'\n", outputPath.c_str());
950  return false;
951  }
952 
953  outFile.write(reinterpret_cast<const char*>(&map), sizeof(map));
954  // Store area data
955  outFile.write(reinterpret_cast<const char*>(&areaHeader), sizeof(areaHeader));
956  if (!(areaHeader.flags & MAP_AREA_NO_AREA))
957  outFile.write(reinterpret_cast<const char*>(area_ids), sizeof(area_ids));
958 
959  // Store height data
960  outFile.write(reinterpret_cast<const char*>(&heightHeader), sizeof(heightHeader));
961  if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
962  {
963  if (heightHeader.flags & MAP_HEIGHT_AS_INT16)
964  {
965  outFile.write(reinterpret_cast<const char*>(uint16_V9), sizeof(uint16_V9));
966  outFile.write(reinterpret_cast<const char*>(uint16_V8), sizeof(uint16_V8));
967  }
968  else if (heightHeader.flags & MAP_HEIGHT_AS_INT8)
969  {
970  outFile.write(reinterpret_cast<const char*>(uint8_V9), sizeof(uint8_V9));
971  outFile.write(reinterpret_cast<const char*>(uint8_V8), sizeof(uint8_V8));
972  }
973  else
974  {
975  outFile.write(reinterpret_cast<const char*>(V9), sizeof(V9));
976  outFile.write(reinterpret_cast<const char*>(V8), sizeof(V8));
977  }
978  }
979 
980  if (heightHeader.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
981  {
982  outFile.write(reinterpret_cast<char*>(flight_box_max), sizeof(flight_box_max));
983  outFile.write(reinterpret_cast<char*>(flight_box_min), sizeof(flight_box_min));
984  }
985 
986  // Store liquid data if need
987  if (map.liquidMapOffset)
988  {
989  outFile.write(reinterpret_cast<const char*>(&liquidHeader), sizeof(liquidHeader));
990  if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
991  {
992  outFile.write(reinterpret_cast<const char*>(liquid_entry), sizeof(liquid_entry));
993  outFile.write(reinterpret_cast<const char*>(liquid_flags), sizeof(liquid_flags));
994  }
995 
996  if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
997  {
998  for (int y = 0; y < liquidHeader.height; y++)
999  outFile.write(reinterpret_cast<const char*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width);
1000  }
1001  }
1002 
1003  // store hole data
1004  if (hasHoles)
1005  outFile.write(reinterpret_cast<const char*>(holes), map.holesSize);
1006 
1007  outFile.close();
1008 
1009  return true;
1010 }
float CONF_float_to_int16_limit
Definition: System.cpp:102
float ypos
Definition: adt.h:130
float selectUInt16StepStore(float maxDiff)
Definition: System.cpp:426
#define MAP_AREA_NO_AREA
Definition: System.cpp:374
Definition: adt.h:31
uint8 offsetY
Definition: Map.h:125
Definition: adt.h:32
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:433
uint8 height
Definition: Map.h:127
uint32 fourcc
Definition: Map.h:110
uint16 flags
Definition: Map.h:122
uint32 areaMapSize
Definition: Map.h:85
float CONF_float_to_int8_limit
Definition: System.cpp:101
plane max
Definition: adt.h:234
Definition: loadlib.h:80
#define ADT_GRID_SIZE
Definition: adt.h:41
Definition: adt.h:33
union adt_MCNK::@346 union_5_3_0
float gridMaxHeight
Definition: Map.h:113
uint8 offsetX
Definition: Map.h:124
#define MAP_LIQUID_NO_TYPE
Definition: System.cpp:406
FileChunk * GetChunk(std::string const &name)
Definition: loadlib.cpp:140
std::multimap< std::string, FileChunk * > chunks
Definition: loadlib.h:96
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
uint32 ix
Definition: adt.h:96
uint32 flags
Definition: Map.h:111
Definition: Map.h:96
static char const * MAP_AREA_MAGIC
Definition: System.cpp:355
uint32 fourcc
Definition: Map.h:121
#define MAP_LIQUID_NO_HEIGHT
Definition: System.cpp:407
uint8 HighResHoles[8]
Definition: adt.h:107
uint32 areaMapOffset
Definition: Map.h:84
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:438
uint32 holes
Definition: adt.h:117
#define MAP_HEIGHT_AS_INT8
Definition: System.cpp:385
Definition: adt.h:222
Definition: adt.h:156
static char const * MAP_HEIGHT_MAGIC
Definition: System.cpp:356
uint16 uint16_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:436
Definition: adtfile.h:57
uint16 gridArea
Definition: Map.h:100
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:440
#define MAP_LIQUID_TYPE_WATER
Definition: System.cpp:397
uint16_t uint16
Definition: g3dmath.h:166
adt_liquid_header * getLiquidData(int x, int y)
Definition: adt.h:170
uint16 liquidType
Definition: Map.h:123
float CONF_flat_height_delta_limit
Definition: System.cpp:103
uint8 width
Definition: Map.h:126
struct adt_MCLQ::liquid_data liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1]
float liquidLevel
Definition: Map.h:128
Definition: adt.h:48
uint64 getLiquidShowMap(adt_liquid_header *h)
Definition: adt.h:212
HANDLE CascStorage
Definition: System.cpp:69
Definition: Map.h:79
Definition: adt.h:61
Definition: Map.h:119
uint32 heightMapOffset
Definition: Map.h:86
uint32 areaid
Definition: adt.h:115
bool CONF_allow_float_to_int
Definition: System.cpp:100
uint32 flags
Definition: adt.h:95
float height_map[(ADT_CELL_SIZE+1)*(ADT_CELL_SIZE+1)+ADT_CELL_SIZE *ADT_CELL_SIZE]
Definition: adt.h:55
#define ADT_CELLS_PER_GRID
Definition: adt.h:39
uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE]
Definition: adt.h:81
uint32 holesOffset
Definition: Map.h:90
bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:442
float selectUInt8StepStore(float maxDiff)
Definition: System.cpp:421
Definition: adt.h:139
uint8 yOffset
Definition: adt.h:146
float height
Definition: adt.h:72
bool CONF_allow_height_limit
Definition: System.cpp:96
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
G3D::int16 y
Definition: Vector2int16.h:38
uint16_t uint16
Definition: Define.h:151
uint16 uint16_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:435
static char const * MAP_LIQUID_MAGIC
Definition: System.cpp:357
uint8 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8]
Definition: System.cpp:444
Definition: loadlib.h:64
uint32 liquidMapOffset
Definition: Map.h:88
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:434
uint8 width
Definition: adt.h:147
uint16 area_ids[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:431
uint32 liquidMapSize
Definition: Map.h:89
uint16 flags
Definition: Map.h:99
#define ADT_CELL_SIZE
Definition: adt.h:40
#define MAP_LIQUID_TYPE_SLIME
Definition: System.cpp:400
float gridHeight
Definition: Map.h:112
uint32 heightMapSize
Definition: Map.h:87
uint8_t uint8
Definition: g3dmath.h:164
#define MAP_HEIGHT_AS_INT16
Definition: System.cpp:384
uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:437
uint32 sizeMCLQ
Definition: adt.h:127
uint16 * LiqType
Definition: System.cpp:78
#define MAP_LIQUID_TYPE_MAGMA
Definition: System.cpp:399
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition: System.cpp:386
#define MAP_HEIGHT_NO_HEIGHT
Definition: System.cpp:383
uint32 fourcc
Definition: Map.h:98
uint16 liquidType
Definition: adt.h:141
static char const * MAP_MAGIC
Definition: System.cpp:353
float heightLevel1
Definition: adt.h:143
Definition: adt.h:30
uint8_t uint8
Definition: Define.h:152
uint8 * getLiquidLightMap(adt_liquid_header *h)
Definition: adt.h:186
static char const * MAP_VERSION_MAGIC
Definition: System.cpp:354
u_map_magic mapMagic
Definition: Map.h:81
uint8 xOffset
Definition: adt.h:145
float CONF_use_minHeight
Definition: System.cpp:97
#define const
Definition: zconf.h:217
G3D::int16 x
Definition: Vector2int16.h:37
plane min
Definition: adt.h:235
uint32 iy
Definition: adt.h:97
int16 flight_box_max[3][3]
Definition: System.cpp:446
bool loadFile(HANDLE mpq, std::string const &fileName, bool log=true)
Definition: loadlib.cpp:36
bool TransformToHighRes(uint16 lowResHoles, uint8 hiResHoles[8])
Definition: System.cpp:449
uint8 height
Definition: adt.h:148
#define MAP_LIQUID_TYPE_OCEAN
Definition: System.cpp:398
int16 flight_box_min[3][3]
Definition: System.cpp:447
uint32 holesSize
Definition: Map.h:91
u_map_magic buildMagic
Definition: Map.h:83
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:443
#define MAP_LIQUID_TYPE_DARK_WATER
Definition: System.cpp:402
u_map_magic versionMagic
Definition: Map.h:82
Definition: adt.h:88
float CONF_flat_liquid_delta_limit
Definition: System.cpp:104
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083
Definition: Map.h:108
float * getLiquidHeightMap(adt_liquid_header *h)
Definition: adt.h:177
uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:441

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreateDir ( boost::filesystem::path const path)
140 {
141  namespace fs = boost::filesystem;
142  if (fs::exists(path))
143  return;
144 
145  if (!fs::create_directory(path))
146  throw new std::runtime_error("Unable to create directory" + path.string());
147 }

+ Here is the caller graph for this function:

void ExtractDBFilesClient ( int  l)
1120 {
1121  printf("Extracting dbc/db2 files...\n");
1122 
1123  std::string outputPath = output_path;
1124  outputPath += "/dbc/";
1125 
1126  CreateDir(outputPath);
1127  outputPath += localeNames[l];
1128  outputPath += "/";
1129  CreateDir(outputPath);
1130 
1131  printf("locale %s output path %s\n", localeNames[l], outputPath.c_str());
1132 
1133  uint32 index = 0;
1134  uint32 count = 0;
1135  char const* fileName = DBFilesClientList[index];
1136  HANDLE dbcFile;
1137  while (fileName)
1138  {
1139  std::string filename = fileName;
1140  if (CascOpenFile(CascStorage, (filename = (filename + ".db2")).c_str(), WowLocaleToCascLocaleFlags[l], 0, &dbcFile) ||
1141  CascOpenFile(CascStorage, (filename = (filename.substr(0, filename.length() - 4) + ".dbc")).c_str(), WowLocaleToCascLocaleFlags[l], 0, &dbcFile))
1142  {
1143  filename = outputPath + filename.substr(filename.rfind('\\') + 1);
1144 
1145  if (!boost::filesystem::exists(filename))
1146  if (ExtractFile(dbcFile, filename))
1147  ++count;
1148 
1149  CascCloseFile(dbcFile);
1150  }
1151  else
1152  printf("Unable to open file %s in the archive for locale %s: %s\n", fileName, localeNames[l], HumanReadableCASCError(GetLastError()));
1153 
1154  fileName = DBFilesClientList[++index];
1155  }
1156 
1157  printf("Extracted %u files\n\n", count);
1158 }
void * HANDLE
Definition: CascPort.h:146
char output_path[MAX_PATH_LENGTH]
Definition: System.cpp:80
char const * DBFilesClientList[]
Definition: DBFilesClientList.h:21
uint32 WowLocaleToCascLocaleFlags[12]
Definition: System.cpp:123
HANDLE CascStorage
Definition: System.cpp:69
void CreateDir(boost::filesystem::path const &path)
Definition: System.cpp:139
uint32_t uint32
Definition: Define.h:150
int GetLastError()
Definition: Common.cpp:70
bool WINAPI CascCloseFile(HANDLE hFile)
Definition: CascOpenFile.cpp:273
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
bool WINAPI CascOpenFile(HANDLE hStorage, const char *szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:196
bool ExtractFile(HANDLE fileInArchive, std::string filename)
Definition: System.cpp:1096
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ExtractFile ( HANDLE  fileInArchive,
std::string  filename 
)
1097 {
1098  FILE* output = fopen(filename.c_str(), "wb");
1099  if (!output)
1100  {
1101  printf("Can't create the output file '%s'\n", filename.c_str());
1102  return false;
1103  }
1104 
1105  char buffer[0x10000];
1106  DWORD readBytes = 1;
1107 
1108  while (readBytes > 0)
1109  {
1110  CascReadFile(fileInArchive, buffer, sizeof(buffer), &readBytes);
1111  if (readBytes > 0)
1112  fwrite(buffer, 1, readBytes, output);
1113  }
1114 
1115  fclose(output);
1116  return true;
1117 }
#define output
Definition: wire_format_lite.h:381
unsigned int DWORD
Definition: CascPort.h:139
bool WINAPI CascReadFile(HANDLE hFile, void *lpBuffer, DWORD dwToRead, PDWORD pdwRead)
Definition: CascReadFile.cpp:459
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExtractMaps ( uint32  build)
1030 {
1031  std::string storagePath;
1032  std::string outputFileName;
1033 
1034  printf("Extracting maps...\n");
1035 
1037 
1039 
1040  std::string path = output_path;
1041  path += "/maps/";
1042  CreateDir(path);
1043 
1044  std::set<std::string> wmoList;
1045 
1046  printf("Convert map files\n");
1047  for (uint32 z = 0; z < map_count; ++z)
1048  {
1049  printf("Extract %s (%d/%u) \n", map_ids[z].name, z+1, map_count);
1050  // Loadup map grid data
1051  storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
1052  ChunkedFile wdt;
1053  if (!wdt.loadFile(CascStorage, storagePath, false))
1054  continue;
1055 
1056  ExtractWmos(wdt, wmoList);
1057 
1058  FileChunk* chunk = wdt.GetChunk("MAIN");
1059  for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
1060  {
1061  for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
1062  {
1063  if (!(chunk->As<wdt_MAIN>()->adt_list[y][x].flag & 0x1))
1064  continue;
1065 
1066  storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
1067  outputFileName = Trinity::StringFormat("%s/maps/%04u_%02u_%02u.map", output_path, map_ids[z].id, y, x);
1068  ConvertADT(storagePath, outputFileName, y, x, build);
1069 
1070  storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s_%u_%u_obj0.adt", map_ids[z].name, map_ids[z].name, x, y);
1071  ChunkedFile adtObj;
1072  if (adtObj.loadFile(CascStorage, storagePath, false))
1073  ExtractWmos(adtObj, wmoList);
1074  }
1075 
1076  // draw progress bar
1077  printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
1078  }
1079  }
1080 
1081  if (!wmoList.empty())
1082  {
1083  if (FILE* wmoListFile = fopen("wmo_list.txt", "w"))
1084  {
1085  for (std::string const& wmo : wmoList)
1086  fprintf(wmoListFile, "%s\n", wmo.c_str());
1087 
1088  fclose(wmoListFile);
1089  }
1090  }
1091 
1092  printf("\n");
1093  delete[] map_ids;
1094 }
bool ConvertADT(std::string const &inputPath, std::string const &outputPath, int, int, uint32 build)
Definition: System.cpp:464
uint32 map_count
Definition: vmapexport.cpp:73
Definition: loadlib.h:80
Definition: wdt.h:31
FileChunk * GetChunk(std::string const &name)
Definition: loadlib.cpp:140
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
void ExtractWmos(ChunkedFile &file, std::set< std::string > &wmoList)
Definition: System.cpp:1012
char output_path[MAX_PATH_LENGTH]
Definition: System.cpp:80
Definition: adtfile.h:57
struct wdt_MAIN::adtData adt_list[64][64]
T * As()
Definition: loadlib.h:74
HANDLE CascStorage
Definition: System.cpp:69
G3D::int16 z
Definition: Vector3int16.h:46
void CreateDir(boost::filesystem::path const &path)
Definition: System.cpp:139
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
Definition: loadlib.h:64
map_id * map_ids
Definition: System.cpp:77
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
uint32 flag
Definition: wdt.h:43
uint32 ReadMapDBC()
Definition: System.cpp:278
void ReadLiquidTypeTableDBC()
Definition: System.cpp:319
G3D::int16 x
Definition: Vector2int16.h:37
bool loadFile(HANDLE mpq, std::string const &fileName, bool log=true)
Definition: loadlib.cpp:36
#define WDT_MAP_SIZE
Definition: wdt.h:26
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExtractWmos ( ChunkedFile file,
std::set< std::string > &  wmoList 
)
1013 {
1014  if (FileChunk* chunk = file.GetChunk("MWMO"))
1015  {
1016  file_MWMO* wmo = chunk->As<file_MWMO>();
1017  if (wmo->size)
1018  {
1019  char* fileName = wmo->FileList;
1020  while (fileName < wmo->FileList + wmo->size)
1021  {
1022  wmoList.insert(fileName);
1023  fileName += strlen(fileName) + 1;
1024  }
1025  }
1026  }
1027 }
char FileList[1]
Definition: loadlib.h:61
FileChunk * GetChunk(std::string const &name)
Definition: loadlib.cpp:140
Definition: adtfile.h:57
Definition: loadlib.h:57
uint32 size
Definition: loadlib.h:60
Definition: loadlib.h:64

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HandleArgs ( int  argc,
char *  arg[] 
)
164 {
165  for (int c = 1; c < argc; ++c)
166  {
167  // i - input path
168  // o - output path
169  // e - extract only MAP(1)/DBC(2) - standard both(3)
170  // f - use float to int conversion
171  // h - limit minimum height
172  // b - target client build
173  if (arg[c][0] != '-')
174  Usage(arg[0]);
175 
176  switch (arg[c][1])
177  {
178  case 'i':
179  if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok
180  {
181  strncpy(input_path, arg[c++ + 1], MAX_PATH_LENGTH);
182  input_path[MAX_PATH_LENGTH - 1] = '\0';
183  }
184  else
185  Usage(arg[0]);
186  break;
187  case 'o':
188  if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok
189  {
190  strncpy(output_path, arg[c++ + 1], MAX_PATH_LENGTH);
191  output_path[MAX_PATH_LENGTH - 1] = '\0';
192  }
193  else
194  Usage(arg[0]);
195  break;
196  case 'f':
197  if (c + 1 < argc) // all ok
198  CONF_allow_float_to_int = atoi(arg[c++ + 1])!=0;
199  else
200  Usage(arg[0]);
201  break;
202  case 'e':
203  if (c + 1 < argc) // all ok
204  {
205  CONF_extract = atoi(arg[c++ + 1]);
206  if (!(CONF_extract > 0 && CONF_extract < 4))
207  Usage(arg[0]);
208  }
209  else
210  Usage(arg[0]);
211  break;
212  case 'l':
213  if (c + 1 < argc) // all ok
214  {
215  for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
216  if (!strcmp(arg[c + 1], localeNames[i]))
217  CONF_Locale = 1 << i;
218  ++c;
219  }
220  else
221  Usage(arg[0]);
222  break;
223  case 'h':
224  Usage(arg[0]);
225  break;
226  default:
227  break;
228  }
229  }
230 }
#define MAX_PATH_LENGTH
Definition: System.cpp:79
char input_path[MAX_PATH_LENGTH]
Definition: System.cpp:81
char output_path[MAX_PATH_LENGTH]
Definition: System.cpp:80
uint32 CONF_Locale
Definition: System.cpp:106
bool CONF_allow_float_to_int
Definition: System.cpp:100
int CONF_extract
Definition: System.cpp:93
uint32_t uint32
Definition: Define.h:150
void Usage(char const *prg)
Definition: System.cpp:149
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
Definition: Common.h:130

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int main ( int  argc,
char *  arg[] 
)
1181 {
1182  printf("Map & DBC Extractor\n");
1183  printf("===================\n");
1184 
1185  boost::filesystem::path current(boost::filesystem::current_path());
1186  strcpy(input_path, current.string().c_str());
1187  strcpy(output_path, current.string().c_str());
1188 
1189  HandleArgs(argc, arg);
1190 
1191  int FirstLocale = -1;
1192  uint32 build = 0;
1193 
1194  for (int i = 0; i < TOTAL_LOCALES; ++i)
1195  {
1196  if (CONF_Locale && !(CONF_Locale & (1 << i)))
1197  continue;
1198 
1199  if (i == LOCALE_none)
1200  continue;
1201 
1202  if (!OpenCascStorage(i))
1203  continue;
1204 
1205  if ((CONF_extract & EXTRACT_DBC) == 0)
1206  {
1207  FirstLocale = i;
1208  build = ReadBuild(i);
1209  if (!build)
1210  {
1212  continue;
1213  }
1214 
1215  printf("Detected client build: %u\n\n", build);
1216  break;
1217  }
1218 
1219  //Extract DBC files
1220  uint32 tempBuild = ReadBuild(i);
1221  if (!tempBuild)
1222  {
1224  continue;
1225  }
1226 
1227  printf("Detected client build %u for locale %s\n\n", tempBuild, localeNames[i]);
1230 
1231  if (FirstLocale < 0)
1232  {
1233  FirstLocale = i;
1234  build = tempBuild;
1235  }
1236  }
1237 
1238  if (FirstLocale < 0)
1239  {
1240  printf("No locales detected\n");
1241  return 0;
1242  }
1243 
1244  if (CONF_extract & EXTRACT_MAP)
1245  {
1246  OpenCascStorage(FirstLocale);
1247  ExtractMaps(build);
1249  }
1250 
1251  return 0;
1252 }
Definition: System.cpp:88
void ExtractMaps(uint32 build)
Definition: System.cpp:1029
Definition: Common.h:126
char input_path[MAX_PATH_LENGTH]
Definition: System.cpp:81
char output_path[MAX_PATH_LENGTH]
Definition: System.cpp:80
HANDLE CascStorage
Definition: System.cpp:69
bool WINAPI CascCloseStorage(HANDLE hStorage)
Definition: CascOpenStorage.cpp:1133
uint32 CONF_Locale
Definition: System.cpp:106
void HandleArgs(int argc, char *arg[])
Definition: System.cpp:163
Definition: System.cpp:89
int CONF_extract
Definition: System.cpp:93
uint32_t uint32
Definition: Define.h:150
bool OpenCascStorage(int locale)
Definition: System.cpp:1160
uint32 ReadBuild(int locale)
Definition: System.cpp:232
void ExtractDBFilesClient(int l)
Definition: System.cpp:1119
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
Definition: Common.h:130
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

bool OpenCascStorage ( int  locale)
1161 {
1162  try
1163  {
1164  boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
1165  if (!CascOpenStorage(storage_dir.string().c_str(), WowLocaleToCascLocaleFlags[locale], &CascStorage))
1166  {
1167  printf("error opening casc storage '%s' locale %s: %s\n", storage_dir.string().c_str(), localeNames[locale], HumanReadableCASCError(GetLastError()));
1168  return false;
1169  }
1170  printf("opened casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]);
1171  return true;
1172  }
1173  catch (boost::filesystem::filesystem_error& error)
1174  {
1175  printf("error opening casc storage : %s\n", error.what());
1176  return false;
1177  }
1178 }
char input_path[MAX_PATH_LENGTH]
Definition: System.cpp:81
uint32 WowLocaleToCascLocaleFlags[12]
Definition: System.cpp:123
HANDLE CascStorage
Definition: System.cpp:69
int GetLastError()
Definition: Common.cpp:70
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
bool WINAPI CascOpenStorage(const TCHAR *szDataPath, DWORD dwLocaleMask, HANDLE *phStorage)
Definition: CascOpenStorage.cpp:1011
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 ReadBuild ( int  locale)
233 {
234  // include build info file also
235  std::string filename = Trinity::StringFormat("component.wow-%s.txt", localeNames[locale]);
236  //printf("Read %s file... ", filename.c_str());
237 
238  HANDLE dbcFile;
239  if (!CascOpenFile(CascStorage, filename.c_str(), CASC_LOCALE_ALL, 0, &dbcFile))
240  {
241  printf("Locale %s not installed.\n", localeNames[locale]);
242  return 0;
243  }
244 
245  char buff[512];
246  DWORD readBytes = 0;
247  CascReadFile(dbcFile, buff, 512, &readBytes);
248  if (!readBytes)
249  {
250  printf("Fatal error: Not found %s file!\n", filename.c_str());
251  exit(1);
252  }
253 
254  std::string text = std::string(buff, readBytes);
255  CascCloseFile(dbcFile);
256 
257  size_t pos = text.find("version=\"");
258  size_t pos1 = pos + strlen("version=\"");
259  size_t pos2 = text.find("\"", pos1);
260  if (pos == text.npos || pos2 == text.npos || pos1 >= pos2)
261  {
262  printf("Fatal error: Invalid %s file format!\n", filename.c_str());
263  exit(1);
264  }
265 
266  std::string build_str = text.substr(pos1,pos2-pos1);
267 
268  int build = atoi(build_str.c_str());
269  if (build <= 0)
270  {
271  printf("Fatal error: Invalid %s file format!\n", filename.c_str());
272  exit(1);
273  }
274 
275  return build;
276 }
#define CASC_LOCALE_ALL
Definition: CascLib.h:64
void * HANDLE
Definition: CascPort.h:146
HANDLE CascStorage
Definition: System.cpp:69
unsigned int DWORD
Definition: CascPort.h:139
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
bool WINAPI CascCloseFile(HANDLE hFile)
Definition: CascOpenFile.cpp:273
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:21
bool WINAPI CascReadFile(HANDLE hFile, void *lpBuffer, DWORD dwToRead, PDWORD pdwRead)
Definition: CascReadFile.cpp:459
bool WINAPI CascOpenFile(HANDLE hStorage, const char *szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:196
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ReadLiquidTypeTableDBC ( )
320 {
321  printf("Read LiquidType.dbc file...");
322  HANDLE dbcFile;
323  if (!CascOpenFile(CascStorage, "DBFilesClient\\LiquidType.dbc", CASC_LOCALE_NONE, 0, &dbcFile))
324  {
325  printf("Fatal error: Cannot find LiquidType.dbc in archive! %s\n", HumanReadableCASCError(GetLastError()));
326  exit(1);
327  }
328 
329  DBCFile dbc(dbcFile);
330  if(!dbc.open())
331  {
332  printf("Fatal error: Invalid LiquidType.dbc file format!\n");
333  exit(1);
334  }
335 
336  size_t liqTypeCount = dbc.getRecordCount();
337  size_t liqTypeMaxId = dbc.getMaxId();
338  LiqType = new uint16[liqTypeMaxId + 1];
339  memset(LiqType, 0xff, (liqTypeMaxId + 1) * sizeof(uint16));
340 
341  for(uint32 x = 0; x < liqTypeCount; ++x)
342  LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
343 
344  CascCloseFile(dbcFile);
345  printf("Done! (" SZFMTD " LiqTypes loaded)\n", liqTypeCount);
346 }
void * HANDLE
Definition: CascPort.h:146
Definition: dbcfile.h:25
#define SZFMTD
Definition: Define.h:143
#define CASC_LOCALE_NONE
Definition: CascLib.h:65
HANDLE CascStorage
Definition: System.cpp:69
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
int GetLastError()
Definition: Common.cpp:70
bool WINAPI CascCloseFile(HANDLE hFile)
Definition: CascOpenFile.cpp:273
uint16 * LiqType
Definition: System.cpp:78
G3D::int16 x
Definition: Vector2int16.h:37
bool WINAPI CascOpenFile(HANDLE hStorage, const char *szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:196
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 ReadMapDBC ( )
279 {
280  printf("Read Map.dbc file... ");
281 
282  HANDLE dbcFile;
283  if (!CascOpenFile(CascStorage, "DBFilesClient\\Map.dbc", CASC_LOCALE_NONE, 0, &dbcFile))
284  {
285  printf("Fatal error: Cannot find Map.dbc in archive! %s\n", HumanReadableCASCError(GetLastError()));
286  exit(1);
287  }
288 
289  DBCFile dbc(dbcFile);
290  if (!dbc.open())
291  {
292  printf("Fatal error: Invalid Map.dbc file format!\n");
293  exit(1);
294  }
295 
296  size_t map_count = dbc.getRecordCount();
297  map_ids = new map_id[map_count];
298  for(uint32 x = 0; x < map_count; ++x)
299  {
300  map_ids[x].id = dbc.getRecord(x).getUInt(0);
301 
302  const char* map_name = dbc.getRecord(x).getString(1);
303  size_t max_map_name_length = sizeof(map_ids[x].name);
304  if (strlen(map_name) >= max_map_name_length)
305  {
306  printf("Fatal error: Map name too long!\n");
307  exit(1);
308  }
309 
310  strncpy(map_ids[x].name, map_name, max_map_name_length);
311  map_ids[x].name[max_map_name_length - 1] = '\0';
312  }
313 
314  CascCloseFile(dbcFile);
315  printf("Done! (" SZFMTD " maps loaded)\n", map_count);
316  return map_count;
317 }
void * HANDLE
Definition: CascPort.h:146
Definition: dbcfile.h:25
uint32 map_count
Definition: vmapexport.cpp:73
#define SZFMTD
Definition: Define.h:143
char name[64]
Definition: System.cpp:73
#define CASC_LOCALE_NONE
Definition: CascLib.h:65
uint32 id
Definition: System.cpp:74
Definition: System.cpp:71
HANDLE CascStorage
Definition: System.cpp:69
uint32_t uint32
Definition: Define.h:150
map_id * map_ids
Definition: System.cpp:77
int GetLastError()
Definition: Common.cpp:70
bool WINAPI CascCloseFile(HANDLE hFile)
Definition: CascOpenFile.cpp:273
G3D::int16 x
Definition: Vector2int16.h:37
bool WINAPI CascOpenFile(HANDLE hStorage, const char *szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:196
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float selectUInt16StepStore ( float  maxDiff)
427 {
428  return 65535 / maxDiff;
429 }

+ Here is the caller graph for this function:

float selectUInt8StepStore ( float  maxDiff)
422 {
423  return 255 / maxDiff;
424 }

+ Here is the caller graph for this function:

bool TransformToHighRes ( uint16  lowResHoles,
uint8  hiResHoles[8] 
)
450 {
451  for (uint8 i = 0; i < 8; i++)
452  {
453  for (uint8 j = 0; j < 8; j++)
454  {
455  int32 holeIdxL = (i / 2) * 4 + (j / 2);
456  if (((lowResHoles >> holeIdxL) & 1) == 1)
457  hiResHoles[i] |= (1 << j);
458  }
459  }
460 
461  return *((uint64*)hiResHoles) != 0;
462 }
int32_t int32
Definition: Define.h:146
uint64_t uint64
Definition: Define.h:149
uint8_t uint8
Definition: Define.h:152

+ Here is the caller graph for this function:

void Usage ( char const prg)
150 {
151  printf(
152  "Usage:\n"\
153  "%s -[var] [value]\n"\
154  "-i set input path (max %d characters)\n"\
155  "-o set output path (max %d characters)\n"\
156  "-e extract only MAP(1)/DBC(2) - standard: both(3)\n"\
157  "-f height stored as int (less map size but lost some accuracy) 1 by default\n"\
158  "-l dbc locale\n"\
159  "Example: %s -f 0 -i \"c:\\games\\game\"\n", prg, MAX_PATH_LENGTH - 1, MAX_PATH_LENGTH - 1, prg);
160  exit(1);
161 }
#define MAX_PATH_LENGTH
Definition: System.cpp:79
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

char const* CascLocaleNames[CASC_LOCALES_COUNT]
Initial value:
=
{
"none", "enUS",
"koKR", "unknown",
"frFR", "deDE",
"zhCN", "esES",
"zhTW", "enGB",
"enCN", "enTW",
"esMX", "ruRU",
"ptBR", "itIT",
"ptPT"
}
HANDLE CascStorage = NULL
bool CONF_allow_float_to_int = true
bool CONF_allow_height_limit = true
int CONF_extract = EXTRACT_MAP | EXTRACT_DBC
float CONF_flat_height_delta_limit = 0.005f
float CONF_flat_liquid_delta_limit = 0.001f
float CONF_float_to_int16_limit = 2048.0f
float CONF_float_to_int8_limit = 2.0f
uint32 CONF_Locale = 0
float CONF_use_minHeight = -500.0f
int16 flight_box_max[3][3]
int16 flight_box_min[3][3]
char input_path[MAX_PATH_LENGTH]
uint16* LiqType
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
char const* MAP_AREA_MAGIC = "AREA"
static
char const* MAP_HEIGHT_MAGIC = "MHGT"
static
map_id* map_ids
char const* MAP_LIQUID_MAGIC = "MLIQ"
static
char const* MAP_MAGIC = "MAPS"
static
char const* MAP_VERSION_MAGIC = "v1.8"
static
char output_path[MAX_PATH_LENGTH]
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
uint32 WowLocaleToCascLocaleFlags[12]
Initial value:
=
{
0,
}
#define CASC_LOCALE_ESES
Definition: CascLib.h:73
#define CASC_LOCALE_DEDE
Definition: CascLib.h:71
#define CASC_LOCALE_KOKR
Definition: CascLib.h:68
#define CASC_LOCALE_FRFR
Definition: CascLib.h:70
#define CASC_LOCALE_ENUS
Definition: CascLib.h:67
#define CASC_LOCALE_ZHCN
Definition: CascLib.h:72
#define CASC_LOCALE_ZHTW
Definition: CascLib.h:74
#define CASC_LOCALE_ESMX
Definition: CascLib.h:78
#define CASC_LOCALE_RURU
Definition: CascLib.h:79
#define CASC_LOCALE_ITIT
Definition: CascLib.h:81
#define CASC_LOCALE_PTBR
Definition: CascLib.h:80
#define CASC_LOCALE_ENGB
Definition: CascLib.h:75
#define CASC_LOCALE_PTPT
Definition: CascLib.h:82