From 07e90754ab86f7d56df2f813ceb93de12d4aa0d5 Mon Sep 17 00:00:00 2001 From: Emma Miler <27428383+emma-miler@users.noreply.github.com> Date: Fri, 13 May 2022 01:53:22 +0200 Subject: Block `emit` command when sv_cheats is disabled (#170) --- .../NorthstarDedicatedTest.vcxproj | 2 ++ .../NorthstarDedicatedTest.vcxproj.filters | 21 ++++++++++++----- NorthstarDedicatedTest/dllmain.cpp | 2 ++ NorthstarDedicatedTest/emit_blocker.cpp | 26 ++++++++++++++++++++++ NorthstarDedicatedTest/emit_blocker.h | 3 +++ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 NorthstarDedicatedTest/emit_blocker.cpp create mode 100644 NorthstarDedicatedTest/emit_blocker.h diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 1d065006..8f969d3e 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -115,6 +115,7 @@ + @@ -582,6 +583,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index c6815227..0424fcf6 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -133,6 +133,9 @@ {b30e08b1-b962-4264-8cbb-a0a31924b93e} + + {7f609cee-d2c0-46a2-b06e-83b9f0511915} + @@ -1491,12 +1494,6 @@ Header Files\Client - - Source Files\Shared\Exploit Fixes - - - Source Files\Shared\Exploit Fixes - Source Files\Shared\Exploit Fixes\UTF8Parser @@ -1506,6 +1503,15 @@ Header Files + + Header Files\Shared\ExploitFixes + + + Header Files\Shared\ExploitFixes + + + Header Files\Shared\ExploitFixes + @@ -1667,6 +1673,9 @@ Source Files + + Source Files\Shared\Exploit Fixes + diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index c0674d94..1b98105c 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -49,6 +49,7 @@ #include "rapidjson/writer.h" #include "rapidjson/error/en.h" #include "ExploitFixes.h" +#include "emit_blocker.h" typedef void (*initPluginFuncPtr)(void* getPluginObject); @@ -283,6 +284,7 @@ bool InitialiseNorthstar() // activate exploit fixes AddDllLoadCallback("server.dll", ExploitFixes::LoadCallback); + AddDllLoadCallback("server.dll", InitialiseServerEmit_Blocker); // run callbacks for any libraries that are already loaded by now CallAllPendingDLLLoadCallbacks(); diff --git a/NorthstarDedicatedTest/emit_blocker.cpp b/NorthstarDedicatedTest/emit_blocker.cpp new file mode 100644 index 00000000..3f996c69 --- /dev/null +++ b/NorthstarDedicatedTest/emit_blocker.cpp @@ -0,0 +1,26 @@ +#include "pch.h" +#include "cvar.h" + +ConVar* sv_cheats; + +typedef char(__fastcall* function_containing_emit_t)(uint64_t a1, uint64_t a2); +function_containing_emit_t function_containing_emit; + +char function_containing_emit_hook(uint64_t unknown_value, uint64_t command_ptr) +{ + char* command_string = *(char**)(command_ptr + 1040); // From decompile + if (!sv_cheats->m_Value.m_nValue && !strncmp(command_string, "emit", 5)) + { + spdlog::info("Blocking command \"emit\" because sv_cheats was 0"); + return 1; + } + return function_containing_emit(unknown_value, command_ptr); +} + +void InitialiseServerEmit_Blocker(HMODULE baseAddress) +{ + HookEnabler hook; + sv_cheats = g_pCVar->FindVar("sv_cheats"); + ENABLER_CREATEHOOK( + hook, (char*)baseAddress + 0x5889A0, &function_containing_emit_hook, reinterpret_cast(&function_containing_emit)); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/emit_blocker.h b/NorthstarDedicatedTest/emit_blocker.h new file mode 100644 index 00000000..43991927 --- /dev/null +++ b/NorthstarDedicatedTest/emit_blocker.h @@ -0,0 +1,3 @@ +#pragma once + +void InitialiseServerEmit_Blocker(HMODULE baseAddress); \ No newline at end of file -- cgit v1.2.3