From a2ec80b14ced0d32e5929af6286667de63e9d0ae Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 20 Dec 2022 16:01:28 +0100 Subject: Core/vmaps: Stop worldserver startup when gameobject models cannot be loaded --- src/common/Collision/Models/GameObjectModel.cpp | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/common/Collision/Models/GameObjectModel.cpp') diff --git a/src/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp index 5ef59a727ea..72a9a706bdc 100644 --- a/src/common/Collision/Models/GameObjectModel.cpp +++ b/src/common/Collision/Models/GameObjectModel.cpp @@ -22,6 +22,7 @@ #include "GameObjectModel.h" #include "Log.h" #include "MapTree.h" +#include "Memory.h" #include "Timer.h" #include @@ -42,24 +43,23 @@ struct GameobjectModelData typedef std::unordered_map ModelList; ModelList model_list; -void LoadGameObjectModelList(std::string const& dataPath) +bool LoadGameObjectModelList(std::string const& dataPath) { uint32 oldMSTime = getMSTime(); - FILE* model_list_file = fopen((dataPath + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb"); + auto model_list_file = Trinity::make_unique_ptr_with_deleter(fopen((dataPath + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb"), &::fclose); if (!model_list_file) { TC_LOG_ERROR("misc", "Unable to open '%s' file.", VMAP::GAMEOBJECT_MODELS); - return; + return false; } char magic[8]; - if (fread(magic, 1, 8, model_list_file) != 8 + if (fread(magic, 1, 8, model_list_file.get()) != 8 || memcmp(magic, VMAP::VMAP_MAGIC, 8) != 0) { TC_LOG_ERROR("misc", "File '%s' has wrong header, expected %s.", VMAP::GAMEOBJECT_MODELS, VMAP::VMAP_MAGIC); - fclose(model_list_file); - return; + return false; } uint32 name_length, displayId; @@ -68,16 +68,16 @@ void LoadGameObjectModelList(std::string const& dataPath) while (true) { Vector3 v1, v2; - if (fread(&displayId, sizeof(uint32), 1, model_list_file) != 1) - if (feof(model_list_file)) // EOF flag is only set after failed reading attempt + if (fread(&displayId, sizeof(uint32), 1, model_list_file.get()) != 1) + if (feof(model_list_file.get())) // EOF flag is only set after failed reading attempt break; - if (fread(&isWmo, sizeof(uint8), 1, model_list_file) != 1 - || fread(&name_length, sizeof(uint32), 1, model_list_file) != 1 + if (fread(&isWmo, sizeof(uint8), 1, model_list_file.get()) != 1 + || fread(&name_length, sizeof(uint32), 1, model_list_file.get()) != 1 || name_length >= sizeof(buff) - || fread(&buff, sizeof(char), name_length, model_list_file) != name_length - || fread(&v1, sizeof(Vector3), 1, model_list_file) != 1 - || fread(&v2, sizeof(Vector3), 1, model_list_file) != 1) + || fread(&buff, sizeof(char), name_length, model_list_file.get()) != name_length + || fread(&v1, sizeof(Vector3), 1, model_list_file.get()) != 1 + || fread(&v2, sizeof(Vector3), 1, model_list_file.get()) != 1) { TC_LOG_ERROR("misc", "File '%s' seems to be corrupted!", VMAP::GAMEOBJECT_MODELS); break; @@ -92,8 +92,8 @@ void LoadGameObjectModelList(std::string const& dataPath) model_list.emplace(std::piecewise_construct, std::forward_as_tuple(displayId), std::forward_as_tuple(&buff[0], name_length, v1, v2, isWmo != 0)); } - fclose(model_list_file); TC_LOG_INFO("server.loading", ">> Loaded %u GameObject models in %u ms", uint32(model_list.size()), GetMSTimeDiffToNow(oldMSTime)); + return true; } GameObjectModel::~GameObjectModel() -- cgit v1.2.3