Skip to content

Commit e92d2fa

Browse files
committed
feat(state): add compression dictionary for RedM
!! THIS IS A BREAKING CHANGE !! Having a compression dictionary for RedM reduces the net traffic from 18-30kb/s to 16-24kb/s in testing This is protocol breaking since our compression dict will no longer be the same one used for FiveM, this adds a protocol version file that can be shared between server/client to the bump easier if its ever done again
1 parent 476f550 commit e92d2fa

File tree

6 files changed

+4115
-2
lines changed

6 files changed

+4115
-2
lines changed

code/components/citizen-server-impl/src/InitConnectMethod.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <HttpClient.h>
5555

5656
#include "CnlEndpoint.h"
57+
#include <net/ProtocolVersion.h>
5758

5859
using json = nlohmann::json;
5960

@@ -564,7 +565,7 @@ static InitFunction initFunction([]()
564565
auto gameBuildField = (gameBuildIt != postMap.end()) ? gameBuildIt->second : "0";
565566
auto gameName = (gameNameIt != postMap.end()) ? gameNameIt->second : "";
566567

567-
if (protocol < 12)
568+
if (protocol < kNetworkProtocolVersion)
568569
{
569570
sendError("Client/server version mismatch. Restart your game client to update. If that did not help, "
570571
"this server is using too new a version for the current game client.");

code/components/citizen-server-impl/src/state/ServerGameState.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,7 +3792,11 @@ static std::tuple<uint32_t, int> UncompressClonePacket(const net::Span<char>& bu
37923792

37933793
const static uint8_t dictBuffer[65536] =
37943794
{
3795+
#ifdef STATE_RDR3
3796+
#include <state/dict_redm_20250412.h>
3797+
#else
37953798
#include <state/dict_five_20210329.h>
3799+
#endif
37963800
};
37973801
int bufferLength = LZ4_decompress_safe_usingDict(reinterpret_cast<const char*>(readBuffer.GetData() + readBuffer.GetOffset()), bufferData.data(), readBuffer.GetRemaining(), bufferData.size(), reinterpret_cast<const char*>(dictBuffer), std::size(dictBuffer));
37983802

code/components/gta-net-five/src/CloneManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ void CloneManagerLocal::BindNetLibrary(NetLibrary* netLibrary)
457457
LZ4_initStreamHC(&m_compStreamDict, sizeof(m_compStreamDict));
458458

459459
const static uint8_t dictBuffer[65536] = {
460+
#ifdef IS_RDR3
461+
#include <state/dict_redm_20250412.h>
462+
#else
460463
#include <state/dict_five_20210329.h>
464+
#endif
461465
};
462466

463467
LZ4_loadDictHC(&m_compStreamDict, reinterpret_cast<const char*>(dictBuffer), std::size(dictBuffer));

code/components/net/src/NetLibrary.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
using json = nlohmann::json;
5151

5252
#include <Error.h>
53+
#include <net/ProtocolVersion.h>
5354

5455
fwEvent<const std::string&> OnRichPresenceSetTemplate;
5556
fwEvent<int, const std::string&> OnRichPresenceSetValue;
@@ -954,7 +955,7 @@ concurrency::task<void> NetLibrary::ConnectToServer(const std::string& rootUrl)
954955
static fwMap<fwString, fwString> postMap;
955956
postMap["method"] = "initConnect";
956957
postMap["name"] = GetPlayerName();
957-
postMap["protocol"] = va("%d", NETWORK_PROTOCOL);
958+
postMap["protocol"] = va("%d", kNetworkProtocolVersion);
958959

959960
#if defined(IS_RDR3)
960961
std::string gameName = "rdr3";

code/shared/net/ProtocolVersion.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include "StdInc.h"
3+
#if defined(GTA_FIVE) || defined(STATE_FIVE)
4+
constexpr uint16_t kNetworkProtocolVersion = 12;
5+
#else defined(IS_RDR3) || defined(STATE_RDR3)
6+
constexpr uint16_t kNetworkProtocolVersion = 13;
7+
#endif

0 commit comments

Comments
 (0)