Skip to content

Commit afc5d4f

Browse files
Add files via upload
1 parent f41b61d commit afc5d4f

File tree

12 files changed

+154
-68
lines changed

12 files changed

+154
-68
lines changed

ArduinoStrike/ArduinoStrike/Arduino.cpp

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,45 @@ Arduino::Arduino(LPCSTR device_name) : m_arduinoHandle(INVALID_HANDLE_VALUE)
1212
{
1313
char port[100] = "\\.\\";
1414

15-
while (!this->GetDevice(device_name, port))
15+
while (!GetDevice(device_name, port))
1616
{
1717
sleep_for(milliseconds(1000));
1818
}
1919

20-
m_arduinoHandle = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
21-
22-
if (m_arduinoHandle == INVALID_HANDLE_VALUE)
20+
this->m_arduinoHandle = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
21+
if (this->m_arduinoHandle)
2322
{
24-
cerr << "Error opening port: " << GetLastError() << endl;
25-
return;
26-
}
27-
28-
DCB dcb = {};
29-
dcb.DCBlength = sizeof(dcb);
30-
31-
if (!GetCommState(m_arduinoHandle, &dcb))
32-
return;
33-
34-
dcb.BaudRate = CBR_9600;
35-
dcb.ByteSize = 8;
36-
dcb.StopBits = ONESTOPBIT;
37-
dcb.Parity = NOPARITY;
38-
39-
if (!SetCommState(m_arduinoHandle, &dcb))
40-
return;
41-
42-
COMMTIMEOUTS cto = {};
43-
cto.ReadIntervalTimeout = 50;
44-
cto.ReadTotalTimeoutConstant = 50;
45-
cto.ReadTotalTimeoutMultiplier = 10;
46-
cto.WriteTotalTimeoutConstant = 50;
47-
cto.WriteTotalTimeoutMultiplier = 10;
23+
DCB dcb = { 0 };
24+
dcb.DCBlength = sizeof(dcb);
25+
if (!GetCommState(this->m_arduinoHandle, &dcb))
26+
{
27+
printf("GetCommState() failed\n");
28+
CloseHandle(this->m_arduinoHandle);
29+
}
4830

49-
if (!SetCommTimeouts(m_arduinoHandle, &cto))
50-
return;
31+
dcb.BaudRate = CBR_9600;
32+
dcb.ByteSize = 8;
33+
dcb.StopBits = ONESTOPBIT;
34+
dcb.Parity = NOPARITY;
35+
if (!SetCommState(this->m_arduinoHandle, &dcb))
36+
{
37+
printf("SetCommState() failed\n");
38+
CloseHandle(this->m_arduinoHandle);
39+
}
5140

52-
cout << "Successfully connected!" << endl;
41+
COMMTIMEOUTS cto = { 0 };
42+
cto.ReadIntervalTimeout = 50;
43+
cto.ReadTotalTimeoutConstant = 50;
44+
cto.ReadTotalTimeoutMultiplier = 10;
45+
cto.WriteTotalTimeoutConstant = 50;
46+
cto.WriteTotalTimeoutMultiplier = 10;
47+
if (!SetCommTimeouts(this->m_arduinoHandle, &cto))
48+
{
49+
printf("SetCommTimeouts() failed\n");
50+
CloseHandle(this->m_arduinoHandle);
51+
}
52+
cout << "Successfully connected!" << endl;
53+
}
5354
}
5455

5556
bool Arduino::IsAvailable() const
@@ -68,41 +69,42 @@ bool Arduino::IsAvailable() const
6869

6970
bool Arduino::GetDevice(LPCSTR friendly_name, LPSTR com_port)
7071
{
71-
const char com[] = "COM";
72-
HDEVINFO device_info = SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS, nullptr, nullptr, DIGCF_PRESENT);
72+
char com[] = "COM";
73+
bool status = false;
7374

