From 7d2e4e199378977fa83ed7b3d2b1304bd597e35f Mon Sep 17 00:00:00 2001 From: Gosha <284210+Lordron@users.noreply.github.com> Date: Mon, 16 Oct 2023 03:23:01 +0300 Subject: [PATCH 1/4] Core/Cells: align Cell.data.Part fields by 8 bits and enlarge Cell structure to 8 bytes 8-bits align removes unneded shift operations --- src/server/game/Grids/Cells/Cell.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/server/game/Grids/Cells/Cell.h b/src/server/game/Grids/Cells/Cell.h index 0cd4f042aa8..162c5499c34 100644 --- a/src/server/game/Grids/Cells/Cell.h +++ b/src/server/game/Grids/Cells/Cell.h @@ -96,14 +96,14 @@ struct Cell { struct { - unsigned grid_x : 6; - unsigned grid_y : 6; - unsigned cell_x : 6; - unsigned cell_y : 6; - unsigned nocreate : 1; - unsigned reserved : 7; + unsigned grid_x : 8; + unsigned grid_y : 8; + unsigned cell_x : 8; + unsigned cell_y : 8; + unsigned nocreate : 8; + unsigned reserved : 24; } Part; - uint32 All; + uint64 All; } data; template void Visit(CellCoord const&, TypeContainerVisitor& visitor, Map&, WorldObject const& obj, float radius) const; From d5cb122e3a844e9a29fddc44a82c789628245b11 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 11 Dec 2023 20:45:33 +0100 Subject: [PATCH 2/4] Core/Cells: Improve cell copy constructor and argument passing codegen (now fully done through a single register) --- src/server/game/Grids/Cells/Cell.h | 24 +++++++----------------- src/server/game/Grids/Cells/CellImpl.h | 15 +-------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/src/server/game/Grids/Cells/Cell.h b/src/server/game/Grids/Cells/Cell.h index 162c5499c34..ab711e9a140 100644 --- a/src/server/game/Grids/Cells/Cell.h +++ b/src/server/game/Grids/Cells/Cell.h @@ -18,8 +18,6 @@ #ifndef TRINITY_CELL_H #define TRINITY_CELL_H -#include - #include "TypeContainer.h" #include "TypeContainerVisitor.h" @@ -47,10 +45,9 @@ struct CellArea struct Cell { - Cell() { data.All = 0; } - Cell(Cell const& cell) { data.All = cell.data.All; } + Cell() : data() { } explicit Cell(CellCoord const& p); - explicit Cell(float x, float y); + explicit Cell(float x, float y) : Cell(Trinity::ComputeCellCoord(x, y)) { } void Compute(uint32 &x, uint32 &y) const { @@ -84,24 +81,17 @@ struct Cell data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y); } - Cell& operator=(Cell const& cell) - { - this->data.All = cell.data.All; - return *this; - } - bool operator == (Cell const& cell) const { return (data.All == cell.data.All); } bool operator != (Cell const& cell) const { return !operator == (cell); } union { struct { - unsigned grid_x : 8; - unsigned grid_y : 8; - unsigned cell_x : 8; - unsigned cell_y : 8; - unsigned nocreate : 8; - unsigned reserved : 24; + uint8 grid_x; + uint8 grid_y; + uint8 cell_x; + uint8 cell_y; + uint8 nocreate; } Part; uint64 All; } data; diff --git a/src/server/game/Grids/Cells/CellImpl.h b/src/server/game/Grids/Cells/CellImpl.h index bfd642abe81..6b05b5c9be3 100644 --- a/src/server/game/Grids/Cells/CellImpl.h +++ b/src/server/game/Grids/Cells/CellImpl.h @@ -24,25 +24,12 @@ #include "Map.h" #include "Object.h" -inline Cell::Cell(CellCoord const& p) +inline Cell::Cell(CellCoord const& p) : data() { data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS; data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS; data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS; data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS; - data.Part.nocreate = 0; - data.Part.reserved = 0; -} - -inline Cell::Cell(float x, float y) -{ - CellCoord p = Trinity::ComputeCellCoord(x, y); - data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS; - data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS; - data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS; - data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS; - data.Part.nocreate = 0; - data.Part.reserved = 0; } inline CellArea Cell::CalculateCellArea(float x, float y, float radius) From d02827d22873e47768837d7819cbece04068aec3 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 14 Dec 2023 01:06:34 +0100 Subject: [PATCH 3/4] Core/Misc: Added windows version checks during startup to avoid confusion about crashes when running on unsupported OS --- cmake/platform/win/settings.cmake | 6 ++++- src/common/Debugging/Errors.cpp | 14 +++++++++++ src/common/Debugging/Errors.h | 3 +++ .../Debugging/WheatyExceptionReport.cpp | 2 +- src/common/Utilities/Util.cpp | 24 +++++++++++++++---- src/common/Utilities/Util.h | 5 ++++ src/server/bnetserver/Main.cpp | 2 ++ src/server/worldserver/Main.cpp | 2 ++ src/tools/map_extractor/System.cpp | 3 +++ src/tools/mmaps_generator/PathGenerator.cpp | 2 ++ src/tools/vmap4_assembler/VMapAssembler.cpp | 3 +++ src/tools/vmap4_extractor/vmapexport.cpp | 3 +++ 12 files changed, 63 insertions(+), 6 deletions(-) diff --git a/cmake/platform/win/settings.cmake b/cmake/platform/win/settings.cmake index d30d81479a2..40d2c578ba4 100644 --- a/cmake/platform/win/settings.cmake +++ b/cmake/platform/win/settings.cmake @@ -1,4 +1,8 @@ -add_definitions(-D_WIN32_WINNT=0x0601) +add_definitions(-D_WIN32_WINNT=0x0A00) # Windows 10 +add_definitions(-DNTDDI_VERSION=0x0A000007) # 19H1 (1903) +add_definitions(-DWIN32_LEAN_AND_MEAN) +add_definitions(-DNOMINMAX) +add_definitions(-DTRINITY_REQUIRED_WINDOWS_BUILD=18362) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake) diff --git a/src/common/Debugging/Errors.cpp b/src/common/Debugging/Errors.cpp index b00402d5ff9..8532906d852 100644 --- a/src/common/Debugging/Errors.cpp +++ b/src/common/Debugging/Errors.cpp @@ -129,6 +129,20 @@ void Abort(char const* file, int line, char const* function) Crash(formattedMessage.c_str()); } +void Abort(char const* file, int line, char const* function, char const* message, ...) +{ + va_list args; + va_start(args, message); + + std::string formattedMessage = StringFormat("\n%s:%i in %s ABORTED:\n", file, line, function) + FormatAssertionMessage(message, args) + '\n'; + va_end(args); + + fprintf(stderr, "%s", formattedMessage.c_str()); + fflush(stderr); + + Crash(formattedMessage.c_str()); +} + void AbortHandler(int sigval) { // nothing useful to log here, no way to pass args diff --git a/src/common/Debugging/Errors.h b/src/common/Debugging/Errors.h index 2233f49cd21..bd662eef2d4 100644 --- a/src/common/Debugging/Errors.h +++ b/src/common/Debugging/Errors.h @@ -30,6 +30,7 @@ namespace Trinity DECLSPEC_NORETURN TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN; DECLSPEC_NORETURN TC_COMMON_API void Abort(char const* file, int line, char const* function) ATTR_NORETURN; + DECLSPEC_NORETURN TC_COMMON_API void Abort(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN; TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message); @@ -54,6 +55,7 @@ namespace Trinity #define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END #define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END #define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END +#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END #ifdef PERFORMANCE_PROFILING #define ASSERT(cond, ...) ((void)0) @@ -62,6 +64,7 @@ namespace Trinity #endif #define ABORT WPAbort +#define ABORT_MSG WPAbort_MSG template inline T* ASSERT_NOTNULL(T* pointer) { diff --git a/src/common/Debugging/WheatyExceptionReport.cpp b/src/common/Debugging/WheatyExceptionReport.cpp index 32e9051f1ab..0384ab4b582 100644 --- a/src/common/Debugging/WheatyExceptionReport.cpp +++ b/src/common/Debugging/WheatyExceptionReport.cpp @@ -264,7 +264,7 @@ BOOL WheatyExceptionReport::_GetWindowsVersion(TCHAR* szVersion, DWORD cntMax) RTL_OSVERSIONINFOEXW osvi = { }; osvi.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); NTSTATUS bVersionEx = RtlGetVersion((PRTL_OSVERSIONINFOW)&osvi); - if (bVersionEx < 0) + if (FAILED(bVersionEx)) { osvi.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW); if (!RtlGetVersion((PRTL_OSVERSIONINFOW)&osvi)) diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 68bfe601f51..10e8bf16d58 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -28,11 +28,27 @@ #include #include -#if TRINITY_COMPILER == TRINITY_COMPILER_GNU - #include - #include - #include +void Trinity::VerifyOsVersion() +{ +#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS + auto isWindowsBuildGreaterOrEqual = [](DWORD build) + { + OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, build, 0, {0}, 0, 0, 0, 0 }; + ULONGLONG conditionMask = 0; + VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); + + return VerifyVersionInfo(&osvi, VER_BUILDNUMBER, conditionMask); + }; + + if (!isWindowsBuildGreaterOrEqual(TRINITY_REQUIRED_WINDOWS_BUILD)) + { + OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, 0, 0 }; + GetVersionEx((LPOSVERSIONINFO)&osvi); + ABORT_MSG("TrinityCore requires Windows 10 19H1 (1903) or Windows Server 2019 (1903) - require build number 10.0.%d but found %d.%d.%d", + TRINITY_REQUIRED_WINDOWS_BUILD, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber); + } #endif +} Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve /*= 0*/, bool keepEmptyStrings /*= true*/) { diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index cc2bfa879db..d75c7c31690 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -25,6 +25,11 @@ #include #include +namespace Trinity +{ + TC_COMMON_API void VerifyOsVersion(); +} + class TC_COMMON_API Tokenizer { public: diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp index 70918081800..839da862f21 100644 --- a/src/server/bnetserver/Main.cpp +++ b/src/server/bnetserver/Main.cpp @@ -88,6 +88,8 @@ int main(int argc, char** argv) { signal(SIGABRT, &Trinity::AbortHandler); + Trinity::VerifyOsVersion(); + auto configFile = fs::absolute(_TRINITY_BNET_CONFIG); std::string configService; auto vm = GetConsoleArguments(argc, argv, configFile, configService); diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index c223dd18246..65f89d73b78 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -133,6 +133,8 @@ extern int main(int argc, char** argv) { signal(SIGABRT, &Trinity::AbortHandler); + Trinity::VerifyOsVersion(); + auto configFile = fs::absolute(_TRINITY_CORE_CONFIG); std::string configService; diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index d6d59884333..a0a22e2e460 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -16,6 +16,7 @@ */ #include "StringFormat.h" +#include "Util.h" #include "MapDefines.h" #include #include @@ -1373,6 +1374,8 @@ void LoadCommonMPQFiles(uint32 build) int main(int argc, char * arg[]) { + Trinity::VerifyOsVersion(); + Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr); PrintProgress = isatty(fileno(stdout)); diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 5d30b8dd559..3a216ba4613 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -344,6 +344,8 @@ std::unordered_map> LoadMap(std::string const& local int main(int argc, char** argv) { + Trinity::VerifyOsVersion(); + Trinity::Banner::Show("MMAP generator", [](char const* text) { printf("%s\n", text); }, nullptr); unsigned int threads = std::thread::hardware_concurrency(); diff --git a/src/tools/vmap4_assembler/VMapAssembler.cpp b/src/tools/vmap4_assembler/VMapAssembler.cpp index 2e55f16240b..13dd30883c1 100644 --- a/src/tools/vmap4_assembler/VMapAssembler.cpp +++ b/src/tools/vmap4_assembler/VMapAssembler.cpp @@ -20,9 +20,12 @@ #include "TileAssembler.h" #include "Banner.h" +#include "Util.h" int main(int argc, char* argv[]) { + Trinity::VerifyOsVersion(); + Trinity::Banner::Show("VMAP assembler", [](char const* text) { std::cout << text << std::endl; }, nullptr); std::string src = "Buildings"; diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index 6430846b1a4..27e6f8b80d8 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -21,6 +21,7 @@ #include "mpqfile.h" #include "wmo.h" #include "StringFormat.h" +#include "Util.h" #include "vmapexport.h" #include "VMapDefinitions.h" #include "Banner.h" @@ -476,6 +477,8 @@ bool processArgv(int argc, char ** argv, const char *versionString) int main(int argc, char ** argv) { + Trinity::VerifyOsVersion(); + Trinity::Banner::Show("VMAP data extractor", [](char const* text) { printf("%s\n", text); }, nullptr); input_path = boost::filesystem::current_path(); From 45f0c797e9b71dedfdb0f1d36321929d62a4f648 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Thu, 14 Dec 2023 01:20:28 +0100 Subject: [PATCH 4/4] Core/Common: ported windows settings manifest from https://github.com/TrinityCore/TrinityCore/commit/b299902881cb6525b5a6cc08c5721c0c1c7401ab --- src/CMakeLists.txt | 1 + src/common/WindowsSettings.manifest | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/common/WindowsSettings.manifest diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 22d6fd1218c..425c40b0a87 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ if(WIN32) set(sources_windows ${CMAKE_SOURCE_DIR}/src/common/Debugging/WheatyExceptionReport.cpp ${CMAKE_SOURCE_DIR}/src/common/Debugging/WheatyExceptionReport.h + ${CMAKE_SOURCE_DIR}/src/common/WindowsSettings.manifest ) endif(WIN32) diff --git a/src/common/WindowsSettings.manifest b/src/common/WindowsSettings.manifest new file mode 100644 index 00000000000..b7da14cfe5c --- /dev/null +++ b/src/common/WindowsSettings.manifest @@ -0,0 +1,13 @@ + + + + + UTF-8 + + + + + + + +