diff options
-rw-r--r-- | src/common/Collision/Management/IVMapManager.h | 9 | ||||
-rw-r--r-- | src/common/Collision/Management/VMapManager2.cpp | 2 | ||||
-rw-r--r-- | src/common/Collision/Management/VMapManager2.h | 2 | ||||
-rw-r--r-- | src/common/Collision/Maps/MapTree.cpp | 28 | ||||
-rw-r--r-- | src/common/Collision/Maps/MapTree.h | 3 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Maps/Map.cpp | 19 |
7 files changed, 47 insertions, 24 deletions
diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h index d876136fe10..d8073e86b78 100644 --- a/src/common/Collision/Management/IVMapManager.h +++ b/src/common/Collision/Management/IVMapManager.h @@ -39,6 +39,13 @@ namespace VMAP VMAP_LOAD_RESULT_IGNORED }; + enum class LoadResult : uint8 + { + Success, + FileNotFound, + VersionMismatch + }; + #define VMAP_INVALID_HEIGHT -100000.0f // for check #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case @@ -56,7 +63,7 @@ namespace VMAP virtual int loadMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0; - virtual bool existsMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0; + virtual LoadResult existsMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0; virtual void unloadMap(unsigned int pMapId, int x, int y) = 0; virtual void unloadMap(unsigned int pMapId) = 0; diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 1f3e001b054..0ad872fe6c1 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -351,7 +351,7 @@ namespace VMAP } } - bool VMapManager2::existsMap(const char* basePath, unsigned int mapId, int x, int y) + LoadResult VMapManager2::existsMap(const char* basePath, unsigned int mapId, int x, int y) { return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y, this); } diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h index 32a4ec17e32..c48a8e985a6 100644 --- a/src/common/Collision/Management/VMapManager2.h +++ b/src/common/Collision/Management/VMapManager2.h @@ -131,7 +131,7 @@ namespace VMAP { return getMapFileName(mapId); } - virtual bool existsMap(const char* basePath, unsigned int mapId, int x, int y) override; + virtual LoadResult existsMap(const char* basePath, unsigned int mapId, int x, int y) override; void getInstanceMapTree(InstanceTreeMap &instanceMapTree); diff --git a/src/common/Collision/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp index ab48c4ebe0c..9b735061c29 100644 --- a/src/common/Collision/Maps/MapTree.cpp +++ b/src/common/Collision/Maps/MapTree.cpp @@ -255,35 +255,43 @@ namespace VMAP } //========================================================= - - bool StaticMapTree::CanLoadMap(const std::string &vmapPath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm) + LoadResult StaticMapTree::CanLoadMap(const std::string &vmapPath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm) { std::string basePath = vmapPath; if (basePath.length() > 0 && basePath[basePath.length()-1] != '/' && basePath[basePath.length()-1] != '\\') basePath.push_back('/'); std::string fullname = basePath + VMapManager2::getMapFileName(mapID); - bool success = true; + + LoadResult result = LoadResult::Success; + FILE* rf = fopen(fullname.c_str(), "rb"); if (!rf) - return false; + return LoadResult::FileNotFound; char chunk[8]; if (!readChunk(rf, chunk, VMAP_MAGIC, 8)) { fclose(rf); - return false; + return LoadResult::VersionMismatch; } FILE* tf = OpenMapTileFile(basePath, mapID, tileX, tileY, vm).File; if (!tf) - success = false; + return LoadResult::FileNotFound; else { - if (!readChunk(tf, chunk, VMAP_MAGIC, 8)) - success = false; - fclose(tf); + std::string tilefile = basePath + getTileFileName(mapID, tileX, tileY); + FILE* tf = fopen(tilefile.c_str(), "rb"); + if (!tf) + result = LoadResult::FileNotFound; + else + { + if (!readChunk(tf, chunk, VMAP_MAGIC, 8)) + result = LoadResult::VersionMismatch; + fclose(tf); + } } fclose(rf); - return success; + return result; } //========================================================= diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h index 9b24c9abb1a..df1ce431109 100644 --- a/src/common/Collision/Maps/MapTree.h +++ b/src/common/Collision/Maps/MapTree.h @@ -28,6 +28,7 @@ namespace VMAP class ModelInstance; class GroupModel; class VMapManager2; + enum class LoadResult : uint8; enum class ModelIgnoreFlags : uint32; struct TC_COMMON_API LocationInfo @@ -72,7 +73,7 @@ namespace VMAP static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY); static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; } static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID >> 16; tileY = ID & 0xFF; } - static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm); + static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm); StaticMapTree(uint32 mapID, const std::string &basePath); ~StaticMapTree(); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 746782fa1ec..2dd2753cde3 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -1989,8 +1989,8 @@ void ObjectMgr::LoadCreatures() int gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord; int gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord; - bool exists = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), data.mapid, gx, gy); - if (!exists) + VMAP::LoadResult result = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), data.mapid, gx, gy); + if (result != VMAP::LoadResult::Success) TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: " UI64FMTD " Entry: %u MapID: %u) spawned on a possible invalid position (X: %f Y: %f Z: %f)", guid, data.id, data.mapid, data.posX, data.posY, data.posZ); } @@ -2348,8 +2348,8 @@ void ObjectMgr::LoadGameobjects() int gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord; int gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord; - bool exists = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), data.mapid, gx, gy); - if (!exists) + VMAP::LoadResult result = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), data.mapid, gx, gy); + if (result != VMAP::LoadResult::Success) TC_LOG_ERROR("sql.sql", "Table `gameobject` has gameobject (GUID: " UI64FMTD " Entry: %u MapID: %u) spawned on a possible invalid position (X: %f Y: %f Z: %f)", guid, data.id, data.mapid, data.posX, data.posY, data.posZ); } diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index dfd8b7fd5b7..a0e7043532d 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -125,13 +125,20 @@ bool Map::ExistVMap(uint32 mapid, int gx, int gy) { if (vmgr->isMapLoadingEnabled()) { - bool exists = vmgr->existsMap((sWorld->GetDataPath()+ "vmaps").c_str(), mapid, gx, gy); - if (!exists) + VMAP::LoadResult result = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), mapid, gx, gy); + std::string name = vmgr->getDirFileName(mapid, gx, gy); + switch (result) { - std::string name = vmgr->getDirFileName(mapid, gx, gy); - TC_LOG_ERROR("maps", "VMap file '%s' does not exist", (sWorld->GetDataPath()+"vmaps/"+name).c_str()); - TC_LOG_ERROR("maps", "Please place VMAP-files (*.vmtree and *.vmtile) in the vmap-directory (%s), or correct the DataDir setting in your worldserver.conf file.", (sWorld->GetDataPath()+"vmaps/").c_str()); - return false; + case VMAP::LoadResult::Success: + break; + case VMAP::LoadResult::FileNotFound: + TC_LOG_ERROR("maps", "VMap file '%s' does not exist", (sWorld->GetDataPath() + "vmaps/" + name).c_str()); + TC_LOG_ERROR("maps", "Please place VMAP files (*.vmtree and *.vmtile) in the vmap directory (%s), or correct the DataDir setting in your worldserver.conf file.", (sWorld->GetDataPath() + "vmaps/").c_str()); + return false; + case VMAP::LoadResult::VersionMismatch: + TC_LOG_ERROR("maps", "VMap file '%s' couldn't be loaded", (sWorld->GetDataPath() + "vmaps/" + name).c_str()); + TC_LOG_ERROR("maps", "This is because the version of the VMap file and the version of this module are different, please re-extract the maps with the tools compiled with this module."); + return false; } } } |