74-
if (device_info == INVALID_HANDLE_VALUE)
75-
return false;
75+
HDEVINFO device_info = SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS, NULL, NULL, DIGCF_PRESENT);
76+
if (device_info == INVALID_HANDLE_VALUE) return false;
7677

77-
SP_DEVINFO_DATA dev_info_data = {};
78+
SP_DEVINFO_DATA dev_info_data;
7879
dev_info_data.cbSize = sizeof(dev_info_data);
7980

80-
DWORD device_count = 0;
81+
DWORD count = 0;
8182

82-
while (SetupDiEnumDeviceInfo(device_info, device_count++, &dev_info_data))
83+
while (SetupDiEnumDeviceInfo(device_info, count++, &dev_info_data))
8384
{
84-
BYTE buff[256] = { 0 };
85-
86-
if (SetupDiGetDeviceRegistryProperty(device_info, &dev_info_data, SPDRP_FRIENDLYNAME, nullptr, buff, sizeof(buff), nullptr))
85+
BYTE buffer[256];
86+
if (SetupDiGetDeviceRegistryProperty(device_info, &dev_info_data, SPDRP_FRIENDLYNAME, NULL, buffer, sizeof(buffer), NULL))
8787
{
88-
LPCSTR port_name_pos = strstr(reinterpret_cast<LPCSTR>(buff), com);
88+
DWORD i = strlen(com_port);
89+
LPCSTR lp_pos = strstr((LPCSTR)buffer, com);
90+
DWORD len = i + (lp_pos ? strlen(lp_pos) : 0);
8991

90-
if (port_name_pos == nullptr)
91-
continue;
92-
93-
if (strstr(reinterpret_cast<LPCSTR>(buff), friendly_name))
92+
if (strstr((LPCSTR)buffer, friendly_name) && lp_pos)
9493
{
95-
strncpy_s(com_port, 100, port_name_pos, strlen(port_name_pos) - 1);
96-
com_port[strlen(port_name_pos) - 1] = '\0';
97-
SetupDiDestroyDeviceInfoList(device_info);
98-
99-
return true;
94+
for (DWORD j = 0; i < len; i++, j++)
95+
{
96+
com_port[i] = lp_pos[j];
97+
}
98+
99+
com_port[i - 1] = '\0';
100+
status = true;
101+
break;
100102
}
101103
}
102104
}
103105

104106
SetupDiDestroyDeviceInfoList(device_info);
105-
return false;
107+
return status;
106108
}
107109

108110
bool Arduino::WriteMessage(const string& message) const

ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#include "Weapons.h"
55
#include "AsciiArt.h"
66
#include "ColorBot.h"
7+
#include "FastReload.h"
78

89
Weapon weapon = OFF;
910

