Skip to content

Commit 39c6ec1

Browse files
committed
Release
1 parent a521a6e commit 39c6ec1

2 files changed

Lines changed: 120 additions & 89 deletions

File tree

includes/detect.hpp

Lines changed: 103 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,36 @@
1717
// DisplayFrame — data the main thread renders in the debug overlay
1818
// ─────────────────────────────────────────────────────────────────────────────
1919

20-
struct DisplayFrame {
21-
cv::Mat bgr;
20+
struct DisplayFrame
21+
{
22+
cv::Mat bgr;
2223
std::vector<cv::Point> contour;
23-
int tx_f{0}, ty_f{0};
24-
float dist{0.f};
25-
float strength{0.f};
26-
int move_dx{0}, move_dy{0};
27-
bool has_target{false};
28-
bool triggerbot_fired{false};
24+
int tx_f{0}, ty_f{0};
25+
float dist{0.f};
26+
float strength{0.f};
27+
int move_dx{0}, move_dy{0};
28+
bool has_target{false};
29+
bool triggerbot_fired{false};
2930
};
3031

3132
// ─────────────────────────────────────────────────────────────────────────────
3233
// Contour scoring
3334
// ─────────────────────────────────────────────────────────────────────────────
3435

35-
inline double score_contour(const std::vector<cv::Point>& cnt,
36-
double ref_x, double ref_y,
37-
int min_area, int max_area)
36+
inline double score_contour(const std::vector<cv::Point> &cnt,
37+
double ref_x, double ref_y,
38+
int min_area, int max_area)
3839
{
3940
double area = cv::contourArea(cnt);
40-
if (area < min_area || area > max_area) return 1e18;
41+
if (area < min_area || area > max_area)
42+
return 1e18;
4143
cv::Moments M = cv::moments(cnt);
42-
if (M.m00 == 0.0) return 1e18;
44+
if (M.m00 == 0.0)
45+
return 1e18;
4346
double tx = M.m10 / M.m00;
4447
double ty = M.m01 / M.m00;
4548
double dx = tx - ref_x, dy = ty - ref_y;
46-
return (dx*dx + dy*dy) / (area + 1.0);
49+
return (dx * dx + dy * dy) / (area + 1.0);
4750
}
4851

4952
// ─────────────────────────────────────────────────────────────────────────────
@@ -52,38 +55,47 @@ inline double score_contour(const std::vector<cv::Point>& cnt,
5255

5356
static constexpr int LOST_THRESH = 4;
5457

55-
class AimThread {
58+
class AimThread
59+
{
5660
public:
57-
AimThread(const Config& cfg,
58-
Mouse& mouse,
59-
TripleBuffer<Frame>& frame_buf,
60-
TripleBuffer<DisplayFrame>& disp_buf,
61-
std::atomic<bool>& running,
62-
std::atomic<bool>& enabled,
63-
std::atomic<bool>& debug,
64-
std::atomic<bool>& btn_held,
65-
std::atomic<bool>& triggerbot)
61+
AimThread(const Config &cfg,
62+
Mouse &mouse,
63+
TripleBuffer<Frame> &frame_buf,
64+
TripleBuffer<DisplayFrame> &disp_buf,
65+
std::atomic<bool> &running,
66+
std::atomic<bool> &enabled,
67+
std::atomic<bool> &debug,
68+
std::atomic<bool> &btn_held,
69+
std::atomic<bool> &triggerbot)
6670
: cfg_(cfg), mouse_(mouse),
6771
frame_buf_(frame_buf), disp_buf_(disp_buf),
6872
running_(running), enabled_(enabled), debug_(debug),
6973
btn_held_(btn_held), triggerbot_(triggerbot) {}
7074

7175
void start() { thread_ = std::thread(&AimThread::loop, this); }
72-
void join() { if (thread_.joinable()) thread_.join(); }
76+
void join()
77+
{
78+
if (thread_.joinable())
79+
thread_.join();
80+
}
7381

7482
private:
7583
using clk = std::chrono::steady_clock;
7684

77-
void loop() {
85+
void loop()
86+
{
7887
Frame frame;
7988

80-
while (running_.load(std::memory_order_relaxed)) {
81-
if (!frame_buf_.consume(frame) || !frame.valid) {
89+
while (running_.load(std::memory_order_relaxed))
90+
{
91+
if (!frame_buf_.consume(frame) || !frame.valid)
92+
{
8293
std::this_thread::sleep_for(std::chrono::microseconds(500));
8394
continue;
8495
}
8596

86-
if (!enabled_.load() || !btn_held_.load()) {
97+
if (!enabled_.load() || !btn_held_.load())
98+
{
8799
vel_x_ *= cfg_.smoothness;
88100
vel_y_ *= cfg_.smoothness;
89101
push_display(frame, {}, 0, 0, 0.f, 0.f, 0, 0, false, false);
@@ -102,21 +114,28 @@ class AimThread {
102114
double ref_y = has_history_ ? last_ty_ : fc_y;
103115

104116
double best_score = 1e18;
105-
int best_idx = -1;
106-
for (int i = 0; i < (int)contours.size(); ++i) {
117+
int best_idx = -1;
118+
for (int i = 0; i < (int)contours.size(); ++i)
119+
{
107120
double s = score_contour(contours[i], ref_x, ref_y,
108121
cfg_.min_area, cfg_.max_area);
109-
if (s < best_score) { best_score = s; best_idx = i; }
122+
if (s < best_score)
123+
{
124+
best_score = s;
125+
best_idx = i;
126+
}
110127
}
111128

112-
if (best_idx < 0) {
129+
if (best_idx < 0)
130+
{
113131
vel_x_ *= cfg_.smoothness;
114132
vel_y_ *= cfg_.smoothness;
115133
++lost_frames_;
116-
if (lost_frames_ >= LOST_THRESH) {
134+
if (lost_frames_ >= LOST_THRESH)
135+
{
117136
has_history_ = false;
118137
lost_frames_ = 0;
119-
prev_valid_ = false;
138+
prev_valid_ = false;
120139
}
121140
push_display(frame, {}, 0, 0, 0.f, 0.f, 0, 0, false, false);
122141
continue;
@@ -129,19 +148,24 @@ class AimThread {
129148
double ty_f = M.m01 / M.m00;
130149

131150
// ── Velocity EMA ──────────────────────────────────────────────
132-
if (!prev_valid_) {
133-
prev_tx_ = tx_f; prev_ty_ = ty_f;
151+
if (!prev_valid_)
152+
{
153+
prev_tx_ = tx_f;
154+
prev_ty_ = ty_f;
134155
vel_x_ = vel_y_ = 0.0;
135156
prev_valid_ = true;
136-
} else {
137-
double s = cfg_.smoothness;
157+
}
158+
else
159+
{
160+
double s = cfg_.smoothness;
138161
vel_x_ = s * vel_x_ + (1.0 - s) * (tx_f - prev_tx_);
139162
vel_y_ = s * vel_y_ + (1.0 - s) * (ty_f - prev_ty_);
140-
prev_tx_ = tx_f; prev_ty_ = ty_f;
163+
prev_tx_ = tx_f;
164+
prev_ty_ = ty_f;
141165
}
142166

143-
last_tx_ = tx_f;
144-
last_ty_ = ty_f;
167+
last_tx_ = tx_f;
168+
last_ty_ = ty_f;
145169
has_history_ = true;
146170

147171
// ── Lead prediction ───────────────────────────────────────────
@@ -150,7 +174,7 @@ class AimThread {
150174

151175
double raw_dx = pred_x - fc_x;
152176
double raw_dy = pred_y - fc_y;
153-
double dist = std::hypot(raw_dx, raw_dy);
177+
double dist = std::hypot(raw_dx, raw_dy);
154178

155179
// ── Triggerbot ────────────────────────────────────────────────
156180
// Fires a click when the crosshair is within trigger_dist pixels
@@ -159,26 +183,30 @@ class AimThread {
159183
// Triggerbot is independent of aim movement — it still fires even
160184
// if dist < 0.5 (already on target, no mouse move needed).
161185
bool tb_fired = false;
162-
if (triggerbot_.load() && dist <= cfg_.trigger_dist) {
186+
if (triggerbot_.load() && dist <= cfg_.trigger_dist)
187+
{
163188
auto now = clk::now();
164189
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
165-
now - last_click_).count();
166-
if (elapsed >= cfg_.trigger_delay) {
190+
now - last_click_)
191+
.count();
192+
if (elapsed >= cfg_.trigger_delay)
193+
{
167194
mouse_.left_click();
168195
last_click_ = now;
169196
tb_fired = true;
170197
}
171198
}
172199

173-
if (dist < 0.5) {
200+
if (dist < 0.5)
201+
{
174202
push_display(frame, contours[best_idx],
175203
(int)tx_f, (int)ty_f, (float)dist, 0.f,
176204
0, 0, true, tb_fired);
177205
continue;
178206
}
179207

180208
// ── Strength lerp ─────────────────────────────────────────────
181-
double t = std::min(dist / std::max(cfg_.fov, 1), 1.0);
209+
double t = std::min(dist / std::max(cfg_.fov, 1), 1.0);
182210
double strength = cfg_.min_strength +
183211
t * (cfg_.max_strength - cfg_.min_strength);
184212

@@ -196,49 +224,50 @@ class AimThread {
196224
}
197225
}
198226

199-
void push_display(const Frame& frame,
200-
const std::vector<cv::Point>& cnt,
227+
void push_display(const Frame &frame,
228+
const std::vector<cv::Point> &cnt,
201229
int tx, int ty,
202230
float dist, float strength,
203231
int dx, int dy,
204232
bool has_target, bool triggerbot_fired)
205233
{
206-
if (!debug_.load()) return;
207-
DisplayFrame& slot = disp_buf_.write_slot();
208-
slot.bgr = frame.bgr.clone();
209-
slot.contour = cnt;
210-
slot.tx_f = tx;
211-
slot.ty_f = ty;
212-
slot.dist = dist;
213-
slot.strength = strength;
214-
slot.move_dx = dx;
215-
slot.move_dy = dy;
216-
slot.has_target = has_target;
234+
if (!debug_.load())
235+
return;
236+
DisplayFrame &slot = disp_buf_.write_slot();
237+
slot.bgr = frame.bgr.clone();
238+
slot.contour = cnt;
239+
slot.tx_f = tx;
240+
slot.ty_f = ty;
241+
slot.dist = dist;
242+
slot.strength = strength;
243+
slot.move_dx = dx;
244+
slot.move_dy = dy;
245+
slot.has_target = has_target;
217246
slot.triggerbot_fired = triggerbot_fired;
218247
disp_buf_.publish();
219248
}
220249

221250
// ── Config + external refs ────────────────────────────────────────────
222-
const Config& cfg_;
223-
Mouse& mouse_;
224-
TripleBuffer<Frame>& frame_buf_;
225-
TripleBuffer<DisplayFrame>& disp_buf_;
226-
std::atomic<bool>& running_;
227-
std::atomic<bool>& enabled_;
228-
std::atomic<bool>& debug_;
229-
std::atomic<bool>& btn_held_;
230-
std::atomic<bool>& triggerbot_;
231-
std::thread thread_;
251+
const Config &cfg_;
252+
Mouse &mouse_;
253+
TripleBuffer<Frame> &frame_buf_;
254+
TripleBuffer<DisplayFrame> &disp_buf_;
255+
std::atomic<bool> &running_;
256+
std::atomic<bool> &enabled_;
257+
std::atomic<bool> &debug_;
258+
std::atomic<bool> &btn_held_;
259+
std::atomic<bool> &triggerbot_;
260+
std::thread thread_;
232261

233262
// ── Velocity state ────────────────────────────────────────────────────
234-
bool prev_valid_{false};
263+
bool prev_valid_{false};
235264
double prev_tx_{0}, prev_ty_{0};
236265
double vel_x_{0}, vel_y_{0};
237266

238267
// ── Multi-target tracking state ───────────────────────────────────────
239-
bool has_history_{false};
268+
bool has_history_{false};
240269
double last_tx_{0}, last_ty_{0};
241-
int lost_frames_{0};
270+
int lost_frames_{0};
242271

243272
// ── Triggerbot cooldown ───────────────────────────────────────────────
244273
clk::time_point last_click_{clk::now()};

includes/mouse.hpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class Mouse
4545
// Fix: run aimbot as Administrator.
4646
{
4747
INPUT probe{};
48-
probe.type = INPUT_MOUSE;
48+
probe.type = INPUT_MOUSE;
4949
probe.mi.dwFlags = MOUSEEVENTF_MOVE;
50-
probe.mi.dx = 0;
51-
probe.mi.dy = 0;
50+
probe.mi.dx = 0;
51+
probe.mi.dy = 0;
5252
if (SendInput(1, &probe, sizeof(INPUT)) == 0)
5353
{
5454
std::cerr << "[mouse] WARNING: SendInput returned 0 (err="
@@ -77,7 +77,7 @@ class Mouse
7777

7878
uinput_setup us{};
7979
us.id.bustype = BUS_USB;
80-
us.id.vendor = 0x1234;
80+
us.id.vendor = 0x1234;
8181
us.id.product = 0x5678;
8282
std::strncpy(us.name, "aimbot-mouse", UINPUT_MAX_NAME_SIZE);
8383
if (ioctl(fd_, UI_DEV_SETUP, &us) < 0)
@@ -107,14 +107,16 @@ class Mouse
107107

108108
#if defined(_WIN32)
109109
INPUT inp{};
110-
inp.type = INPUT_MOUSE;
110+
inp.type = INPUT_MOUSE;
111111
inp.mi.dwFlags = MOUSEEVENTF_MOVE;
112-
inp.mi.dx = static_cast<LONG>(ix);
113-
inp.mi.dy = static_cast<LONG>(iy);
112+
inp.mi.dx = static_cast<LONG>(ix);
113+
inp.mi.dy = static_cast<LONG>(iy);
114114
SendInput(1, &inp, sizeof(INPUT));
115115
#else
116-
if (ix != 0) emit(EV_REL, REL_X, ix);
117-
if (iy != 0) emit(EV_REL, REL_Y, iy);
116+
if (ix != 0)
117+
emit(EV_REL, REL_X, ix);
118+
if (iy != 0)
119+
emit(EV_REL, REL_Y, iy);
118120
sync();
119121
#endif
120122
}
@@ -128,12 +130,12 @@ class Mouse
128130
if (btn == 0)
129131
{
130132
down_flag = MOUSEEVENTF_LEFTDOWN;
131-
up_flag = MOUSEEVENTF_LEFTUP;
133+
up_flag = MOUSEEVENTF_LEFTUP;
132134
}
133135
else
134136
{
135137
down_flag = MOUSEEVENTF_RIGHTDOWN;
136-
up_flag = MOUSEEVENTF_RIGHTUP;
138+
up_flag = MOUSEEVENTF_RIGHTUP;
137139
}
138140
send_click_win(down_flag);
139141
std::this_thread::sleep_for(std::chrono::milliseconds(50));
@@ -148,7 +150,7 @@ class Mouse
148150
#endif
149151
}
150152

151-
void left_click() { click(0); }
153+
void left_click() { click(0); }
152154
void right_click() { click(1); }
153155

154156
// ── Cleanup ───────────────────────────────────────────────────────────────
@@ -175,7 +177,7 @@ class Mouse
175177
void send_click_win(DWORD flag)
176178
{
177179
INPUT inp{};
178-
inp.type = INPUT_MOUSE;
180+
inp.type = INPUT_MOUSE;
179181
inp.mi.dwFlags = flag;
180182
SendInput(1, &inp, sizeof(INPUT));
181183
}
@@ -185,8 +187,8 @@ class Mouse
185187
void emit(uint16_t type, uint16_t code, int32_t value)
186188
{
187189
input_event ev{};
188-
ev.type = type;
189-
ev.code = code;
190+
ev.type = type;
191+
ev.code = code;
190192
ev.value = value;
191193
write(fd_, &ev, sizeof(ev));
192194
}

0 commit comments

Comments
 (0)