44#include < thread>
55#include < Windows.h>
66
7- namespace features {
7+ namespace features
8+ {
89 void TriggerBot::Run (const Memory& memory) noexcept {
9- while (globals::isRunning) {
10- if (!globals::TriggerBot) {
10+ while (globals::isRunning)
11+ {
12+ if (!globals::TriggerBot)
13+ {
1114 std::this_thread::sleep_for (std::chrono::milliseconds (20 ));
1215 continue ;
1316 }
1417
15- bool keyState = GetAsyncKeyState (globals::TriggerBotKey) & 0x8000 ;
16-
17- if (globals::TriggerBotMode == 0 ) {
18- if (!keyState) {
18+ bool keyDown = (GetAsyncKeyState (globals::TriggerBotKey) & 0x8000 ) != 0 ;
19+ if (globals::TriggerBotMode == 0 )
20+ {
21+ if (!keyDown)
22+ {
1923 std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
2024 continue ;
2125 }
2226 }
23- else if (globals::TriggerBotMode == 1 ) {
24- if (keyState) {
27+ else if (globals::TriggerBotMode == 1 )
28+ {
29+ if (keyDown)
30+ {
2531 globals::TriggerBotToggled = !globals::TriggerBotToggled;
2632 std::this_thread::sleep_for (std::chrono::milliseconds (200 ));
2733 }
2834
29- if (!globals::TriggerBotToggled) {
35+ if (!globals::TriggerBotToggled)
36+ {
3037 std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
3138 continue ;
3239 }
@@ -35,7 +42,8 @@ namespace features {
3542 std::uintptr_t localPlayer = memory.Read <std::uintptr_t >(globals::client + offsets::dwLocalPlayerPawn);
3643 BYTE team = memory.Read <BYTE>(localPlayer + offsets::m_iTeamNum);
3744
38- if (!globals::TriggerBotIgnoreFlash) {
45+ if (!globals::TriggerBotIgnoreFlash)
46+ {
3947 float flashDuration = memory.Read <float >(localPlayer + offsets::flFlashDuration);
4048 if (flashDuration > 0 .0f ) {
4149 std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
@@ -44,32 +52,25 @@ namespace features {
4452 }
4553
4654 int crosshairEntityIndex = memory.Read <int >(localPlayer + offsets::m_iIDEntIndex);
47- if (crosshairEntityIndex == 0 ) {
55+ if (crosshairEntityIndex == 0 )
4856 continue ;
49- }
5057
5158 std::uintptr_t entityList = memory.Read <std::uintptr_t >(globals::client + offsets::dwEntityList);
52- std::uintptr_t listEntry = memory.Read <std::uintptr_t >(entityList + 0x8 * (crosshairEntityIndex >> 9 ) + 0x10 );
53- std::uintptr_t entity = memory.Read <std::uintptr_t >(listEntry + 120 * (crosshairEntityIndex & 0x1ff ));
54-
55- if (!entity) {
59+ std::uintptr_t entity = memory.Read <std::uintptr_t >(memory.Read <std::uintptr_t >(entityList + 0x8 * (crosshairEntityIndex >> 9 ) + 0x10 ) + 120 * (crosshairEntityIndex & 0x1ff ));
60+ if (!entity)
5661 continue ;
57- }
5862
59- if (globals::TriggerBotTeamCheck && team == memory.Read <BYTE>(entity + offsets::m_iTeamNum)) {
63+ // Skip teammate or dead target (optional)
64+ if (globals::TriggerBotTeamCheck && team == memory.Read <BYTE>(entity + offsets::m_iTeamNum))
6065 continue ;
61- }
6266
63- if (memory.Read <int >(entity + offsets::m_iHealth) <= 0 ) {
67+ if (memory.Read <int >(entity + offsets::m_iHealth) <= 0 )
6468 continue ;
65- }
66-
67- memory.Write <int >(globals::client + offsets::attack, 65537 );
6869
70+ // Simulate shooting
71+ memory.Write <int >(globals::client + offsets::attack, 65537 ); // Set attack command
6972 std::this_thread::sleep_for (std::chrono::milliseconds (globals::TriggerBotDelay));
70-
71- memory.Write <int >(globals::client + offsets::attack, 256 );
72-
73+ memory.Write <int >(globals::client + offsets::attack, 256 ); // Clear attack command
7374 std::this_thread::sleep_for (std::chrono::milliseconds (globals::TriggerBotDelay));
7475 }
7576 }
0 commit comments