diff --git a/ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp b/ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp index 2beaff7..4e9456c 100644 --- a/ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp +++ b/ArduinoStrike/ArduinoStrike/ArduinoStrike.cpp @@ -5,23 +5,21 @@ Weapon weapon = OFF; -static void HandleWeaponFire(Arduino& arduino, const vector& x, const vector& y, const vector& delay) +static void HandleWeaponFire(const Arduino& arduino, const vector& x, const vector& y, const vector& delay, const Config& config) { for (size_t i = 0; i < x.size(); i++) { - if (IsKeyHolded(VK_LBUTTON)) + bool isRecoilControlActive = IsKeyHolded(VK_LBUTTON) && (config.confirmationKey == 0 || IsKeyHolded(config.confirmationKey)); + + if (isRecoilControlActive) { + arduino.WriteMessage("MOUSE_LEFT_HOLDED:" + to_string(x[i]) + "," + to_string(y[i]) + "," + to_string(delay[i])); sleep_for(milliseconds(delay[i])); - - if (IsKeyHolded(VK_LBUTTON)) - { - arduino.WriteMessage("MOUSE_LEFT_HOLDED:" + to_string(x[i]) + "," + to_string(y[i]) + "," + to_string(delay[i])); - } } } } -static void ProcessKeyEvents(Arduino& arduino, Config& config) +static void ProcessKeyEvents(const Arduino& arduino, const Config& config) { if (IsKeyHolded(VK_SPACE) && config.bhop != 0) { @@ -56,14 +54,15 @@ int main() if (message.rfind("ARDUINO_INITIATED", 0) != 0) { double modifier = 2.52 / config.sensitivity; + bool isRecoilControlActive = IsKeyHolded(VK_LBUTTON) && (config.confirmationKey == 0 || IsKeyHolded(config.confirmationKey)); - if (IsKeyHolded(VK_LBUTTON)) + if (isRecoilControlActive) { WeaponData data = GetWeaponData(weapon, modifier); - HandleWeaponFire(arduino, data.x, data.y, data.delay); + HandleWeaponFire(arduino, data.x, data.y, data.delay, config); } ProcessKeyEvents(arduino, config); } } -} \ No newline at end of file +} diff --git a/ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj.user b/ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj.user index 0f14913..3e74e6c 100644 --- a/ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj.user +++ b/ArduinoStrike/ArduinoStrike/ArduinoStrike.vcxproj.user @@ -1,4 +1,6 @@  - + + WindowsLocalDebugger + \ No newline at end of file diff --git a/ArduinoStrike/ArduinoStrike/Utils.cpp b/ArduinoStrike/ArduinoStrike/Utils.cpp index 05c0a34..f7ba1cd 100644 --- a/ArduinoStrike/ArduinoStrike/Utils.cpp +++ b/ArduinoStrike/ArduinoStrike/Utils.cpp @@ -51,52 +51,17 @@ void Utils::Install() void Utils::LoadConfig(Config& config) { - string input; ifstream file("Settings.cfg"); if (!file.is_open()) { - do - { - cout << "Enter bhop boolean value (1/0) -> "; - getline(cin, input); - istringstream iss(input); - if (!(iss >> config.bhop) || (config.bhop != 0 && config.bhop != 1)) - { - config.bhop = -1; - cout << "Invalid input! Please enter 1 or 0." << endl << endl; - } - } - while (config.bhop != 0 && config.bhop != 1); - - do - { - cout << "Enter rapid-fire boolean value (1/0) -> "; - getline(cin, input); - istringstream iss(input); - if (!(iss >> config.rapidFire) || (config.rapidFire != 0 && config.rapidFire != 1)) - { - config.rapidFire = -1; - cout << "Invalid input! Please enter 1 or 0." << endl << endl; - } - } - while (config.rapidFire != 0 && config.rapidFire != 1); - - do - { - cout << "Enter sensitivity integer value (1-8) -> "; - getline(cin, input); - istringstream iss(input); - if (!(iss >> config.sensitivity) || config.sensitivity < 1 || config.sensitivity > 8) - { - config.sensitivity = -1; - cout << "Invalid input! Please enter an integer between 1 and 8." << endl << endl; - } - } - while (config.sensitivity < 1 || config.sensitivity > 8); + config.bhop = GetValidatedIntInput("Enter bhop boolean value (1/0) -> ", 0, 1); + config.rapidFire = GetValidatedIntInput("Enter rapid-fire boolean value (1/0) -> ", 0, 1); + config.sensitivity = GetValidatedIntInput("Enter sensitivity integer value (1-8) -> ", 1, 8); + config.confirmationKey = GetValidatedKeyInput("Enter recoil control confirmation key (0/VK_CODE) -> "); ofstream out("Settings.cfg"); - out << config.bhop << endl << config.rapidFire << endl << config.sensitivity; + out << config.bhop << endl << config.rapidFire << endl << config.sensitivity << endl << hex << config.confirmationKey; out.close(); cout << "Configuration successfully saved!" << endl; @@ -106,6 +71,7 @@ void Utils::LoadConfig(Config& config) file >> config.bhop; file >> config.rapidFire; file >> config.sensitivity; + file >> hex >> config.confirmationKey; file.close(); if (!ValidateConfig(config)) @@ -119,9 +85,64 @@ void Utils::LoadConfig(Config& config) } } +int Utils::GetValidatedIntInput(const string& prompt, int min, int max) +{ + string input; + int value = -1; + + do + { + cout << prompt; + getline(cin, input); + istringstream iss(input); + + if (!(iss >> value) || value < min || value > max) + { + value = -1; + + if (min == 0 && max == 1) + { + cout << "Invalid input! Please enter 0 or 1." << endl << endl; + } + else + { + cout << "Invalid input! Please enter an integer between " << min << " and " << max << "." << endl << endl; + } + } + } while (value == -1); + + return value; +} + +int Utils::GetValidatedKeyInput(const string& prompt) +{ + string input; + int value = -1; + + do + { + cout << prompt; + getline(cin, input); + istringstream iss(input); + + if (!(iss >> hex >> value) || (value != 0 && (value < 0x01 || value > 0xFE))) + { + value = -1; + cout << "Invalid input! Please enter 0 or VK_CODE." << endl << endl; + } + } while (value == -1); + + return value; +} + bool Utils::ValidateConfig(Config& config) { - return ((config.bhop == 0 || config.bhop == 1) && (config.rapidFire == 0 || config.rapidFire == 1) && (config.sensitivity >= 1 && config.sensitivity <= 8)) ? true : false; + bool validBhop = (config.bhop == 0 || config.bhop == 1); + bool validRapidFire = (config.rapidFire == 0 || config.rapidFire == 1); + bool validSensitivity = (config.sensitivity >= 1 && config.sensitivity <= 8); + bool validConfirmationKey = (config.confirmationKey == 0 || (config.confirmationKey >= 0x01 && config.confirmationKey <= 0xFE)); + + return validBhop && validRapidFire && validSensitivity && validConfirmationKey; } void Utils::PrintAscii(const string& asciiArt) diff --git a/ArduinoStrike/ArduinoStrike/Utils.h b/ArduinoStrike/ArduinoStrike/Utils.h index 5f96e6d..bfdfd18 100644 --- a/ArduinoStrike/ArduinoStrike/Utils.h +++ b/ArduinoStrike/ArduinoStrike/Utils.h @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; using namespace filesystem; @@ -14,6 +15,7 @@ struct Config int bhop; int rapidFire; int sensitivity; + int confirmationKey; }; class Utils @@ -21,13 +23,15 @@ class Utils public: static void Install(); static void LoadConfig(Config& config); - static bool ValidateConfig(Config& config); static void PrintAscii(const string& asciiArt); static void PrintHotkeys(const string& hotkeys); private: static void ConsoleClear(); + static bool ValidateConfig(Config& config); static string GenerateRandomData(int length); static void SetConsoleMode(const string& title); + static int GetValidatedIntInput(const string& prompt, int min, int max); + static int GetValidatedKeyInput(const string& prompt); }; \ No newline at end of file