From 4a8ad9b55056c779ad6f727850bfd8cd1d4ba3fc Mon Sep 17 00:00:00 2001
From: NY00123 <ny00@outlook.com>
Date: Fri, 3 Apr 2020 23:48:16 +0300
Subject: [PATCH] Fix multiplayer desync after the change to q16 angle and
 horiz. Note that this includes non-portable unaligned accesses, but this
 already applies to surrounding code. Just add comments for now.

---
 source/sw/src/network.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/source/sw/src/network.cpp b/source/sw/src/network.cpp
index 032acaccb..a2b85aaa9 100644
--- a/source/sw/src/network.cpp
+++ b/source/sw/src/network.cpp
@@ -282,6 +282,7 @@ int EncodeBits(SW_PACKET *pak, SW_PACKET *old_pak, uint8_t* buf)
     *buf = 0;
     buf++;
 
+    // TODO: Properly copy the values in a cross-platform manner
     if (pak->vel != old_pak->vel)
     {
         *((short *)buf) = pak->vel;
@@ -298,14 +299,14 @@ int EncodeBits(SW_PACKET *pak, SW_PACKET *old_pak, uint8_t* buf)
 
     if (pak->q16avel != old_pak->q16avel)
     {
-        *((char *)buf) = pak->q16avel;
+        *((fix16_t *)buf) = pak->q16avel;
         buf += sizeof(pak->q16avel);
         SET(*base_ptr, BIT(2));
     }
 
     if (pak->q16horz != old_pak->q16horz)
     {
-        *((char *)buf) = pak->q16horz;
+        *((fix16_t *)buf) = pak->q16horz;
         buf += sizeof(pak->q16horz);
         SET(*base_ptr, BIT(3));
     }
@@ -334,6 +335,7 @@ int DecodeBits(SW_PACKET *pak, SW_PACKET *old_pak, uint8_t* buf)
 
     *pak = *old_pak;
 
+    // TODO: Properly copy the values in a cross-platform manner
     if (TEST(*base_ptr, BIT(0)))
     {
         pak->vel = *(short *)buf;
@@ -348,13 +350,13 @@ int DecodeBits(SW_PACKET *pak, SW_PACKET *old_pak, uint8_t* buf)
 
     if (TEST(*base_ptr, BIT(2)))
     {
-        pak->q16avel = *(char *)buf;
+        pak->q16avel = *(fix16_t *)buf;
         buf += sizeof(pak->q16avel);
     }
 
     if (TEST(*base_ptr, BIT(3)))
     {
-        pak->q16horz = *(char *)buf;
+        pak->q16horz = *(fix16_t *)buf;
         buf += sizeof(pak->q16horz);
     }