Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crouch blockbot #599

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/Hacks/autoblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "../Utils/math.h"
#include "../settings.h"
#include "../interfaces.h"

void Autoblock::CreateMove(CUserCmd* cmd)
{
if (!Settings::Autoblock::enabled)
Expand Down Expand Up @@ -43,13 +42,34 @@ void Autoblock::CreateMove(CUserCmd* cmd)
if (!target)
return;

bool crouchBlock = false;
if (localplayer->GetAbsOrigin().z - target->GetAbsOrigin().z >= target->GetCollideable()->OBBMaxs().z)
crouchBlock = true;

QAngle angles = Math::CalcAngle(localplayer->GetVecOrigin(), target->GetVecOrigin());

angles.y -= localplayer->GetEyeAngles()->y;
Math::NormalizeAngles(angles);

if (angles.y < 0.0f)
cmd->sidemove = 250.f;
else if (angles.y > 0.0f)
cmd->sidemove = -250.f;
if (crouchBlock)
{
Vector forward = target->GetAbsOrigin() - localplayer->GetAbsOrigin();
float angle = localplayer->GetVAngles()->y;

cmd->forwardmove = Math::Clamp((
(sin(DEG2RAD(angle)) * forward.y) +
(cos(DEG2RAD(angle)) * forward.x)) * 250.f,
-250.f, 250.f);
cmd->sidemove = Math::Clamp((
(cos(DEG2RAD(angle)) * -forward.y) +
(sin(DEG2RAD(angle)) * forward.x)) * 250.f,
-250.f, 250.f);
}
else
{
if (angles.y < 0.f)
cmd->sidemove = 250.f;
else if (angles.y > 0.f)
cmd->sidemove = -250.f;
}
}
5 changes: 5 additions & 0 deletions src/Utils/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ void Math::ClampAngles(QAngle& angle)
angle.z = 0;
}

float Math::Clamp(float f, float min, float max)
{
return (f <= min) ? min : (f >= max) ? max : f;
}

void Math::CorrectMovement(const QAngle &vOldAngles, CUserCmd* pCmd, float fOldForward, float fOldSidemove)
{
// side/forward move correction
Expand Down
3 changes: 2 additions & 1 deletion src/Utils/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ namespace Math {
void NormalizeAngles(QAngle& angle);
void NormalizeYaw( float& yaw );
void ClampAngles(QAngle& angle);
float Clamp(float x, float min, float max);
void CorrectMovement(const QAngle &vOldAngles, CUserCmd* pCmd, float fOldForward, float fOldSidemove);
float GetFov(const QAngle &viewAngle, const QAngle &aimAngle);
float DotProduct(const Vector &v1, const float* v2);
void VectorAngles(const Vector &forward, QAngle &angles);
void VectorTransform (const Vector &in1, const matrix3x4_t& in2, Vector &out);
QAngle CalcAngle(const Vector &src, const Vector &dst);
float float_rand( float min, float max );
}
}