-
Notifications
You must be signed in to change notification settings - Fork 1
/
aim.cpp
128 lines (115 loc) · 2.66 KB
/
aim.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "aim.h"
#include "sdk.h"
#include "settings.h"
#include "Menu.h"
#include "input.h"
namespace aim_assist
{
vec2_t lock_position = vec2_t{};
float init_center_dist = 10000.0f;
float min_center_dist = init_center_dist;
float init_distance = 10000.0f;
float min_distance = init_distance;
void reset_lock()
{
min_center_dist = init_center_dist;
min_distance = init_distance;
}
bool is_key_down(int vk_key)
{
return ((GetAsyncKeyState(vk_key) & 0x8000) ? 1 : 0);
}
unsigned long get_bone_opt()
{
switch (Settings::aimbot::i_bone)
{
case 0:
return sdk::BONE_POS_MID;
case 1:
return sdk::BONE_POS_HEAD;
case 2:
return sdk::BONE_POS_NECK;
case 3:
return sdk::BONE_POS_CHEST;
};
return sdk::BONE_POS_HEAD;
}
void get_closest_enemy(vec2_t target_pos, float distance)
{
if (distance < min_distance)
{
min_distance = distance;
lock_position = target_pos;
}
}
void get_enemy_in_fov(vec2_t target_pos)
{
const float x = target_pos.x - (g_data::refdef->Width / 2);
const float y = target_pos.y - (g_data::refdef->Height / 2);
float center_dis = sqrt(pow(y, 2) + pow(x, 2));
if (center_dis < min_center_dist && center_dis < Settings::esp::fov_size)
{
min_center_dist = center_dis;
lock_position = target_pos;
}
}
void aim_at()
{
vec2_t target(0, 0);
vec2_t center(g_data::refdef->Width / 2, g_data::refdef->Height / 2);
if (min_center_dist != init_center_dist || min_distance != init_distance)
{
if (lock_position.x != 0)
{
if (lock_position.x > center.x)
{
target.x = -(center.x - lock_position.x);
target.x /= Settings::aimbot::f_speed;
if (target.x + center.x > center.x * 2)
target.x = 0;
}
if (lock_position.x < center.x)
{
target.x = lock_position.x - center.x;
target.x /= Settings::aimbot::f_speed;
if (target.x + center.x < 0)
target.x = 0;
}
}
if (lock_position.y != 0)
{
if (lock_position.y > center.y)
{
target.y = -(center.y - lock_position.y);
target.y /= Settings::aimbot::f_speed;
if (target.y + center.y > center.y * 2)
target.y = 0;
}
if (lock_position.y < center.y)
{
target.y = lock_position.y - center.y;
target.y /= Settings::aimbot::f_speed;
if (target.y + center.y < 0)
target.y = 0;
}
}
if (Settings::aimbot::b_smooth)
{
target.x /= 2.0f;
target.y /= 2.0f;
}
if (!target.is_Zero()) {
mouse_event(MOUSEEVENTF_MOVE, static_cast<DWORD>(target.x), static_cast<DWORD>(target.y), NULL, NULL);
}
}
}
void is_aiming()
{
if (keyPressed)
{
globals::is_aiming = true;
aim_at();
}
globals::is_aiming = false;
}
}