mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-20 18:54:34 +00:00
refactor(Core): Rename ...Manager to ...Mgr (#6910)
* Rename MapManager.h to MapMgr.h * Rename BanManager.h to BanMgr.h * Rename MapManager.cpp to MapMgr.cpp * Rename BanManager.cpp to BanMgr.cpp * Rename MapRefManager.h to MapRefMgr.h * Rename ThreatManager.h to ThreatMgr.h * Rename GridRefManager.h to GridRefMgr.h * Rename ThreatManager.cpp to ThreatMgr.cpp * Rename GroupRefManager.h to GroupRefMgr.h * Rename HostileRefManager.h to HostileRefMgr.h * Rename HostileRefManager.cpp to HostileRefMgr.cpp * Rename MMapManager.h to MMapMgr.h * Rename FollowerRefManager.h to FollowerRefMgr.h * Rename VMapManager2.h to VMapMgr2.h * Rename IVMapManager.h to IVMapMgr.h * Rename MMapManager.cpp to MMapMgr.cpp * Rename VMapManager2.cpp to VMapMgr2.cpp * Rename RefManager.h to RefMgr.h * Rename WaypointManager.h to WaypointMgr.h * Rename WaypointManager.cpp to WaypointMgr.cpp * Rename MPQManager.h to MPQMgr.h * Rename MPQManager.cpp to MPQMgr.cpp * Rename IMMAPManager.h to IMMAPMgr.h * fix build * Update Main.cpp * chore(Core/Misc): Remove toxic language * Revert "chore(Core/Misc): Remove toxic language" * fix build * build
This commit is contained in:
121
src/tools/mesh_extractor/MPQMgr.cpp
Normal file
121
src/tools/mesh_extractor/MPQMgr.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#include "MPQMgr.h"
|
||||
#include "MPQ.h"
|
||||
#include "DBC.h"
|
||||
#include "Utils.h"
|
||||
|
||||
char const* MPQMgr::Files[] =
|
||||
{
|
||||
"common.MPQ",
|
||||
"common-2.MPQ",
|
||||
"expansion.MPQ",
|
||||
"lichking.MPQ",
|
||||
"patch.MPQ",
|
||||
"patch-2.MPQ",
|
||||
"patch-3.MPQ"
|
||||
};
|
||||
|
||||
char const* MPQMgr::Languages[] = { "enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
|
||||
|
||||
void MPQMgr::Initialize()
|
||||
{
|
||||
InitializeDBC();
|
||||
uint32 size = sizeof(Files) / sizeof(char*);
|
||||
for (uint32 i = 0; i < size; ++i)
|
||||
{
|
||||
MPQArchive* arc = new MPQArchive(std::string("Data/" + std::string(Files[i])).c_str());
|
||||
Archives.push_front(arc); // MPQ files have to be transversed in reverse order to properly account for patched files
|
||||
printf("Opened %s\n", Files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MPQMgr::InitializeDBC()
|
||||
{
|
||||
BaseLocale = -1;
|
||||
std::string fileName;
|
||||
uint32 size = sizeof(Languages) / sizeof(char*);
|
||||
MPQArchive* _baseLocale = nullptr;
|
||||
for (uint32 i = 0; i < size; ++i)
|
||||
{
|
||||
std::string _fileName = "Data/" + std::string(Languages[i]) + "/locale-" + std::string(Languages[i]) + ".MPQ";
|
||||
FILE* file = fopen(_fileName.c_str(), "rb");
|
||||
if (file)
|
||||
{
|
||||
if (BaseLocale == -1)
|
||||
{
|
||||
BaseLocale = i;
|
||||
_baseLocale = new MPQArchive(_fileName.c_str());
|
||||
fileName = _fileName;
|
||||
LocaleFiles[i] = _baseLocale;
|
||||
}
|
||||
else
|
||||
LocaleFiles[i] = new MPQArchive(_fileName.c_str());
|
||||
|
||||
AvailableLocales.insert(i);
|
||||
printf("Detected locale: %s\n", Languages[i]);
|
||||
}
|
||||
}
|
||||
Archives.push_front(_baseLocale);
|
||||
if (BaseLocale == -1)
|
||||
{
|
||||
printf("No locale data detected. Please make sure that the executable is in the same folder as your WoW installation.\n");
|
||||
ABORT();
|
||||
}
|
||||
else
|
||||
printf("Using default locale: %s\n", Languages[BaseLocale]);
|
||||
}
|
||||
|
||||
FILE* MPQMgr::GetFile(const std::string& path )
|
||||
{
|
||||
GUARD_RETURN(mutex, nullptr);
|
||||
MPQFile file(path.c_str());
|
||||
if (file.isEof())
|
||||
return nullptr;
|
||||
return file.GetFileStream();
|
||||
}
|
||||
|
||||
DBC* MPQMgr::GetDBC(const std::string& name )
|
||||
{
|
||||
std::string path = "DBFilesClient\\" + name + ".dbc";
|
||||
return new DBC(GetFile(path));
|
||||
}
|
||||
|
||||
FILE* MPQMgr::GetFileFrom(const std::string& path, MPQArchive* file )
|
||||
{
|
||||
GUARD_RETURN(mutex, nullptr);
|
||||
mpq_archive* mpq_a = file->mpq_a;
|
||||
|
||||
uint32_t filenum;
|
||||
if (libmpq__file_number(mpq_a, path.c_str(), &filenum))
|
||||
return nullptr;
|
||||
|
||||
libmpq__off_t transferred;
|
||||
libmpq__off_t size = 0;
|
||||
libmpq__file_unpacked_size(mpq_a, filenum, &size);
|
||||
|
||||
// HACK: in patch.mpq some files don't want to open and give 1 for filesize
|
||||
if (size <= 1)
|
||||
return nullptr;
|
||||
|
||||
uint8* buffer = new uint8[size];
|
||||
|
||||
//libmpq_file_getdata
|
||||
libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
|
||||
|
||||
// Pack the return into a FILE stream
|
||||
FILE* ret = tmpfile();
|
||||
if (!ret)
|
||||
{
|
||||
printf("Could not create temporary file. Please run as Administrator or root\n");
|
||||
exit(1);
|
||||
}
|
||||
fwrite(buffer, sizeof(uint8), size, ret);
|
||||
fseek(ret, 0, SEEK_SET);
|
||||
delete[] buffer;
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user