Add an Auto Viewmodel flipper

This commit is contained in:
BenCat07 2020-09-02 21:10:03 +02:00 committed by LightCat
parent 87863e495d
commit 71c541af4f
3 changed files with 67 additions and 0 deletions

View File

@ -20,6 +20,7 @@
<AutoVariable width="fill" target="aimbot.miss-chance" label="Miss chance" tooltip="% chance the aimbot will miss on purpose."/>
<AutoVariable width="fill" target="aimbot.extrapolate" label="Extrapolate"/>
<AutoVariable width="fill" target="aimbot.zoomed-only" label="Zoomed only" tooltip="If applicable, the aimbot will only shoot if you are scoped in."/>
<AutoVariable width="fill" target="misc.auto-flip-viewmodel" label="Flip Viewmodel" tooltip="Automatically flip the viewmodel for projectile weapons."/>
</List>
</Box>
<Box padding="12 6 6 6" width="content" height="content" name="Autoshoot" y="215">

View File

@ -42,6 +42,11 @@ public:
typedef int (*fn_t)(IClientEntity *);
return vfunc<fn_t>(self, offsets::PlatformOffset(445, offsets::undefined, 445), 0)(self);
}
inline static bool IsViewModelFlipped(IClientEntity *self)
{
typedef bool (*fn_t)(IClientEntity *);
return vfunc<fn_t>(self, offsets::PlatformOffset(494, offsets::undefined, 494), 0)(self);
}
inline static IClientEntity *GetOwnerViaInterface(IClientEntity *self)
{
typedef IClientEntity *(*fn_t)(IClientEntity *);

View File

@ -0,0 +1,61 @@
#include "common.hpp"
static settings::Boolean auto_viewmodel_flipper{ "misc.auto-flip-viewmodel", "false" };
void CreateMove()
{
if (!auto_viewmodel_flipper)
return;
static auto cl_flipviewmodels = g_ICvar->FindVar("cl_flipviewmodels");
if (!cl_flipviewmodels)
{
cl_flipviewmodels = g_ICvar->FindVar("cl_flipviewmodels");
return;
}
static bool defaults = cl_flipviewmodels->GetBool();
// Should we test if a flip would help?
bool should_test_viewmodel = true;
for (int i = 1; i <= g_IEngine->GetMaxClients(); i++)
{
CachedEntity *ent = ENTITY(i);
if (CE_BAD(ent) || !ent->m_bEnemy() || !ent->m_bAlivePlayer() || ent == LOCAL_E)
continue;
auto eye = g_pLocalPlayer->v_Eye;
auto angle = GetAimAtAngles(eye, ent->m_vecOrigin());
eye = getShootPos(angle);
if (IsVectorVisible(eye, ent->m_vecOrigin()))
{
should_test_viewmodel = false;
break;
}
}
bool keep_flipped = false;
// Noone is visible, test if flipping helps
if (should_test_viewmodel)
{
cl_flipviewmodels->SetValue(!cl_flipviewmodels->GetBool());
for (int i = 0; i <= g_IEngine->GetMaxClients(); i++)
{
CachedEntity *ent = ENTITY(i);
if (CE_BAD(ent) || !ent->m_bEnemy() || !ent->m_bAlivePlayer() || ent == LOCAL_E)
continue;
auto eye = g_pLocalPlayer->v_Eye;
auto angle = GetAimAtAngles(eye, ent->m_vecOrigin());
eye = getShootPos(angle);
if (IsVectorVisible(eye, ent->m_vecOrigin()))
{
keep_flipped = true;
break;
}
}
}
// Reset status as noone is in range
if (!keep_flipped && should_test_viewmodel)
cl_flipviewmodels->SetValue(defaults);
}
static InitRoutine init([]() { EC::Register(EC::CreateMove, CreateMove, "viewmodel_flip_cm"); });