mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Tools/vmap extractor: Various fixes
* Fixed output file name case normalization - exclude names built from file ids (starting with FILE) * Skip antiportal WMO groups Closes #23972 Closes #24798
This commit is contained in:
@@ -158,6 +158,15 @@ CASC::File::~File()
|
||||
::CascCloseFile(_handle);
|
||||
}
|
||||
|
||||
uint32 CASC::File::GetId() const
|
||||
{
|
||||
CASC_FILE_FULL_INFO info;
|
||||
if (!::CascGetFileInfo(_handle, CascFileFullInfo, &info, sizeof(info), nullptr))
|
||||
return CASC_INVALID_ID;
|
||||
|
||||
return info.FileDataId;
|
||||
}
|
||||
|
||||
int64 CASC::File::GetSize() const
|
||||
{
|
||||
ULONGLONG size;
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace CASC
|
||||
public:
|
||||
~File();
|
||||
|
||||
uint32 GetId() const;
|
||||
int64 GetSize() const;
|
||||
int64 GetPointer() const;
|
||||
bool SetPointer(int64 position);
|
||||
|
||||
@@ -395,18 +395,17 @@ namespace VMAP
|
||||
|
||||
// temporary use defines to simplify read/check code (close file and return at fail)
|
||||
#define READ_OR_RETURN(V, S) if (fread((V), (S), 1, rf) != 1) { \
|
||||
fclose(rf); printf("readfail, op = %i\n", readOperation); return(false); }
|
||||
fclose(rf); printf("%s readfail, op = %s\n", __FUNCTION__, #V); return(false); }
|
||||
#define READ_OR_RETURN_WITH_DELETE(V, S) if (fread((V), (S), 1, rf) != 1) { \
|
||||
fclose(rf); printf("readfail, op = %i\n", readOperation); delete[] V; return(false); };
|
||||
fclose(rf); printf("%s readfail, op = %s\n", __FUNCTION__, #V); delete[] V; return(false); };
|
||||
#define CMP_OR_RETURN(V, S) if (strcmp((V), (S)) != 0) { \
|
||||
fclose(rf); printf("cmpfail, %s!=%s\n", V, S);return(false); }
|
||||
fclose(rf); printf("%s cmpfail, %s!=%s\n", __FUNCTION__, V, S);return(false); }
|
||||
|
||||
bool GroupModel_Raw::Read(FILE* rf)
|
||||
{
|
||||
char blockId[5];
|
||||
blockId[4] = 0;
|
||||
int blocksize;
|
||||
int readOperation = 0;
|
||||
|
||||
READ_OR_RETURN(&mogpflags, sizeof(uint32));
|
||||
READ_OR_RETURN(&GroupWMOID, sizeof(uint32));
|
||||
@@ -511,7 +510,6 @@ namespace VMAP
|
||||
|
||||
char ident[9];
|
||||
ident[8] = '\0';
|
||||
int readOperation = 0;
|
||||
|
||||
READ_OR_RETURN(&ident, 8);
|
||||
CMP_OR_RETURN(ident, RAW_VMAP_MAGIC);
|
||||
@@ -536,5 +534,6 @@ namespace VMAP
|
||||
|
||||
// drop of temporary use defines
|
||||
#undef READ_OR_RETURN
|
||||
#undef READ_OR_RETURN_WITH_DELETE
|
||||
#undef CMP_OR_RETURN
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ char const* GetPlainName(char const* FileName)
|
||||
{
|
||||
const char * szTemp;
|
||||
|
||||
if((szTemp = strrchr(FileName, '\\')) != NULL)
|
||||
if((szTemp = strrchr(FileName, '\\')) != nullptr)
|
||||
FileName = szTemp + 1;
|
||||
return FileName;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ char* GetPlainName(char* FileName)
|
||||
{
|
||||
char * szTemp;
|
||||
|
||||
if((szTemp = strrchr(FileName, '\\')) != NULL)
|
||||
if((szTemp = strrchr(FileName, '\\')) != nullptr)
|
||||
FileName = szTemp + 1;
|
||||
return FileName;
|
||||
}
|
||||
@@ -67,11 +67,20 @@ void FixNameSpaces(char* name, size_t len)
|
||||
name[i] = '_';
|
||||
}
|
||||
|
||||
void NormalizeFileName(char* name, size_t len)
|
||||
{
|
||||
if (len >= 4 && !memcmp(name, "FILE", 4)) // name is FileDataId formatted, do not normalize
|
||||
return;
|
||||
|
||||
FixNameCase(name, len);
|
||||
FixNameSpaces(name, len);
|
||||
}
|
||||
|
||||
char* GetExtension(char* FileName)
|
||||
{
|
||||
if (char* szTemp = strrchr(FileName, '.'))
|
||||
return szTemp;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
@@ -130,8 +139,7 @@ bool ADTFile::init(uint32 map_num, uint32 originalMapId)
|
||||
std::string path(p);
|
||||
|
||||
char* s = GetPlainName(p);
|
||||
FixNameCase(s, strlen(s));
|
||||
FixNameSpaces(s, strlen(s));
|
||||
NormalizeFileName(s, strlen(s));
|
||||
|
||||
ModelInstanceNames.emplace_back(s);
|
||||
|
||||
@@ -154,8 +162,7 @@ bool ADTFile::init(uint32 map_num, uint32 originalMapId)
|
||||
std::string path(p);
|
||||
|
||||
char* s = GetPlainName(p);
|
||||
FixNameCase(s, strlen(s));
|
||||
FixNameSpaces(s, strlen(s));
|
||||
NormalizeFileName(s, strlen(s));
|
||||
|
||||
WmoInstanceNames.emplace_back(s);
|
||||
|
||||
|
||||
@@ -75,8 +75,7 @@ public:
|
||||
char const* GetPlainName(char const* FileName);
|
||||
char* GetPlainName(char* FileName);
|
||||
char* GetExtension(char* FileName);
|
||||
void FixNameCase(char* name, size_t len);
|
||||
void FixNameSpaces(char* name, size_t len);
|
||||
void NormalizeFileName(char* name, size_t len);
|
||||
//void fixMapNamen(char *name, size_t len);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -42,9 +42,7 @@ bool ExtractSingleModel(std::string& fname)
|
||||
std::string originalName = fname;
|
||||
|
||||
char* name = GetPlainName((char*)fname.c_str());
|
||||
if (fname.substr(0, 4) != "FILE")
|
||||
FixNameCase(name, strlen(name));
|
||||
FixNameSpaces(name, strlen(name));
|
||||
NormalizeFileName(name, strlen(name));
|
||||
|
||||
std::string output(szWorkDirWmo);
|
||||
output += "/";
|
||||
|
||||
@@ -249,8 +249,7 @@ void Doodad::ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, b
|
||||
ASSERT(false);
|
||||
|
||||
uint32 nlen = strlen(ModelInstName);
|
||||
FixNameCase(ModelInstName, nlen);
|
||||
FixNameSpaces(ModelInstName, nlen);
|
||||
NormalizeFileName(ModelInstName, nlen);
|
||||
if (nlen > 3)
|
||||
{
|
||||
char const* extension = &ModelInstName[nlen - 4];
|
||||
|
||||
@@ -162,9 +162,7 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
|
||||
char szLocalFile[1024];
|
||||
char* plain_name = GetPlainName(&fname[0]);
|
||||
if (fname.substr(0, 4) != "FILE")
|
||||
FixNameCase(plain_name, strlen(plain_name));
|
||||
FixNameSpaces(plain_name, strlen(plain_name));
|
||||
NormalizeFileName(plain_name, strlen(plain_name));
|
||||
sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
|
||||
|
||||
if (FileExists(szLocalFile))
|
||||
@@ -173,17 +171,10 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
int p = 0;
|
||||
// Select root wmo files
|
||||
char const* rchr = strrchr(plain_name, '_');
|
||||
if (rchr != NULL)
|
||||
{
|
||||
char cpy[4];
|
||||
memcpy(cpy, rchr, 4);
|
||||
if (rchr != nullptr)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
int m = cpy[i];
|
||||
if (isdigit(m))
|
||||
if (isdigit(rchr[i]))
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
if (p == 3)
|
||||
return true;
|
||||
@@ -205,6 +196,7 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
WMODoodadData& doodads = WmoDoodads[plain_name];
|
||||
std::swap(doodads, froot.DoodadData);
|
||||
int Wmo_nVertices = 0;
|
||||
uint32 groupCount = 0;
|
||||
//printf("root has %d groups\n", froot->nGroups);
|
||||
for (std::size_t i = 0; i < froot.groupFileDataIDs.size(); ++i)
|
||||
{
|
||||
@@ -217,7 +209,11 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
break;
|
||||
}
|
||||
|
||||
if (fgroup.ShouldSkip(&froot))
|
||||
continue;
|
||||
|
||||
Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, preciseVectorData);
|
||||
++groupCount;
|
||||
for (uint16 groupReference : fgroup.DoodadReferences)
|
||||
{
|
||||
if (groupReference >= doodads.Spawns.size())
|
||||
@@ -232,7 +228,8 @@ bool ExtractSingleWmo(std::string& fname)
|
||||
}
|
||||
|
||||
fseek(output, 8, SEEK_SET); // store the correct no of vertices
|
||||
fwrite(&Wmo_nVertices,sizeof(int),1,output);
|
||||
fwrite(&Wmo_nVertices, sizeof(int), 1, output);
|
||||
fwrite(&groupCount, sizeof(uint32), 1, output);
|
||||
fclose(output);
|
||||
|
||||
// Delete the extracted file in the case of an error
|
||||
@@ -270,12 +267,12 @@ void ParsMapFiles()
|
||||
return &itr->second;
|
||||
};
|
||||
|
||||
for (auto itr = map_ids.begin(); itr != map_ids.end(); ++itr)
|
||||
for (MapEntry const& mapEntry : map_ids)
|
||||
{
|
||||
if (WDTFile* WDT = getWDT(itr->Id))
|
||||
if (WDTFile* WDT = getWDT(mapEntry.Id))
|
||||
{
|
||||
WDTFile* parentWDT = itr->ParentMapID >= 0 ? getWDT(itr->ParentMapID) : nullptr;
|
||||
printf("Processing Map %u\n[", itr->Id);
|
||||
WDTFile* parentWDT = mapEntry.ParentMapID >= 0 ? getWDT(mapEntry.ParentMapID) : nullptr;
|
||||
printf("Processing Map %u\n[", mapEntry.Id);
|
||||
for (int32 x = 0; x < 64; ++x)
|
||||
{
|
||||
for (int32 y = 0; y < 64; ++y)
|
||||
@@ -283,14 +280,14 @@ void ParsMapFiles()
|
||||
bool success = false;
|
||||
if (ADTFile* ADT = WDT->GetMap(x, y))
|
||||
{
|
||||
success = ADT->init(itr->Id, itr->Id);
|
||||
success = ADT->init(mapEntry.Id, mapEntry.Id);
|
||||
WDT->FreeADT(ADT);
|
||||
}
|
||||
if (!success && parentWDT)
|
||||
{
|
||||
if (ADTFile* ADT = parentWDT->GetMap(x, y))
|
||||
{
|
||||
ADT->init(itr->Id, itr->ParentMapID);
|
||||
ADT->init(mapEntry.Id, mapEntry.ParentMapID);
|
||||
parentWDT->FreeADT(ADT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,6 @@
|
||||
#include "StringFormat.h"
|
||||
#include <cstdio>
|
||||
|
||||
char * wdtGetPlainName(char * FileName)
|
||||
{
|
||||
char * szTemp;
|
||||
|
||||
if((szTemp = strrchr(FileName, '\\')) != NULL)
|
||||
FileName = szTemp + 1;
|
||||
return FileName;
|
||||
}
|
||||
|
||||
extern std::shared_ptr<CASC::Storage> CascStorage;
|
||||
|
||||
WDTFile::WDTFile(uint32 fileDataId, std::string const& description, std::string mapName, bool cache)
|
||||
@@ -104,11 +95,10 @@ bool WDTFile::init(uint32 mapId)
|
||||
{
|
||||
std::string path(p);
|
||||
|
||||
char* s = wdtGetPlainName(p);
|
||||
FixNameCase(s, strlen(s));
|
||||
FixNameSpaces(s, strlen(s));
|
||||
char* s = GetPlainName(p);
|
||||
NormalizeFileName(s, strlen(s));
|
||||
p = p + strlen(p) + 1;
|
||||
_wmoNames.push_back(s);
|
||||
_wmoNames.emplace_back(s);
|
||||
|
||||
ExtractSingleWmo(path);
|
||||
}
|
||||
@@ -160,7 +150,7 @@ ADTFile* WDTFile::GetMap(int32 x, int32 y)
|
||||
return nullptr;
|
||||
|
||||
ADTFile* adt;
|
||||
std::string name = Trinity::StringFormat("World\\Maps\\%s\\%s_%d_%d_obj0.adt", _mapName.c_str(), _mapName.c_str(), x, y);
|
||||
std::string name = Trinity::StringFormat(R"(World\Maps\%s\%s_%d_%d_obj0.adt)", _mapName.c_str(), _mapName.c_str(), x, y);
|
||||
if (_header.Flags & 0x200)
|
||||
adt = new ADTFile(_adtFileDataIds->Data[y][x].Obj0ADT, name, _adtCache != nullptr);
|
||||
else
|
||||
|
||||
@@ -76,6 +76,11 @@ bool WMORoot::open()
|
||||
f.read(&flags, 2);
|
||||
f.read(&numLod, 2);
|
||||
}
|
||||
else if (!strcmp(fourcc, "MOGN"))
|
||||
{
|
||||
GroupNames.resize(size);
|
||||
f.read(GroupNames.data(), size);
|
||||
}
|
||||
else if (!strcmp(fourcc, "MODS"))
|
||||
{
|
||||
DoodadData.Sets.resize(size / sizeof(WMO::MODS));
|
||||
@@ -94,8 +99,7 @@ bool WMORoot::open()
|
||||
std::string path = ptr;
|
||||
|
||||
char* s = GetPlainName(ptr);
|
||||
FixNameCase(s, strlen(s));
|
||||
FixNameSpaces(s, strlen(s));
|
||||
NormalizeFileName(s, strlen(s));
|
||||
|
||||
uint32 doodadNameIndex = ptr - f.getPointer();
|
||||
ptr += path.length() + 1;
|
||||
@@ -158,9 +162,6 @@ bool WMORoot::open()
|
||||
else if (!strcmp(fourcc,"MOMT"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MOGN"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MOGI"))
|
||||
{
|
||||
}
|
||||
@@ -202,8 +203,8 @@ bool WMORoot::ConvertToVMAPRootWmo(FILE* pOutfile)
|
||||
}
|
||||
|
||||
WMOGroup::WMOGroup(const std::string &filename) :
|
||||
filename(filename), MOPY(0), MOVI(0), MoviEx(0), MOVT(0), MOBA(0), MobaEx(0),
|
||||
hlq(0), LiquEx(0), LiquBytes(0), groupName(0), descGroupName(0), mogpFlags(0),
|
||||
filename(filename), MOPY(nullptr), MOVI(nullptr), MoviEx(nullptr), MOVT(nullptr), MOBA(nullptr), MobaEx(nullptr),
|
||||
hlq(nullptr), LiquEx(nullptr), LiquBytes(nullptr), groupName(0), descGroupName(0), mogpFlags(0),
|
||||
moprIdx(0), moprNItems(0), nBatchA(0), nBatchB(0), nBatchC(0), fogIdx(0),
|
||||
groupLiquid(0), groupWMOID(0), mopy_size(0), moba_size(0), LiquEx_size(0),
|
||||
nVertices(0), nTriangles(0), liquflags(0)
|
||||
@@ -221,17 +222,15 @@ bool WMOGroup::open(WMORoot* rootWMO)
|
||||
return false;
|
||||
}
|
||||
uint32 size;
|
||||
char fourcc[5];
|
||||
char fourcc[5] = { };
|
||||
while (!f.isEof())
|
||||
{
|
||||
f.read(fourcc,4);
|
||||
f.read(&size, 4);
|
||||
flipcc(fourcc);
|
||||
if (!strcmp(fourcc,"MOGP"))//Fix sizeoff = Data size.
|
||||
{
|
||||
if (!strcmp(fourcc,"MOGP")) //size specified in MOGP chunk is all the other chunks combined, adjust to read MOGP-only
|
||||
size = 68;
|
||||
}
|
||||
fourcc[4] = 0;
|
||||
|
||||
size_t nextpos = f.getPos() + size;
|
||||
if (!strcmp(fourcc,"MOGP"))//header
|
||||
{
|
||||
@@ -542,6 +541,18 @@ uint32 WMOGroup::GetLiquidTypeId(uint32 liquidTypeId)
|
||||
return liquidTypeId;
|
||||
}
|
||||
|
||||
bool WMOGroup::ShouldSkip(WMORoot const* root) const
|
||||
{
|
||||
// skip antiportals
|
||||
if (mogpFlags & 0x4000000)
|
||||
return true;
|
||||
|
||||
if (groupName < int32(root->GroupNames.size()) && !strcmp(&root->GroupNames[groupName], "antiportal"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WMOGroup::~WMOGroup()
|
||||
{
|
||||
delete [] MOPY;
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
float bbcorn2[3];
|
||||
uint16 flags, numLod;
|
||||
|
||||
std::vector<char> GroupNames;
|
||||
WMODoodadData DoodadData;
|
||||
std::unordered_set<uint32> ValidDoodadNames;
|
||||
std::vector<uint32> groupFileDataIDs;
|
||||
@@ -156,6 +157,7 @@ public:
|
||||
bool open(WMORoot* rootWMO);
|
||||
int ConvertToVMAPGroupWmo(FILE* output, bool preciseVectorData);
|
||||
uint32 GetLiquidTypeId(uint32 liquidTypeId);
|
||||
bool ShouldSkip(WMORoot const* root) const;
|
||||
};
|
||||
|
||||
namespace MapObject
|
||||
|
||||
Reference in New Issue
Block a user