diff options
| author | Xanadu <none@none> | 2010-07-20 02:49:28 +0200 |
|---|---|---|
| committer | Xanadu <none@none> | 2010-07-20 02:49:28 +0200 |
| commit | 79622802f397258ee0f34327ba3ae6977ca3e7ff (patch) | |
| tree | 1868946c234ab9ee256a6b7766a15713eae94235 /src/tools/map_extractor | |
| parent | 7dd2dc91816ab8b3bc3b99a1b1c99c7ea314d5a8 (diff) | |
| parent | f906976837502fa5aa81b982b901d1509f5aa0c4 (diff) | |
Merge. Revision history for source files should be all back now.
--HG--
branch : trunk
rename : sql/CMakeLists.txt => sql/tools/CMakeLists.txt
rename : src/server/game/Pools/PoolHandler.cpp => src/server/game/Pools/PoolMgr.cpp
rename : src/server/game/Pools/PoolHandler.h => src/server/game/Pools/PoolMgr.h
rename : src/server/game/PrecompiledHeaders/NixCorePCH.cpp => src/server/game/PrecompiledHeaders/gamePCH.cpp
rename : src/server/game/PrecompiledHeaders/NixCorePCH.h => src/server/game/PrecompiledHeaders/gamePCH.h
Diffstat (limited to 'src/tools/map_extractor')
17 files changed, 544 insertions, 1131 deletions
diff --git a/src/tools/map_extractor/CMakeLists.txt b/src/tools/map_extractor/CMakeLists.txt index 9052903b1ed..cb3778c7c6a 100644 --- a/src/tools/map_extractor/CMakeLists.txt +++ b/src/tools/map_extractor/CMakeLists.txt @@ -1,4 +1,5 @@ # Copyright (C) 2005-2009 MaNGOS project <http://getmangos.com/> +# Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without @@ -8,19 +9,30 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -cmake_minimum_required (VERSION 2.6) -project (MANGOS_MAP_EXTRACTOR) +file(GLOB sources *.cpp) -add_subdirectory (libmpq) -add_subdirectory (loadlib) +include_directories ( + ${CMAKE_SOURCE_DIR}/src/server/shared + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/loadlib +) -include_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/libmpq) -include_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/loadlib) +add_executable(mapextractor + ${sources} +) -link_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/libmpq) -link_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/loadlib) +if(WIN32) + target_link_libraries(mapextractor + mpq + bzip2 + ) +else() + target_link_libraries(mapextractor + mpq + ${BZIP2_LIBRARIES} + ) +endif() -add_executable (ad dbcfile.cpp mpq_libmpq.cpp System.cpp) - -target_link_libraries (ad libmpq) -target_link_libraries (ad loadlib) +if( UNIX ) + install(TARGETS mapextractor DESTINATION bin) +endif() diff --git a/src/tools/map_extractor/README.linux b/src/tools/map_extractor/README.linux deleted file mode 100644 index 1986831e751..00000000000 --- a/src/tools/map_extractor/README.linux +++ /dev/null @@ -1,7 +0,0 @@ -Linux instructions ------------------- - -1. install cmake -2. cmake -i -3. make -4. ./ad diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index 683f89ac11e..2640b65d8b1 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -5,17 +5,17 @@ #include <set> #include <cstdlib> -#ifdef WIN32 +#ifdef _WIN32 #include "direct.h" #else #include <sys/stat.h> #endif #include "dbcfile.h" -#include "mpq_libmpq.h" +#include "mpq_libmpq04.h" -#include "loadlib/adt.h" -#include "loadlib/wdt.h" +#include "adt.h" +#include "wdt.h" #include <fcntl.h> #if defined( __GNUC__ ) @@ -88,7 +88,7 @@ static char* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "z void CreateDir( const std::string& Path ) { - #ifdef WIN32 + #ifdef _WIN32 _mkdir( Path.c_str()); #else mkdir( Path.c_str(), 0777 ); @@ -166,6 +166,43 @@ 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"; + //printf("Read %s file... ", filename.c_str()); + + MPQFile m(filename.c_str()); + if(m.isEof()) + { + printf("Fatal error: Not found %s file!\n", filename.c_str()); + exit(1); + } + + std::string text = m.getPointer(); + m.close(); + + size_t pos = text.find("version=\""); + size_t pos1 = pos + strlen("version=\""); + 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); + + int build = atoi(build_str.c_str()); + if (build <= 0) + { + printf("Fatal error: Invalid %s file format!\n", filename.c_str()); + exit(1); + } + + return build; +} + uint32 ReadMapDBC() { printf("Read Map.dbc file... "); @@ -238,16 +275,17 @@ void ReadLiquidTypeTableDBC() // // Map file format data -#define MAP_MAGIC 'SPAM' -#define MAP_VERSION_MAGIC '0.1w' -#define MAP_AREA_MAGIC 'AERA' -#define MAP_HEIGHT_MAGIC 'TGHM' -#define MAP_LIQUID_MAGIC 'QILM' +static char const* MAP_MAGIC = "MAPS"; +static char const* MAP_VERSION_MAGIC = "v1.1"; +static char const* MAP_AREA_MAGIC = "AREA"; +static char const* MAP_HEIGHT_MAGIC = "MHGT"; +static char const* MAP_LIQUID_MAGIC = "MLIQ"; struct map_fileheader { uint32 mapMagic; uint32 versionMagic; + uint32 buildMagic; uint32 areaMapOffset; uint32 areaMapSize; uint32 heightMapOffset; @@ -325,7 +363,7 @@ uint8 liquid_type[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]; -bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x) +bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x, uint32 build) { ADT_file adt; @@ -344,8 +382,9 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x) // Prepare map header map_fileheader map; - map.mapMagic = MAP_MAGIC; - map.versionMagic = MAP_VERSION_MAGIC; + map.mapMagic = *(uint32 const*)MAP_MAGIC; + map.versionMagic = *(uint32 const*)MAP_VERSION_MAGIC; + map.buildMagic = build; // Get area flags data for (int i=0;i<ADT_CELLS_PER_GRID;i++) @@ -387,7 +426,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x) map.areaMapSize = sizeof(map_areaHeader); map_areaHeader areaHeader; - areaHeader.fourcc = MAP_AREA_MAGIC; + areaHeader.fourcc = *(uint32 const*)MAP_AREA_MAGIC; areaHeader.flags = 0; if (fullAreaData) { @@ -516,7 +555,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x) map.heightMapSize = sizeof(map_heightHeader); map_heightHeader heightHeader; - heightHeader.fourcc = MAP_HEIGHT_MAGIC; + heightHeader.fourcc = *(uint32 const*)MAP_HEIGHT_MAGIC; heightHeader.flags = 0; heightHeader.gridHeight = minHeight; heightHeader.gridMaxHeight = maxHeight; @@ -751,7 +790,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x) } map.liquidMapOffset = map.heightMapOffset + map.heightMapSize; map.liquidMapSize = sizeof(map_liquidHeader); - liquidHeader.fourcc = MAP_LIQUID_MAGIC; + liquidHeader.fourcc = *(uint32 const*)MAP_LIQUID_MAGIC; liquidHeader.flags = 0; liquidHeader.liquidType = 0; liquidHeader.offsetX = minX; @@ -830,7 +869,7 @@ bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x) return true; } -void ExtractMapsFromMpq() +void ExtractMapsFromMpq(uint32 build) { char mpq_filename[1024]; char output_filename[1024]; @@ -868,7 +907,7 @@ void ExtractMapsFromMpq() continue; sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y); sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x); - ConvertADT(mpq_filename, output_filename, y, x); + ConvertADT(mpq_filename, output_filename, y, x, build); } // draw progress bar printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE); @@ -878,11 +917,27 @@ void ExtractMapsFromMpq() delete [] map_ids; } +bool ExtractFile( char const* mpq_name, std::string const& filename ) +{ + FILE *output = fopen(filename.c_str(), "wb"); + if(!output) + { + printf("Can't create the output file '%s'\n", filename.c_str()); + return false; + } + MPQFile m(mpq_name); + if(!m.isEof()) + fwrite(m.getPointer(), 1, m.getSize(), output); + + fclose(output); + return true; +} + void ExtractDBCFiles(int locale, bool basicLocale) { printf("Extracting dbc files...\n"); - set<string> dbcfiles; + std::set<std::string> dbcfiles; // get DBC file list for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) @@ -894,7 +949,7 @@ void ExtractDBCFiles(int locale, bool basicLocale) dbcfiles.insert(*iter); } - string path = output_path; + std::string path = output_path; path += "/dbc/"; CreateDir(path); if(!basicLocale) @@ -904,6 +959,14 @@ void ExtractDBCFiles(int locale, bool basicLocale) CreateDir(path); } + // extract Build info file + { + string mpq_name = std::string("component.wow-") + langs[locale] + ".txt"; + string filename = path + mpq_name; + + ExtractFile(mpq_name.c_str(), filename); + } + // extract DBCs int count = 0; for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter) @@ -911,18 +974,8 @@ void ExtractDBCFiles(int locale, bool basicLocale) string filename = path; filename += (iter->c_str() + strlen("DBFilesClient\\")); - FILE *output = fopen(filename.c_str(), "wb"); - if(!output) - { - printf("Can't create the output file '%s'\n", filename.c_str()); - continue; - } - MPQFile m(iter->c_str()); - if(!m.isEof()) - fwrite(m.getPointer(), 1, m.getSize(), output); - - fclose(output); - ++count; + if(ExtractFile(iter->c_str(), filename)) + ++count; } printf("Extracted %u DBC files\n\n", count); } @@ -972,6 +1025,7 @@ int main(int argc, char * arg[]) HandleArgs(argc, arg); int FirstLocale = -1; + uint32 build = 0; for (int i = 0; i < LANG_COUNT; i++) { @@ -987,14 +1041,18 @@ int main(int argc, char * arg[]) if((CONF_extract & EXTRACT_DBC) == 0) { FirstLocale = i; + build = ReadBuild(FirstLocale); + printf("Detected client build: %u\n", build); break; } //Extract DBC files if(FirstLocale < 0) { - ExtractDBCFiles(i, true); FirstLocale = i; + build = ReadBuild(FirstLocale); + printf("Detected client build: %u\n", build); + ExtractDBCFiles(i, true); } else ExtractDBCFiles(i, false); @@ -1019,7 +1077,7 @@ int main(int argc, char * arg[]) LoadCommonMPQFiles(); // Extract maps - ExtractMapsFromMpq(); + ExtractMapsFromMpq(build); // Close MPQs CloseMPQFiles(); @@ -1027,4 +1085,3 @@ int main(int argc, char * arg[]) return 0; } - diff --git a/src/tools/map_extractor/VC90_ad.vcproj b/src/tools/map_extractor/VC90/VC90_mapextractor.vcproj index 9a039a0fbb0..3cc367f0fc8 100644 --- a/src/tools/map_extractor/VC90_ad.vcproj +++ b/src/tools/map_extractor/VC90/VC90_mapextractor.vcproj @@ -2,7 +2,7 @@ <VisualStudioProject ProjectType="Visual C++" Version="9,00" - Name="ad" + Name="mapextractor" ProjectGUID="{D7552D4F-408F-4F8E-859B-366659150CF4}" RootNamespace="ad" TargetFrameworkVersion="131072" @@ -17,10 +17,9 @@ <Configurations> <Configuration Name="Debug|Win32" - OutputDirectory="." - IntermediateDirectory=".\debug\" + OutputDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)" + IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)" ConfigurationType="1" - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="false" CharacterSet="2" @@ -49,21 +48,22 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories="libmpq" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS" + AdditionalIncludeDirectories="..\loadlib;..\..\..\..\externals;..\..\..\..\externals\libmpq;..\..\..\..\externals\libmpq\win;..\server\shared" + MinimalRebuild="false" BasicRuntimeChecks="3" - RuntimeLibrary="1" + RuntimeLibrary="3" + EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" - PrecompiledHeaderFile="$(IntDir)ad.pch" - AssemblerListingLocation="$(IntDir)\" - ObjectFile="$(IntDir)\" - ProgramDataBaseFileName="$(IntDir)\" + PrecompiledHeaderFile="$(IntDir)\ad.pch" + AssemblerListingLocation="" + ObjectFile=".\$(ProjectName)__$(PlatformName)_$(ConfigurationName)\" + ProgramDataBaseFileName=".\$(ProjectName)__$(PlatformName)_$(ConfigurationName)\" XMLDocumentationFileName="$(IntDir)\" - BrowseInformation="1" - BrowseInformationFile="$(IntDir)" + BrowseInformation="0" + BrowseInformationFile="" WarningLevel="3" SuppressStartupBanner="true" - DebugInformationFormat="4" + DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" @@ -78,14 +78,13 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="zlib.lib" - OutputFile="ad debug.exe" - LinkIncremental="0" + OutputFile="..\..\bin\$(PlatformName)_$(ConfigurationName)\$(ProjectName)_d.exe" + LinkIncremental="2" SuppressStartupBanner="true" - AdditionalLibraryDirectories="./debug/" - IgnoreDefaultLibraryNames="LIBCD.lib" + AdditionalLibraryDirectories="" + IgnoreDefaultLibraryNames="" GenerateDebugInformation="true" - ProgramDatabaseFile="./ad debug.pdb" + ProgramDatabaseFile="$(IntDir)\$(TargetName).pdb" SubSystem="1" RandomizedBaseAddress="1" DataExecutionPrevention="0" @@ -102,6 +101,7 @@ /> <Tool Name="VCBscMakeTool" + OutputFile="$(OutDir)\$(ProjectName).bsc" /> <Tool Name="VCFxCopTool" @@ -115,10 +115,9 @@ </Configuration> <Configuration Name="Release|Win32" - OutputDirectory="." - IntermediateDirectory=".\release" + OutputDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)" + IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)" ConfigurationType="1" - InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="false" CharacterSet="2" @@ -146,19 +145,23 @@ /> <Tool Name="VCCLCompilerTool" - Optimization="3" - InlineFunctionExpansion="1" - AdditionalIncludeDirectories="libmpq" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" - RuntimeLibrary="0" + Optimization="2" + InlineFunctionExpansion="0" + AdditionalIncludeDirectories="..\loadlib;..\..\..\..\externals;..\..\..\..\externals\libmpq;..\..\..\..\externals\libmpq\win;..\server\shared" + StringPooling="true" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + EnableEnhancedInstructionSet="1" UsePrecompiledHeader="0" - PrecompiledHeaderFile="$(IntDir)ad.pch" - AssemblerListingLocation="$(IntDir)\" - ObjectFile="$(IntDir)\" - ProgramDataBaseFileName="$(IntDir)\" + PrecompiledHeaderFile="" + AssemblerListingLocation="" + ObjectFile=".\$(ProjectName)__$(PlatformName)_$(ConfigurationName)\" + ProgramDataBaseFileName=".\$(ProjectName)__$(PlatformName)_$(ConfigurationName)\" XMLDocumentationFileName="$(IntDir)\" + BrowseInformation="0" WarningLevel="3" SuppressStartupBanner="true" + DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" @@ -173,14 +176,16 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="zlib.lib" - OutputFile="./ad.exe" - LinkIncremental="0" + OutputFile="..\..\bin\$(PlatformName)_$(ConfigurationName)\$(ProjectName).exe" + LinkIncremental="1" SuppressStartupBanner="true" - AdditionalLibraryDirectories="./release/" - IgnoreDefaultLibraryNames="LIBC.lib" - ProgramDatabaseFile="./ad.pdb" + AdditionalLibraryDirectories="" + IgnoreDefaultLibraryNames="" + GenerateDebugInformation="true" + ProgramDatabaseFile="$(IntDir)\$(TargetName).pdb" SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" RandomizedBaseAddress="1" DataExecutionPrevention="0" TargetMachine="1" @@ -216,75 +221,27 @@ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > <File - RelativePath=".\loadlib\loadlib.cpp" - > - </File> - <File - RelativePath=".\loadlib\adt.cpp" - > - </File> - <File - RelativePath=".\loadlib\wdt.cpp" - > - </File> - <File - RelativePath=".\libmpq\common.cpp" - > - </File> - <File - RelativePath=".\dbcfile.cpp" - > - </File> - <File - RelativePath=".\libmpq\explode.cpp" + RelativePath="..\adt.cpp" > </File> <File - RelativePath=".\libmpq\extract.cpp" + RelativePath="..\dbcfile.cpp" > </File> <File - RelativePath=".\libmpq\huffman.cpp" + RelativePath="..\loadlib.cpp" > </File> <File - RelativePath=".\libmpq\mpq.cpp" + RelativePath="..\mpq_libmpq.cpp" > </File> <File - RelativePath=".\mpq_libmpq.cpp" + RelativePath="..\System.cpp" > </File> <File - RelativePath=".\libmpq\parser.cpp" - > - </File> - <File - RelativePath="system.cpp" - > - <FileConfiguration - Name="Debug|Win32" - > - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="" - BasicRuntimeChecks="3" - BrowseInformation="1" - /> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32" - > - <Tool - Name="VCCLCompilerTool" - Optimization="3" - PreprocessorDefinitions="" - /> - </FileConfiguration> - </File> - <File - RelativePath=".\libmpq\wave.cpp" + RelativePath="..\wdt.cpp" > </File> </Filter> @@ -293,7 +250,7 @@ Filter="h;hpp;hxx;hm;inl" > <File - RelativePath=".\libmpq\common.h" + RelativePath="..\adt.h" > </File> <File @@ -301,23 +258,11 @@ > </File> <File - RelativePath=".\libmpq\explode.h" - > - </File> - <File - RelativePath=".\libmpq\huffman.h" - > - </File> - <File - RelativePath=".\libmpq\mpq.h" - > - </File> - <File RelativePath=".\mpq_libmpq.h" > </File> <File - RelativePath=".\libmpq\wave.h" + RelativePath="..\wdt.h" > </File> </Filter> diff --git a/src/tools/map_extractor/VC90_AD.sln b/src/tools/map_extractor/VC90_AD.sln deleted file mode 100644 index 68dd66e1f7f..00000000000 --- a/src/tools/map_extractor/VC90_AD.sln +++ /dev/null @@ -1,19 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ad", "VC90_ad.vcproj", "{D7552D4F-408F-4F8E-859B-366659150CF4}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D7552D4F-408F-4F8E-859B-366659150CF4}.Debug|Win32.ActiveCfg = Debug|Win32 - {D7552D4F-408F-4F8E-859B-366659150CF4}.Debug|Win32.Build.0 = Debug|Win32 - {D7552D4F-408F-4F8E-859B-366659150CF4}.Release|Win32.ActiveCfg = Release|Win32 - {D7552D4F-408F-4F8E-859B-366659150CF4}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/tools/map_extractor/adt.cpp b/src/tools/map_extractor/adt.cpp index fcbfc95a072..fde70681113 100644 --- a/src/tools/map_extractor/adt.cpp +++ b/src/tools/map_extractor/adt.cpp @@ -1,176 +1,11 @@ #define _CRT_SECURE_NO_DEPRECATE -#ifdef WIN32 -#include <windows.h> -#endif - -#include <string.h> -#include <stdio.h> -#include <math.h> -#include <string> -#include <map> -#include <vector> -#include <set> - #include "adt.h" -#include "mpq_libmpq.h" - -extern uint16 *areas; -extern uint16 *LiqType; -extern uint32 maxAreaId; - -vec wmoc; -Cell *cell; -mcell *mcells; +// Helper int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888}; int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000}; -bool LoadADT(char* filename) -{ - size_t size; - MPQFile mf(filename); - - if(mf.isEof()) - { - //printf("No such file %s\n", filename); - return false; - } - - MapLiqFlag = new uint8[256]; - for(uint32 j = 0; j < 256; ++j) - MapLiqFlag[j] = 0; // no water - - MapLiqHeight = new float[16384]; - for(uint32 j = 0; j < 16384; ++j) - MapLiqHeight[j] = -999999; // no water - - mcells = new mcell; - - wmoc.x = 65 * TILESIZE; - wmoc.z = 65 * TILESIZE; - - size_t mcnk_offsets[256], mcnk_sizes[256]; - - chunk_num = 0; - k = 0; - m = 0; - while (!mf.isEof()) - { - uint32 fourcc; - mf.read(&fourcc, 4); - mf.read(&size, 4); - - size_t nextpos = mf.getPos() + size; - - //if(fourcc==0x4d484452) // MHDR header - //if(fourcc==0x4d564552) // MVER - if(fourcc == 0x4d43494e) // MCIN - { - for (uint32 i = 0; i < 256; ++i) - { - mf.read(&mcnk_offsets[i], 4); - mf.read(&mcnk_sizes[i], 4); - mf.seekRelative(8); - } - } - //if(fourcc == 0x4d544558) // MTEX textures (strings) - //if(fourcc == 0x4d4d4458) // MMDX m2 models (strings) - //if(fourcc == 0x4d4d4944) // MMID offsets for strings in MMDX - //if(fourcc == 0x4d574d4f) // MWMO - //if(fourcc == 0x4d574944) // MWID offsets for strings in MWMO - //if(fourcc == 0x4d444446) // MDDF - //if(fourcc == 0x4d4f4446) // MODF - if(fourcc == 0x4d48324f) // MH2O new in WotLK - { - // здес?надо запомнит?базову?позици??файл?тк вс?смещен? буду?от него - uint32 base_pos = mf.getPos(); - uint32 header_pos = 0; - MH2O_offsData *LiqOffsData = new MH2O_offsData; - MH2O_Data1 *LiqChunkData1 = new MH2O_Data1; - float *ChunkLiqHeight = new float[81]; - for(chunk_num = 0; chunk_num < 256; ++chunk_num) - { - mf.read(LiqOffsData, 0x0C); - header_pos = mf.getPos(); - if(LiqOffsData->offsData1 != 0) // если данные ?Data1 ?воде есть, то их надо конвертировать - { - // перехо?по смещению из offsData1 ОТ ЧА?куск? - mf.seek(base_pos + LiqOffsData->offsData1); - mf.read(LiqChunkData1, 0x18); // считывае?сами данные ?структур?типа MH2O_Data1 - // заноси?данные флаг?для куск? - if(LiqType[LiqChunkData1->LiquidTypeId] == 0xffff) - printf("\nCan't find Liquid type for map %s\nchunk %d\n", filename, chunk_num); - else if(LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_WATER || LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_OCEAN) - MapLiqFlag[chunk_num] |= 1; // water/ocean - else if(LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_MAGMA || LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_SLIME) - MapLiqFlag[chunk_num] |= 2; // magma/slime - // предварительно заполняем весь кусо?данным?- не?воды - for(int j = 0; j < 81; ++j) - { - ChunkLiqHeight[j] = -999999; // no liquid/water - } - // теперь вычисляем те чт??водо??перезаписываем их ?куск? - for(int b = 0; b <= LiqChunkData1->height; ++b) - { - for(int c = LiqChunkData1->xOffset; c <= (LiqChunkData1->xOffset + LiqChunkData1->width); ++c) - { - int n = (9 * (LiqChunkData1->yOffset + b)) + c; - ChunkLiqHeight[n] = LiqChunkData1->heightLevel1; - } - } - mf.seek(header_pos); // ?не забыть вернуться на исходную позици?именно ?ХИДЕРЕ - } - else // если данных ?Data1 не? то надо заполнит?весь кусо? но данным?- не?воды - { - for(int j = 0; j < 81; ++j) - ChunkLiqHeight[j] = -999999; // no liquid/water - } - - if(!(chunk_num % 16)) - m = 1024 * (chunk_num / 16); // смещение по ?да?кусков ?перекрытие?= 1024 - k = m + (chunk_num % 16) * 8; // устанавливаемся на начальны?индекс для заполнен? ?да - // заноси?данные куск??массив для карт? ?перекрытие??обрезанием кусков тк данных 81 - // эт?аналог старог?обрезания граничны?правых-боковы??нижних данных - for(int p = 0; p < 72; p += 9) // нижние 8 не заноси?тк он?дублируется след куском - { - for(int s = 0; s < 8; ++s) // 9 значение ?строке не заноси?тк он?дублируется след куском, ??првы?боковы?обрезает? для 128?28 - { - MapLiqHeight[k] = ChunkLiqHeight[p + s]; - ++k; - } - k = k + 120; - } - } - delete LiqOffsData; - delete LiqChunkData1; - delete []ChunkLiqHeight; - - } - //case 0x4d434e4b: // MCNK - //case 0x4d46424f: // MFBO new in BC - //case 0x4d545846: // MTXF new in WotLK - mf.seek(nextpos); - } - - //printf("Loading chunks info\n"); - // read individual map chunks - chunk_num = 0; - k = 0; - m = 0; - for (int j = 0; j < 16; ++j) - { - for (int i = 0; i < 16; ++i) - { - mf.seek((int)mcnk_offsets[j * 16 + i]); - LoadMapChunk(mf, &(mcells->ch[i][j])); - ++chunk_num; - } - } - mf.close(); - return true; -} - bool isHole(int holes, int i, int j) { int testi = i / 2; @@ -180,202 +15,117 @@ bool isHole(int holes, int i, int j) return (holes & holetab_h[testi] & holetab_v[testj]) != 0; } -inline void LoadMapChunk(MPQFile &mf, chunk *_chunk) +// +// Adt file loader class +// +ADT_file::ADT_file() { - float h; - uint32 fourcc; - uint32 size; - MapChunkHeader header; - - mf.seekRelative(4); - mf.read(&size, 4); - - size_t lastpos = mf.getPos() + size; - mf.read(&header, 0x80); // what if header size got changed? - _chunk->area_id = header.areaid; + a_grid = 0; +} - float xbase = header.xpos; - float ybase = header.ypos; - float zbase = header.zpos; - zbase = TILESIZE * 32 - zbase; - xbase = TILESIZE * 32 - xbase; - if(wmoc.x > xbase) wmoc.x = xbase; - if(wmoc.z > zbase) wmoc.z = zbase; - int chunkflags = header.flags; - //printf("LMC: flags %X\n", chunkflags); - float zmin = 999999999.0f; - float zmax = -999999999.0f; - // must be there, bl!zz uses some crazy format - while (mf.getPos() < lastpos) - { - mf.read(&fourcc, 4); - mf.read(&size, 4); - size_t nextpos = mf.getPos() + size; - if(fourcc == 0x4d435654) // MCVT - { - for (int j = 0; j < 17; ++j) - { - for (int i = 0; i < ((j % 2) ? 8 : 9); ++i) - { - mf.read(&h, 4); - float z = h + ybase; - if (j % 2) - { - if(isHole(header.holes, i, j)) - _chunk->v8[i][j / 2] = -1000; - else - _chunk->v8[i][j / 2] = z; - } - else - { - if(isHole(header.holes, i, j)) - _chunk->v9[i][j / 2] = -1000; - else - _chunk->v9[i][j / 2] = z; - } +ADT_file::~ADT_file() +{ + free(); +} - if(z > zmax) zmax = z; - //if(z < zmin) zmin = z; - } - } - } - else if(fourcc == 0x4d434e52) // MCNR - { - nextpos = mf.getPos() + 0x1C0; // size fix - } - else if(fourcc == 0x4d434c51) // не буде?учитыват?если уж?были данные ?MH2O, перестраховк?:) // MCLQ - { - // liquid / water level - char fcc1[5]; - mf.read(fcc1, 4); - flipcc(fcc1); - fcc1[4] = 0; - float *ChunkLiqHeight = new float[81]; +void ADT_file::free() +{ + a_grid = 0; + FileLoader::free(); +} - if (!strcmp(fcc1, "MCSE")) - { - for(int j = 0; j < 81; ++j) - { - ChunkLiqHeight[j] = -999999; // no liquid/water - } - } - else - { - float maxheight; - mf.read(&maxheight, 4); - for(int j = 0; j < 81; ++j) - { - LiqData liq; - mf.read(&liq, 8); +// +// Adt file check function +// +bool ADT_file::prepareLoadedData() +{ + // Check parent + if (!FileLoader::prepareLoadedData()) + return false; - if(liq.height > maxheight) - ChunkLiqHeight[j] = -999999; - else - ChunkLiqHeight[j] = h; - } + // Check and prepare MHDR + a_grid = (adt_MHDR *)(GetData()+8+version->size); + if (!a_grid->prepareLoadedData()) + return false; - if(chunkflags & 4 || chunkflags & 8) - MapLiqFlag[chunk_num] |= 1; // water - if(chunkflags & 16) - MapLiqFlag[chunk_num] |= 2; // magma/slime - } - // аполне?та?же ка??MH2O - if(!(chunk_num % 16)) - m = 1024 * (chunk_num / 16); - k = m + (chunk_num % 16) * 8; - - for(int p = 0; p < 72; p += 9) - { - for(int s = 0; s < 8; ++s) - { - MapLiqHeight[k] = ChunkLiqHeight[p + s]; - ++k; - } - k = k + 120; - } - delete []ChunkLiqHeight; - break; - } - mf.seek(nextpos); - } + return true; } -inline void TransformData() +bool adt_MHDR::prepareLoadedData() { - cell = new Cell; + if (fcc != 'MHDR') + return false; - for(uint32 x = 0; x < 128; ++x) - { - for(uint32 y = 0; y < 128; ++y) - { - cell->v8[y][x] = (float)mcells->ch[x / 8][y / 8].v8[x % 8][y % 8]; - cell->v9[y][x] = (float)mcells->ch[x / 8][y / 8].v9[x % 8][y % 8]; - } + if (size!=sizeof(adt_MHDR)-8) + return false; - // extra 1 point on bounds - cell->v9[128][x] = (float)mcells->ch[x / 8][15].v9[x % 8][8]; - // x == y - cell->v9[x][128] = (float)mcells->ch[15][x / 8].v9[8][x % 8]; - } + // Check and prepare MCIN + if (offsMCIN && !getMCIN()->prepareLoadedData()) + return false; - // and the last 1 - cell->v9[128][128] = (float)mcells->ch[15][15].v9[8][8]; + // Check and prepare MH2O + if (offsMH2O && !getMH2O()->prepareLoadedData()) + return false; - delete mcells; + return true; } -const char MAP_MAGIC[] = "MAP_3.00"; - -bool ConvertADT(char *filename, char *filename2) +bool adt_MCIN::prepareLoadedData() { - if(!LoadADT(filename)) + if (fcc != 'MCIN') return false; - FILE *output=fopen(filename2, "wb"); - if(!output) - { - printf("Can't create the output file '%s'\n", filename2); - delete [] MapLiqHeight; - delete [] MapLiqFlag; + // 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()) + return false; + + return true; +} + +bool adt_MH2O::prepareLoadedData() +{ + if (fcc != 'MH2O') return false; - } - // write magic header - fwrite(MAP_MAGIC, 1, 8, output); + // Check liquid data +// for (int i=0; i<ADT_CELLS_PER_GRID;i++) +// for (int j=0; j<ADT_CELLS_PER_GRID;j++) - for(uint32 x = 0; x < 16; ++x) - { - for(uint32 y = 0; y < 16; ++y) - { - if(mcells->ch[y][x].area_id && mcells->ch[y][x].area_id <= maxAreaId) - { - if(areas[mcells->ch[y][x].area_id] == 0xffff) - printf("\nCan't find area flag for areaid %u.\n", mcells->ch[y][x].area_id); + return true; +} - fwrite(&areas[mcells->ch[y][x].area_id], 1, 2, output); - } - else - { - uint16 flag = 0xffff; - fwrite(&flag, 1, 2, output); - } - } - } +bool adt_MCNK::prepareLoadedData() +{ + if (fcc != 'MCNK') + return false; - fwrite(MapLiqFlag, 1, 256, output); - delete [] MapLiqFlag; + // Check height map + if (offsMCVT && !getMCVT()->prepareLoadedData()) + return false; + // Check liquid data + if (offsMCLQ && !getMCLQ()->prepareLoadedData()) + return false; - fwrite(MapLiqHeight, sizeof(float), 16384, output); - delete [] MapLiqHeight; + return true; +} - TransformData(); +bool adt_MCVT::prepareLoadedData() +{ + if (fcc != 'MCVT') + return false; + if (size != sizeof(adt_MCVT)-8) + return false; - fwrite(&cell->v9, 1, sizeof(cell->v9), output); - fwrite(&cell->v8, 1, sizeof(cell->v8), output); - fclose(output); - delete cell; - 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 index 516ed88a86e..725c5b994ee 100644 --- a/src/tools/map_extractor/adt.h +++ b/src/tools/map_extractor/adt.h @@ -1,130 +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) -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; -class Liquid; -typedef struct -{ - float x; - float y; - float z; -} svec; - -typedef struct +enum LiquidType { - double x; - double y; - double z; -} vec; + LIQUID_TYPE_WATER = 0, + LIQUID_TYPE_OCEAN = 1, + LIQUID_TYPE_MAGMA = 2, + LIQUID_TYPE_SLIME = 3 +}; -typedef struct -{ - vec v[3]; -} triangle; +//************************************************************************************** +// 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) -typedef struct +// +// Adt file height map chunk +// +class adt_MCVT { - float v9[16 * 8 + 1][16 * 8 + 1]; - float v8[16 * 8][16 * 8]; -} Cell; + 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]; -typedef struct -{ - double v9[9][9]; - double v8[8][8]; - uint16 area_id; -} chunk; + bool prepareLoadedData(); +}; -typedef struct +// +// Adt file liquid map chunk (old) +// +class adt_MCLQ { - chunk ch[16][16]; -} mcell; + 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(); +}; -struct MapChunkHeader +// +// 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 ofsHeight; - uint32 ofsNormal; - uint32 ofsLayer; - uint32 ofsRefs; - uint32 ofsAlpha; - uint32 sizeAlpha; - uint32 ofsShadow; - uint32 sizeShadow; + 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 s1; - uint16 s2; - uint32 d1; - uint32 d2; - uint32 d3; + uint16 s[2]; + uint32 data1; + uint32 data2; + uint32 data3; uint32 predTex; uint32 nEffectDoodad; - uint32 ofsSndEmitters; + uint32 offsMCSE; uint32 nSndEmitters; - uint32 ofsLiquid; // not use in WotLK - uint32 sizeLiquid; // not use in WotLK + uint32 offsMCLQ; // Liqid level (old) + uint32 sizeMCLQ; // float zpos; float xpos; float ypos; - uint32 textureId; // new offsColorValues in WotLK + 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; + } }; -typedef struct +// +// Adt file grid chunk +// +class adt_MCIN { - uint32 offsData1; - uint32 used; - uint32 offsData2; -} MH2O_offsData; + 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]; -typedef struct -{ - uint16 LiquidTypeId; - uint16 type; - float heightLevel1; - float heightLevel2; - uint8 xOffset; - uint8 yOffset; - uint8 width; - uint8 height; - uint32 ofsData2a; - uint32 ofsData2b; -} MH2O_Data1; - -typedef struct -{ - uint16 unk1; - uint16 unk2; - float height; -} LiqData; + 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; + } +}; -enum LiquidType +#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 { - LIQUID_TYPE_WATER = 0, - LIQUID_TYPE_OCEAN = 1, - LIQUID_TYPE_MAGMA = 2, - LIQUID_TYPE_SLIME = 3 +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; + } + }; -class MPQFile; +// +// Adt file header chunk +// +class adt_MHDR +{ + union{ + uint32 fcc; + char fcc_txt[4]; + }; + uint32 size; -float *MapLiqHeight; -uint8 *MapLiqFlag; -uint32 k, m, chunk_num; -void LoadMapChunk(MPQFile &, chunk*); -#endif + 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/dbcfile.cpp b/src/tools/map_extractor/dbcfile.cpp index dd58ac1b4a6..927d3d62b7f 100644 --- a/src/tools/map_extractor/dbcfile.cpp +++ b/src/tools/map_extractor/dbcfile.cpp @@ -1,7 +1,7 @@ #define _CRT_SECURE_NO_DEPRECATE #include "dbcfile.h" -#include "mpq_libmpq.h" +#include "mpq_libmpq04.h" DBCFile::DBCFile(const std::string &filename): filename(filename), diff --git a/src/tools/map_extractor/loadlib/loadlib.cpp b/src/tools/map_extractor/loadlib.cpp index ed5bd9acb71..465eb04083f 100644 --- a/src/tools/map_extractor/loadlib/loadlib.cpp +++ b/src/tools/map_extractor/loadlib.cpp @@ -1,7 +1,8 @@ #define _CRT_SECURE_NO_DEPRECATE #include "loadlib.h" -#include "../mpq_libmpq.h" +#include "mpq_libmpq04.h" +#include <cstdio> class MPQFile; @@ -61,4 +62,4 @@ void FileLoader::free() data = 0; data_size = 0; version = 0; -}
\ No newline at end of file +} diff --git a/src/tools/map_extractor/loadlib/CMakeLists.txt b/src/tools/map_extractor/loadlib/CMakeLists.txt deleted file mode 100644 index 5680c61d424..00000000000 --- a/src/tools/map_extractor/loadlib/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2005-2009 MaNGOS project <http://getmangos.com/> -# -# This file is free software; as a special exception the author gives -# unlimited permission to copy and/or distribute it, with or without -# modifications, as long as this notice is preserved. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -add_library (loadlib loadlib.cpp adt.cpp wdt.cpp) -# link loadlib with zlib -target_link_libraries (loadlib z) 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; 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; -} - -bool adt_MH2O::prepareLoadedData() -{ - if (fcc != 'MH2O') - 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++) - - return true; -} - -bool adt_MCNK::prepareLoadedData() -{ - if (fcc != 'MCNK') - return false; - - // Check height map - if (offsMCVT && !getMCVT()->prepareLoadedData()) - 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.h b/src/tools/map_extractor/loadlib/loadlib.h index 6acfd107ec7..49d5f590744 100644 --- a/src/tools/map_extractor/loadlib/loadlib.h +++ b/src/tools/map_extractor/loadlib/loadlib.h @@ -1,28 +1,30 @@ #ifndef LOAD_LIB_H #define LOAD_LIB_H -#ifdef WIN32 +#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 <stdint.h> #ifndef uint64_t +#ifdef __linux__ #include <linux/types.h> #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/mpq_libmpq.cpp b/src/tools/map_extractor/mpq_libmpq.cpp index 2a066a83b34..81aa8cc2894 100644 --- a/src/tools/map_extractor/mpq_libmpq.cpp +++ b/src/tools/map_extractor/mpq_libmpq.cpp @@ -1,44 +1,30 @@ -#include "mpq_libmpq.h" +#include "mpq_libmpq04.h" #include <deque> +#include <cstdio> ArchiveSet gOpenArchives; MPQArchive::MPQArchive(const char* filename) { - int result = libmpq_archive_open(&mpq_a, (unsigned char*)filename); + int result = libmpq__archive_open(&mpq_a, filename, -1); printf("Opening %s\n", filename); if(result) { switch(result) { - case LIBMPQ_EFILE : /* error on file operation */ - printf("Error opening archive '%s': File operation Error\n", filename); + case LIBMPQ_ERROR_OPEN : + printf("Error opening archive '%s': Does file really exist?\n", filename); break; - case LIBMPQ_EFILE_FORMAT : /* bad file format */ + case LIBMPQ_ERROR_FORMAT : /* bad file format */ printf("Error opening archive '%s': Bad file format\n", filename); break; - case LIBMPQ_EFILE_CORRUPT : /* file corrupt */ - printf("Error opening archive '%s': File corrupt\n", filename); + case LIBMPQ_ERROR_SEEK : /* seeking in file failed */ + printf("Error opening archive '%s': Seeking in file failed\n", filename); break; - case LIBMPQ_EFILE_NOT_FOUND : /* file in archive not found */ - printf("Error opening archive '%s': File in archive not found\n", filename); - break; - case LIBMPQ_EFILE_READ : /* Read error in archive */ + case LIBMPQ_ERROR_READ : /* Read error in archive */ printf("Error opening archive '%s': Read error in archive\n", filename); break; - case LIBMPQ_EALLOCMEM : /* maybe not enough memory? :) */ + case LIBMPQ_ERROR_MALLOC : /* maybe not enough memory? :) */ printf("Error opening archive '%s': Maybe not enough memory\n", filename); break; - case LIBMPQ_EFREEMEM : /* can not free memory */ - printf("Error opening archive '%s': Cannot free memory\n", filename); - break; - case LIBMPQ_EINV_RANGE : /* Given filenumber is out of range */ - printf("Error opening archive '%s': Given filenumber is out of range\n", filename); - break; - case LIBMPQ_EHASHTABLE : /* error in reading hashtable */ - printf("Error opening archive '%s': Error in reading hashtable\n", filename); - break; - case LIBMPQ_EBLOCKTABLE : /* error in reading blocktable */ - printf("Error opening archive '%s': Error in reading blocktable\n", filename); - break; default: printf("Error opening archive '%s': Unknown error\n", filename); break; @@ -51,7 +37,7 @@ MPQArchive::MPQArchive(const char* filename) void MPQArchive::close() { //gOpenArchives.erase(erase(&mpq_a); - libmpq_archive_close(&mpq_a); + libmpq__archive_close(mpq_a); } MPQFile::MPQFile(const char* filename): @@ -62,25 +48,16 @@ MPQFile::MPQFile(const char* filename): { for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) { - mpq_archive &mpq_a = (*i)->mpq_a; + mpq_archive *mpq_a = (*i)->mpq_a; - mpq_hash hash = (*i)->GetHashEntry(filename); - uint32 blockindex = hash.blockindex; + uint32_t filenum; + if(libmpq__file_number(mpq_a, filename, &filenum)) continue; + libmpq__off_t transferred; + libmpq__file_unpacked_size(mpq_a, filenum, &size); - if ((blockindex == 0xFFFFFFFF) || (blockindex == 0)) { - continue; //file not found - } - - uint32 fileno = blockindex; - - //int fileno = libmpq_file_number(&mpq_a, filename); - //if(fileno == LIBMPQ_EFILE_NOT_FOUND) - // continue; - - // Found! - size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, fileno); // 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); eof = true; buffer = 0; return; @@ -88,7 +65,8 @@ MPQFile::MPQFile(const char* filename): buffer = new char[size]; //libmpq_file_getdata - libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer); + libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); + /*libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);*/ return; } @@ -131,4 +109,3 @@ void MPQFile::close() buffer = 0; eof = true; } - diff --git a/src/tools/map_extractor/mpq_libmpq.h b/src/tools/map_extractor/mpq_libmpq04.h index d61cda7f919..26008f5fba1 100644 --- a/src/tools/map_extractor/mpq_libmpq.h +++ b/src/tools/map_extractor/mpq_libmpq04.h @@ -18,50 +18,20 @@ class MPQArchive { public: - mpq_archive mpq_a; + mpq_archive_s *mpq_a; MPQArchive(const char* filename); void close(); - uint32 HashString(const char* Input, uint32 Offset) { - uint32 seed1 = 0x7fed7fed; - uint32 seed2 = 0xeeeeeeee; - - for (uint32 i = 0; i < strlen(Input); i++) { - uint32 val = toupper(Input[i]); - seed1 = mpq_a.buf[Offset + val] ^ (seed1 + seed2); - seed2 = val + seed1 + seed2 + (seed2 << 5) + 3; - } - - return seed1; - } - mpq_hash GetHashEntry(const char* Filename) { - uint32 index = HashString(Filename, 0); - index &= mpq_a.header->hashtablesize - 1; - uint32 name1 = HashString(Filename, 0x100); - uint32 name2 = HashString(Filename, 0x200); - - for(uint32 i = index; i < mpq_a.header->hashtablesize; ++i) { - mpq_hash hash = mpq_a.hashtable[i]; - if (hash.name1 == name1 && hash.name2 == name2) return hash; - } - - mpq_hash nullhash; - nullhash.blockindex = 0xFFFFFFFF; - return nullhash; - } - void GetFileListTo(vector<string>& filelist) { - mpq_hash hash = GetHashEntry("(listfile)"); - uint32 blockindex = hash.blockindex; - - if ((blockindex == 0xFFFFFFFF) || (blockindex == 0)) - return; + 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); - uint32 size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, blockindex); char *buffer = new char[size]; - - libmpq_file_getdata(&mpq_a, hash, blockindex, (unsigned char*)buffer); + + libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); char seps[] = "\n"; char *token; @@ -87,7 +57,7 @@ class MPQFile //MPQHANDLE handle; bool eof; char *buffer; - size_t pointer,size; + libmpq__off_t pointer,size; // disable copying MPQFile(const MPQFile &f) {} @@ -119,4 +89,3 @@ inline void flipcc(char *fcc) } #endif - diff --git a/src/tools/map_extractor/loadlib/wdt.cpp b/src/tools/map_extractor/wdt.cpp index dedefbb64e5..dedefbb64e5 100644 --- a/src/tools/map_extractor/loadlib/wdt.cpp +++ b/src/tools/map_extractor/wdt.cpp diff --git a/src/tools/map_extractor/loadlib/wdt.h b/src/tools/map_extractor/wdt.h index fcee8ac64f2..fcee8ac64f2 100644 --- a/src/tools/map_extractor/loadlib/wdt.h +++ b/src/tools/map_extractor/wdt.h |
