Skip to content

Commit 68645e3

Browse files
Add files via upload
1 parent fc1e2cb commit 68645e3

4 files changed

Lines changed: 153 additions & 44 deletions

File tree

ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,46 @@
11
#include "Utils.h"
22
#include "Arduino.h"
3-
int sensitivity;
4-
53
Weapon weapon = OFF;
6-
Weapon weaponState(Weapon weapon)
7-
{
8-
if (GetAsyncKeyState(VK_F12) & 1) return OFF;
9-
10-
if (GetAsyncKeyState(VK_F1) & 1) return UMP;
11-
if (GetAsyncKeyState(VK_F2) & 1) return M4A1;
12-
if (GetAsyncKeyState(VK_F3) & 1) return M4A4;
13-
if (GetAsyncKeyState(VK_F4) & 1) return AK47;
14-
if (GetAsyncKeyState(VK_F5) & 1) return GALIL;
15-
if (GetAsyncKeyState(VK_F6) & 1) return FAMAS;
16-
17-
return weapon;
18-
}
194

205
int main()
216
{
7+
string text;
228
Utils::Install();
23-
Arduino arduino("Arduino Leonardo");
249

25-
char input[10];
26-
do
27-
{
28-
printf("Enter sensitivity -> ");
29-
fgets(input, sizeof(input), stdin);
30-
}
31-
while (sscanf_s(input, "%d", &sensitivity) != 1 || sensitivity < 1 || sensitivity > 8);
10+
Config config;
11+
Utils::LoadConfig(config);
3212

33-
string text =
34-
R"(__ __ _ _ )" "\n"
35-
R"(\ \ / /__ _ _| |_(_)_ _ __ _ )" "\n"
36-
R"( \ \/\/ / _ \ '_| / / | ' \/ _` | )" "\n"
37-
R"( \_/\_/\___/_| |_\_\_|_||_\__, | )" "\n"
38-
R"( |___/ )" "\n"
39-
R"( )" "\n"
40-
R"( CTRL + C to stop the program )" "\n";
13+
text = R"(
14+
___ _ _
15+
/ __|___ _ _ _ _ ___ __| |_(_)_ _ __ _
16+
| (__/ _ \ ' \| ' \/ -_) _| _| | ' \/ _` |_ _ _
17+
\___\___/_||_|_||_\___\__|\__|_|_||_\__, (_|_|_)
18+
|___/ )";
4119

