From dc1ce335c88c5e509b5a4d77f57107425283981e Mon Sep 17 00:00:00 2001 From: RD42 Date: Wed, 30 Apr 2025 03:41:20 -0700 Subject: [PATCH] [saco] Match `ReliabilityLayer::CreateInternalPacketFromBitStream(...)` --- raknet/MTUSize.h | 4 ++-- raknet/PacketPriority.h | 2 +- raknet/ReliabilityLayer.cpp | 12 +++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/raknet/MTUSize.h b/raknet/MTUSize.h index 9af6b0d..0597abc 100644 --- a/raknet/MTUSize.h +++ b/raknet/MTUSize.h @@ -33,12 +33,12 @@ #ifdef _COMPATIBILITY_1 #define DEFAULT_MTU_SIZE 1264 #else -#define DEFAULT_MTU_SIZE 1500 +#define DEFAULT_MTU_SIZE 576 #endif /// The largest value for an UDP datagram /// \sa RakPeer::SetMTUSize() -#define MAXIMUM_MTU_SIZE 1500 +#define MAXIMUM_MTU_SIZE 1492 #endif diff --git a/raknet/PacketPriority.h b/raknet/PacketPriority.h index e3ee020..b6c4877 100644 --- a/raknet/PacketPriority.h +++ b/raknet/PacketPriority.h @@ -32,7 +32,7 @@ enum PacketPriority /// \note Note to self: I write this with 3 bits in the stream. If I add more remember to change that enum PacketReliability { - UNRELIABLE, /// Same as regular UDP, except that it will also discard duplicate datagrams. RakNet adds (6 to 17) + 21 bits of overhead, 16 of which is used to detect duplicate packets and 6 to 17 of which is used for message length. + UNRELIABLE = 6, /// Same as regular UDP, except that it will also discard duplicate datagrams. RakNet adds (6 to 17) + 21 bits of overhead, 16 of which is used to detect duplicate packets and 6 to 17 of which is used for message length. UNRELIABLE_SEQUENCED, /// Regular UDP with a sequence counter. Out of order messages will be discarded. This adds an additional 13 bits on top what is used for UNRELIABLE. RELIABLE, /// The message is sent reliably, but not necessarily in any order. Same overhead as UNRELIABLE. RELIABLE_ORDERED, /// This message is reliable and will arrive in the order you sent it. Messages will be delayed while waiting for out of order messages. Same overhead as UNRELIABLE_SEQUENCED. diff --git a/raknet/ReliabilityLayer.cpp b/raknet/ReliabilityLayer.cpp index 9bb0ef8..69657b7 100644 --- a/raknet/ReliabilityLayer.cpp +++ b/raknet/ReliabilityLayer.cpp @@ -1783,7 +1783,7 @@ InternalPacket* ReliabilityLayer::CreateInternalPacketFromBitStream( RakNet::Bit // Read the PacketReliability. This is encoded in 3 bits unsigned char reliability; - bitStreamSucceeded = bitStream->ReadBits( ( unsigned char* ) ( &( reliability ) ), 3 ); + bitStreamSucceeded = bitStream->ReadBits( ( unsigned char* ) ( &( reliability ) ), reliabilitySizeInBits ); internalPacket->reliability = ( const PacketReliability ) reliability; @@ -1792,7 +1792,7 @@ InternalPacket* ReliabilityLayer::CreateInternalPacketFromBitStream( RakNet::Bit // assert( bitStreamSucceeded ); #endif - if ( bitStreamSucceeded == false ) + if ( reliability < UNRELIABLE || bitStreamSucceeded == false ) { internalPacketPool.ReleasePointer( internalPacket ); return 0; @@ -1829,7 +1829,7 @@ InternalPacket* ReliabilityLayer::CreateInternalPacketFromBitStream( RakNet::Bit } // Read if this is a split packet (1 bit) - bool isSplitPacket; + bool isSplitPacket = false; bitStreamSucceeded = bitStream->Read( isSplitPacket ); @@ -1882,9 +1882,11 @@ InternalPacket* ReliabilityLayer::CreateInternalPacketFromBitStream( RakNet::Bit return 0; } } - else - internalPacket->splitPacketIndex = internalPacket->splitPacketCount = 0; + { + internalPacket->splitPacketIndex = 0; + internalPacket->splitPacketCount = 0; + } // Optimization - do byte alignment here //unsigned char zero;