[Dvar]: Add argument to protect dvars (#823)
This commit is contained in:
parent
602f8e741e
commit
d6c23efe68
@ -298,8 +298,25 @@ namespace Components
|
|||||||
return flag.value();
|
return flag.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Dvar::IsSettingArchiveDvarsDisabled()
|
||||||
|
{
|
||||||
|
static std::optional<bool> flag;
|
||||||
|
|
||||||
|
if (!flag.has_value())
|
||||||
|
{
|
||||||
|
flag.emplace(Flags::HasFlag("protect-dvars"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag.value();
|
||||||
|
}
|
||||||
|
|
||||||
void Dvar::DvarSetFromStringByName_Stub(const char* dvarName, const char* value)
|
void Dvar::DvarSetFromStringByName_Stub(const char* dvarName, const char* value)
|
||||||
{
|
{
|
||||||
|
if (IsSettingArchiveDvarsDisabled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Save the dvar original value if it has the archive flag
|
// Save the dvar original value if it has the archive flag
|
||||||
const auto* dvar = Game::Dvar_FindVar(dvarName);
|
const auto* dvar = Game::Dvar_FindVar(dvarName);
|
||||||
if (dvar && dvar->flags & Game::DVAR_ARCHIVE)
|
if (dvar && dvar->flags & Game::DVAR_ARCHIVE)
|
||||||
|
@ -48,6 +48,7 @@ namespace Components
|
|||||||
static void SetFromStringByNameSafeExternal(const char* dvarName, const char* string);
|
static void SetFromStringByNameSafeExternal(const char* dvarName, const char* string);
|
||||||
|
|
||||||
static bool AreArchiveDvarsUnprotected();
|
static bool AreArchiveDvarsUnprotected();
|
||||||
|
static bool IsSettingArchiveDvarsDisabled();
|
||||||
static void DvarSetFromStringByName_Stub(const char* dvarName, const char* value);
|
static void DvarSetFromStringByName_Stub(const char* dvarName, const char* value);
|
||||||
|
|
||||||
static void OnRegisterVariant(Game::dvar_t* dvar);
|
static void OnRegisterVariant(Game::dvar_t* dvar);
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <version.hpp>
|
#include <version.hpp>
|
||||||
|
|
||||||
|
#define CL_MOD_LOADING
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
class JoinContainer
|
class JoinContainer
|
||||||
@ -448,13 +450,13 @@ namespace Components
|
|||||||
Container.valid = false;
|
Container.valid = false;
|
||||||
Container.info = info;
|
Container.info = info;
|
||||||
|
|
||||||
Container.matchType = atoi(info.get("matchtype").data());
|
Container.matchType = std::strtol(info.get("matchtype").data(), nullptr, 10);
|
||||||
auto securityLevel = static_cast<std::uint32_t>(atoi(info.get("securityLevel").data()));
|
auto securityLevel = std::strtoul(info.get("securityLevel").data(), nullptr, 10);
|
||||||
bool isUsermap = !info.get("usermaphash").empty();
|
bool isUsermap = !info.get("usermaphash").empty();
|
||||||
auto usermapHash = static_cast<std::uint32_t>(atoi(info.get("usermaphash").data()));
|
auto usermapHash = std::strtoul(info.get("usermaphash").data(), nullptr, 10);
|
||||||
|
#ifdef CL_MOD_LOADING
|
||||||
std::string mod = (*Game::fs_gameDirVar)->current.string;
|
std::string mod = (*Game::fs_gameDirVar)->current.string;
|
||||||
|
#endif
|
||||||
// set fast server stuff here so its updated when we go to download stuff
|
// set fast server stuff here so its updated when we go to download stuff
|
||||||
if (info.get("wwwDownload") == "1"s)
|
if (info.get("wwwDownload") == "1"s)
|
||||||
{
|
{
|
||||||
@ -497,6 +499,7 @@ namespace Components
|
|||||||
Command::Execute("closemenu popup_reconnectingtoparty");
|
Command::Execute("closemenu popup_reconnectingtoparty");
|
||||||
Download::InitiateMapDownload(info.get("mapname"), info.get("isPrivate") == "1");
|
Download::InitiateMapDownload(info.get("mapname"), info.get("isPrivate") == "1");
|
||||||
}
|
}
|
||||||
|
#ifdef CL_MOD_LOADING
|
||||||
else if (!info.get("fs_game").empty() && Utils::String::ToLower(mod) != Utils::String::ToLower(info.get("fs_game")))
|
else if (!info.get("fs_game").empty() && Utils::String::ToLower(mod) != Utils::String::ToLower(info.get("fs_game")))
|
||||||
{
|
{
|
||||||
Command::Execute("closemenu popup_reconnectingtoparty");
|
Command::Execute("closemenu popup_reconnectingtoparty");
|
||||||
@ -513,6 +516,7 @@ namespace Components
|
|||||||
|
|
||||||
Command::Execute("reconnect", false);
|
Command::Execute("reconnect", false);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!Maps::CheckMapInstalled(Container.info.get("mapname"), true)) return;
|
if (!Maps::CheckMapInstalled(Container.info.get("mapname"), true)) return;
|
||||||
|
@ -281,6 +281,27 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QuickPatch::CL_ShouldSendNotify_Hk(const char* cmd)
|
||||||
|
{
|
||||||
|
if (!cmd)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<std::string> exceptions =
|
||||||
|
{
|
||||||
|
"vstr",
|
||||||
|
"wait",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (std::ranges::find(exceptions, cmd) != exceptions.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Utils::Hook::Call<bool(const char*)>(0x47A640)(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
Game::dvar_t* QuickPatch::Dvar_RegisterConMinicon(const char* dvarName, [[maybe_unused]] bool value, unsigned __int16 flags, const char* description)
|
Game::dvar_t* QuickPatch::Dvar_RegisterConMinicon(const char* dvarName, [[maybe_unused]] bool value, unsigned __int16 flags, const char* description)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -347,6 +368,9 @@ namespace Components
|
|||||||
|
|
||||||
Utils::Hook::Set<const char*>(0x4876C6, "Successfully read stats data\n");
|
Utils::Hook::Set<const char*>(0x4876C6, "Successfully read stats data\n");
|
||||||
|
|
||||||
|
// Protect players from invasive servers
|
||||||
|
Utils::Hook(0x434BD4, CL_ShouldSendNotify_Hk, HOOK_CALL).install()->quick(); // CL_CheckNotify
|
||||||
|
|
||||||
// Numerical ping (cg_scoreboardPingText 1)
|
// Numerical ping (cg_scoreboardPingText 1)
|
||||||
Utils::Hook::Set<BYTE>(0x45888E, 1);
|
Utils::Hook::Set<BYTE>(0x45888E, 1);
|
||||||
Utils::Hook::Set<BYTE>(0x45888C, Game::DVAR_CHEAT);
|
Utils::Hook::Set<BYTE>(0x45888C, Game::DVAR_CHEAT);
|
||||||
@ -597,18 +621,18 @@ namespace Components
|
|||||||
|
|
||||||
for (int i = 0; i < ARRAYSIZE(Game::MaterialTechniqueSet::techniques); ++i)
|
for (int i = 0; i < ARRAYSIZE(Game::MaterialTechniqueSet::techniques); ++i)
|
||||||
{
|
{
|
||||||
Game::MaterialTechnique* technique = asset.techniqueSet->techniques[i];
|
auto* technique = asset.techniqueSet->techniques[i];
|
||||||
|
|
||||||
if (technique)
|
if (technique)
|
||||||
{
|
{
|
||||||
// Size-check is obsolete, as the structure is dynamic
|
// Size-check is obsolete, as the structure is dynamic
|
||||||
buffer.align(Utils::Stream::ALIGN_4);
|
buffer.align(Utils::Stream::ALIGN_4);
|
||||||
|
|
||||||
Game::MaterialTechnique* destTechnique = buffer.dest<Game::MaterialTechnique>();
|
auto* destTechnique = buffer.dest<Game::MaterialTechnique>();
|
||||||
buffer.save(technique, 8);
|
buffer.save(technique, 8);
|
||||||
|
|
||||||
// Save_MaterialPassArray
|
// Save_MaterialPassArray
|
||||||
Game::MaterialPass* destPasses = buffer.dest<Game::MaterialPass>();
|
auto* destPasses = buffer.dest<Game::MaterialPass>();
|
||||||
buffer.saveArray(technique->passArray, technique->passCount);
|
buffer.saveArray(technique->passArray, technique->passCount);
|
||||||
|
|
||||||
for (std::uint16_t j = 0; j < technique->passCount; ++j)
|
for (std::uint16_t j = 0; j < technique->passCount; ++j)
|
||||||
|
@ -34,6 +34,8 @@ namespace Components
|
|||||||
|
|
||||||
static void SND_GetAliasOffset_Stub();
|
static void SND_GetAliasOffset_Stub();
|
||||||
|
|
||||||
|
static bool CL_ShouldSendNotify_Hk(const char* cmd);
|
||||||
|
|
||||||
static Game::dvar_t* Dvar_RegisterConMinicon(const char* dvarName, bool value, unsigned __int16 flags, const char* description);
|
static Game::dvar_t* Dvar_RegisterConMinicon(const char* dvarName, bool value, unsigned __int16 flags, const char* description);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user