#include "../hooks.hpp"
#include "../helpers/math.hpp"
#include "../helpers/input.hpp"
#include "../options.hpp"
#include "desync.h"
#include "../valve_sdk/interfaces/CClientState.hpp"
AntiAim g_AntiAim;
extern float next_lby;
extern float side;
int GetBestHeadAngle(float yaw)
{
float Back, Right, Left;
Vector src3D, dst3D, forward, right, up, src, dst;
trace_t tr;
Ray_t ray, ray2, ray3, ray4, ray5;
CTraceFilter filter;
QAngle engineViewAngles;
engineViewAngles.pitch = 0;
engineViewAngles.yaw = yaw;
Math::AngleVectors(engineViewAngles, forward, right, up);
filter.pSkip = g_LocalPlayer;
src3D = g_LocalPlayer->GetEyePos();
dst3D = src3D + (forward * 384);
ray.Init(src3D, dst3D);
g_EngineTrace->TraceRay(ray, MASK_SHOT, &filter, &tr);
Back = (tr.endpos - tr.startpos).Length();
ray2.Init(src3D + right * 35, dst3D + right * 35);
g_EngineTrace->TraceRay(ray2, MASK_SHOT, &filter, &tr);
Riht = (tr.endpos - tr.startpos).Length();
ray3.Init(src3D - right * 35, dst3D - right * 35);
g_EngineTrace->TraceRay(ray3, MASK_SHOT, &filter, &tr);
Left = (tr.endpos - tr.startpos).Length();
static int result = 0;
if (Left > Right)
{
result = -1;
}
else if (Right > Left)
{
result = 1;
}
return result;
}
float AngleDiff(float destAngle, float srcAngle) {
float delta;
delta = fmodf(destAngle - srcAngle, 360.0f);
if (destAngle > srcAngle) {
if (delta >= 180)
delta -= 360;
}
else {
if (delta <= -180)
delta += 360;
}
return delta;
}
struct pp
{
bool lbyUp;
}info;
void AntiAim::LBY(CUserCmd* cmd)
{
info.lbyUp = false;
static float next_lby_update_time = 0;
auto local = g_LocalPlayer;
if (local->m_vecVelocity().Length2D() > 0.1)
next_lby_update_time = g_GlobalVars->curtime + 0.22f;
else if (next_lby_update_time - g_GlobalVars->curtime <= 0.0f) {
next_lby_update_time = g_GlobalVars->curtime + 0.22f;
info.lbyUp = true;
}
}
inline float FastSqrt222(float x)
{
unsigned int i = *(unsigned int*)&x;
i += 127 << 23;
i >>= 1;
return *(float*)&i;
}
#define square( x ) ( x * x )
struct dickk
{
void MinWalk(CUserCmd* get_cmd, float get_speed)
{
if (get_speed <= 0.f)
return;
float min_speed = (float)(FastSqrt222(square(get_cmd->forwardmove) + square(get_cmd->sidemove) + square(get_cmd->upmove)));
if (min_speed <= 0.f)
return;
if (get_cmd->buttons & IN_DUCK)
get_speed *= 2.94117647f;
if (min_speed <= get_speed)
return;
float kys = get_speed / min_speed;
get_cmd->forwardmove *= kys;
get_cmd->sidemove *= kys;
get_cmd->upmove *= kys;
}
}slowwalk;
void doDesync(CUserCmd* cmd, bool& send_packet)
{
static bool inv = false;
if (GetAsyncKeyState(g_Options.inveter_bind) & 1) inv = !inv;
static int side = 1;
if (inv) side = 1; else side = -1;
if (info.lbyUp && g_LocalPlayer->m_vecVelocity().Length2D() < 6.f)
{
cmd->viewangles.yaw -= 120.f * -side;
if (cmd->command_number & 1)
cmd->forwardmove -= (g_LocalPlayer->m_vecViewOffset().z < 64.f ? 4.941177f : 1.01f);
else
cmd->forwardmove += (g_LocalPlayer->m_vecViewOffset().z < 64.f ? 4.941177f : 1.01f);
}
else if (!send_packet)
{
cmd->viewangles.yaw -= 58.f * side;
}
}
void AntiAim::Fakelagg(CUserCmd* cmd, bool& bSendPacket) {
if (g_EngineClient->IsVoiceRecording())
return;
if (!g_LocalPlayer)
return;
int chockepack = 0;
auto NetChannel = g_EngineClient->GetNetChannelInfo();
if (!NetChannel)
return;
bSendPacket = true;
chockepack = 1.f;
bSendPacket = (g_ClientState->m_NetChannel->m_nChokedPackets >= chockepack);
}
void AntiAim::Desync3(CUserCmd* cmd, bool& bSendPacket) {
static bool inv = false;
if (GetAsyncKeyState(g_Options.inveter_bind) & 1) inv = !inv;
static int side = 1;
if (inv) side = 1; else side = -1;
if (info.lbyUp && g_LocalPlayer->m_vecVelocity().Length2D() < 6.f)
{
cmd->viewangles.yaw -= 120.f * -side;
if (cmd->command_number & 1)
cmd->forwardmove -= (g_LocalPlayer->m_vecViewOffset().z < 64.f ? 4.941177f : 1.01f);
else
cmd->forwardmove += (g_LocalPlayer->m_vecViewOffset().z < 64.f ? 4.941177f : 1.01f);
}
else if (!bSendPacket)
{
cmd->viewangles.yaw -= 58.f * side;
}
/*
if (cmd->buttons & IN_USE || cmd->buttons & IN_ATTACK)
return;
if (info.lbyUp && g_LocalPlayer->m_vecVelocity().Length2D() < 6.f)
{
cmd->viewangles.yaw -= 120.f * -side;
if (cmd->command_number & 1)
cmd->forwardmove -= (g_LocalPlayer->m_vecViewOffset().z < 64.f ? 4.941177f : 1.01f);
else
cmd->forwardmove += (g_LocalPlayer->m_vecViewOffset().z < 64.f ? 4.941177f : 1.01f);
}
static QAngle LastRealAngle = QAngle(0, 0, 0);
if (!bSendPacket) {
//if (GetKeyState(VK_XBUTTON1))
if( cmd->viewangles.yaw += 120.f);
else
cmd->viewangles.yaw -= 120.f;
}
else
LastRealAngle = cmd->viewangles;
*/
}
void AntiAim::Doantiaim(CUserCmd* cmd, bool& send_packet)
{
if (!g_LocalPlayer->IsAlive()) return;
if (!g_EngineClient->IsConnected()) return;
if (GetAsyncKeyState(g_Options.slowwalk_key))
{
slowwalk.MinWalk(cmd, g_Options.slowwalk_velocity);
}
if (g_LocalPlayer->m_vecVelocity().Length2D() > 50.f) return;
if (cmd->buttons & (IN_ATTACK | IN_ATTACK2 | IN_USE) ||
g_LocalPlayer->m_nMoveType() == MOVETYPE_LADDER || g_LocalPlayer->m_nMoveType() == MOVETYPE_NOCLIP
|| !g_LocalPlayer->IsAlive())
return;
if (cmd->buttons & (IN_ATTACK | IN_ATTACK2))
{
if (g_LocalPlayer->m_hActiveWeapon()->m_fThrowTime() > 0.f) return;
}
if (!cmd->buttons & IN_ATTACK)
{
QAngle fixfoda;
g_EngineClient->GetViewAngles(&fixfoda);
cmd->viewangles = fixfoda;
}
if (!g_Options.desync_type == 0) return;
QAngle fix = cmd->viewangles;
LBY(cmd);
doDesync(cmd, send_packet);
//MoveFix(cmd);
Math::FixAngles(cmd->viewangles);
//Math::MovementFix(cmd);
Math::MovementFix(cmd, fix, cmd->viewangles);
}