4220
Utils::PrintAscii(text);
43-
Utils::PrintHotkeys("[F1] - OFF | [F1] - UMP | [F2] - M4A1 | [F3] - M4A4 | [F4] - AK47 | [F5] - GALIL | [F6] - FAMAS");
21+
22+
Arduino arduino("Arduino Leonardo");
23+
24+
text = R"(
25+
__ __ _ _
26+
\ \ / /__ _ _| |_(_)_ _ __ _
27+
\ \/\/ / _ \ '_| / / | ' \/ _` |
28+
\_/\_/\___/_| |_\_\_|_||_\__, |
29+
|___/
30+
31+
CTRL + C to stop the program )";
32+
33+
Utils::PrintAscii(text);
34+
Utils::PrintHotkeys("[F12] - OFF | [F1] - UMP | [F2] - M4A1 | [F3] - M4A4 | [F4] - AK47 | [F5] - GALIL | [F6] - FAMAS");
4435

4536
while (true)
4637
{
47-
weapon = weaponState(weapon);
38+
weapon = Utils::weaponState(weapon);
4839
string message = arduino.readStringUntil('\n');
4940

5041
if (message.rfind("ARDUINO_INITIATED", 0) != 0)
5142
{
52-
double modifier = 2.52 / sensitivity;
43+
double modifier = 2.52 / config.sensitivity;
5344

5445
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
5546
{
@@ -95,20 +86,29 @@ int main()
9586
break;
9687
}
9788

98-
for (size_t i = 0; i < x.size(); ++i)
89+
for (size_t i = 0; i < x.size(); i++)
9990
{
10091
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
10192
{
102-
arduino.send_data("MOUSE_LEFT_HOLDED:" + to_string(x[i]) + "," + to_string(y[i]) + "," + to_string(delay[i]));
103-
sleep_for(milliseconds(delay[i]));
93+
future<int> future = async(launch::async, [&]()
94+
{
95+
Sleep(delay[i]);
96+
return GetAsyncKeyState(VK_LBUTTON) & 0x8000;
97+
});
98+
99+
if (future.get())
100+
{
101+
arduino.send_data("MOUSE_LEFT_HOLDED:" + to_string(x[i]) + "," + to_string(y[i]) + "," + to_string(delay[i]));
102+
}
104103
}
105104
}
105+
106106
}
107-
if (GetAsyncKeyState(VK_SPACE) & 0x8000)
107+
if (GetAsyncKeyState(VK_SPACE) & 0x8000 && config.bhop != 0)
108108
{
109109
arduino.send_data("SPACE_BUTTON_HOLDED");
110110
}
111-
if (GetAsyncKeyState(VK_MBUTTON) & 0x8000)
111+
if (GetAsyncKeyState(VK_MBUTTON) & 0x8000 && config.rapid_fire != 0)
112112
{
113113
arduino.send_data("MOUSE_MIDDLE_HOLDED");
114114
}

ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Keyword>Win32Proj</Keyword>
1616
<ProjectGuid>{827797fa-80de-495f-b3b6-e4cc2be7e444}</ProjectGuid>
1717
<RootNamespace>hwtbcpp</RootNamespace>
18-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
18+
<WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
1919
</PropertyGroup>
2020
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2121
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

ArduinoStrike/ArduinoStrike/Utils.cpp

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,94 @@ void Utils::Install()
4040
SetConsoleMode(random);
4141
}
4242

43+
bool Utils::validateConfig(Config &config)
44+
{
45+
return ((config.bhop == 0 || config.bhop == 1) && (config.rapid_fire == 0 || config.rapid_fire == 1) && (config.sensitivity >= 1 && config.sensitivity <= 8)) ? true : false;
46+
}
47+
48+
void Utils::LoadConfig(Config &config)
49+
{
50+
string input;
51+
ifstream file("Settings.cfg");
52+
53+
if (!file.is_open())
54+
{
55+
do
56+
{
57+
cout << "Enter bhop boolean value (1/0) -> ";
58+
getline(cin, input);
59+
istringstream iss(input);
60+
if (!(iss >> config.bhop) || (config.bhop != 0 && config.bhop != 1))
61+
{
62+
config.bhop = -1;
63+
cout << "Invalid input! Please enter 1 or 0." << endl << endl;
64+
}
65+
}
66+
while (config.bhop != 0 && config.bhop != 1);
67+
68+
do
69+
{
70+
cout << "Enter rapid-fire boolean value (1/0) -> ";
71+
getline(cin, input);
72+
istringstream iss(input);
73+
if (!(iss >> config.rapid_fire) || (config.rapid_fire != 0 && config.rapid_fire != 1))
74+
{
75+
config.rapid_fire = -1;
76+
cout << "Invalid input! Please enter 1 or 0." << endl << endl;
77+
}
78+
}
79+
while (config.rapid_fire != 0 && config.rapid_fire != 1);
80+
81+
do
82+
{
83+
cout << "Enter sensitivity integer value (1-8) -> ";
84+
getline(cin, input);
85+
istringstream iss(input);
86+
if (!(iss >> config.sensitivity) || config.sensitivity < 1 || config.sensitivity > 8)
87+
{
88+
config.sensitivity = -1;
89+
cout << "Invalid input! Please enter an integer between 1 and 8." << endl << endl;
90+
}
91+
}
92+
while (config.sensitivity < 1 || config.sensitivity > 8);
93+
94+
ofstream out("Settings.cfg");
95+
out << config.bhop << endl << config.rapid_fire << endl << config.sensitivity;
96+
out.close();
97+
98+
cout << "Configuration successfully saved!" << endl;
99+
}
100+
else
101+
{
102+
file >> config.bhop;
103+
file >> config.rapid_fire;
104+
file >> config.sensitivity;
105+
file.close();
106+
107+
if (!validateConfig(config))
108+
{
109+
cerr << "Invalid values in config file. Please enter valid values!" << endl;
110+
remove("Settings.cfg");
111+
exit(1);
112+
}
113+
114+
cout << "Configuration successfully loaded!" << endl;
115+
}
116+
}
117+
43118
void Utils::PrintHotkeys(const string &hotkeys)
44119
{
45120
CONSOLE_SCREEN_BUFFER_INFO csbi;
46121
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
47122
int width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
48-
49123
int padding = (width - hotkeys.size()) / 2;
50124

51125
COORD coord;
52126
coord.X = 0;
53127
coord.Y = csbi.srWindow.Bottom;
54128
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
55129

56-
for (int i = 0; i < padding; ++i)
130+
for (int i = 0; i < padding; i++)
57131
{
58132
printf(" ");
59133
}
@@ -80,7 +154,7 @@ void Utils::PrintAscii(const string &asciiArt)
80154

81155
SHORT startY = static_cast<SHORT>(height - lines.size()) / 2;
82156

83-
for (SHORT i = 0; i < static_cast<SHORT>(lines.size()); ++i)
157+
for (SHORT i = 0; i < static_cast<SHORT>(lines.size()); i++)
84158
{
85159
const string &line = lines[i];
86160

@@ -149,4 +223,18 @@ void Utils::SetConsoleMode(const string &title)
149223
SetConsoleScreenBufferSize(console, size);
150224
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
151225
SetConsoleTitleA(title.c_str());
226+
}
227+
228+
Weapon Utils::weaponState(Weapon weapon)
229+
{
230+
if (GetAsyncKeyState(VK_F12) & 1) return OFF;
231+
232+
if (GetAsyncKeyState(VK_F1) & 1) return UMP;
233+
if (GetAsyncKeyState(VK_F2) & 1) return M4A1;
234+
if (GetAsyncKeyState(VK_F3) & 1) return M4A4;
235+
if (GetAsyncKeyState(VK_F4) & 1) return AK47;
236+
if (GetAsyncKeyState(VK_F5) & 1) return GALIL;
237+
if (GetAsyncKeyState(VK_F6) & 1) return FAMAS;
238+
239+
return weapon;
152240
}

ArduinoStrike/ArduinoStrike/Utils.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,43 @@
44
#include <filesystem>
55
#include <thread>
66
#include <sstream>
7+
#include <fstream>
8+
#include <future>
79

810
using namespace std;
911
namespace fs = experimental::filesystem;
1012
using namespace fs;
1113
using namespace chrono;
1214
using namespace this_thread;
1315

14-
enum Weapon { OFF, UMP, M4A1, M4A4, AK47, GALIL, FAMAS };
16+
enum Weapon
17+
{
18+
OFF,
19+
UMP,
20+
M4A1,
21+
M4A4,
22+
AK47,
23+
GALIL,
24+
FAMAS
25+
};
26+
27+
struct Config
28+
{
29+
int bhop;
30+
int rapid_fire;
31+
int sensitivity;
32+
};
1533

1634
class Utils
1735
{
1836
public:
1937
static void Install();
38+
static bool validateConfig(Config & config);
39+
static void LoadConfig(Config & config);
2040
static void ConsoleClear();
2141
static void PrintHotkeys(const string &hotkeys);
2242
static void PrintAscii(const string &asciiArt);
43+
static Weapon weaponState(Weapon weapon);
2344

2445
private:
2546
static string randomData(int length);

0 commit comments

Comments
 (0)