Skip to content

Commit d154d0a

Browse files
Add files via upload
1 parent 9adb731 commit d154d0a

File tree

15 files changed

+1020
-0
lines changed

15 files changed

+1020
-0
lines changed

ArduinoStrike/ArduinoStrike.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.30804.86
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArduinoStrike", "ArduinoStrike\ArduinoStrike.vcxproj", "{827797FA-80DE-495F-B3B6-E4CC2BE7E444}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|x86 = Debug|x86
10+
Release|x86 = Release|x86
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{827797FA-80DE-495F-B3B6-E4CC2BE7E444}.Debug|x86.ActiveCfg = Debug|Win32
14+
{827797FA-80DE-495F-B3B6-E4CC2BE7E444}.Debug|x86.Build.0 = Debug|Win32
15+
{827797FA-80DE-495F-B3B6-E4CC2BE7E444}.Release|x86.ActiveCfg = Release|Win32
16+
{827797FA-80DE-495F-B3B6-E4CC2BE7E444}.Release|x86.Build.0 = Release|Win32
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {0F011D77-ECCF-47FC-9421-C710EE385EB1}
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#include "Arduino.h"
2+
3+
Arduino::~Arduino()
4+
{
5+
if (m_arduinoHandle != INVALID_HANDLE_VALUE)
6+
{
7+
CloseHandle(m_arduinoHandle);
8+
}
9+
}
10+
11+
Arduino::Arduino(LPCSTR device_name) : m_arduinoHandle(INVALID_HANDLE_VALUE)
12+
{
13+
char port[100] = "\\.\\";
14+
15+
while (!this->GetDevice(device_name, port))
16+
{
17+
sleep_for(milliseconds(1000));
18+
}
19+
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)
23+
{
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;
48+
49+
if (!SetCommTimeouts(m_arduinoHandle, &cto))
50+
return;
51+
52+
cout << "Successfully connected!" << endl;
53+
}
54+
55+
bool Arduino::IsAvailable() const
56+
{
57+
DWORD errors;
58+
COMSTAT status;
59+
60+
if (!ClearCommError(m_arduinoHandle, &errors, &status))
61+
{
62+
cerr << "Error checking available data: " << GetLastError() << endl;
63+
return false;
64+
}
65+
66+
return status.cbInQue > 0;
67+
}
68+
69+
bool Arduino::GetDevice(LPCSTR friendly_name, LPSTR com_port)
70+
{
71+
const char com[] = "COM";
72+
HDEVINFO device_info = SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS, nullptr, nullptr, DIGCF_PRESENT);
73+
74+
if (device_info == INVALID_HANDLE_VALUE)
75+
return false;
76+
77+
SP_DEVINFO_DATA dev_info_data = {};
78+
dev_info_data.cbSize = sizeof(dev_info_data);
79+
80+
DWORD device_count = 0;
81+
82+
while (SetupDiEnumDeviceInfo(device_info, device_count++, &dev_info_data))
83+
{
84+
BYTE buff[256] = { 0 };
85+
86+
if (SetupDiGetDeviceRegistryProperty(device_info, &dev_info_data, SPDRP_FRIENDLYNAME, nullptr, buff, sizeof(buff), nullptr))
87+
{
88+
LPCSTR port_name_pos = strstr(reinterpret_cast<LPCSTR>(buff), com);
89+
90+
if (port_name_pos == nullptr)
91+
continue;
92+
93+
if (strstr(reinterpret_cast<LPCSTR>(buff), friendly_name))
94+
{
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;
100+
}
101+
}
102+
}
103+
104+
SetupDiDestroyDeviceInfoList(device_info);
105+
return false;
106+
}
107+
108+
bool Arduino::WriteMessage(const string& message) const
109+
{
110+
DWORD bw = 0;
111+
BOOL result = WriteFile(m_arduinoHandle, message.c_str(), message.size() + 1, &bw, nullptr);
112+
113+
if (result == 0 || bw != message.size() + 1)
114+
{
115+
cerr << "Failed to send message!" << endl;
116+
return false;
117+
}
118+
119+
return true;
120+
}
121+
122+
string Arduino::ReceiveMessage(char delimiter) const
123+
{
124+
string result;
125+
char buffer[256];
126+
DWORD bytesRead = 0;
127+
128+
while (this->IsAvailable())
129+
{
130+
memset(buffer, 0, sizeof(buffer));
131+
132+
if (!ReadFile(m_arduinoHandle, buffer, sizeof(buffer), &bytesRead, nullptr))
133+
break;
134+
135+
for (DWORD i = 0; i < bytesRead; i++)
136+
{
137+
if (buffer[i] == delimiter)
138+
{
139+
return result;
140+
}
141+
142+
result += buffer[i];
143+
}
144+
}
145+
146+
return result;
147+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#pragma comment(lib, "Setupapi.lib")
3+
4+
#include <thread>
5+
#include <iostream>
6+
#include <windows.h>
7+
#include <devguid.h>
8+
#include <SetupAPI.h>
9+
10+
using namespace std;
11+
using namespace chrono;
12+
using namespace this_thread;
13+
14+
class Arduino
15+
{
16+
public:
17+
~Arduino();
18+
Arduino(LPCSTR device_name);
19+
20+
bool WriteMessage(const string& message) const;
21+
string ReceiveMessage(char delimiter) const;
22+
23+
private:
24+
HANDLE m_arduinoHandle;
25+
bool IsAvailable() const;
26+
bool GetDevice(LPCSTR friendly_name, LPSTR com_port);
27+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "Utils.h"
2+
#include "Config.h"
3+
#include "Arduino.h"
4+
#include "Weapons.h"
5+
#include "AsciiArt.h"
6+
#include "ColorBot.h"
7+
8+
Weapon weapon = OFF;
9+
10+
static void HandleWeaponFire(const Arduino& arduino, const Weapon& weapon, const Config& config)
11+
{
12+
double modifier = 2.52 / config.GetSensitivity();
13+
WeaponData data = GetWeaponData(weapon, modifier);
14+
15+
for (size_t i = 0; i < data.x.size(); i++)
16+
{
17+
if (!IsKeyHolded(VK_LBUTTON) || (config.GetConfirmationKey() != 0 && !IsKeyHolded(config.GetConfirmationKey())))
18+
{
19+
break;
20+
}
21+
22+
arduino.WriteMessage("MOUSE_LEFT_HOLDED:" + to_string(data.x[i]) + "," + to_string(data.y[i]) + "," + to_string(data.delay[i]));
23+
sleep_for(milliseconds(data.delay[i]));
24+
}
25+
}
26+
27+
static void ProcessKeyEvents(const Arduino& arduino, const Config& config, const ColorBot& colorBot)
28+
{
29+
if (IsKeyHolded(VK_SPACE) && config.GetBhop() != 0)
30+
{
31+
arduino.WriteMessage("SPACE_BUTTON_HOLDED");
32+
}
33+
34+
if (IsKeyHolded(VK_MBUTTON) && config.GetRapidFire() != 0)
35+
{
36+
arduino.WriteMessage("MOUSE_MIDDLE_HOLDED");
37+
}
38+
39+
if (IsKeyHolded(config.GetColorBotKey()) && config.GetColorBotKey() != 0)
40+
{
41+
colorBot.Process(arduino);
42+
}
43+
}
44+
45+
int main()
46+
{
47+
Utils utils;
48+
Config config;
49+
50+
utils.PrintAscii(ASCII_INTRO);
51+
Arduino arduino("Arduino Leonardo");
52+
utils.PrintAscii(ASCII_OUTRO), utils.PrintHotkeys(ASCII_HOTKEYS);
53+
54+
ColorBot colorBot(config.GetColorBotThreshold(), config.GetColorBotKey());
55+
56+
while (true)
57+
{
58+
weapon = GetWeaponState(weapon);
59+
string message = arduino.ReceiveMessage('\n');
60+
61+
if (message.rfind("ARDUINO_INITIATED", 0) != 0)
62+
{
63+
HandleWeaponFire(arduino, weapon, config);
64+
ProcessKeyEvents(arduino, config, colorBot);
65+
}
66+
}
67+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>16.0</VCProjectVersion>
15+
<Keyword>Win32Proj</Keyword>
16+
<ProjectGuid>{827797fa-80de-495f-b3b6-e4cc2be7e444}</ProjectGuid>
17+
<RootNamespace>hwtbcpp</RootNamespace>
18+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
22+
<ConfigurationType>Application</ConfigurationType>
23+
<UseDebugLibraries>true</UseDebugLibraries>
24+
<PlatformToolset>v143</PlatformToolset>
25+
<CharacterSet>MultiByte</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v143</PlatformToolset>
31+
<WholeProgramOptimization>true</WholeProgramOptimization>
32+
<CharacterSet>MultiByte</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="Shared">
38+
</ImportGroup>
39+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
40+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
41+
</ImportGroup>
42+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
43+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
44+
</ImportGroup>
45+
<PropertyGroup Label="UserMacros" />
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
47+
<LinkIncremental>true</LinkIncremental>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
50+
<LinkIncremental>false</LinkIncremental>
51+
</PropertyGroup>
52+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
53+
<ClCompile>
54+
<WarningLevel>Level3</WarningLevel>
55+
<SDLCheck>true</SDLCheck>
56+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
57+
<ConformanceMode>true</ConformanceMode>
58+
<LanguageStandard>stdcpp17</LanguageStandard>
59+
</ClCompile>
60+
<Link>
61+
<SubSystem>Console</SubSystem>
62+
<GenerateDebugInformation>true</GenerateDebugInformation>
63+
</Link>
64+
</ItemDefinitionGroup>
65+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
66+
<ClCompile>
67+
<WarningLevel>Level3</WarningLevel>
68+
<FunctionLevelLinking>true</FunctionLevelLinking>
69+
<IntrinsicFunctions>true</IntrinsicFunctions>
70+
<SDLCheck>true</SDLCheck>
71+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
72+
<ConformanceMode>true</ConformanceMode>
73+
<LanguageStandard>stdcpp17</LanguageStandard>
74+
<Optimization>MaxSpeed</Optimization>
75+
</ClCompile>
76+
<Link>
77+
<SubSystem>Console</SubSystem>
78+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
79+
<OptimizeReferences>true</OptimizeReferences>
80+
<GenerateDebugInformation>false</GenerateDebugInformation>
81+
</Link>
82+
</ItemDefinitionGroup>
83+
<ItemGroup>
84+
<ClCompile Include="Arduino.cpp" />
85+
<ClCompile Include="ArduinoStrike.cpp" />
86+
<ClCompile Include="ColorBot.cpp" />
87+
<ClCompile Include="Config.cpp" />
88+
<ClCompile Include="Utils.cpp" />
89+
</ItemGroup>
90+
<ItemGroup>
91+
<ClInclude Include="Arduino.h" />
92+
<ClInclude Include="AsciiArt.h" />
93+
<ClInclude Include="ColorBot.h" />
94+
<ClInclude Include="Config.h" />
95+
<ClInclude Include="Utils.h" />
96+
<ClInclude Include="Weapons.h" />
97+
</ItemGroup>
98+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
99+
<ImportGroup Label="ExtensionTargets">
100+
</ImportGroup>
101+
</Project>

0 commit comments

Comments
 (0)