10-
static void HandleWeaponFire(const Arduino& arduino, Weapon& weapon, const Config& config)
11+
static void HandleWeaponFire(const Arduino& arduino, Weapon& weapon, const Config& config, const FastReload& fastReload)
1112
{
1213
if (weapon == OFF) return;
1314

@@ -19,7 +20,6 @@ static void HandleWeaponFire(const Arduino& arduino, Weapon& weapon, const Confi
1920

2021
if (!(data.x.size() == data.y.size() && data.x.size() == data.delay.size()))
2122
{
22-
//cerr << "Warning: Mismatch in the number of elements across x, y, and delay vectors. All three vectors must have the same number of elements." << endl;
2323
weapon = OFF;
2424
return;
2525
}
@@ -28,12 +28,19 @@ static void HandleWeaponFire(const Arduino& arduino, Weapon& weapon, const Confi
2828
{
2929
if (!IsKeyHolded(VK_LBUTTON) || (config.GetConfirmationKey() != 0 && !IsKeyHolded(config.GetConfirmationKey())))
3030
{
31-
break;
31+
return;
3232
}
3333

3434
arduino.WriteMessage("MOUSE_LEFT_HOLDED:" + to_string(data.x[i]) + "," + to_string(data.y[i]) + "," + to_string(data.delay[i]));
3535
sleep_for(milliseconds(data.delay[i]));
3636
}
37+
38+
arduino.WriteMessage("MOUSE_LEFT_CLICK");
39+
40+
if (config.GetFastReload() != 0)
41+
{
42+
fastReload.Process(arduino, weapon);
43+
}
3744
}
3845

3946
static void ProcessKeyEvents(const Arduino& arduino, const Config& config, const ColorBot& colorBot)
@@ -63,6 +70,7 @@ int main()
6370
Arduino arduino("Arduino Leonardo");
6471
utils.PrintAscii(ASCII_OUTRO), utils.PrintHotkeys(ASCII_HOTKEYS);
6572

73+
FastReload fastReload;
6674
ColorBot colorBot(config.GetColorBotThreshold(), config.GetColorBotKey());
6775

6876
while (true)
@@ -72,7 +80,7 @@ int main()
7280

7381
if (message.rfind("ARDUINO_INITIATED", 0) != 0)
7482
{
75-
HandleWeaponFire(arduino, weapon, config);
83+
HandleWeaponFire(arduino, weapon, config, fastReload);
7684
ProcessKeyEvents(arduino, config, colorBot);
7785
}
7886
}

ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@
8585
<ClCompile Include="ArduinoStrike.cpp" />
8686
<ClCompile Include="ColorBot.cpp" />
8787
<ClCompile Include="Config.cpp" />
88+
<ClCompile Include="FastReload.cpp" />
8889
<ClCompile Include="Utils.cpp" />
8990
</ItemGroup>
9091
<ItemGroup>
9192
<ClInclude Include="Arduino.h" />
9293
<ClInclude Include="AsciiArt.h" />
9394
<ClInclude Include="ColorBot.h" />
9495
<ClInclude Include="Config.h" />
96+
<ClInclude Include="FastReload.h" />
9597
<ClInclude Include="Utils.h" />
9698
<ClInclude Include="Weapons.h" />
9799
</ItemGroup>

ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<ClCompile Include="ColorBot.cpp">
1515
<Filter>ColorBot</Filter>
1616
</ClCompile>
17+
<ClCompile Include="FastReload.cpp">
18+
<Filter>FastReload</Filter>
19+
</ClCompile>
1720
</ItemGroup>
1821
<ItemGroup>
1922
<Filter Include="Arduino">
@@ -28,6 +31,9 @@
2831
<Filter Include="ColorBot">
2932
<UniqueIdentifier>{c8ba443a-ed61-4766-959d-bac41db2674f}</UniqueIdentifier>
3033
</Filter>
34+
<Filter Include="FastReload">
35+
<UniqueIdentifier>{7c3cf5af-26d4-4ec5-afdf-f524a9f4c5bc}</UniqueIdentifier>
36+
</Filter>
3137
</ItemGroup>
3238
<ItemGroup>
3339
<ClInclude Include="Arduino.h">
@@ -44,5 +50,8 @@
4450
<ClInclude Include="ColorBot.h">
4551
<Filter>ColorBot</Filter>
4652
</ClInclude>
53+
<ClInclude Include="FastReload.h">
54+
<Filter>FastReload</Filter>
55+
</ClInclude>
4756
</ItemGroup>
4857
</Project>

ArduinoStrike/ArduinoStrike/Config.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ void Config::Load()
3232
int colorBotThreshold = GetValidatedIntInput("Enter colorbot color deviation (0-20) -> ", 0, 20);
3333
SetColorBotThreshold(colorBotThreshold);
3434

35+
int fastReload = GetValidatedIntInput("Enter fast reload boolean value (1/0) -> ", 0, 1);
36+
SetFastReload(fastReload);
37+
3538
Save();
3639
cout << "Configuration successfully saved!" << endl;
3740
}
@@ -44,6 +47,7 @@ void Config::Load()
4447
file >> hex >> confirmationKey;
4548
file >> hex >> colorBotKey;
4649
file >> dec >> colorBotThreshold;
50+
file >> dec >> fastReload;
4751
file.close();
4852

