From 0ed0eae38c9f2487f40e7638ff34e0ae21c9e179 Mon Sep 17 00:00:00 2001 From: shockpast Date: Sun, 1 Dec 2024 02:16:23 +0300 Subject: [PATCH] feat: added "sho:SetAbsOrigin" hook --- README.md | 6 +++++- examples/setabsorigin.lua | 16 ++++++++++++++ premake5.lua | 6 +++--- source/lua.cpp | 16 ++++++++++++++ source/lua.h | 4 ++++ source/main.cpp | 3 +++ source/main.h | 6 ++++++ source/modules/hush.cpp | 45 +++++++++++++++++++++++++++++++++++---- source/symbols.cpp | 20 ++++++++++++----- source/symbols.h | 16 +++++++++----- 10 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 examples/setabsorigin.lua create mode 100644 source/lua.cpp create mode 100644 source/lua.h create mode 100644 source/main.h diff --git a/README.md b/README.md index 882826f..b8b6df6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # gmsv_sho -idk, it removes `do_constraint_system: Couldn't invert rot matrix!` message, maybe it works, idkkkkkkkkkkkkk \ No newline at end of file +idk, it removes `do_constraint_system: Couldn't invert rot matrix!` message, maybe it works, idkkkkkkkkkkkkk + +## hooks +### `sho:SetAbsOrigin` +it has 1 argument, `number idx`, it's id of entity that would spam message "Ignoring Unreasonable Position!", you can hook it and then just remove it, so it won't garbage your server, or do whatever with it *(beware, players can also trigger it)* \ No newline at end of file diff --git a/examples/setabsorigin.lua b/examples/setabsorigin.lua new file mode 100644 index 0000000..0544e40 --- /dev/null +++ b/examples/setabsorigin.lua @@ -0,0 +1,16 @@ +hook.Add("sho:SetAbsOrigin", "t", function(class, idx) + local ent = Entity(idx) + if not IsValid(ent) then return end + if ent:IsPlayer() then + print(ent, " was in wrong position.") + print(ent:SteamID()) + + ent:SetPos(Vector(0, 0, 0)) + return -- just don't delete your player, pretty please :) + end + + print(ent, " was removed") + print(ent:GetPos()) + + ent:Remove() +end) diff --git a/premake5.lua b/premake5.lua index d074306..e075c23 100644 --- a/premake5.lua +++ b/premake5.lua @@ -27,13 +27,13 @@ CreateWorkspace({ name = "sho", abi_compatible = false }) IncludeSDKTier0() IncludeSDKTier1() --IncludeSDKTier3() + IncludeDetouring() + IncludeScanning() + --IncludeSteamAPI() --IncludeSDKMathlib() --IncludeSDKRaytrace() --IncludeSDKBitmap() --IncludeSDKVTF() - --IncludeSteamAPI() - IncludeDetouring() - IncludeScanning() files({ [[source/modules/*.h]], diff --git a/source/lua.cpp b/source/lua.cpp new file mode 100644 index 0000000..5f7dc88 --- /dev/null +++ b/source/lua.cpp @@ -0,0 +1,16 @@ +#include + +#include "lua.h" +#include "main.h" + +void lua::PushHook(const char* name) +{ + g_Lua->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB); + g_Lua->GetField(-1, "hook"); + g_Lua->GetField(-1, "Run"); + int reference = g_Lua->ReferenceCreate(); + g_Lua->Pop(2); + g_Lua->ReferencePush(reference); + g_Lua->ReferenceFree(reference); + g_Lua->PushString(name); +} \ No newline at end of file diff --git a/source/lua.h b/source/lua.h new file mode 100644 index 0000000..23269e2 --- /dev/null +++ b/source/lua.h @@ -0,0 +1,4 @@ +namespace lua +{ + void PushHook(const char* name); +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 5c11c33..f873e7d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,10 +1,13 @@ #include #include +#include "main.h" #include "modules/hush.h" GMOD_MODULE_OPEN() { + g_Lua = LUA; + hush::initialize(); return 0; diff --git a/source/main.h b/source/main.h new file mode 100644 index 0000000..7021ef1 --- /dev/null +++ b/source/main.h @@ -0,0 +1,6 @@ +namespace GarrysMod::Lua +{ + class ILuaBase; +} + +inline GarrysMod::Lua::ILuaBase* g_Lua = nullptr; \ No newline at end of file diff --git a/source/modules/hush.cpp b/source/modules/hush.cpp index cbfe032..3930546 100644 --- a/source/modules/hush.cpp +++ b/source/modules/hush.cpp @@ -3,8 +3,12 @@ #include #include +#include + +#include "lua.h" #include "hush.h" #include "detour.h" +#include "main.h" #define MAX_ERROR_BUFFER_LEN 10000 // vphysics #define MAX_MAKE_STRING_LEN 10000 // vphysics @@ -18,7 +22,7 @@ void hook_ivp_message(const char* pMsgFormat, ...) va_list args; va_start(args, pMsgFormat); - detour_ivp_message.GetTrampoline()(pMsgFormat, args); + detour_ivp_message.GetTrampoline()(pMsgFormat, args); } static Detouring::Hook detour_ConMsg; @@ -36,14 +40,47 @@ void hook_ConMsg(const char* pMsgFormat, ...) va_end(args); // todo: putting just va_list seems to corrupt arguments in string... - detour_ConMsg.GetTrampoline()(buf, args); + detour_ConMsg.GetTrampoline()(buf, args); +} + +static Detouring::Hook detour_Warning; +void hook_Warning(const char* pMsgFormat, ...) +{ + if (strstr(pMsgFormat, "%s[%i]:SetAbsOrigin( %f %f %f ): Ignoring unreasonable position.")) // ? this looks messy + { + va_list args; + va_start(args, pMsgFormat); + + const char* entityClass = va_arg(args, const char*); // ? + int entityIndex = va_arg(args, int); + + va_end(args); + + lua::PushHook("sho:SetAbsOrigin"); // todo i need something unique and good looking + g_Lua->PushString(entityClass); // it's not needed, but i will just send it 😎 + g_Lua->PushNumber(entityIndex); + g_Lua->PCall(3, 0, true); + + return; + } + + va_list args; + va_start(args, pMsgFormat); + + char buf[4096]; + vsprintf(buf, pMsgFormat, args); + + va_end(args); + + detour_Warning.GetTrampoline()(buf, args); } void hush::initialize() { SourceSDK::ModuleLoader vphysics("vphysics"); - detour::Create(&detour_ivp_message, "ivp_message", vphysics.GetModule(), symbols::ivp_messageSym, (void*)hook_ivp_message, 0); + detour::Create(&detour_ivp_message, "ivp_message", vphysics.GetModule(), symbols::vphysics_ivp_messageSym, (void*)hook_ivp_message, 0); SourceSDK::ModuleLoader tier0("libtier0"); - detour::Create(&detour_ConMsg, "ConMsg", tier0.GetModule(), symbols::ConMsgSym, (void*)hook_ConMsg, 0); + detour::Create(&detour_ConMsg, "ConMsg", tier0.GetModule(), symbols::libtier0_ConMsgSym, (void*)hook_ConMsg, 0); + detour::Create(&detour_Warning, "Warning", tier0.GetModule(), symbols::libtier0_WarningSym, (void*)hook_Warning, 0); } \ No newline at end of file diff --git a/source/symbols.cpp b/source/symbols.cpp index 66addd4..5ee665e 100644 --- a/source/symbols.cpp +++ b/source/symbols.cpp @@ -5,19 +5,29 @@ static Symbol NULL_SYMBOL = Symbol::FromSignature(""); namespace symbols { //--------------------------------------------------------------------------------- - // Purpose: "hush" Symbols + // Purpose: vphysics Symbols //--------------------------------------------------------------------------------- - const std::vector ivp_messageSym = { - // - Symbol::FromName("_Z11ivp_messagePKcz"), // not sure + const std::vector vphysics_ivp_messageSym = { + // not sure + Symbol::FromName("_Z11ivp_messagePKcz"), // 55 48 89 E5 41 54 53 48 81 EC ? ? ? ? 84 C0 48 89 B5 ? ? ? ? 48 89 95 ? ? ? ? 48 89 8D ? ? ? ? 4C 89 85 ? ? ? ? 4C 89 8D ? ? ? ? 74 ? 0F 29 85 ? ? ? ? 0F 29 4D ? 0F 29 55 ? 0F 29 5D ? 0F 29 65 ? 0F 29 6D ? 0F 29 75 ? 0F 29 7D ? 48 8D 9D ? ? ? ? 31 F6 49 89 FC 64 48 8B 04 25 ? ? ? ? 48 89 85 ? ? ? ? 31 C0 BA ? ? ? ? 48 89 DF E8 ? ? ? ? 4C 8D 8D Symbol::FromSignature("\x55\x48\x89\xE5\x41\x54\x53\x48\x81\xEC****\x84\xC0\x48\x89\xB5****\x48\x89\x95****\x48\x89\x8D****\x4C\x89\x85****\x4C\x89\x8D****\x74*\x0F\x29\x85****\x0F\x29\x4D*\x0F\x29\x55*\x0F\x29\x5D*\x0F\x29\x65*\x0F\x29\x6D*\x0F\x29\x75*\x0F\x29\x7D*\x48\x8D\x9D****\x31\xF6\x49\x89\xFC\x64\x48\x8B\x04\x25****\x48\x89\x85****\x31\xC0\xBA****\x48\x89\xDF\xE8****\x4C\x8D\x8D") }; - const std::vector ConMsgSym = { + //--------------------------------------------------------------------------------- + // Purpose: tier0 Symbols + //--------------------------------------------------------------------------------- + const std::vector libtier0_ConMsgSym = { // NULL_SYMBOL, // Symbol::FromName("_Z6ConMsgPKcz") }; + + const std::vector libtier0_WarningSym = { + // + NULL_SYMBOL, + // huh + Symbol::FromName("Warning") + }; } \ No newline at end of file diff --git a/source/symbols.h b/source/symbols.h index 97f8c0c..3e8ac17 100644 --- a/source/symbols.h +++ b/source/symbols.h @@ -18,11 +18,17 @@ class Color; namespace symbols { //--------------------------------------------------------------------------------- - // Purpose: "hush" Symbols + // Purpose: vphysics Symbols //--------------------------------------------------------------------------------- - typedef void (GMCOMMON_CALLING_CONVENTION* ivp_message)(const char* templat, ...); - extern const std::vector ivp_messageSym; + typedef void (GMCOMMON_CALLING_CONVENTION* vphysics_ivp_message)(const char* templat, va_list args); + extern const std::vector vphysics_ivp_messageSym; - typedef void (GMCOMMON_CALLING_CONVENTION* ConMsg)(const char* pMsgFormat, va_list args); - extern const std::vector ConMsgSym; + //--------------------------------------------------------------------------------- + // Purpose: tier0 Symbols + //--------------------------------------------------------------------------------- + typedef void (GMCOMMON_CALLING_CONVENTION* libtier0_ConMsg)(const char* pMsgFormat, va_list args); + extern const std::vector libtier0_ConMsgSym; + + typedef void (GMCOMMON_CALLING_CONVENTION* libtier0_Warning)(const char* pMsgFormat, va_list args); + extern const std::vector libtier0_WarningSym; } \ No newline at end of file