/
Aimbot.cpp
76 lines (67 loc) · 3.12 KB
/
Aimbot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define _USE_MATH_DEFINES
#include <cmath>
#include "Aimbot.h"
#include "../Config.h"
#include "../Interfaces.h"
#include "../SDK/Entity.h"
#include "../SDK/UserCmd.h"
#include "../SDK/Vector.h"
#include "../SDK/WeaponId.h"
static constexpr int getBoneId(int weaponIndex) noexcept
{
return 8 - config.aimbot.weapons[weaponIndex].bone;
}
static Vector calculateRelativeAngle(const Vector& source, const Vector& destination, const Vector& viewAngles) noexcept
{
Vector delta = destination - source;
constexpr auto radiansToDegrees = [](float radians) noexcept { return radians * 180 / static_cast<float>(M_PI); };
Vector angles{ radiansToDegrees(atan2f(-delta.z, std::hypotf(delta.x, delta.y))) - viewAngles.x,
radiansToDegrees(atan2f(delta.y, delta.x)) - viewAngles.y };
angles.normalize();
return angles;
}
static int findTarget(UserCmd* cmd, int weaponIndex) noexcept
{
auto bestFov = config.aimbot.weapons[weaponIndex].fov;
auto bestTarget = 0;
auto localPlayer = interfaces.entityList->getEntity(interfaces.engine->getLocalPlayer());
auto localPlayerEyeOrigin = localPlayer->getEyeOrigin();
for (int i = 1; i <= interfaces.engine->getMaxClients(); i++) {
auto entity = interfaces.entityList->getEntity(i);
if (!entity || entity == localPlayer || entity->isDormant() || !entity->isAlive() || !entity->isEnemy() || entity->isImmune())
continue;
auto angle = calculateRelativeAngle(localPlayerEyeOrigin, entity->getBonePosition(getBoneId(weaponIndex)), cmd->viewangles);
auto fov = std::hypotf(angle.x, angle.y);
if (fov < bestFov) {
bestFov = fov;
bestTarget = i;
}
}
return bestTarget;
}
void Aimbot::run(UserCmd* cmd)
{
const auto activeWeapon = interfaces.entityList->getEntityFromHandle(interfaces.entityList->getEntity(interfaces.engine->getLocalPlayer())->getActiveWeaponHandle());
if (!activeWeapon)
return;
auto weaponIndex = getWeaponIndex(activeWeapon->getItemDefinitionIndex());
if (!weaponIndex)
return;
if (!config.aimbot.weapons[weaponIndex].enabled)
weaponIndex = 0;
if (config.aimbot.weapons[weaponIndex].enabled && cmd->buttons & 1) {
const auto activeWeapon = interfaces.entityList->getEntityFromHandle(
interfaces.entityList->getEntity(
interfaces.engine->getLocalPlayer())->getActiveWeaponHandle())->getItemDefinitionIndex();
if (auto target = findTarget(cmd, weaponIndex)) {
auto entity = interfaces.entityList->getEntity(target);
auto localPlayer = interfaces.entityList->getEntity(interfaces.engine->getLocalPlayer());
auto angle = calculateRelativeAngle(localPlayer->getEyeOrigin(), entity->getBonePosition(getBoneId(weaponIndex)), cmd->viewangles);
auto distance = std::hypotf(angle.x, angle.y);
angle /= config.aimbot.weapons[weaponIndex].smooth;
cmd->viewangles += angle;
if (!config.aimbot.weapons[weaponIndex].silent || distance > 1.0f)
interfaces.engine->setViewAngles(cmd->viewangles);
}
}
}