From 0b9104c9a592e622defe3f89dc5b4da68ca6e4cb Mon Sep 17 00:00:00 2001 From: Zyntex Date: Sun, 25 Jun 2023 17:33:24 +0200 Subject: [PATCH 1/3] feat: no viewmodel shadows --- src/Cheats.cpp | 2 ++ src/Cheats.hpp | 1 + src/Modules/Client.cpp | 28 ++++++++++++++++++++++++++++ src/Modules/Client.hpp | 3 +++ src/OffsetsData.hpp | 3 +++ src/Utils/SDK/ICollideable.hpp | 11 ++++++++++- 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Cheats.cpp b/src/Cheats.cpp index 7d2e8f360..d72ebae29 100644 --- a/src/Cheats.cpp +++ b/src/Cheats.cpp @@ -46,6 +46,7 @@ Variable sar_patch_bhop("sar_patch_bhop", "0", 0, 1, "Patches bhop by limiting w Variable sar_patch_cfg("sar_patch_cfg", "0", 0, 1, "Patches Crouch Flying Glitch.\n"); Variable sar_prevent_ehm("sar_prevent_ehm", "0", 0, 1, "Prevents Entity Handle Misinterpretation (EHM) from happening.\n"); Variable sar_disable_weapon_sway("sar_disable_weapon_sway", "0", 0, 1, "Disables the viewmodel lagging behind.\n"); +Variable sar_disable_viewmodel_shadows("sar_disable_viewmodel_shadows", "0", 0, 1, "Disables the shadows on the viewmodel.\n"); Variable sv_laser_cube_autoaim; Variable ui_loadingscreen_transition_time; @@ -290,6 +291,7 @@ void Cheats::Init() { sar_disable_challenge_stats_hud.UniqueFor(SourceGame_Portal2); sar_disable_weapon_sway.UniqueFor(SourceGame_Portal2); + sar_disable_viewmodel_shadows.UniqueFor(SourceGame_Portal2); sar_workshop.UniqueFor(SourceGame_Portal2 | SourceGame_ApertureTag); sar_workshop_update.UniqueFor(SourceGame_Portal2 | SourceGame_ApertureTag); diff --git a/src/Cheats.hpp b/src/Cheats.hpp index 2253ed90a..1d56313e1 100644 --- a/src/Cheats.hpp +++ b/src/Cheats.hpp @@ -28,6 +28,7 @@ extern Variable sar_patch_bhop; extern Variable sar_patch_cfg; extern Variable sar_prevent_ehm; extern Variable sar_disable_weapon_sway; +extern Variable sar_disable_viewmodel_shadows; extern Variable sv_laser_cube_autoaim; extern Variable ui_loadingscreen_transition_time; diff --git a/src/Modules/Client.cpp b/src/Modules/Client.cpp index 07a832536..f30c0ac40 100644 --- a/src/Modules/Client.cpp +++ b/src/Modules/Client.cpp @@ -66,6 +66,7 @@ REDECL(Client::ProcessMovement); REDECL(Client::DrawTranslucentRenderables); REDECL(Client::DrawOpaqueRenderables); REDECL(Client::CalcViewModelLag); +REDECL(Client::AddShadowToReceiver); CMDECL(Client::GetAbsOrigin, Vector, m_vecAbsOrigin); CMDECL(Client::GetAbsAngles, QAngle, m_angAbsRotation); @@ -494,6 +495,23 @@ DETOUR_T(void, Client::CalcViewModelLag, Vector &origin, QAngle &angles, QAngle } Hook g_CalcViewModelLagHook(&Client::CalcViewModelLag_Hook); +extern Hook g_AddShadowToReceiverHook; +DETOUR_T(void, Client::AddShadowToReceiver, unsigned short handle, void *pRenderable, int type) { + if (sar_disable_viewmodel_shadows.GetBool()) { + // IClientRenderable::GetModel() + using _GetModel = model_t *(__rescall *)(void *); + model_t *model = Memory::VMT<_GetModel>(pRenderable, Offsets::GetModel)(pRenderable); + + if (!strcmp(model->szPathName, "models/weapons/v_portalgun.mdl")) + return; + } + + g_AddShadowToReceiverHook.Disable(); + Client::AddShadowToReceiver(thisptr, handle, pRenderable, type); + g_AddShadowToReceiverHook.Enable(); +} +Hook g_AddShadowToReceiverHook(&Client::AddShadowToReceiver_Hook); + bool Client::Init() { bool readJmp = false; @@ -619,6 +637,16 @@ bool Client::Init() { g_CalcViewModelLagHook.SetFunc(Client::CalcViewModelLag); + if (sar.game->Is(SourceGame_Portal2)) { +#ifdef _WIN32 + Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 8B EC 51 53 56 57 0F B7 7D 08 69 FF ? ? ? ? 03 79 2C 51 89 4D FC 8B 0F 8B C4 89 08 8B 0D ? ? ? ? E8 ? ? ? ? 8B 75 0C 8B D8 3B DE 0F 84 ? ? ? ?"); +#else + Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 89 E5 57 56 53 83 EC 44 8B 45 0C 8B 5D 08 8B 55 14 8B 75 10 89 45 C8 0F B7 C0 8B 7B 2C 89 45 D4 69 C0 ? ? ? ? 89 55 CC 89 45 C4 01 C7 8B 07 89 45 E4 8D 45 E4 50 FF 35 ? ? ? ? E8 ? ? ? ? 83 C4 10 89 45 D0 39 F0 74 12"); +#endif + } + + g_AddShadowToReceiverHook.SetFunc(Client::AddShadowToReceiver); + // Get at gamerules { uintptr_t cbk = (uintptr_t)Command("+mouse_menu").ThisPtr()->m_pCommandCallback; diff --git a/src/Modules/Client.hpp b/src/Modules/Client.hpp index b3a218ed0..941d9cbc9 100644 --- a/src/Modules/Client.hpp +++ b/src/Modules/Client.hpp @@ -69,6 +69,9 @@ class Client : public Module { void OpenChat(); public: + // CClientShadowMgr::AddShadowToReceiver + DECL_DETOUR_T(void, AddShadowToReceiver, unsigned short handle, void *pRenderable, int type); + // CBaseViewModel::CalcViewModelLag DECL_DETOUR_T(void, CalcViewModelLag, Vector &origin, QAngle &angles, QAngle &original_angles); diff --git a/src/OffsetsData.hpp b/src/OffsetsData.hpp index fa5371e31..61dd065e0 100644 --- a/src/OffsetsData.hpp +++ b/src/OffsetsData.hpp @@ -253,6 +253,9 @@ OFFSET_DEFAULT(GetSearchPath, 16, 16) // CGameRules OFFSET_DEFAULT(IsMultiplayer, 33, 34) +// IClientRenderable +OFFSET_DEFAULT(GetModel, 8, 9) + // Others OFFSET_DEFAULT(tickcount, 95, 64) OFFSET_DEFAULT(interval_per_tick, 65, 58) diff --git a/src/Utils/SDK/ICollideable.hpp b/src/Utils/SDK/ICollideable.hpp index 258a2fa7c..42dc8be5a 100644 --- a/src/Utils/SDK/ICollideable.hpp +++ b/src/Utils/SDK/ICollideable.hpp @@ -19,7 +19,16 @@ enum SolidType_t { #define FSOLID_NOT_STANDABLE 0x10 #define FSOLID_VOLUME_CONTENTS 0x20 -class model_t; +struct model_t { + void *fnHandle; + char szPathName[260]; + int nLoadFlags; + int nServerCount; + int type; + int flags; + Vector mins, maxs; + float radius; +}; class IClientUnknown; class IPhysicsObject; class CPhysCollide; From 4fddb893cdc8e9d0dc0b970d2277d45bc3506b92 Mon Sep 17 00:00:00 2001 From: Zyntex Date: Sun, 22 Oct 2023 20:21:30 +0200 Subject: [PATCH 2/3] clean up sigs, offset fix --- src/Modules/Client.cpp | 4 ++-- src/OffsetsData.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Modules/Client.cpp b/src/Modules/Client.cpp index f30c0ac40..fc8a86363 100644 --- a/src/Modules/Client.cpp +++ b/src/Modules/Client.cpp @@ -639,9 +639,9 @@ bool Client::Init() { if (sar.game->Is(SourceGame_Portal2)) { #ifdef _WIN32 - Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 8B EC 51 53 56 57 0F B7 7D 08 69 FF ? ? ? ? 03 79 2C 51 89 4D FC 8B 0F 8B C4 89 08 8B 0D ? ? ? ? E8 ? ? ? ? 8B 75 0C 8B D8 3B DE 0F 84 ? ? ? ?"); + Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 8B EC 51 53 56 57 0F B7 7D 08"); #else - Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 89 E5 57 56 53 83 EC 44 8B 45 0C 8B 5D 08 8B 55 14 8B 75 10 89 45 C8 0F B7 C0 8B 7B 2C 89 45 D4 69 C0 ? ? ? ? 89 55 CC 89 45 C4 01 C7 8B 07 89 45 E4 8D 45 E4 50 FF 35 ? ? ? ? E8 ? ? ? ? 83 C4 10 89 45 D0 39 F0 74 12"); + Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 89 E5 57 56 53 83 EC 44 8B 45 0C 8B 5D 08 8B 55 14 8B 75 10"); #endif } diff --git a/src/OffsetsData.hpp b/src/OffsetsData.hpp index 61dd065e0..a3a029083 100644 --- a/src/OffsetsData.hpp +++ b/src/OffsetsData.hpp @@ -254,7 +254,7 @@ OFFSET_DEFAULT(GetSearchPath, 16, 16) OFFSET_DEFAULT(IsMultiplayer, 33, 34) // IClientRenderable -OFFSET_DEFAULT(GetModel, 8, 9) +OFFSET_DEFAULT(GetModel, 8, 8) // Others OFFSET_DEFAULT(tickcount, 95, 64) From d983079a29683dd30c9603b7c964f9693494f3d2 Mon Sep 17 00:00:00 2001 From: Zyntex Date: Sun, 22 Oct 2023 20:51:19 +0200 Subject: [PATCH 3/3] compatibility with other games --- src/Cheats.cpp | 2 +- src/Modules/Client.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cheats.cpp b/src/Cheats.cpp index d72ebae29..bed926939 100644 --- a/src/Cheats.cpp +++ b/src/Cheats.cpp @@ -291,7 +291,7 @@ void Cheats::Init() { sar_disable_challenge_stats_hud.UniqueFor(SourceGame_Portal2); sar_disable_weapon_sway.UniqueFor(SourceGame_Portal2); - sar_disable_viewmodel_shadows.UniqueFor(SourceGame_Portal2); + sar_disable_viewmodel_shadows.UniqueFor(SourceGame_Portal2 | SourceGame_PortalStoriesMel | SourceGame_PortalReloaded); sar_workshop.UniqueFor(SourceGame_Portal2 | SourceGame_ApertureTag); sar_workshop_update.UniqueFor(SourceGame_Portal2 | SourceGame_ApertureTag); diff --git a/src/Modules/Client.cpp b/src/Modules/Client.cpp index fc8a86363..262fbed3d 100644 --- a/src/Modules/Client.cpp +++ b/src/Modules/Client.cpp @@ -637,7 +637,7 @@ bool Client::Init() { g_CalcViewModelLagHook.SetFunc(Client::CalcViewModelLag); - if (sar.game->Is(SourceGame_Portal2)) { + if (sar.game->Is(SourceGame_Portal2 | SourceGame_PortalStoriesMel | SourceGame_PortalReloaded)) { #ifdef _WIN32 Client::AddShadowToReceiver = (decltype(Client::AddShadowToReceiver))Memory::Scan(client->Name(), "55 8B EC 51 53 56 57 0F B7 7D 08"); #else