From d29a4a393b5032df17af562cac37d37255dadc81 Mon Sep 17 00:00:00 2001 From: Ryandw11 <6239385+ryandw11@users.noreply.github.com> Date: Tue, 14 Dec 2021 18:13:56 -0700 Subject: [PATCH] Improved Settings - Settings can now be saved to the settings.acdl file. - Added the ability to add a delay to the mouse down and mouse up done by the auto clicker. - Added the ability to choose which button the auto clicker will click. --- .gitignore | 2 + AutoClickerDL/.gitattributes | 2 - AutoClickerDL/.gitignore | 52 ------- AutoClickerDL/AutoClickerDL.c | 154 +++++++++++++++++--- AutoClickerDL/AutoClickerDL.vcxproj | 2 + AutoClickerDL/AutoClickerDL.vcxproj.filters | 6 + AutoClickerDL/General.h | 18 ++- AutoClickerDL/IO.c | 51 +++++++ AutoClickerDL/IO.h | 10 ++ AutoClickerDL/LICENSE | 21 --- AutoClickerDL/README.md | 2 - 11 files changed, 224 insertions(+), 96 deletions(-) delete mode 100644 AutoClickerDL/.gitattributes delete mode 100644 AutoClickerDL/.gitignore create mode 100644 AutoClickerDL/IO.c create mode 100644 AutoClickerDL/IO.h delete mode 100644 AutoClickerDL/LICENSE delete mode 100644 AutoClickerDL/README.md diff --git a/.gitignore b/.gitignore index 4d13c54..4c83a9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.acdl + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## diff --git a/AutoClickerDL/.gitattributes b/AutoClickerDL/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/AutoClickerDL/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/AutoClickerDL/.gitignore b/AutoClickerDL/.gitignore deleted file mode 100644 index c6127b3..0000000 --- a/AutoClickerDL/.gitignore +++ /dev/null @@ -1,52 +0,0 @@ -# Prerequisites -*.d - -# Object files -*.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf diff --git a/AutoClickerDL/AutoClickerDL.c b/AutoClickerDL/AutoClickerDL.c index 6f8f5a8..06545e9 100644 --- a/AutoClickerDL/AutoClickerDL.c +++ b/AutoClickerDL/AutoClickerDL.c @@ -4,6 +4,7 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include #include +#include #include #include #include @@ -13,11 +14,17 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #endif #include "General.h" +#include "IO.h" #define WIDTH 400 #define HEIGHT 500 +// A macro to insert code that converts an int to a wide character array. +#define itowc(_NAME) wchar_t _NAME[5] = { 0 };\ + swprintf(_NAME, 4, L"%d", loadedSettings._NAME); + #define SETTINGS_TIMED_CHECK_BOX 1 +#define SETTINGS_SAVE_BUTTON 2 // The handle to the main window. HWND mainWindowHandle; @@ -28,12 +35,17 @@ HWND tabControl, generalDisplayArea, settingsDisplayArea, rememberClickDisplayAr // The hotkey control for the start/stop of the Auto Clicker. HWND startStopHotKey; // The spinners -HWND cpsSpinnerHWD, timedAutoSpinnerHWD; +HWND cpsSpinnerHWD, timedAutoSpinnerHWD, delaySpinnerHWD; +// The comboboxes +HWND mouseButtonComboBoxHWD; // The timer used by the clicker. Not null when enabled, NULL when not enabled. UINT_PTR autoClickerTimer = NULL; time_t startClickerTime; +// Keeps track of the current settings when the autoclicker is turned on. +Settings currentSettings; + // Process callbacks. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -84,6 +96,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine 0, 23, WIDTH, HEIGHT - 23, tabControl, NULL, hInstance, NULL); + Settings loadedSettings = { 0 }; + loadSettings("settings.acdl", &loadedSettings); + /* =============== General Display Area @@ -92,11 +107,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine HWND infoLabel = CreateWindow(WC_STATIC, L"Welcome to AutoClickerDL! Head to the settings tab to \npick what button to enable the auto clicking!", WS_VISIBLE | WS_CHILD | SS_CENTER, 0, 23, WIDTH, 30, generalDisplayArea, NULL, hInstance, NULL); + + HWND authorLabel = CreateWindow(WC_STATIC, L"Created by: Ryandw11", WS_VISIBLE | WS_CHILD | SS_CENTER, + 0, HEIGHT - 100, WIDTH, 30, generalDisplayArea, NULL, hInstance, NULL); // Notify the user that they are not running the program as an administrator and that may limit some features. if (!IsUserAnAdmin()) { HWND notAdminLabel = CreateWindow(WC_STATIC, L"Note: Program is not being ran with admin perms! This\n may limit some features", WS_VISIBLE | WS_CHILD | SS_CENTER, - 0, HEIGHT - 120, WIDTH, 30, generalDisplayArea, NULL, hInstance, NULL); + 0, HEIGHT - 160, WIDTH, 30, generalDisplayArea, NULL, hInstance, NULL); } Spinner cpsSpinner = { 0 }; @@ -107,7 +125,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine cpsSpinner.labelSize = 0; cpsSpinner.rangeMin = 1; cpsSpinner.rangeMax = 80; - cpsSpinner.defaultValue = L"2"; + itowc(cps) + cpsSpinner.defaultValue = cps; cpsSpinnerHWD = CreateSpinner(generalDisplayArea, hInstance, cpsSpinner); @@ -120,11 +139,13 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine 10, 23, 150, 20, settingsDisplayArea, NULL, hInstance, NULL); startStopHotKey = CreateWindow(HOTKEY_CLASS, L"Start/StopHotKey", WS_VISIBLE | WS_CHILD, 10, 43, 150, 20, settingsDisplayArea, NULL, hInstance, NULL); - SendMessage(startStopHotKey, HKM_SETHOTKEY, MAKEWORD(VK_F1, 0), 0); - RegisterHotKey(windowHandle, 0, MOD_NOREPEAT, VK_F1); + SendMessage(startStopHotKey, HKM_SETHOTKEY, MAKEWORD(LOBYTE(loadedSettings.hotkey), HIBYTE(loadedSettings.hotkey)), 0); + RegisterHotKey(windowHandle, 0, HIBYTE(loadedSettings.hotkey), LOBYTE(loadedSettings.hotkey)); HWND checkbox = CreateWindow(WC_BUTTON, L"Timed Auto Click", WS_VISIBLE | WS_CHILD | BS_CHECKBOX, 10, 70, 130, 20, settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX, hInstance, NULL); + CheckDlgButton(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX, loadedSettings.timedAutoClick); + Spinner timedAutoClickSpinner = { 0 }; timedAutoClickSpinner.x = 10; timedAutoClickSpinner.y = 100; @@ -133,10 +154,39 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine timedAutoClickSpinner.labelSize = 0; timedAutoClickSpinner.rangeMin = 1; timedAutoClickSpinner.rangeMax = 20; - timedAutoClickSpinner.defaultValue = L"5"; + itowc(timedAutoClickValue); + timedAutoClickSpinner.defaultValue = timedAutoClickValue; timedAutoSpinnerHWD = CreateSpinner(settingsDisplayArea, hInstance, timedAutoClickSpinner); - EnableWindow(timedAutoSpinnerHWD, FALSE); - EnableWindow((HWND)SendMessage(timedAutoSpinnerHWD, UDM_GETBUDDY, NULL, NULL), FALSE); + EnableWindow(timedAutoSpinnerHWD, loadedSettings.timedAutoClick); + EnableWindow((HWND)SendMessage(timedAutoSpinnerHWD, UDM_GETBUDDY, NULL, NULL), loadedSettings.timedAutoClick); + + HWND delayLabel = CreateWindow(WC_STATIC, L"Delay between mouse down and up:", WS_VISIBLE | WS_CHILD, + 10, 130, 200, 40, settingsDisplayArea, NULL, hInstance, NULL); + Spinner delayClickSpinner = { 0 }; + delayClickSpinner.x = 10; + delayClickSpinner.y = 170; + delayClickSpinner.step = 10; + delayClickSpinner.labelPtr = L"ms"; + delayClickSpinner.labelSize = 0; + delayClickSpinner.rangeMin = 0; + delayClickSpinner.rangeMax = 100; + itowc(delayTime); + delayClickSpinner.defaultValue = delayTime; + delaySpinnerHWD = CreateSpinner(settingsDisplayArea, hInstance, delayClickSpinner); + + HWND mouseButtonLabel = CreateWindow(WC_STATIC, L"Mouse button to click:", WS_VISIBLE | WS_CHILD, + 10, 200, 200, 40, settingsDisplayArea, NULL, hInstance, NULL); + + mouseButtonComboBoxHWD = CreateWindow(WC_COMBOBOX, L"", CBS_HASSTRINGS | CBS_DROPDOWNLIST | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, + 10, 220, 120, 20, settingsDisplayArea, NULL, hInstance, NULL); + SendMessage(mouseButtonComboBoxHWD, CB_ADDSTRING, NULL, L"Left Click"); + SendMessage(mouseButtonComboBoxHWD, CB_ADDSTRING, NULL, L"Right Click"); + SendMessage(mouseButtonComboBoxHWD, CB_ADDSTRING, NULL, L"Middle Click"); + // Set the current selection for the combo box. + SendMessage(mouseButtonComboBoxHWD, CB_SETCURSEL, loadedSettings.mouseClickType, NULL); + + HWND saveButton = CreateWindow(WC_BUTTON, L"Save Settings", WS_CHILD | WS_VISIBLE | WS_TABSTOP, + WIDTH / 2 - (80), HEIGHT - 120, 130, 35, settingsDisplayArea, SETTINGS_SAVE_BUTTON, hInstance, NULL); /* =============== @@ -154,6 +204,20 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine return 0; } +/* + Updates a settings struct with the current settings. + + @param settings The pointer to the Settings struct to update. +*/ +void updateCurrentSettings(Settings* settings) { + settings->cps = SendMessage(cpsSpinnerHWD, UDM_GETPOS32, NULL, NULL); + settings->timedAutoClick = IsDlgButtonChecked(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX); + settings->timedAutoClickValue = SendMessage(timedAutoSpinnerHWD, UDM_GETPOS32, NULL, NULL); + settings->delayTime = SendMessage(delaySpinnerHWD, UDM_GETPOS32, NULL, NULL); + settings->mouseClickType = SendMessage(mouseButtonComboBoxHWD, CB_GETCURSEL, NULL, NULL); + settings->hotkey = SendMessage(startStopHotKey, HKM_GETHOTKEY, NULL, NULL); +} + /* This is the callback for the messages of the settings display background. */ @@ -188,6 +252,15 @@ LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam EnableWindow((HWND)SendMessage(timedAutoSpinnerHWD, UDM_GETBUDDY, NULL, NULL), TRUE); } } + // Handle the clicking of the save button. + else if (id == SETTINGS_SAVE_BUTTON) { + Settings settings = { 0 }; + updateCurrentSettings(&settings); + if(saveSettings("settings.acdl", &settings) == 0) + MessageBox(NULL, L"Your current settings have been successfuly saved!", L"Save Settings", MB_OK | MB_ICONINFORMATION); + else + MessageBox(NULL, L"Your current settings could not be saved! Does this program have the correct permissions?", L"Save Settings Error", MB_OK | MB_ICONEXCLAMATION); + } } } break; @@ -197,6 +270,34 @@ LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam return DefWindowProc(hwnd, uMsg, wParam, lParam); } +/* + Get the mouse event type depending on the current settings. + + @param up The pointer to the up variable that will be set with LEFT, RIGHT, or MIDDLEDOWN. + @param down The pointer to the down variable that will be set with LEFT, RIGHT, or MIDDLEUP. + @param settings The pointer of the settings struct to pull the mouse button setting from. +*/ +void getMouseFromSettings(int* up, int* down, Settings* settings) { + switch (settings->mouseClickType) { + case 0: + (*down) = MOUSEEVENTF_LEFTDOWN; + (*up) = MOUSEEVENTF_LEFTUP; + return; + case 1: + (*down) = MOUSEEVENTF_RIGHTDOWN; + (*up) = MOUSEEVENTF_RIGHTUP; + return; + case 2: + (*down) = MOUSEEVENTF_MIDDLEDOWN; + (*up) = MOUSEEVENTF_MIDDLEUP; + return; + default: + (*down) = MOUSEEVENTF_LEFTDOWN; + (*up) = MOUSEEVENTF_LEFTUP; + return; + } +} + /* Callback for the main window message process. */ @@ -245,9 +346,9 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // If the timmer is not running, trigger it. if (autoClickerTimer == NULL) { - int pos = SendMessage(cpsSpinnerHWD, UDM_GETPOS32, NULL, NULL); + updateCurrentSettings(¤tSettings); startClickerTime = time(NULL); - autoClickerTimer = SetTimer(hwnd, 1001, (1000 / pos), (TIMERPROC)NULL); + autoClickerTimer = SetTimer(hwnd, 1001, (1000 / currentSettings.cps), (TIMERPROC)NULL); } // Else, kill it. else { @@ -260,14 +361,31 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case WM_TIMER: { - // When the timmer is triggered, send a click event. - INPUT inputs[2] = { 0 }; - - inputs[0].type = INPUT_MOUSE; - inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN; - inputs[1].type = INPUT_MOUSE; - inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTUP; - SendInput(2, &inputs, sizeof(INPUT)); + int up = 0; + int down = 0; + getMouseFromSettings(&up, &down, ¤tSettings); + if (currentSettings.delayTime == 0) { + // When the timmer is triggered, send a click event. + INPUT inputs[2] = { 0 }; + + inputs[0].type = INPUT_MOUSE; + inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE | down; + inputs[1].type = INPUT_MOUSE; + inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE | up; + SendInput(2, &inputs, sizeof(INPUT)); + } + else { + INPUT inputOne = { 0 }; + INPUT inputTwo = { 0 }; + + inputOne.type = INPUT_MOUSE; + inputOne.mi.dwFlags = MOUSEEVENTF_MOVE | down; + inputTwo.type = INPUT_MOUSE; + inputTwo.mi.dwFlags = MOUSEEVENTF_MOVE | up; + SendInput(1, &inputOne, sizeof(INPUT)); + Sleep(currentSettings.delayTime); + SendInput(1, &inputTwo, sizeof(INPUT)); + } // If timer mode is enabled, shut off the timer if over time. if (IsDlgButtonChecked(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX) && time(NULL) - startClickerTime >= SendMessage(timedAutoSpinnerHWD, UDM_GETPOS32, NULL, NULL)) { diff --git a/AutoClickerDL/AutoClickerDL.vcxproj b/AutoClickerDL/AutoClickerDL.vcxproj index 3ca17f8..de73517 100644 --- a/AutoClickerDL/AutoClickerDL.vcxproj +++ b/AutoClickerDL/AutoClickerDL.vcxproj @@ -141,9 +141,11 @@ + + diff --git a/AutoClickerDL/AutoClickerDL.vcxproj.filters b/AutoClickerDL/AutoClickerDL.vcxproj.filters index 3e275a0..3c1607c 100644 --- a/AutoClickerDL/AutoClickerDL.vcxproj.filters +++ b/AutoClickerDL/AutoClickerDL.vcxproj.filters @@ -21,10 +21,16 @@ Source Files + + Source Files + Header Files + + Header Files + \ No newline at end of file diff --git a/AutoClickerDL/General.h b/AutoClickerDL/General.h index f6655a5..599a134 100644 --- a/AutoClickerDL/General.h +++ b/AutoClickerDL/General.h @@ -1,5 +1,19 @@ #pragma once +#ifndef GENERAL_H +#define GENERAL_H + +#define AutoClickerDL_VER_NUM 1 + +typedef struct { + int cps; + BOOL timedAutoClick; + int timedAutoClickValue; + int delayTime; + int mouseClickType; + int hotkey; +} Settings; + typedef struct { int x; int y; @@ -13,4 +27,6 @@ typedef struct { HWND CreateTabDisplayArea(HWND parent, HINSTANCE hInstance, LPCWSTR className, int width, int height, WNDPROC procCallback); HWND CreateSpinner(HWND parent, HINSTANCE hInstance, Spinner spinner); -HWND CreateCheckBox(HWND parent, HINSTANCE hInstance, LPCWSTR text, int x, int y, int width, int height, WNDPROC procCallback); \ No newline at end of file +HWND CreateCheckBox(HWND parent, HINSTANCE hInstance, LPCWSTR text, int x, int y, int width, int height, WNDPROC procCallback); + +#endif \ No newline at end of file diff --git a/AutoClickerDL/IO.c b/AutoClickerDL/IO.c new file mode 100644 index 0000000..0ed51e5 --- /dev/null +++ b/AutoClickerDL/IO.c @@ -0,0 +1,51 @@ +#include +#include +#include + +#include "IO.h" + +#pragma warning(disable: 4996) +void loadSettings(const char* fileName, Settings* settings) { + FILE* inputFile = fopen(fileName, "r"); + + if (inputFile == NULL) { + // Unable to open file. + settings->cps = 2; + settings->timedAutoClick = 0; + settings->timedAutoClickValue = 5; + settings->delayTime = 0; + settings->hotkey = 112; + return; + } + + char hotkey[5] = { 0 }; + char ver; + char cps, timedAutoClick, timedAutoClickValue, delayTime, mouseClickType; + int output = fscanf(inputFile, "%c%c%c%c%c%c%c%c%c%c", &ver, &cps, &timedAutoClick, &timedAutoClickValue, &delayTime, &mouseClickType, &hotkey[0], &hotkey[1], &hotkey[2], &hotkey[3]); + settings->cps = cps; + settings->timedAutoClick = timedAutoClick; + settings->timedAutoClickValue = timedAutoClickValue; + settings->delayTime = delayTime; + settings->mouseClickType = mouseClickType; + + int hotkeyI = atoi(hotkey); + settings->hotkey = hotkeyI; + fclose(inputFile); +} + + +// FILE FORMAT:: +// (1 bytes vernum) - (1 bytes CPS) - (1 byte bool) - (1 bytes - timedAutoClickerValue) - (1 bytes - delay time) - (1 bytes - mouse click type) - (4 bytes - hotkey) +int saveSettings(const char* fileName, Settings* settings) { + FILE* outputFile = fopen(fileName, "w"); + + if (outputFile == NULL) { + // Unable to open file. + return -1; + } + char hotkey[5] = { 0 }; + itoa(settings->hotkey, hotkey, 10); + fprintf(outputFile, "%c%c%c%c%c%c%c%c%c%c", 1, settings->cps, settings->timedAutoClick, settings->timedAutoClickValue, settings->delayTime, settings->mouseClickType, hotkey[0],hotkey[1],hotkey[2],hotkey[3]); + fclose(outputFile); + return 0; +} \ No newline at end of file diff --git a/AutoClickerDL/IO.h b/AutoClickerDL/IO.h new file mode 100644 index 0000000..8da4b5d --- /dev/null +++ b/AutoClickerDL/IO.h @@ -0,0 +1,10 @@ +#pragma once +#ifndef IO_H +#define IO_H + +#include "General.h" + +void loadSettings(Settings* settings); +int saveSettings(const char* fileName, Settings* settings); + +#endif \ No newline at end of file diff --git a/AutoClickerDL/LICENSE b/AutoClickerDL/LICENSE deleted file mode 100644 index 357c06c..0000000 --- a/AutoClickerDL/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Ryandw11 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/AutoClickerDL/README.md b/AutoClickerDL/README.md deleted file mode 100644 index 8fca13d..0000000 --- a/AutoClickerDL/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# AutoClickerDL -