From 5b35b5ceb3f7bec3cc933fb6b1925d99bc3ad70b Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 18:07:42 -0600 Subject: [PATCH] fix: PlatformResync writes its rotation w first The client reads the rotation of a PlatformResync as w, x, y, z, and live sent it that way (a NJ counterweight's resync began with its w). It was written x, y, z, w, which only showed with a rotation other than none. Co-Authored-By: Claude Fable 5.2 --- dGame/dGameMessages/MovementMessages.cpp | 4 ++-- dGame/dGameMessages/MovementMessages.h | 3 ++- .../dGameMessagesTests/RemainingMessagesTests.cpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dGame/dGameMessages/MovementMessages.cpp b/dGame/dGameMessages/MovementMessages.cpp index 19ebc90fd..0879f0ff9 100644 --- a/dGame/dGameMessages/MovementMessages.cpp +++ b/dGame/dGameMessages/MovementMessages.cpp @@ -66,10 +66,10 @@ namespace GameMessages { const bool hasRotation = qUnexpectedRotation != QuatUtils::IDENTITY; bitStream.Write(hasRotation); if (hasRotation) { + bitStream.Write(qUnexpectedRotation.w); bitStream.Write(qUnexpectedRotation.x); bitStream.Write(qUnexpectedRotation.y); bitStream.Write(qUnexpectedRotation.z); - bitStream.Write(qUnexpectedRotation.w); } } @@ -92,10 +92,10 @@ namespace GameMessages { VALIDATE_READ(bitStream.Read(hasRotation)); qUnexpectedRotation = QuatUtils::IDENTITY; if (hasRotation) { + VALIDATE_READ(bitStream.Read(qUnexpectedRotation.w)); VALIDATE_READ(bitStream.Read(qUnexpectedRotation.x)); VALIDATE_READ(bitStream.Read(qUnexpectedRotation.y)); VALIDATE_READ(bitStream.Read(qUnexpectedRotation.z)); - VALIDATE_READ(bitStream.Read(qUnexpectedRotation.w)); } return true; } diff --git a/dGame/dGameMessages/MovementMessages.h b/dGame/dGameMessages/MovementMessages.h index 6b8bf680f..53a2c61ad 100644 --- a/dGame/dGameMessages/MovementMessages.h +++ b/dGame/dGameMessages/MovementMessages.h @@ -64,7 +64,8 @@ namespace GameMessages { int32_t iIndex{ 0 }; int32_t iNextIndex{ 1 }; NiPoint3 ptUnexpectedLocation{ NiPoint3Constant::ZERO }; - // optional (default identity), written x, y, z, w + // optional (default identity), written w, x, y, z: the order the client reads and live sent (a NJ counterweight's + // resync began with its w, 0.936) NiQuaternion qUnexpectedRotation{ QuatUtils::IDENTITY }; }; diff --git a/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp b/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp index e105a031a..4c3a034ef 100644 --- a/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp @@ -116,6 +116,20 @@ TEST_F(RemainingMessagesTests, StartPathingAndPlatformResyncMatchLegacy) { rotated.qUnexpectedRotation = NiQuaternion(0.5f, 0.5f, -0.5f, 0.5f); const auto copy = RoundTrip(rotated); EXPECT_EQ(copy.qUnexpectedRotation, rotated.qUnexpectedRotation); + + // The rotation goes w first, as live sent a NJ counterweight's (w 0.936, y 0.352) + GameMessages::PlatformResync counterweight; + counterweight.qUnexpectedRotation = NiQuaternion(0.936f, 0.0f, 0.352f, 0.0f); + RakNet::BitStream stream; + counterweight.Serialize(stream); + // two flags, nine 32 bit values, the location and the flag for a rotation + stream.IgnoreBits(2 + 9 * 32 + 3 * 32 + 1); + float first{}, second{}, third{}, fourth{}; + ASSERT_TRUE(stream.Read(first) && stream.Read(second) && stream.Read(third) && stream.Read(fourth)); + EXPECT_FLOAT_EQ(first, 0.936f); + EXPECT_FLOAT_EQ(second, 0.0f); + EXPECT_FLOAT_EQ(third, 0.352f); + EXPECT_FLOAT_EQ(fourth, 0.0f); } TEST_F(RemainingMessagesTests, SmallMovementMessagesMatchLegacy) {