From 73ff8e4585daee71f1b40f06385764370993aeba Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Sun, 18 Aug 2024 22:10:32 -0400 Subject: [PATCH] Core/Movement: Fixed spline packed deltas validation check Port From (https://github.com/TrinityCore/TrinityCore/commit/ad6ef5237d0bd2d18e15462c9b55576ebb68fb22) --- Source/Game/Movement/MoveSplineInitArgs.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/Game/Movement/MoveSplineInitArgs.cs b/Source/Game/Movement/MoveSplineInitArgs.cs index b107eedc5..832e346e4 100644 --- a/Source/Game/Movement/MoveSplineInitArgs.cs +++ b/Source/Game/Movement/MoveSplineInitArgs.cs @@ -78,12 +78,15 @@ namespace Game.Movement bool _checkPathLengths() { - float MIN_OFFSET = 1.0f / 4.0f; - float MAX_XY_OFFSET = (1 << 11) / 4.0f; - float MAX_Z_OFFSET = (1 << 10) / 4.0f; + float MIN_XY_OFFSET = -(1 << 11) / 4.0f; + float MIN_Z_OFFSET = -(1 << 10) / 4.0f; - var isValidPackedXYOffset = (float coord) => coord < MAX_XY_OFFSET && (coord < 0.1f || coord >= MIN_OFFSET); - var isValidPackedZOffset = (float coord) => coord < MAX_Z_OFFSET && (coord < 0.1f || coord >= MIN_OFFSET); + // positive values have 1 less bit limit (if the highest bit was set, value would be sign extended into negative when decompressing) + float MAX_XY_OFFSET = (1 << 10) / 4.0f; + float MAX_Z_OFFSET = (1 << 9) / 4.0f; + + var isValidPackedXYOffset = (float coord) => coord > MIN_XY_OFFSET && coord < MAX_XY_OFFSET; + var isValidPackedZOffset = (float coord) => coord > MIN_Z_OFFSET && coord < MAX_Z_OFFSET; if (path.Count > 2) { @@ -98,9 +101,9 @@ namespace Game.Movement // when compression is enabled, each point coord is packed into 11 bits (10 for Z) if (!flags.HasFlag(MoveSplineFlagEnum.UncompressedPath)) - if (!isValidPackedXYOffset(MathF.Abs(path[i].X - middle.X)) - || !isValidPackedXYOffset(MathF.Abs(path[i].Y - middle.Y)) - || !isValidPackedZOffset(MathF.Abs(path[i].Z - middle.Z))) + if (!isValidPackedXYOffset(middle.X - path[i].X) + || !isValidPackedXYOffset(middle.Y - path[i].Y) + || !isValidPackedZOffset(middle.Z - path[i].Z)) flags.SetUnsetFlag(MoveSplineFlagEnum.UncompressedPath, true); } }