From 0c4f681066d8731e9dc387b8b74afab4e79e5bd2 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sun, 14 Apr 2024 21:19:44 +0800 Subject: [PATCH] [raknet] Implement `RakPeer::GetCompressionRatio()` --- raknet/RakPeer.cpp | 15 +++++++++++++-- raknet/RakPeer.h | 16 ++++++++++++++-- raknet/RakPeerInterface.h | 6 +++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/raknet/RakPeer.cpp b/raknet/RakPeer.cpp index 9312bc6..0de29d8 100644 --- a/raknet/RakPeer.cpp +++ b/raknet/RakPeer.cpp @@ -8,6 +8,7 @@ RakPeer::RakPeer() { memset( frequencyTable, 0, sizeof( unsigned int ) * 256 ); + rawBytesSent = compressedBytesSent = 0; MTUSize = DEFAULT_MTU_SIZE; trackFrequencyTable = false; maximumIncomingConnections = 0; @@ -490,9 +491,19 @@ void RakPeer::vftable_DC() // TODO: RakPeer::vftable_DC() (saco W: 1003ACA0) (server W: 451FE0 L: 806E250) (bot W: 405CD0 L: 80756CC) } -void RakPeer::vftable_E0() +// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +// Returns: +// The compression ratio. A low compression ratio is good. Compression is for outgoing data +// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +float RakPeer::GetCompressionRatio( void ) const { - // TODO: RakPeer::vftable_E0() (saco W: 10038B50) (server W: 450630 L: 806E330) (bot W: 404570 L: 80757FA) + if ( rawBytesSent > 0 ) + { + return ( float ) compressedBytesSent / ( float ) rawBytesSent; + } + + else + return 0.0f; } void RakPeer::vftable_E4() diff --git a/raknet/RakPeer.h b/raknet/RakPeer.h index e2a5ef4..cb6d71d 100644 --- a/raknet/RakPeer.h +++ b/raknet/RakPeer.h @@ -163,7 +163,11 @@ public: void vftable_D8(); void vftable_DC(); - void vftable_E0(); + + /// Returns the compression ratio. A low compression ratio is good. Compression is for outgoing data + /// \return The compression ratio + float GetCompressionRatio( void ) const; + void vftable_E4(); void vftable_E8(); void vftable_EC(); @@ -202,7 +206,15 @@ protected: /// Compression stuff unsigned int frequencyTable[ 256 ]; - char _gap7D1[48]; + char _gap7D1[8]; + + unsigned int rawBytesSent; + + char _gap7DD[4]; + + unsigned int compressedBytesSent; + + char _gap7E5[28]; 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 3d8bba0..85e0c77 100644 --- a/raknet/RakPeerInterface.h +++ b/raknet/RakPeerInterface.h @@ -159,7 +159,11 @@ public: virtual void vftable_D8()=0; virtual void vftable_DC()=0; - virtual void vftable_E0()=0; + + /// Returns the compression ratio. A low compression ratio is good. Compression is for outgoing data + /// \return The compression ratio + virtual float GetCompressionRatio( void ) const=0; + virtual void vftable_E4()=0; virtual void vftable_E8()=0; virtual void vftable_EC()=0;