Skip to content

feat(state)!: add compression dictionary for RedM #3372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <HttpClient.h>

#include "CnlEndpoint.h"
#include <net/ProtocolVersion.h>

using json = nlohmann::json;

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

if (protocol < 12)
if (protocol < kNetworkProtocolVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this breaking the compatibility when the current clients still send 12, because of the NETWORK_PROTOCOL macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I put the wrong protocol number here, will fix it when I get home this should be 12 and 13

{
sendError("Client/server version mismatch. Restart your game client to update. If that did not help, "
"this server is using too new a version for the current game client.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3792,7 +3792,11 @@ static std::tuple<uint32_t, int> UncompressClonePacket(const net::Span<char>& bu

const static uint8_t dictBuffer[65536] =
{
#ifdef STATE_RDR3
#include <state/dict_redm_20250412.h>
#else
#include <state/dict_five_20210329.h>
#endif
};
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));

Expand Down
4 changes: 4 additions & 0 deletions code/components/gta-net-five/src/CloneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,11 @@ void CloneManagerLocal::BindNetLibrary(NetLibrary* netLibrary)
LZ4_initStreamHC(&m_compStreamDict, sizeof(m_compStreamDict));

const static uint8_t dictBuffer[65536] = {
#ifdef IS_RDR3
#include <state/dict_redm_20250412.h>
#else
#include <state/dict_five_20210329.h>
#endif
};

LZ4_loadDictHC(&m_compStreamDict, reinterpret_cast<const char*>(dictBuffer), std::size(dictBuffer));
Expand Down
3 changes: 2 additions & 1 deletion code/components/net/src/NetLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
using json = nlohmann::json;

#include <Error.h>
#include <net/ProtocolVersion.h>

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

#if defined(IS_RDR3)
std::string gameName = "rdr3";
Expand Down
7 changes: 7 additions & 0 deletions code/shared/net/ProtocolVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "StdInc.h"
#if defined(GTA_FIVE) || defined(STATE_FIVE)
constexpr uint16_t kNetworkProtocolVersion = 12;
#else defined(IS_RDR3) || defined(STATE_RDR3)
constexpr uint16_t kNetworkProtocolVersion = 13;
#endif
Loading