aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/shared
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDLL/shared')
-rw-r--r--NorthstarDLL/shared/exploit_fixes/exploitfixes.cpp6
-rw-r--r--NorthstarDLL/shared/misccommands.cpp78
2 files changed, 79 insertions, 5 deletions
diff --git a/NorthstarDLL/shared/exploit_fixes/exploitfixes.cpp b/NorthstarDLL/shared/exploit_fixes/exploitfixes.cpp
index e4430fd4..8cb956e6 100644
--- a/NorthstarDLL/shared/exploit_fixes/exploitfixes.cpp
+++ b/NorthstarDLL/shared/exploit_fixes/exploitfixes.cpp
@@ -266,8 +266,6 @@ bool, __fastcall, (const char* pModName)) // 48 83 EC 28 48 8B 0D ? ? ? ? 48 8D
}
// ratelimit stringcmds, and prevent remote clients from calling commands that they shouldn't
-bool (*CCommand__Tokenize)(CCommand& self, const char* pCommandString, R2::cmd_source_t commandSource);
-
// clang-format off
AUTOHOOK(CGameClient__ExecuteStringCommand, engine.dll + 0x1022E0,
bool, __fastcall, (R2::CBaseClient* self, uint32_t unknown, const char* pCommandString))
@@ -287,7 +285,7 @@ bool, __fastcall, (R2::CBaseClient* self, uint32_t unknown, const char* pCommand
memset(commandBuf, 0, sizeof(commandBuf));
CCommand tempCommand = *(CCommand*)&commandBuf;
- if (!CCommand__Tokenize(tempCommand, pCommandString, R2::cmd_source_t::kCommandSrcCode) || !tempCommand.ArgC())
+ if (!R2::CCommand__Tokenize(tempCommand, pCommandString, R2::cmd_source_t::kCommandSrcCode) || !tempCommand.ArgC())
return false;
ConCommand* command = R2::g_pCVar->FindCommand(tempCommand.Arg(0));
@@ -402,8 +400,6 @@ ON_DLL_LOAD("engine.dll", EngineExploitFixes, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(engine.dll)
- CCommand__Tokenize = module.Offset(0x418380).As<bool (*)(CCommand&, const char*, R2::cmd_source_t)>();
-
// allow client/ui to run clientcommands despite restricting servercommands
module.Offset(0x4FB65).Patch("EB 11");
module.Offset(0x4FBAC).Patch("EB 16");
diff --git a/NorthstarDLL/shared/misccommands.cpp b/NorthstarDLL/shared/misccommands.cpp
index ad8b2a32..f3817867 100644
--- a/NorthstarDLL/shared/misccommands.cpp
+++ b/NorthstarDLL/shared/misccommands.cpp
@@ -45,6 +45,72 @@ void ConCommand_ns_end_reauth_and_leave_to_lobby(const CCommand& arg)
}
}
+void ConCommand_cvar_setdefaultvalue(const CCommand& arg)
+{
+ if (arg.ArgC() < 3)
+ {
+ spdlog::info("usage: cvar_setdefaultvalue mp_gamemode tdm");
+ return;
+ }
+
+ ConVar* pCvar = R2::g_pCVar->FindVar(arg.Arg(1));
+ if (!pCvar)
+ {
+ spdlog::info("usage: cvar_setdefaultvalue mp_gamemode tdm");
+ return;
+ }
+
+ // unfortunately no way for us to not leak memory here, as default value might not be in writeable memory by default
+ int nLen = strlen(arg.Arg(2));
+ char* pBuf = new char[nLen + 1];
+ strncpy_s(pBuf, nLen + 1, arg.Arg(2), nLen);
+
+ pCvar->m_pszDefaultValue = pBuf;
+}
+
+void ConCommand_cvar_setvalueanddefaultvalue(const CCommand& arg)
+{
+ if (arg.ArgC() < 3)
+ {
+ spdlog::info("usage: cvar_setvalueanddefaultvalue mp_gamemode tdm");
+ return;
+ }
+
+ ConVar* pCvar = R2::g_pCVar->FindVar(arg.Arg(1));
+ if (!pCvar)
+ {
+ spdlog::info("usage: cvar_setvalueanddefaultvalue mp_gamemode tdm");
+ return;
+ }
+
+ // unfortunately no way for us to not leak memory here, as default value might not be in writeable memory by default
+ int nLen = strlen(arg.Arg(2));
+ char* pBuf = new char[nLen + 1];
+ strncpy_s(pBuf, nLen + 1, arg.Arg(2), nLen);
+
+ pCvar->m_pszDefaultValue = pBuf;
+ pCvar->SetValue(pCvar->m_pszDefaultValue);
+}
+
+void ConCommand_cvar_reset(const CCommand& arg)
+{
+ if (arg.ArgC() < 2)
+ {
+ spdlog::info("usage: cvar_reset mp_gamemode");
+ return;
+ }
+
+ ConVar* pCvar = R2::g_pCVar->FindVar(arg.Arg(1));
+ if (!pCvar)
+ {
+ spdlog::info("usage: cvar_reset mp_gamemode");
+ return;
+ }
+
+ // reset cvar
+ pCvar->SetValue(pCvar->m_pszDefaultValue);
+}
+
void AddMiscConCommands()
{
RegisterConCommand(
@@ -61,6 +127,18 @@ void AddMiscConCommands()
// this is a concommand because we make a deferred call to it from another thread
RegisterConCommand("ns_end_reauth_and_leave_to_lobby", ConCommand_ns_end_reauth_and_leave_to_lobby, "", FCVAR_NONE);
+
+ RegisterConCommand(
+ "cvar_setdefaultvalue",
+ ConCommand_cvar_setdefaultvalue,
+ "overwrites the default value of a cvar, for use with script and cvar_reset",
+ FCVAR_NONE);
+ RegisterConCommand(
+ "cvar_setvalueanddefaultvalue",
+ ConCommand_cvar_setvalueanddefaultvalue,
+ "overwrites the current value and default value of a cvar, for use with script and cvar_reset",
+ FCVAR_NONE);
+ RegisterConCommand("cvar_reset", ConCommand_cvar_reset, "resets a cvar's value to its default value", FCVAR_NONE);
}
// fixes up various cvar flags to have more sane values