diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-05-26 12:50:38 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-05-26 12:50:38 +0200 |
| commit | bc57ce984bd8ac7e066e86a18b8cfd95616f86dd (patch) | |
| tree | 53eee77330140f340615fff7619c4bd85fdc264b /src/tools/map_extractor | |
| parent | 1a5af00760e8ba96a01c0e9049cca9de30ded567 (diff) | |
Tools/Extractors: Load the same MPQ file set as the client does (including custom patches)
Diffstat (limited to 'src/tools/map_extractor')
| -rw-r--r-- | src/tools/map_extractor/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/tools/map_extractor/System.cpp | 131 | ||||
| -rw-r--r-- | src/tools/map_extractor/dbcfile.cpp | 4 | ||||
| -rw-r--r-- | src/tools/map_extractor/loadlib.cpp | 2 | ||||
| -rw-r--r-- | src/tools/map_extractor/mpq_libmpq.cpp | 128 | ||||
| -rw-r--r-- | src/tools/map_extractor/mpq_libmpq04.h | 105 |
6 files changed, 40 insertions, 333 deletions
diff --git a/src/tools/map_extractor/CMakeLists.txt b/src/tools/map_extractor/CMakeLists.txt index e80c9d9a939..0613d0a7d4f 100644 --- a/src/tools/map_extractor/CMakeLists.txt +++ b/src/tools/map_extractor/CMakeLists.txt @@ -27,8 +27,7 @@ target_link_libraries(mapextractor PRIVATE trinity-core-interface PUBLIC - common - mpq) + extractor_common) CollectIncludeDirectories( ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index 9e8b0dbb3b2..c1830e57253 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -18,7 +18,7 @@ #include "dbcfile.h" #include "Banner.h" #include "Locales.h" -#include "mpq_libmpq04.h" +#include "mpq_libmpq.h" #include "StringFormat.h" #include "Util.h" @@ -38,8 +38,6 @@ #include <G3D/Plane.h> #include <boost/filesystem.hpp> -extern ArchiveSet gOpenArchives; - typedef struct { char name[64]; @@ -80,21 +78,7 @@ float CONF_float_to_int16_limit = 2048.0f; // Max accuracy = val/65536 float CONF_flat_height_delta_limit = 0.005f; // If max - min less this value - surface is flat float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - liquid surface is flat -// List MPQ for extract from -const char *CONF_mpq_list[]={ - "common.MPQ", - "common-2.MPQ", - "lichking.MPQ", - "expansion.MPQ", - "patch.MPQ", - "patch-2.MPQ", - "patch-3.MPQ", - "patch-4.MPQ", - "patch-5.MPQ", -}; - -static char const* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; -#define LANG_COUNT 12 +static constexpr std::array<std::string_view, 12> MpqLocaleNames = { "enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; void CreateDir(boost::filesystem::path const& path) { @@ -174,7 +158,7 @@ void HandleArgs(int argc, char * arg[]) uint32 ReadBuild(int locale) { // include build info file also - std::string filename = Trinity::StringFormat("component.wow-{}.txt", langs[locale]); + std::string filename = Trinity::StringFormat("component.wow-{}.txt", MpqLocaleNames[locale]); //printf("Read %s file... ", filename.c_str()); MPQFile m(filename.c_str()); @@ -995,7 +979,7 @@ void ExtractDBCFiles(int locale, bool basicLocale) for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) { std::vector<std::string> files; - (*i)->GetFileListTo(files); + i->GetFileListTo(files); for (std::vector<std::string>::iterator iter = files.begin(); iter != files.end(); ++iter) if (iter->rfind(".dbc") == iter->length() - strlen(".dbc")) dbcfiles.insert(*iter); @@ -1006,14 +990,14 @@ void ExtractDBCFiles(int locale, bool basicLocale) CreateDir(path); if(!basicLocale) { - path += langs[locale]; + path += MpqLocaleNames[locale]; path += "/"; CreateDir(path); } // extract Build info file { - std::string mpq_name = std::string("component.wow-") + langs[locale] + ".txt"; + std::string mpq_name = Trinity::StringFormat("component.wow-{}.txt", MpqLocaleNames[locale]); std::string filename = path + mpq_name; ExtractFile(mpq_name.c_str(), filename); @@ -1064,7 +1048,7 @@ void ExtractCameraFiles(int locale, bool basicLocale) CreateDir(path); if (!basicLocale) { - path += langs[locale]; + path += MpqLocaleNames[locale]; path += "/"; CreateDir(path); } @@ -1085,42 +1069,6 @@ void ExtractCameraFiles(int locale, bool basicLocale) printf("Extracted %u camera files\n", count); } -void LoadLocaleMPQFiles(int const locale) -{ - std::string fileName = Trinity::StringFormat("{}/Data/{}/locale-{}.MPQ", input_path, langs[locale], langs[locale]); - - new MPQArchive(fileName.c_str()); - - for(int i = 1; i < 5; ++i) - { - std::string ext; - if (i > 1) - ext = Trinity::StringFormat("-{}", i); - - fileName = Trinity::StringFormat("{}/Data/{}/patch-{}{}.MPQ", input_path, langs[locale], langs[locale], ext); - if (boost::filesystem::exists(fileName)) - new MPQArchive(fileName.c_str()); - } -} - -void LoadCommonMPQFiles() -{ - std::string fileName; - int count = sizeof(CONF_mpq_list)/sizeof(char*); - for(int i = 0; i < count; ++i) - { - fileName = Trinity::StringFormat("{}/Data/{}", input_path, CONF_mpq_list[i]); - if (boost::filesystem::exists(fileName)) - new MPQArchive(fileName.c_str()); - } -} - -inline void CloseMPQFiles() -{ - for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close(); - gOpenArchives.clear(); -} - int main(int argc, char * arg[]) { Trinity::VerifyOsVersion(); @@ -1134,38 +1082,35 @@ int main(int argc, char * arg[]) int FirstLocale = -1; uint32 build = 0; - for (int i = 0; i < LANG_COUNT; i++) + for (std::size_t i = 0; i < MpqLocaleNames.size(); i++) { - std::string filename = Trinity::StringFormat("{}/Data/{}/locale-{}.MPQ", input_path, langs[i], langs[i]); - if (boost::filesystem::exists(filename)) - { - printf("Detected locale: %s\n", langs[i]); - - //Open MPQs - LoadLocaleMPQFiles(i); + //Open MPQs + if (!MPQ::OpenArchives(input_path, MpqLocaleNames[i])) + continue; - if((CONF_extract & EXTRACT_DBC) == 0) - { - FirstLocale = i; - build = ReadBuild(FirstLocale); - printf("Detected client build: %u\n", build); - break; - } + printf("Detected locale: " STRING_VIEW_FMT "\n", STRING_VIEW_FMT_ARG(MpqLocaleNames[i])); - //Extract DBC files - if(FirstLocale < 0) - { - FirstLocale = i; - build = ReadBuild(FirstLocale); - printf("Detected client build: %u\n", build); - ExtractDBCFiles(i, true); - } - else - ExtractDBCFiles(i, false); + if((CONF_extract & EXTRACT_DBC) == 0) + { + FirstLocale = i; + build = ReadBuild(FirstLocale); + printf("Detected client build: %u\n", build); + break; + } - //Close MPQs - CloseMPQFiles(); + //Extract DBC files + if(FirstLocale < 0) + { + FirstLocale = i; + build = ReadBuild(FirstLocale); + printf("Detected client build: %u\n", build); + ExtractDBCFiles(i, true); } + else + ExtractDBCFiles(i, false); + + //Close MPQs + MPQ::CloseArchives(); } if(FirstLocale < 0) @@ -1176,30 +1121,28 @@ int main(int argc, char * arg[]) if (CONF_extract & EXTRACT_CAMERA) { - printf("Using locale: %s\n", langs[FirstLocale]); + printf("Using locale: " STRING_VIEW_FMT "\n", STRING_VIEW_FMT_ARG(MpqLocaleNames[FirstLocale])); // Open MPQs - LoadLocaleMPQFiles(FirstLocale); - LoadCommonMPQFiles(); + MPQ::OpenArchives(input_path, MpqLocaleNames[FirstLocale]); ExtractCameraFiles(FirstLocale, true); // Close MPQs - CloseMPQFiles(); + MPQ::CloseArchives(); } if (CONF_extract & EXTRACT_MAP) { - printf("Using locale: %s\n", langs[FirstLocale]); + printf("Using locale: " STRING_VIEW_FMT "\n", STRING_VIEW_FMT_ARG(MpqLocaleNames[FirstLocale])); // Open MPQs - LoadLocaleMPQFiles(FirstLocale); - LoadCommonMPQFiles(); + MPQ::OpenArchives(input_path, MpqLocaleNames[FirstLocale]); // Extract maps ExtractMapsFromMpq(build); // Close MPQs - CloseMPQFiles(); + MPQ::CloseArchives(); } return 0; diff --git a/src/tools/map_extractor/dbcfile.cpp b/src/tools/map_extractor/dbcfile.cpp index fa61fee22a1..66caf752992 100644 --- a/src/tools/map_extractor/dbcfile.cpp +++ b/src/tools/map_extractor/dbcfile.cpp @@ -15,10 +15,8 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define _CRT_SECURE_NO_DEPRECATE - #include "dbcfile.h" -#include "mpq_libmpq04.h" +#include "mpq_libmpq.h" DBCFile::DBCFile(const std::string& filename): filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr) diff --git a/src/tools/map_extractor/loadlib.cpp b/src/tools/map_extractor/loadlib.cpp index 72c6b73e38c..67cdfba1664 100644 --- a/src/tools/map_extractor/loadlib.cpp +++ b/src/tools/map_extractor/loadlib.cpp @@ -18,7 +18,7 @@ #define _CRT_SECURE_NO_DEPRECATE #include "loadlib.h" -#include "mpq_libmpq04.h" +#include "mpq_libmpq.h" #include <cstdio> class MPQFile; diff --git a/src/tools/map_extractor/mpq_libmpq.cpp b/src/tools/map_extractor/mpq_libmpq.cpp deleted file mode 100644 index d4766b27a58..00000000000 --- a/src/tools/map_extractor/mpq_libmpq.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "mpq_libmpq04.h" -#include <deque> -#include <cstdio> - -ArchiveSet gOpenArchives; - -MPQArchive::MPQArchive(char const* filename) -{ - int result = libmpq__archive_open(&mpq_a, filename, -1); - printf("Opening %s\n", filename); - if(result) { - switch(result) { - case LIBMPQ_ERROR_OPEN : - printf("Error opening archive '%s': Does file really exist?\n", filename); - break; - case LIBMPQ_ERROR_FORMAT : /* bad file format */ - printf("Error opening archive '%s': Bad file format\n", filename); - break; - case LIBMPQ_ERROR_SEEK : /* seeking in file failed */ - printf("Error opening archive '%s': Seeking in file failed\n", filename); - break; - case LIBMPQ_ERROR_READ : /* Read error in archive */ - printf("Error opening archive '%s': Read error in archive\n", filename); - break; - case LIBMPQ_ERROR_MALLOC : /* maybe not enough memory? :) */ - printf("Error opening archive '%s': Maybe not enough memory\n", filename); - break; - default: - printf("Error opening archive '%s': Unknown error\n", filename); - break; - } - return; - } - gOpenArchives.push_front(this); -} - -void MPQArchive::close() -{ - //gOpenArchives.erase(erase(&mpq_a); - libmpq__archive_close(mpq_a); -} - -MPQFile::MPQFile(char const* filename): - eof(false), - buffer(0), - pointer(0), - size(0) -{ - for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) - { - mpq_archive *mpq_a = (*i)->mpq_a; - - uint32_t filenum; - if(libmpq__file_number(mpq_a, filename, &filenum)) continue; - libmpq__off_t transferred; - libmpq__file_size_unpacked(mpq_a, filenum, &size); - - // HACK: in patch.mpq some files don't want to open and give 1 for filesize - if (size<=1) { -// printf("warning: file %s has size %d; cannot read.\n", filename, size); - eof = true; - buffer = 0; - return; - } - buffer = new char[size]; - - //libmpq_file_getdata - libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); - /*libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);*/ - return; - - } - eof = true; - buffer = 0; -} - -size_t MPQFile::read(void* dest, size_t bytes) -{ - if (eof) return 0; - - size_t rpos = pointer + bytes; - if (rpos > size_t(size)) { - bytes = size - pointer; - eof = true; - } - - memcpy(dest, &(buffer[pointer]), bytes); - - pointer = rpos; - - return bytes; -} - -void MPQFile::seek(int offset) -{ - pointer = offset; - eof = (pointer >= size); -} - -void MPQFile::seekRelative(int offset) -{ - pointer += offset; - eof = (pointer >= size); -} - -void MPQFile::close() -{ - delete[] buffer; - buffer = 0; - eof = true; -} diff --git a/src/tools/map_extractor/mpq_libmpq04.h b/src/tools/map_extractor/mpq_libmpq04.h deleted file mode 100644 index f1763069c1a..00000000000 --- a/src/tools/map_extractor/mpq_libmpq04.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MPQ_H -#define MPQ_H - -#include "loadlib/loadlib.h" -#include "libmpq/mpq.h" -#include <string.h> -#include <ctype.h> -#include <vector> -#include <iostream> -#include <deque> - -class MPQArchive -{ - -public: - mpq_archive_s *mpq_a; - - MPQArchive(char const* filename); - ~MPQArchive() { close(); } - void close(); - - void GetFileListTo(std::vector<std::string>& filelist) { - uint32_t filenum; - if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return; - libmpq__off_t size, transferred; - libmpq__file_size_unpacked(mpq_a, filenum, &size); - - char *buffer = new char[size+1]; - buffer[size] = '\0'; - - libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); - - char seps[] = "\n"; - char *token; - - token = strtok( buffer, seps ); - uint32 counter = 0; - while ((token != nullptr) && (counter < size)) { - //cout << token << endl; - token[strlen(token) - 1] = 0; - std::string s = token; - filelist.push_back(s); - counter += strlen(token) + 2; - token = strtok(nullptr, seps); - } - - delete[] buffer; - } -}; -typedef std::deque<MPQArchive*> ArchiveSet; - -class MPQFile -{ - //MPQHANDLE handle; - bool eof; - char *buffer; - libmpq__off_t pointer,size; - - // disable copying - MPQFile(MPQFile const& /*f*/) = delete; - void operator=(MPQFile const& /*f*/) = delete; - -public: - MPQFile(char const* filename); // filenames are not case sensitive - ~MPQFile() { close(); } - size_t read(void* dest, size_t bytes); - size_t getSize() { return size; } - size_t getPos() { return pointer; } - char* getBuffer() { return buffer; } - char* getPointer() { return buffer + pointer; } - bool isEof() { return eof; } - void seek(int offset); - void seekRelative(int offset); - void close(); -}; - -inline void flipcc(char *fcc) -{ - char t; - t=fcc[0]; - fcc[0]=fcc[3]; - fcc[3]=t; - t=fcc[1]; - fcc[1]=fcc[2]; - fcc[2]=t; -} - -#endif |
