From 7bf807aee4603896cfc15adc85944654a1ea81c8 Mon Sep 17 00:00:00 2001 From: click Date: Wed, 23 Jun 2010 10:16:40 +0200 Subject: Kill off the issues with the map/dbcextractors - and a thanks to imbecile@lavabit for the comment about loadlib.h Just now the intent was to get it sorted out, as we might merge the tools into one "datatool" for all of this stuff. --HG-- branch : trunk rename : src/tools/map_extractor/loadlib/adt.cpp => src/tools/map_extractor/adt.cpp rename : src/tools/map_extractor/loadlib/adt.h => src/tools/map_extractor/adt.h rename : src/tools/map_extractor/loadlib/loadlib.cpp => src/tools/map_extractor/loadlib.cpp rename : src/tools/map_extractor/loadlib/wdt.cpp => src/tools/map_extractor/wdt.cpp rename : src/tools/map_extractor/loadlib/wdt.h => src/tools/map_extractor/wdt.h --- src/tools/map_extractor/CMakeLists.txt | 38 +--- src/tools/map_extractor/System.cpp | 4 +- src/tools/map_extractor/adt.cpp | 131 +++++++++++++ src/tools/map_extractor/adt.h | 289 ++++++++++++++++++++++++++++ src/tools/map_extractor/loadlib.cpp | 65 +++++++ src/tools/map_extractor/loadlib/adt.cpp | 131 ------------- src/tools/map_extractor/loadlib/adt.h | 289 ---------------------------- src/tools/map_extractor/loadlib/loadlib.cpp | 65 ------- src/tools/map_extractor/loadlib/loadlib.h | 26 +-- src/tools/map_extractor/loadlib/wdt.cpp | 62 ------ src/tools/map_extractor/loadlib/wdt.h | 68 ------- src/tools/map_extractor/wdt.cpp | 62 ++++++ src/tools/map_extractor/wdt.h | 68 +++++++ 13 files changed, 634 insertions(+), 664 deletions(-) mode change 100644 => 100755 src/tools/map_extractor/System.cpp create mode 100644 src/tools/map_extractor/adt.cpp create mode 100644 src/tools/map_extractor/adt.h create mode 100644 src/tools/map_extractor/loadlib.cpp delete mode 100644 src/tools/map_extractor/loadlib/adt.cpp delete mode 100644 src/tools/map_extractor/loadlib/adt.h delete mode 100644 src/tools/map_extractor/loadlib/loadlib.cpp delete mode 100644 src/tools/map_extractor/loadlib/wdt.cpp delete mode 100644 src/tools/map_extractor/loadlib/wdt.h create mode 100644 src/tools/map_extractor/wdt.cpp create mode 100644 src/tools/map_extractor/wdt.h (limited to 'src') diff --git a/src/tools/map_extractor/CMakeLists.txt b/src/tools/map_extractor/CMakeLists.txt index ce5e54ac4f0..a18ee7cd517 100644 --- a/src/tools/map_extractor/CMakeLists.txt +++ b/src/tools/map_extractor/CMakeLists.txt @@ -10,41 +10,11 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. file(GLOB sources *.cpp) -file(GLOB loadlib_sources loadlib/*.cpp) include_directories ( ${CMAKE_SOURCE_DIR}/src/server/shared - ${CMAKE_SOURCE_DIR}/externals/libmpq ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/loadlib -) - -link_directories( - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq - ${CMAKE_CURRENT_SOURCE_DIR}}/loadlib -) - -add_library(loadlib - ${loadlib_sources} -) - -if(NOT UNIX) - target_link_libraries(loadlib - zlib - ) -else() - target_link_libraries(loadlib - ${ZLIB_LIBRARIES} - ) -endif() - -add_library(libmpq - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq/common.c - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq/explode.c - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq/extract.c - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq/huffman.c - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq/mpq.c - ${CMAKE_SOURCE_DIR}/externals/libmpq/libmpq/wave.c + ${CMAKE_CURRENT_SOURCE_DIR}/loadlib ) add_executable(mapextractor @@ -53,14 +23,12 @@ add_executable(mapextractor if(WIN32) target_link_libraries(mapextractor - libmpq - loadlib + mpq bzip2 ) else() target_link_libraries(mapextractor - libmpq - loadlib + mpq ${BZIP2_LIBRARIES} ) endif() diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp old mode 100644 new mode 100755 index 3a328e91bf4..2640b65d8b1 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -14,8 +14,8 @@ #include "dbcfile.h" #include "mpq_libmpq04.h" -#include "loadlib/adt.h" -#include "loadlib/wdt.h" +#include "adt.h" +#include "wdt.h" #include #if defined( __GNUC__ ) diff --git a/src/tools/map_extractor/adt.cpp b/src/tools/map_extractor/adt.cpp new file mode 100644 index 00000000000..fde70681113 --- /dev/null +++ b/src/tools/map_extractor/adt.cpp @@ -0,0 +1,131 @@ +#define _CRT_SECURE_NO_DEPRECATE + +#include "adt.h" + +// Helper +int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888}; +int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000}; + +bool isHole(int holes, int i, int j) +{ + int testi = i / 2; + int testj = j / 4; + if(testi > 3) testi = 3; + if(testj > 3) testj = 3; + return (holes & holetab_h[testi] & holetab_v[testj]) != 0; +} + +// +// Adt file loader class +// +ADT_file::ADT_file() +{ + a_grid = 0; +} + +ADT_file::~ADT_file() +{ + free(); +} + +void ADT_file::free() +{ + a_grid = 0; + FileLoader::free(); +} + +// +// Adt file check function +// +bool ADT_file::prepareLoadedData() +{ + // Check parent + if (!FileLoader::prepareLoadedData()) + return false; + + // Check and prepare MHDR + a_grid = (adt_MHDR *)(GetData()+8+version->size); + if (!a_grid->prepareLoadedData()) + return false; + + return true; +} + +bool adt_MHDR::prepareLoadedData() +{ + if (fcc != 'MHDR') + return false; + + if (size!=sizeof(adt_MHDR)-8) + return false; + + // Check and prepare MCIN + if (offsMCIN && !getMCIN()->prepareLoadedData()) + return false; + + // Check and prepare MH2O + if (offsMH2O && !getMH2O()->prepareLoadedData()) + return false; + + return true; +} + +bool adt_MCIN::prepareLoadedData() +{ + if (fcc != 'MCIN') + return false; + + // Check cells data + for (int i=0; iprepareLoadedData()) + return false; + + return true; +} + +bool adt_MH2O::prepareLoadedData() +{ + if (fcc != 'MH2O') + return false; + + // Check liquid data +// for (int i=0; iprepareLoadedData()) + return false; + // Check liquid data + if (offsMCLQ && !getMCLQ()->prepareLoadedData()) + return false; + + return true; +} + +bool adt_MCVT::prepareLoadedData() +{ + if (fcc != 'MCVT') + return false; + + if (size != sizeof(adt_MCVT)-8) + return false; + + return true; +} + +bool adt_MCLQ::prepareLoadedData() +{ + if (fcc != 'MCLQ') + return false; + + return true; +} \ No newline at end of file diff --git a/src/tools/map_extractor/adt.h b/src/tools/map_extractor/adt.h new file mode 100644 index 00000000000..725c5b994ee --- /dev/null +++ b/src/tools/map_extractor/adt.h @@ -0,0 +1,289 @@ +#ifndef ADT_H +#define ADT_H + +#include "loadlib.h" + +#define TILESIZE (533.33333f) +#define CHUNKSIZE ((TILESIZE) / 16.0f) +#define UNITSIZE (CHUNKSIZE / 8.0f) + +enum LiquidType +{ + LIQUID_TYPE_WATER = 0, + LIQUID_TYPE_OCEAN = 1, + LIQUID_TYPE_MAGMA = 2, + LIQUID_TYPE_SLIME = 3 +}; + +//************************************************************************************** +// ADT file class +//************************************************************************************** +#define ADT_CELLS_PER_GRID 16 +#define ADT_CELL_SIZE 8 +#define ADT_GRID_SIZE (ADT_CELLS_PER_GRID*ADT_CELL_SIZE) + +// +// Adt file height map chunk +// +class adt_MCVT +{ + 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]; + + bool prepareLoadedData(); +}; + +// +// Adt file liquid map chunk (old) +// +class adt_MCLQ +{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; + uint32 size; +public: + float height1; + float height2; + struct liquid_data{ + uint32 light; + float height; + } liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1]; + + // 1<<0 - ochen + // 1<<1 - lava/slime + // 1<<2 - water + // 1<<6 - all water + // 1<<7 - dark water + // == 0x0F - not show liquid + uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE]; + uint8 data[84]; + bool prepareLoadedData(); +}; + +// +// Adt file cell chunk +// +class adt_MCNK +{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; + uint32 size; +public: + uint32 flags; + uint32 ix; + uint32 iy; + uint32 nLayers; + uint32 nDoodadRefs; + uint32 offsMCVT; // height map + uint32 offsMCNR; // Normal vectors for each vertex + uint32 offsMCLY; // Texture layer definitions + uint32 offsMCRF; // A list of indices into the parent file's MDDF chunk + uint32 offsMCAL; // Alpha maps for additional texture layers + uint32 sizeMCAL; + uint32 offsMCSH; // Shadow map for static shadows on the terrain + uint32 sizeMCSH; + uint32 areaid; + uint32 nMapObjRefs; + uint32 holes; + uint16 s[2]; + uint32 data1; + uint32 data2; + uint32 data3; + uint32 predTex; + uint32 nEffectDoodad; + uint32 offsMCSE; + uint32 nSndEmitters; + uint32 offsMCLQ; // Liqid level (old) + uint32 sizeMCLQ; // + float zpos; + float xpos; + float ypos; + uint32 offsMCCV; // offsColorValues in WotLK + uint32 props; + uint32 effectId; + + bool prepareLoadedData(); + adt_MCVT *getMCVT() + { + if (offsMCVT) + return (adt_MCVT *)((uint8 *)this + offsMCVT); + return 0; + } + adt_MCLQ *getMCLQ() + { + if (offsMCLQ) + return (adt_MCLQ *)((uint8 *)this + offsMCLQ); + return 0; + } +}; + +// +// Adt file grid chunk +// +class adt_MCIN +{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; + uint32 size; +public: + struct adt_CELLS{ + uint32 offsMCNK; + uint32 size; + uint32 flags; + uint32 asyncId; + } cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; + + bool prepareLoadedData(); + // offset from begin file (used this-84) + adt_MCNK *getMCNK(int x, int y) + { + if (cells[x][y].offsMCNK) + return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84); + return 0; + } +}; + +#define ADT_LIQUID_HEADER_FULL_LIGHT 0x01 +#define ADT_LIQUID_HEADER_NO_HIGHT 0x02 + +struct adt_liquid_header{ + uint16 liquidType; // Index from LiquidType.dbc + uint16 formatFlags; + float heightLevel1; + float heightLevel2; + uint8 xOffset; + uint8 yOffset; + uint8 width; + uint8 height; + uint32 offsData2a; + uint32 offsData2b; +}; + +// +// Adt file liquid data chunk (new) +// +class adt_MH2O +{ +public: + union{ + uint32 fcc; + char fcc_txt[4]; + }; + uint32 size; + + struct adt_LIQUID{ + uint32 offsData1; + uint32 used; + uint32 offsData2; + } liquid[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; + + bool prepareLoadedData(); + + 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 0; + } + + 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 0; + } + + uint8 *getLiquidLightMap(adt_liquid_header *h) + { + 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 0; + } + + uint32 *getLiquidFullLightMap(adt_liquid_header *h) + { + 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 0; + } + + uint64 getLiquidShowMap(adt_liquid_header *h) + { + if (h->offsData2a) + return *((uint64 *)((uint8*)this + 8 + h->offsData2a)); + else + return 0xFFFFFFFFFFFFFFFFLL; + } + +}; + +// +// Adt file header chunk +// +class adt_MHDR +{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; + uint32 size; + + uint32 pad; + uint32 offsMCIN; // MCIN + uint32 offsTex; // MTEX + uint32 offsModels; // MMDX + uint32 offsModelsIds; // MMID + uint32 offsMapObejcts; // MWMO + uint32 offsMapObejctsIds; // MWID + uint32 offsDoodsDef; // MDDF + uint32 offsObjectsDef; // MODF + uint32 offsMFBO; // MFBO + uint32 offsMH2O; // MH2O + uint32 data1; + uint32 data2; + uint32 data3; + uint32 data4; + uint32 data5; +public: + bool prepareLoadedData(); + adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);} + adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;} + +}; + +class ADT_file : public FileLoader{ +public: + bool prepareLoadedData(); + ADT_file(); + ~ADT_file(); + void free(); + + adt_MHDR *a_grid; +}; + +#endif diff --git a/src/tools/map_extractor/loadlib.cpp b/src/tools/map_extractor/loadlib.cpp new file mode 100644 index 00000000000..465eb04083f --- /dev/null +++ b/src/tools/map_extractor/loadlib.cpp @@ -0,0 +1,65 @@ +#define _CRT_SECURE_NO_DEPRECATE + +#include "loadlib.h" +#include "mpq_libmpq04.h" +#include + +class MPQFile; + +FileLoader::FileLoader() +{ + data = 0; + data_size = 0; + version = 0; +} + +FileLoader::~FileLoader() +{ + free(); +} + +bool FileLoader::loadFile(char *filename, bool log) +{ + free(); + MPQFile mf(filename); + if(mf.isEof()) + { + if (log) + printf("No such file %s\n", filename); + return false; + } + + data_size = mf.getSize(); + + data = new uint8 [data_size]; + if (data) + { + mf.read(data, data_size); + mf.close(); + if (prepareLoadedData()) + return true; + } + printf("Error loading %s", filename); + mf.close(); + free(); + return false; +} + +bool FileLoader::prepareLoadedData() +{ + // Check version + version = (file_MVER *) data; + if (version->fcc != 'MVER') + return false; + if (version->ver != FILE_FORMAT_VERSION) + return false; + return true; +} + +void FileLoader::free() +{ + if (data) delete[] data; + data = 0; + data_size = 0; + version = 0; +} diff --git a/src/tools/map_extractor/loadlib/adt.cpp b/src/tools/map_extractor/loadlib/adt.cpp deleted file mode 100644 index fde70681113..00000000000 --- a/src/tools/map_extractor/loadlib/adt.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#define _CRT_SECURE_NO_DEPRECATE - -#include "adt.h" - -// Helper -int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888}; -int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000}; - -bool isHole(int holes, int i, int j) -{ - int testi = i / 2; - int testj = j / 4; - if(testi > 3) testi = 3; - if(testj > 3) testj = 3; - return (holes & holetab_h[testi] & holetab_v[testj]) != 0; -} - -// -// Adt file loader class -// -ADT_file::ADT_file() -{ - a_grid = 0; -} - -ADT_file::~ADT_file() -{ - free(); -} - -void ADT_file::free() -{ - a_grid = 0; - FileLoader::free(); -} - -// -// Adt file check function -// -bool ADT_file::prepareLoadedData() -{ - // Check parent - if (!FileLoader::prepareLoadedData()) - return false; - - // Check and prepare MHDR - a_grid = (adt_MHDR *)(GetData()+8+version->size); - if (!a_grid->prepareLoadedData()) - return false; - - return true; -} - -bool adt_MHDR::prepareLoadedData() -{ - if (fcc != 'MHDR') - return false; - - if (size!=sizeof(adt_MHDR)-8) - return false; - - // Check and prepare MCIN - if (offsMCIN && !getMCIN()->prepareLoadedData()) - return false; - - // Check and prepare MH2O - if (offsMH2O && !getMH2O()->prepareLoadedData()) - return false; - - return true; -} - -bool adt_MCIN::prepareLoadedData() -{ - if (fcc != 'MCIN') - return false; - - // Check cells data - for (int i=0; iprepareLoadedData()) - return false; - - return true; -} - -bool adt_MH2O::prepareLoadedData() -{ - if (fcc != 'MH2O') - return false; - - // Check liquid data -// for (int i=0; iprepareLoadedData()) - return false; - // Check liquid data - if (offsMCLQ && !getMCLQ()->prepareLoadedData()) - return false; - - return true; -} - -bool adt_MCVT::prepareLoadedData() -{ - if (fcc != 'MCVT') - return false; - - if (size != sizeof(adt_MCVT)-8) - return false; - - return true; -} - -bool adt_MCLQ::prepareLoadedData() -{ - if (fcc != 'MCLQ') - return false; - - return true; -} \ No newline at end of file diff --git a/src/tools/map_extractor/loadlib/adt.h b/src/tools/map_extractor/loadlib/adt.h deleted file mode 100644 index 725c5b994ee..00000000000 --- a/src/tools/map_extractor/loadlib/adt.h +++ /dev/null @@ -1,289 +0,0 @@ -#ifndef ADT_H -#define ADT_H - -#include "loadlib.h" - -#define TILESIZE (533.33333f) -#define CHUNKSIZE ((TILESIZE) / 16.0f) -#define UNITSIZE (CHUNKSIZE / 8.0f) - -enum LiquidType -{ - LIQUID_TYPE_WATER = 0, - LIQUID_TYPE_OCEAN = 1, - LIQUID_TYPE_MAGMA = 2, - LIQUID_TYPE_SLIME = 3 -}; - -//************************************************************************************** -// ADT file class -//************************************************************************************** -#define ADT_CELLS_PER_GRID 16 -#define ADT_CELL_SIZE 8 -#define ADT_GRID_SIZE (ADT_CELLS_PER_GRID*ADT_CELL_SIZE) - -// -// Adt file height map chunk -// -class adt_MCVT -{ - 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]; - - bool prepareLoadedData(); -}; - -// -// Adt file liquid map chunk (old) -// -class adt_MCLQ -{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; - uint32 size; -public: - float height1; - float height2; - struct liquid_data{ - uint32 light; - float height; - } liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1]; - - // 1<<0 - ochen - // 1<<1 - lava/slime - // 1<<2 - water - // 1<<6 - all water - // 1<<7 - dark water - // == 0x0F - not show liquid - uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE]; - uint8 data[84]; - bool prepareLoadedData(); -}; - -// -// Adt file cell chunk -// -class adt_MCNK -{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; - uint32 size; -public: - uint32 flags; - uint32 ix; - uint32 iy; - uint32 nLayers; - uint32 nDoodadRefs; - uint32 offsMCVT; // height map - uint32 offsMCNR; // Normal vectors for each vertex - uint32 offsMCLY; // Texture layer definitions - uint32 offsMCRF; // A list of indices into the parent file's MDDF chunk - uint32 offsMCAL; // Alpha maps for additional texture layers - uint32 sizeMCAL; - uint32 offsMCSH; // Shadow map for static shadows on the terrain - uint32 sizeMCSH; - uint32 areaid; - uint32 nMapObjRefs; - uint32 holes; - uint16 s[2]; - uint32 data1; - uint32 data2; - uint32 data3; - uint32 predTex; - uint32 nEffectDoodad; - uint32 offsMCSE; - uint32 nSndEmitters; - uint32 offsMCLQ; // Liqid level (old) - uint32 sizeMCLQ; // - float zpos; - float xpos; - float ypos; - uint32 offsMCCV; // offsColorValues in WotLK - uint32 props; - uint32 effectId; - - bool prepareLoadedData(); - adt_MCVT *getMCVT() - { - if (offsMCVT) - return (adt_MCVT *)((uint8 *)this + offsMCVT); - return 0; - } - adt_MCLQ *getMCLQ() - { - if (offsMCLQ) - return (adt_MCLQ *)((uint8 *)this + offsMCLQ); - return 0; - } -}; - -// -// Adt file grid chunk -// -class adt_MCIN -{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; - uint32 size; -public: - struct adt_CELLS{ - uint32 offsMCNK; - uint32 size; - uint32 flags; - uint32 asyncId; - } cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; - - bool prepareLoadedData(); - // offset from begin file (used this-84) - adt_MCNK *getMCNK(int x, int y) - { - if (cells[x][y].offsMCNK) - return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84); - return 0; - } -}; - -#define ADT_LIQUID_HEADER_FULL_LIGHT 0x01 -#define ADT_LIQUID_HEADER_NO_HIGHT 0x02 - -struct adt_liquid_header{ - uint16 liquidType; // Index from LiquidType.dbc - uint16 formatFlags; - float heightLevel1; - float heightLevel2; - uint8 xOffset; - uint8 yOffset; - uint8 width; - uint8 height; - uint32 offsData2a; - uint32 offsData2b; -}; - -// -// Adt file liquid data chunk (new) -// -class adt_MH2O -{ -public: - union{ - uint32 fcc; - char fcc_txt[4]; - }; - uint32 size; - - struct adt_LIQUID{ - uint32 offsData1; - uint32 used; - uint32 offsData2; - } liquid[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; - - bool prepareLoadedData(); - - 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 0; - } - - 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 0; - } - - uint8 *getLiquidLightMap(adt_liquid_header *h) - { - 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 0; - } - - uint32 *getLiquidFullLightMap(adt_liquid_header *h) - { - 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 0; - } - - uint64 getLiquidShowMap(adt_liquid_header *h) - { - if (h->offsData2a) - return *((uint64 *)((uint8*)this + 8 + h->offsData2a)); - else - return 0xFFFFFFFFFFFFFFFFLL; - } - -}; - -// -// Adt file header chunk -// -class adt_MHDR -{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; - uint32 size; - - uint32 pad; - uint32 offsMCIN; // MCIN - uint32 offsTex; // MTEX - uint32 offsModels; // MMDX - uint32 offsModelsIds; // MMID - uint32 offsMapObejcts; // MWMO - uint32 offsMapObejctsIds; // MWID - uint32 offsDoodsDef; // MDDF - uint32 offsObjectsDef; // MODF - uint32 offsMFBO; // MFBO - uint32 offsMH2O; // MH2O - uint32 data1; - uint32 data2; - uint32 data3; - uint32 data4; - uint32 data5; -public: - bool prepareLoadedData(); - adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);} - adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;} - -}; - -class ADT_file : public FileLoader{ -public: - bool prepareLoadedData(); - ADT_file(); - ~ADT_file(); - void free(); - - adt_MHDR *a_grid; -}; - -#endif diff --git a/src/tools/map_extractor/loadlib/loadlib.cpp b/src/tools/map_extractor/loadlib/loadlib.cpp deleted file mode 100644 index 465eb04083f..00000000000 --- a/src/tools/map_extractor/loadlib/loadlib.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#define _CRT_SECURE_NO_DEPRECATE - -#include "loadlib.h" -#include "mpq_libmpq04.h" -#include - -class MPQFile; - -FileLoader::FileLoader() -{ - data = 0; - data_size = 0; - version = 0; -} - -FileLoader::~FileLoader() -{ - free(); -} - -bool FileLoader::loadFile(char *filename, bool log) -{ - free(); - MPQFile mf(filename); - if(mf.isEof()) - { - if (log) - printf("No such file %s\n", filename); - return false; - } - - data_size = mf.getSize(); - - data = new uint8 [data_size]; - if (data) - { - mf.read(data, data_size); - mf.close(); - if (prepareLoadedData()) - return true; - } - printf("Error loading %s", filename); - mf.close(); - free(); - return false; -} - -bool FileLoader::prepareLoadedData() -{ - // Check version - version = (file_MVER *) data; - if (version->fcc != 'MVER') - return false; - if (version->ver != FILE_FORMAT_VERSION) - return false; - return true; -} - -void FileLoader::free() -{ - if (data) delete[] data; - data = 0; - data_size = 0; - version = 0; -} diff --git a/src/tools/map_extractor/loadlib/loadlib.h b/src/tools/map_extractor/loadlib/loadlib.h index 48fe794f8dc..49d5f590744 100644 --- a/src/tools/map_extractor/loadlib/loadlib.h +++ b/src/tools/map_extractor/loadlib/loadlib.h @@ -3,26 +3,28 @@ #ifdef _WIN32 typedef __int64 int64; -typedef long int32; -typedef short int16; -typedef char int8; +typedef __int32 int32; +typedef __int16 int16; +typedef __int8 int8; typedef unsigned __int64 uint64; -typedef unsigned long uint32; -typedef unsigned short uint16; -typedef unsigned char uint8; +typedef unsigned __int32 uint32; +typedef unsigned __int16 uint16; +typedef unsigned __int8 uint8; #else #include #ifndef uint64_t +#ifdef __linux__ #include #endif +#endif typedef int64_t int64; -typedef long int32; -typedef short int16; -typedef char int8; +typedef int32_t int32; +typedef int16_t int16; +typedef int8_t int8; typedef uint64_t uint64; -typedef unsigned long uint32; -typedef unsigned short uint16; -typedef unsigned char uint8; +typedef uint32_t uint32; +typedef uint16_t uint16; +typedef uint8_t uint8; #endif #define FILE_FORMAT_VERSION 18 diff --git a/src/tools/map_extractor/loadlib/wdt.cpp b/src/tools/map_extractor/loadlib/wdt.cpp deleted file mode 100644 index dedefbb64e5..00000000000 --- a/src/tools/map_extractor/loadlib/wdt.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#define _CRT_SECURE_NO_DEPRECATE - -#include "wdt.h" - -bool wdt_MWMO::prepareLoadedData() -{ - if (fcc != 'MWMO') - return false; - return true; -} - -bool wdt_MPHD::prepareLoadedData() -{ - if (fcc != 'MPHD') - return false; - return true; -} - -bool wdt_MAIN::prepareLoadedData() -{ - if (fcc != 'MAIN') - return false; - return true; -} - -WDT_file::WDT_file() -{ - mphd = 0; - main = 0; - wmo = 0; -} - -WDT_file::~WDT_file() -{ - free(); -} - -void WDT_file::free() -{ - mphd = 0; - main = 0; - wmo = 0; - FileLoader::free(); -} - -bool WDT_file::prepareLoadedData() -{ - // Check parent - if (!FileLoader::prepareLoadedData()) - return false; - - mphd = (wdt_MPHD *)((uint8*)version+version->size+8); - if (!mphd->prepareLoadedData()) - return false; - main = (wdt_MAIN *)((uint8*)mphd + mphd->size+8); - if (!main->prepareLoadedData()) - return false; - wmo = (wdt_MWMO *)((uint8*)main+ main->size+8); - if (!wmo->prepareLoadedData()) - return false; - return true; -} \ No newline at end of file diff --git a/src/tools/map_extractor/loadlib/wdt.h b/src/tools/map_extractor/loadlib/wdt.h deleted file mode 100644 index fcee8ac64f2..00000000000 --- a/src/tools/map_extractor/loadlib/wdt.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef WDT_H -#define WDT_H -#include "loadlib.h" - -//************************************************************************************** -// WDT file class and structures -//************************************************************************************** -#define WDT_MAP_SIZE 64 - -class wdt_MWMO{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; -public: - uint32 size; - bool prepareLoadedData(); -}; - -class wdt_MPHD{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; -public: - uint32 size; - - uint32 data1; - uint32 data2; - uint32 data3; - uint32 data4; - uint32 data5; - uint32 data6; - uint32 data7; - uint32 data8; - bool prepareLoadedData(); -}; - -class wdt_MAIN{ - union{ - uint32 fcc; - char fcc_txt[4]; - }; -public: - uint32 size; - - struct adtData{ - uint32 exist; - uint32 data1; - } adt_list[64][64]; - - bool prepareLoadedData(); -}; - -class WDT_file : public FileLoader{ -public: - bool prepareLoadedData(); - - WDT_file(); - ~WDT_file(); - void free(); - - wdt_MPHD *mphd; - wdt_MAIN *main; - wdt_MWMO *wmo; -}; - -#endif \ No newline at end of file diff --git a/src/tools/map_extractor/wdt.cpp b/src/tools/map_extractor/wdt.cpp new file mode 100644 index 00000000000..dedefbb64e5 --- /dev/null +++ b/src/tools/map_extractor/wdt.cpp @@ -0,0 +1,62 @@ +#define _CRT_SECURE_NO_DEPRECATE + +#include "wdt.h" + +bool wdt_MWMO::prepareLoadedData() +{ + if (fcc != 'MWMO') + return false; + return true; +} + +bool wdt_MPHD::prepareLoadedData() +{ + if (fcc != 'MPHD') + return false; + return true; +} + +bool wdt_MAIN::prepareLoadedData() +{ + if (fcc != 'MAIN') + return false; + return true; +} + +WDT_file::WDT_file() +{ + mphd = 0; + main = 0; + wmo = 0; +} + +WDT_file::~WDT_file() +{ + free(); +} + +void WDT_file::free() +{ + mphd = 0; + main = 0; + wmo = 0; + FileLoader::free(); +} + +bool WDT_file::prepareLoadedData() +{ + // Check parent + if (!FileLoader::prepareLoadedData()) + return false; + + mphd = (wdt_MPHD *)((uint8*)version+version->size+8); + if (!mphd->prepareLoadedData()) + return false; + main = (wdt_MAIN *)((uint8*)mphd + mphd->size+8); + if (!main->prepareLoadedData()) + return false; + wmo = (wdt_MWMO *)((uint8*)main+ main->size+8); + if (!wmo->prepareLoadedData()) + return false; + return true; +} \ No newline at end of file diff --git a/src/tools/map_extractor/wdt.h b/src/tools/map_extractor/wdt.h new file mode 100644 index 00000000000..fcee8ac64f2 --- /dev/null +++ b/src/tools/map_extractor/wdt.h @@ -0,0 +1,68 @@ +#ifndef WDT_H +#define WDT_H +#include "loadlib.h" + +//************************************************************************************** +// WDT file class and structures +//************************************************************************************** +#define WDT_MAP_SIZE 64 + +class wdt_MWMO{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; +public: + uint32 size; + bool prepareLoadedData(); +}; + +class wdt_MPHD{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; +public: + uint32 size; + + uint32 data1; + uint32 data2; + uint32 data3; + uint32 data4; + uint32 data5; + uint32 data6; + uint32 data7; + uint32 data8; + bool prepareLoadedData(); +}; + +class wdt_MAIN{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; +public: + uint32 size; + + struct adtData{ + uint32 exist; + uint32 data1; + } adt_list[64][64]; + + bool prepareLoadedData(); +}; + +class WDT_file : public FileLoader{ +public: + bool prepareLoadedData(); + + WDT_file(); + ~WDT_file(); + void free(); + + wdt_MPHD *mphd; + wdt_MAIN *main; + wdt_MWMO *wmo; +}; + +#endif \ No newline at end of file -- cgit v1.2.3