diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Collision/Management/IVMapManager.h | 2 | ||||
-rw-r--r-- | src/common/Collision/Management/MMapManager.cpp | 2 | ||||
-rw-r--r-- | src/common/Collision/Management/VMapManager2.cpp | 2 | ||||
-rw-r--r-- | src/common/Collision/Maps/MapDefines.h | 2 | ||||
-rw-r--r-- | src/common/Collision/Maps/MapTree.h | 2 | ||||
-rw-r--r-- | src/common/Collision/Maps/TileAssembler.cpp | 3 | ||||
-rw-r--r-- | src/common/Collision/RegularGrid.h | 2 | ||||
-rw-r--r-- | src/common/Debugging/WheatyExceptionReport.cpp | 15 | ||||
-rw-r--r-- | src/common/Logging/Log.cpp | 4 | ||||
-rw-r--r-- | src/common/Utilities/Containers.h | 26 | ||||
-rw-r--r-- | src/common/Utilities/IteratorPair.h | 58 | ||||
-rw-r--r-- | src/common/Utilities/StringFormat.h | 2 | ||||
-rw-r--r-- | src/common/Utilities/Util.h | 7 |
13 files changed, 85 insertions, 42 deletions
diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h index 0371135cfa5..c32bb2d41e5 100644 --- a/src/common/Collision/Management/IVMapManager.h +++ b/src/common/Collision/Management/IVMapManager.h @@ -66,7 +66,7 @@ namespace VMAP uint32 const type; float const level; }; - + float floorZ = VMAP_INVALID_HEIGHT; Optional<AreaInfo> areaInfo; Optional<LiquidInfo> liquidInfo; diff --git a/src/common/Collision/Management/MMapManager.cpp b/src/common/Collision/Management/MMapManager.cpp index ff87ed369cc..44ef59d5360 100644 --- a/src/common/Collision/Management/MMapManager.cpp +++ b/src/common/Collision/Management/MMapManager.cpp @@ -157,7 +157,7 @@ namespace MMAP long pos = ftell(file); fseek(file, 0, SEEK_END); - if (static_cast<int32>(fileHeader.size) > ftell(file) - pos) + if (pos < 0 || static_cast<int32>(fileHeader.size) > ftell(file) - pos) { TC_LOG_ERROR("maps", "MMAP:loadMap: %03u%02i%02i.mmtile has corrupted data size", mapId, x, y); fclose(file); diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 7c894efa1ca..8140a66c61c 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -303,7 +303,7 @@ namespace VMAP if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & reqLiquidType)) if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel)) data.liquidInfo = boost::in_place(liquidType, liquidLevel); - + if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG)) data.areaInfo = boost::in_place(info.hitInstance->adtId, info.rootId, info.hitModel->GetWmoID(), info.hitModel->GetMogpFlags()); } diff --git a/src/common/Collision/Maps/MapDefines.h b/src/common/Collision/Maps/MapDefines.h index 3dd19735ff9..ad7bdd5fddc 100644 --- a/src/common/Collision/Maps/MapDefines.h +++ b/src/common/Collision/Maps/MapDefines.h @@ -22,7 +22,7 @@ #include "DetourNavMesh.h" const uint32 MMAP_MAGIC = 0x4d4d4150; // 'MMAP' -#define MMAP_VERSION 6 +#define MMAP_VERSION 7 struct MmapTileHeader { diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h index 6dc32c1241a..3df75551018 100644 --- a/src/common/Collision/Maps/MapTree.h +++ b/src/common/Collision/Maps/MapTree.h @@ -34,7 +34,7 @@ namespace VMAP struct TC_COMMON_API LocationInfo { - LocationInfo(): hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { } + LocationInfo(): rootId(-1), hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { } int32 rootId; ModelInstance const* hitInstance; GroupModel const* hitModel; diff --git a/src/common/Collision/Maps/TileAssembler.cpp b/src/common/Collision/Maps/TileAssembler.cpp index fe00458cf6d..8a9080473a9 100644 --- a/src/common/Collision/Maps/TileAssembler.cpp +++ b/src/common/Collision/Maps/TileAssembler.cpp @@ -24,6 +24,7 @@ #include <set> #include <iomanip> #include <sstream> +#include <boost/filesystem.hpp> using G3D::Vector3; using G3D::AABox; @@ -55,7 +56,7 @@ namespace VMAP TileAssembler::TileAssembler(const std::string& pSrcDirName, const std::string& pDestDirName) : iDestDir(pDestDirName), iSrcDir(pSrcDirName), iFilterMethod(nullptr), iCurrentUniqueNameId(0) { - //mkdir(iDestDir); + boost::filesystem::create_directory(iDestDir); //init(); } diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h index 0800276f065..8fe82589339 100644 --- a/src/common/Collision/RegularGrid.h +++ b/src/common/Collision/RegularGrid.h @@ -18,8 +18,8 @@ #ifndef _REGULAR_GRID_H #define _REGULAR_GRID_H -#include "Containers.h" #include "Errors.h" +#include "IteratorPair.h" #include <G3D/Ray.h> #include <G3D/BoundsTrait.h> #include <G3D/PositionTrait.h> diff --git a/src/common/Debugging/WheatyExceptionReport.cpp b/src/common/Debugging/WheatyExceptionReport.cpp index 5b6e9e76ebc..e818df4e8fb 100644 --- a/src/common/Debugging/WheatyExceptionReport.cpp +++ b/src/common/Debugging/WheatyExceptionReport.cpp @@ -126,7 +126,7 @@ PEXCEPTION_POINTERS pExceptionInfo) ++pos; TCHAR crash_folder_path[MAX_PATH]; - sprintf(crash_folder_path, "%s\\%s", module_folder_name, CrashFolder); + sprintf_s(crash_folder_path, "%s\\%s", module_folder_name, CrashFolder); if (!CreateDirectory(crash_folder_path, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) @@ -827,7 +827,7 @@ PVOID UserContext) { ClearSymbols(); FormatSymbolValue(pSymInfo, (STACKFRAME64*)UserContext); - + } __except (EXCEPTION_EXECUTE_HANDLER) { @@ -1385,12 +1385,15 @@ int __cdecl WheatyExceptionReport::StackLog(const TCHAR * format, va_list argptr int __cdecl WheatyExceptionReport::HeapLog(const TCHAR * format, va_list argptr) { - int retValue; + int retValue = 0; DWORD cbWritten; TCHAR* szBuff = (TCHAR*)malloc(sizeof(TCHAR) * WER_LARGE_BUFFER_SIZE); - retValue = vsprintf(szBuff, format, argptr); - WriteFile(m_hReportFile, szBuff, retValue * sizeof(TCHAR), &cbWritten, 0); - free(szBuff); + if (szBuff != nullptr) + { + retValue = vsprintf(szBuff, format, argptr); + WriteFile(m_hReportFile, szBuff, retValue * sizeof(TCHAR), &cbWritten, 0); + free(szBuff); + } return retValue; } diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp index d0ba17b52a7..95b617e7e40 100644 --- a/src/common/Logging/Log.cpp +++ b/src/common/Logging/Log.cpp @@ -65,7 +65,7 @@ void Log::CreateAppenderFromConfig(std::string const& appenderName) // Format = type, level, flags, optional1, optional2 // if type = File. optional1 = file and option2 = mode // if type = Console. optional1 = Color - std::string options = sConfigMgr->GetStringDefault(appenderName.c_str(), ""); + std::string options = sConfigMgr->GetStringDefault(appenderName, ""); Tokenizer tokens(options, ','); auto iter = tokens.begin(); @@ -118,7 +118,7 @@ void Log::CreateLoggerFromConfig(std::string const& appenderName) LogLevel level = LOG_LEVEL_DISABLED; uint8 type = uint8(-1); - std::string options = sConfigMgr->GetStringDefault(appenderName.c_str(), ""); + std::string options = sConfigMgr->GetStringDefault(appenderName, ""); std::string name = appenderName.substr(7); if (options.empty()) diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index 6cd95676bdf..424b4079e69 100644 --- a/src/common/Utilities/Containers.h +++ b/src/common/Utilities/Containers.h @@ -198,32 +198,6 @@ namespace Trinity return itr != map.end() ? AddressOrSelf(itr->second) : nullptr; } - /** - * @class IteratorPair - * - * @brief Utility class to enable range for loop syntax for multimap.equal_range uses - */ - template<class iterator> - class IteratorPair - { - public: - IteratorPair() : _iterators() { } - IteratorPair(iterator first, iterator second) : _iterators(first, second) { } - IteratorPair(std::pair<iterator, iterator> iterators) : _iterators(iterators) { } - - iterator begin() const { return _iterators.first; } - iterator end() const { return _iterators.second; } - - private: - std::pair<iterator, iterator> _iterators; - }; - - template<class M> - inline auto MapEqualRange(M& map, typename M::key_type const& key) -> IteratorPair<decltype(map.begin())> - { - return { map.equal_range(key) }; - } - template<class K, class V, template<class, class, class...> class M, class... Rest> void MultimapErasePair(M<K, V, Rest...>& multimap, K const& key, V const& value) { diff --git a/src/common/Utilities/IteratorPair.h b/src/common/Utilities/IteratorPair.h new file mode 100644 index 00000000000..cc6683be3f3 --- /dev/null +++ b/src/common/Utilities/IteratorPair.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * + * 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 IteratorPair_h__ +#define IteratorPair_h__ + +#include "Define.h" +#include <utility> + +namespace Trinity +{ + /** + * @class IteratorPair + * + * @brief Utility class to enable range for loop syntax for multimap.equal_range uses + */ + template<class iterator> + class IteratorPair + { + public: + IteratorPair() : _iterators() { } + IteratorPair(iterator first, iterator second) : _iterators(first, second) { } + IteratorPair(std::pair<iterator, iterator> iterators) : _iterators(iterators) { } + + iterator begin() const { return _iterators.first; } + iterator end() const { return _iterators.second; } + + private: + std::pair<iterator, iterator> _iterators; + }; + + namespace Containers + { + template<class M> + inline auto MapEqualRange(M& map, typename M::key_type const& key) -> IteratorPair<decltype(map.begin())> + { + return { map.equal_range(key) }; + } + } + //! namespace Containers +} +//! namespace Trinity + +#endif // IteratorPair_h__ diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index 12eeb2a6d14..1138b97759e 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -19,7 +19,7 @@ #ifndef TRINITYCORE_STRING_FORMAT_H #define TRINITYCORE_STRING_FORMAT_H -#include "fmt/format.h" +#include "fmt/printf.h" namespace Trinity { diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 458c783152c..ec3f5c2c9e2 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -493,4 +493,11 @@ bool CompareValues(ComparisionType type, T val1, T val2) } } +template<typename E> +typename std::underlying_type<E>::type AsUnderlyingType(E enumValue) +{ + static_assert(std::is_enum<E>::value, "AsUnderlyingType can only be used with enums"); + return static_cast<typename std::underlying_type<E>::type>(enumValue); +} + #endif |