Skip to content

Commit

Permalink
feat: no viewmodel shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
hero622 committed Jun 25, 2023
1 parent 29f8e99 commit 0b9104c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Cheats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/Modules/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Modules/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/OffsetsData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion src/Utils/SDK/ICollideable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0b9104c

Please sign in to comment.