Skip to content

Commit

Permalink
feat: added "sho:SetAbsOrigin" hook
Browse files Browse the repository at this point in the history
  • Loading branch information
shockpast committed Nov 30, 2024
1 parent 6b9ef0c commit 0ed0eae
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 18 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# gmsv_sho
idk, it removes `do_constraint_system: Couldn't invert rot matrix!` message, maybe it works, idkkkkkkkkkkkkk
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)*
16 changes: 16 additions & 0 deletions examples/setabsorigin.lua
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
16 changes: 16 additions & 0 deletions source/lua.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <GarrysMod/Lua/LuaInterface.h>

#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);
}
4 changes: 4 additions & 0 deletions source/lua.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace lua
{
void PushHook(const char* name);
}
3 changes: 3 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <GarrysMod/Lua/Interface.h>
#include <interfaces/interfaces.h>

#include "main.h"
#include "modules/hush.h"

GMOD_MODULE_OPEN()
{
g_Lua = LUA;

hush::initialize();

return 0;
Expand Down
6 changes: 6 additions & 0 deletions source/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GarrysMod::Lua
{
class ILuaBase;
}

inline GarrysMod::Lua::ILuaBase* g_Lua = nullptr;
45 changes: 41 additions & 4 deletions source/modules/hush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include <stdio.h>
#include <regex>

#include <GarrysMod/Lua/LuaInterface.h>

#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
Expand All @@ -18,7 +22,7 @@ void hook_ivp_message(const char* pMsgFormat, ...)
va_list args;
va_start(args, pMsgFormat);

detour_ivp_message.GetTrampoline<symbols::ivp_message>()(pMsgFormat, args);
detour_ivp_message.GetTrampoline<symbols::vphysics_ivp_message>()(pMsgFormat, args);
}

static Detouring::Hook detour_ConMsg;
Expand All @@ -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<symbols::ConMsg>()(buf, args);
detour_ConMsg.GetTrampoline<symbols::libtier0_ConMsg>()(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<symbols::libtier0_Warning>()(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);
}
20 changes: 15 additions & 5 deletions source/symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ static Symbol NULL_SYMBOL = Symbol::FromSignature("");
namespace symbols
{
//---------------------------------------------------------------------------------
// Purpose: "hush" Symbols
// Purpose: vphysics Symbols
//---------------------------------------------------------------------------------
const std::vector<Symbol> ivp_messageSym = {
//
Symbol::FromName("_Z11ivp_messagePKcz"), // not sure
const std::vector<Symbol> 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<Symbol> ConMsgSym = {
//---------------------------------------------------------------------------------
// Purpose: tier0 Symbols
//---------------------------------------------------------------------------------
const std::vector<Symbol> libtier0_ConMsgSym = {
//
NULL_SYMBOL,
//
Symbol::FromName("_Z6ConMsgPKcz")
};

const std::vector<Symbol> libtier0_WarningSym = {
//
NULL_SYMBOL,
// huh
Symbol::FromName("Warning")
};
}
16 changes: 11 additions & 5 deletions source/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol> ivp_messageSym;
typedef void (GMCOMMON_CALLING_CONVENTION* vphysics_ivp_message)(const char* templat, va_list args);
extern const std::vector<Symbol> vphysics_ivp_messageSym;

typedef void (GMCOMMON_CALLING_CONVENTION* ConMsg)(const char* pMsgFormat, va_list args);
extern const std::vector<Symbol> ConMsgSym;
//---------------------------------------------------------------------------------
// Purpose: tier0 Symbols
//---------------------------------------------------------------------------------
typedef void (GMCOMMON_CALLING_CONVENTION* libtier0_ConMsg)(const char* pMsgFormat, va_list args);
extern const std::vector<Symbol> libtier0_ConMsgSym;

typedef void (GMCOMMON_CALLING_CONVENTION* libtier0_Warning)(const char* pMsgFormat, va_list args);
extern const std::vector<Symbol> libtier0_WarningSym;
}

0 comments on commit 0ed0eae

Please sign in to comment.