Skip to content

Commit

Permalink
tweak(client): user agent for ROS calls
Browse files Browse the repository at this point in the history
The default cURL user agent might lead to erratic behavior with third-
party security providers filtering out user requests.

(also, adds a unified place to get `release.txt` from)
  • Loading branch information
blattersturm committed Jul 21, 2023
1 parent bc1ac1b commit 30e875c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 50 deletions.
25 changes: 3 additions & 22 deletions code/components/font-renderer/src/GtaGameInterface.cpp
Expand Up @@ -15,7 +15,8 @@
#include <CrossBuildRuntime.h>
#include <utf8.h>
#include <Hooking.h>
#include <CL2LaunchMode.h>
#include <CL2LaunchMode.h>
#include <CfxReleaseInfo.h>

#include "memdbgon.h"

Expand Down Expand Up @@ -453,27 +454,7 @@ static InitFunction initFunction([] ()
}
else // (!inGame), i.e. menu
{
static auto version = ([]()
{
FILE* f = _wfopen(MakeRelativeCitPath(L"citizen/release.txt").c_str(), L"r");
int version = -1;

if (f)
{
char ver[128];

fgets(ver, sizeof(ver), f);
fclose(f);

version = atoi(ver);
}
else
{
version = 0;
}

return version;
})();
static auto version = cfx::GetPlatformRelease();

static auto updateChannelTag = ([]() -> std::wstring
{
Expand Down
52 changes: 24 additions & 28 deletions code/components/ros-patches-five/src/AccountID.cpp
Expand Up @@ -36,6 +36,21 @@
#include "ROSErrors.h"
#include <boost/algorithm/string/replace.hpp>

#include "CfxReleaseInfo.h"

template<typename... Ts>
static auto PostAutoLogin(Ts&&... args)
{
return cpr::Post(
cpr::Header{
{ "Content-Type", "application/json; charset=utf-8" },
{ "Accept", "application/json" },
{ "X-Requested-With", "XMLHttpRequest" } },
cpr::UserAgent{ fmt::sprintf("CitizenFX/1 (rel. %d)") },
std::forward<Ts>(args)...
);
}

static bool TryFindError(const std::string& errorString, std::string* outMessage)
{
if (auto it = g_rosErrors.find("Errors_" + errorString); it != g_rosErrors.end())
Expand Down Expand Up @@ -705,15 +720,10 @@ void ValidateEpic(int parentPid)

j["tpaTokens"] = GetTpaTokens();

r = cpr::Post(
r = PostAutoLogin(
cpr::Url{ "https://rgl.rockstargames.com/api/launcher/autologinepic" },
cpr::Header{
{ { "Content-Type", "application/json; charset=utf-8" },
{ "Accept", "application/json" },
{ "X-Requested-With", "XMLHttpRequest" } } },
cpr::Body{
j.dump() },
cpr::VerifySsl{ false });
j.dump() });

if (r.error)
{
Expand Down Expand Up @@ -792,18 +802,14 @@ void ValidateEpic(int parentPid)
{ "version", 11 },
});

r = cpr::Post(
r = PostAutoLogin(
cpr::Url{ "https://rgl.rockstargames.com/api/launcher/bindepicaccount" },
cpr::Header{
{
{ "Content-Type", "application/json; charset=utf-8" },
{ "Accept", "application/json" },
{ "X-Requested-With", "XMLHttpRequest" },
{ "Authorization", fmt::sprintf("SCAUTH val=\"%s\"", tick) },
{ "Authorization", fmt::sprintf("SCAUTH val=\"%s\"", tick) },
} },
cpr::Body{
j.dump() },
cpr::VerifySsl{ false });
j.dump() });

if (r.error)
{
Expand Down Expand Up @@ -894,17 +900,11 @@ void ValidateSteam(int parentPid)

j["tpaTokens"] = GetTpaTokens();

r = cpr::Post(
r = PostAutoLogin(
cpr::Url{ "https://rgl.rockstargames.com/api/launcher/autologinsteam" },
cpr::Header{
{"Content-Type", "application/json; charset=utf-8"},
{"Accept", "application/json"},
{"X-Requested-With", "XMLHttpRequest"}
},
cpr::Body{
j.dump()
},
cpr::VerifySsl{ false });
});

if (r.error)
{
Expand Down Expand Up @@ -973,18 +973,14 @@ void ValidateSteam(int parentPid)
{ "version", 11 },
});

r = cpr::Post(
r = PostAutoLogin(
cpr::Url{ "https://rgl.rockstargames.com/api/launcher/bindsteamaccount" },
cpr::Header{
{"Content-Type", "application/json; charset=utf-8"},
{"Accept", "application/json"},
{"X-Requested-With", "XMLHttpRequest"},
{"Authorization", fmt::sprintf("SCAUTH val=\"%s\"", tick) },
},
cpr::Body{
j.dump()
},
cpr::VerifySsl{ false });
});

if (r.error)
{
Expand Down
33 changes: 33 additions & 0 deletions code/shared/CfxReleaseInfo.h
@@ -0,0 +1,33 @@
#pragma once

#ifndef IS_FXSERVER
namespace cfx
{
inline auto GetPlatformRelease()
{
static auto version = ([]()
{
FILE* f = _wfopen(MakeRelativeCitPath(L"citizen/release.txt").c_str(), L"r");
int version = -1;

if (f)
{
char ver[128];

fgets(ver, sizeof(ver), f);
fclose(f);

version = atoi(ver);
}
else
{
version = 0;
}

return version;
})();

return version;
}
}
#endif

0 comments on commit 30e875c

Please sign in to comment.