4953
if (!Validate())
@@ -66,13 +70,14 @@ void Config::Save() const
6670
out << dec << zoomSensitivity << endl;
6771
out << hex << confirmationKey << endl;
6872
out << hex << colorBotKey << endl;
69-
out << dec << colorBotThreshold;
73+
out << dec << colorBotThreshold << endl;
74+
out << dec << fastReload << endl;
7075
out.close();
7176
}
7277

7378
bool Config::Validate() const
7479
{
75-
return (bhop == 0 || bhop == 1) && (rapidFire == 0 || rapidFire == 1) && (sensitivity >= 1 && sensitivity <= 8) && (confirmationKey == 0 || (confirmationKey >= 0x01 && confirmationKey <= 0xFE)) && (colorBotKey == 0 || (colorBotKey >= 0x01 && colorBotKey <= 0xFE)) && (colorBotThreshold >= 0 && colorBotThreshold <= 20) && (zoomSensitivity >= 0.01 && zoomSensitivity <= 3.00);
80+
return (bhop == 0 || bhop == 1) && (rapidFire == 0 || rapidFire == 1) && (sensitivity >= 1 && sensitivity <= 8) && (confirmationKey == 0 || (confirmationKey >= 0x01 && confirmationKey <= 0xFE)) && (colorBotKey == 0 || (colorBotKey >= 0x01 && colorBotKey <= 0xFE)) && (colorBotThreshold >= 0 && colorBotThreshold <= 20) && (zoomSensitivity >= 0.01 && zoomSensitivity <= 3.00) && (fastReload == 0 || fastReload == 1);
7681
}
7782

7883
int Config::GetBhop() const
@@ -145,6 +150,16 @@ void Config::SetColorBotThreshold(int value)
145150
colorBotThreshold = value;
146151
}
147152

153+
int Config::GetFastReload() const
154+
{
155+
return fastReload;
156+
}
157+
158+
void Config::SetFastReload(int value)
159+
{
160+
fastReload = value;
161+
}
162+
148163
int Config::GetValidatedKeyInput(const string& prompt)
149164
{
150165
string input;

ArduinoStrike/ArduinoStrike/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Config
3939
int GetColorBotThreshold() const;
4040
void SetColorBotThreshold(int value);
4141

42+
int GetFastReload() const;
43+
void SetFastReload(int value);
44+
4245
private:
4346
int bhop;
4447
int rapidFire;
@@ -48,6 +51,7 @@ class Config
4851

4952
int colorBotKey;
5053
int colorBotThreshold;
54+
int fastReload;
5155

5256
int GetValidatedKeyInput(const string& prompt);
5357
int GetValidatedIntInput(const string& prompt, int min, int max);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "FastReload.h"
2+
3+
FastReload::FastReload() : times
4+
{
5+
{ UMP, 1600 },
6+
{ M4A1, 1495 },
7+
{ M4A4, 1450 },
8+
{ AK47, 1200 },
9+
{ GALIL, 1200 },
10+
{ FAMAS, 1700 },
11+
{ SG, 1200 }
12+
} {}
13+
14+
void FastReload::Process(const Arduino& arduino, const Weapon weapon) const
15+
{
16+
auto iterator = times.find(weapon);
17+
18+
if (iterator != times.end())
19+
{
20+
sleep_for(milliseconds(iterator->second));
21+
arduino.WriteMessage("KEYBOARD_PRESS_Q");
22+
}
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include "Arduino.h"
4+
#include "Weapons.h"
5+
#include <unordered_map>
6+
7+
class FastReload
8+
{
9+
public:
10+
FastReload();
11+
void Process(const Arduino& arduino, const Weapon weapon) const;
12+
13+
private:
14+
unordered_map<Weapon, int> times;
15+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1
2+
1
3+
8
4+
1
5+
0
6+
58
7+
20
8+
1

ArduinoStrike/ArduinoStrike/WeaponManager.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)