From 2f2123f9d33f3c754300579bdc97195aec6cc3d9 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sun, 14 Apr 2024 21:34:17 +0800 Subject: [PATCH] [raknet] Implement `RakPeer::GetDecompressionRatio()` --- raknet/RakPeer.cpp | 16 +++++++++++++--- raknet/RakPeer.h | 13 ++++++------- raknet/RakPeerInterface.h | 5 ++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/raknet/RakPeer.cpp b/raknet/RakPeer.cpp index 0de29d8..56e8d47 100644 --- a/raknet/RakPeer.cpp +++ b/raknet/RakPeer.cpp @@ -8,7 +8,7 @@ RakPeer::RakPeer() { memset( frequencyTable, 0, sizeof( unsigned int ) * 256 ); - rawBytesSent = compressedBytesSent = 0; + rawBytesSent = rawBytesReceived = compressedBytesSent = compressedBytesReceived = 0; MTUSize = DEFAULT_MTU_SIZE; trackFrequencyTable = false; maximumIncomingConnections = 0; @@ -506,9 +506,19 @@ float RakPeer::GetCompressionRatio( void ) const return 0.0f; } -void RakPeer::vftable_E4() +// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +// Returns: +// The decompression ratio. A high decompression ratio is good. Decompression is for incoming data +// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +float RakPeer::GetDecompressionRatio( void ) const { - // TODO: RakPeer::vftable_E4() (saco W: 10038B90) (server W: 450670 L: 806E3C0) (bot W: 4045B0 L: 80758BE) + if ( rawBytesReceived > 0 ) + { + return ( float ) compressedBytesReceived / ( float ) rawBytesReceived; + } + + else + return 0.0f; } void RakPeer::vftable_E8() diff --git a/raknet/RakPeer.h b/raknet/RakPeer.h index cb6d71d..dac00cb 100644 --- a/raknet/RakPeer.h +++ b/raknet/RakPeer.h @@ -168,7 +168,10 @@ public: /// \return The compression ratio float GetCompressionRatio( void ) const; - void vftable_E4(); + ///Returns the decompression ratio. A high decompression ratio is good. Decompression is for incoming data + /// \return The decompression ratio + float GetDecompressionRatio( void ) const; + void vftable_E8(); void vftable_EC(); void vftable_F0(); @@ -208,13 +211,9 @@ protected: char _gap7D1[8]; - unsigned int rawBytesSent; + unsigned int rawBytesSent, rawBytesReceived, compressedBytesSent, compressedBytesReceived; - char _gap7DD[4]; - - unsigned int compressedBytesSent; - - char _gap7E5[28]; + char _gap7E9[24]; RPCMap rpcMap; // Can't use StrPtrHash because runtime insertions will screw up the indices int MTUSize; diff --git a/raknet/RakPeerInterface.h b/raknet/RakPeerInterface.h index 85e0c77..b4eec32 100644 --- a/raknet/RakPeerInterface.h +++ b/raknet/RakPeerInterface.h @@ -164,7 +164,10 @@ public: /// \return The compression ratio virtual float GetCompressionRatio( void ) const=0; - virtual void vftable_E4()=0; + ///Returns the decompression ratio. A high decompression ratio is good. Decompression is for incoming data + /// \return The decompression ratio + virtual float GetDecompressionRatio( void ) const=0; + virtual void vftable_E8()=0; virtual void vftable_EC()=0; virtual void vftable_F0()=0;