-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New clicker randomization, new features.
- Loading branch information
Showing
46 changed files
with
1,104 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,125 @@ | ||
#include "pch.hpp" | ||
#include "clicker.hpp" | ||
|
||
void clicker::work( ) | ||
void clicker::init( ) | ||
{ | ||
while ( true ) | ||
{ | ||
// Please PR if you found a better way to do this. CPU Usage is high without. | ||
sleep( 1 ); | ||
// https://randomascii.wordpress.com/2020/10/04/windows-timer-resolution-the-great-rule-change/ | ||
// Not sure if this will affect anything. | ||
timeBeginPeriod( 1 ); | ||
|
||
if ( vars::b_hotkey_enabled ) // if hotkey is enabled, and selected window is active | ||
// Sleep for saving CPU cycles, affects just a little on the algorithm. | ||
std::this_thread::sleep_for( 1ms ); | ||
|
||
const auto get_cursor_status = [ ]( ) | ||
{ | ||
return config.clicker.only_in_game ? !util::other::is_cursor_visible( ) : util::other::is_cursor_visible( ); | ||
}; | ||
|
||
if ( vars::b_hotkey_enabled ) | ||
{ | ||
if ( util::get_active_window_title( ).find( config.clicker.window_title ) != std::string::npos ) | ||
// check if window is active and current window is not focused | ||
if ( util::other::get_active_window_title( ).find( config.clicker.window_title ) != std::string::npos && !util::other::application_focused( ) ) | ||
{ | ||
if ( config.clicker.left_enabled && vars::b_l_mouse_down && !vars::b_r_mouse_down ) // if left is enabled, left mouse is down and right mouse isn't down start clicking. | ||
// check if cursor is visible, in-game. | ||
if ( get_cursor_status( ) || !config.clicker.only_in_game ) | ||
{ | ||
g_clicker->click( left_mb, config.clicker.l_cps, vars::b_l_first_click ); // click! | ||
} | ||
if ( config.clicker.left_enabled && vars::b_l_mouse_down && !vars::b_r_mouse_down ) | ||
g_clicker->click( left_mb, config.clicker.l_cps, vars::b_l_first_click ); | ||
|
||
if ( config.clicker.right_enabled && vars::b_r_mouse_down ) // if right is enabled, right mouse is down start clicking. | ||
{ | ||
g_clicker->click( right_mb, config.clicker.r_cps, vars::b_r_first_click ); // click! | ||
if ( config.clicker.right_enabled && vars::b_r_mouse_down ) | ||
g_clicker->click( right_mb, config.clicker.r_cps, vars::b_r_first_click ); | ||
} | ||
} | ||
} | ||
|
||
timeEndPeriod( 1 ); | ||
} | ||
} | ||
|
||
void clicker::click( bool button, int cps, bool &is_first_click ) | ||
{ | ||
// used to measure the time that it takes for one click precisely | ||
#ifdef _DEBUG | ||
auto start = std::chrono::high_resolution_clock::now( ); | ||
#endif | ||
|
||
if ( cps <= 0 ) // return if our cps is 0. let's not divide it by 0. | ||
return; | ||
|
||
if ( !config.clicker.blatant ) // if blatant is not enabled randomize values. | ||
{ | ||
random = util::random_int( -( cps / 5 ), ( cps / 5 ) ); // random int between negative 1 / 5 of our cps and 1 / 5 of our cps | ||
cps += random; // add our values to the i_cps variable. | ||
|
||
// TODO: | ||
/* | ||
if ( config.clicker.cps_drop_chance && config.clicker.cps_drop_chance_val > 0 && std::rand( ) % ( 100 / config.clicker.cps_drop_chance_val ) == 0 ) | ||
{ | ||
// cps drop code | ||
} | ||
if ( !config.clicker.blatant ) | ||
cps += random; | ||
|
||
if ( config.clicker.cps_spike_chance && config.clicker.cps_spike_chance_val > 0 && std::rand( ) % ( 100 / config.clicker.cps_spike_chance_val ) == 0 ) | ||
{ | ||
// cps spike code | ||
} | ||
*/ | ||
} | ||
delay = ( 1000 / cps ) / 2 - cps / 2; // delay is half because we'll be calling it two times, on mouse down and up. | ||
|
||
delay = ( 1000 / cps ) / 2; // delay is half because we'll be calling it two times, on mouse down and up. | ||
if ( !config.clicker.blatant ) | ||
delay += util::numbers::random( 2, 5 ); // apply randomization naturally. | ||
|
||
if ( is_first_click ) // if it's our first click, delay and send a up input to our function. | ||
{ | ||
sleep( delay ); | ||
std::this_thread::sleep_for( std::chrono::milliseconds( delay ) ); | ||
g_clicker->click_mouse( input_up, button ); | ||
is_first_click = false; | ||
_log( LDEBUG, "[ clicker ] first click." ); | ||
} | ||
|
||
sleep( delay ); // sleep on input down | ||
g_clicker->click_mouse( input_down, button ); // the actual input down call | ||
std::this_thread::sleep_for( std::chrono::milliseconds( delay ) ); | ||
g_clicker->click_mouse( input_down, button ); | ||
|
||
if ( config.clicker.blockhit && config.clicker.blockhit_chance > 0 && std::rand( ) % ( 100 / config.clicker.blockhit_chance ) == 0 ) // if blockhit is enabled and blockhit chance is higher than 0 and blockhit chance matches | ||
if ( config.clicker.blockhit && config.clicker.blockhit_chance > 0 && std::rand( ) % ( 100 / config.clicker.blockhit_chance ) == 0 ) | ||
{ | ||
blockhitted = true; // set blockhitted bool to true | ||
g_clicker->click_mouse( input_down, right_mb ); // right click | ||
blockhitted = true; | ||
g_clicker->click_mouse( input_down, right_mb ); | ||
} | ||
|
||
sleep( delay ); // sleep on input up | ||
g_clicker->click_mouse( input_up, button ); // the actual input up call | ||
std::this_thread::sleep_for( std::chrono::milliseconds( delay ) ); | ||
g_clicker->click_mouse( input_up, button ); | ||
|
||
if ( blockhitted ) // check if blockhitted bool was true | ||
if ( blockhitted ) | ||
{ | ||
g_clicker->click_mouse( input_up, right_mb ); // right click up | ||
blockhitted = false; // set blockhitted variable back to false. | ||
g_clicker->click_mouse( input_up, right_mb ); | ||
blockhitted = false; | ||
} | ||
|
||
#ifdef _DEBUG | ||
auto end = std::chrono::high_resolution_clock::now( ); | ||
std::chrono::duration<double, std::milli> elapsed = end - start; | ||
#endif | ||
|
||
_log( LDEBUG, "[ clicker ] cps: %d delay %d.", cps, delay ); | ||
_log( LDEBUG, "[ clicker ] cps: %d delay %d time elapsed %.3f.", cps, delay, elapsed.count( ) ); | ||
} | ||
|
||
void clicker::randomization_thread( int delay ) | ||
{ | ||
bool should_update = false; | ||
while ( true ) | ||
{ | ||
if ( should_update ) | ||
{ | ||
random = util::numbers::random( -2, 2 ); | ||
|
||
if ( config.clicker.cps_drop_chance | ||
&& config.clicker.cps_drop_chance_val > 0 | ||
&& std::rand( ) % ( 100 / config.clicker.cps_drop_chance_val ) == 0 ) | ||
random -= 3; | ||
|
||
if ( config.clicker.cps_spike_chance | ||
&& config.clicker.cps_spike_chance_val > 0 | ||
&& std::rand( ) % ( 100 / config.clicker.cps_spike_chance_val ) == 0 ) | ||
random += 3; | ||
|
||
should_update = false; | ||
} | ||
|
||
std::this_thread::sleep_for( std::chrono::milliseconds( util::numbers::random( -delay, delay ) ) ); | ||
|
||
should_update = true; | ||
} | ||
} | ||
|
||
void clicker::click_mouse( bool is_down, bool button ) | ||
{ | ||
is_down ? ( button ? g_mouse->left_down( ) : g_mouse->right_down( ) ) : ( button ? g_mouse->left_up( ) : g_mouse->right_up( ) ); | ||
is_down ? ( button ? hooks::mouse::left_down( ) : hooks::mouse::right_down( ) ) : ( button ? hooks::mouse::left_up( ) : hooks::mouse::right_up( ) ); | ||
++vars::i_clicks_this_session; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
#pragma once | ||
|
||
#include "../def/includes.hpp" | ||
#include "../mouse/mouse.hpp" | ||
// For timeBeginPeriod | ||
#include <timeapi.h> | ||
#pragma comment(lib, "Winmm.lib") | ||
|
||
#define sleep(ms) (std::this_thread::sleep_for(std::chrono::milliseconds(ms))); | ||
using namespace std::chrono_literals; | ||
|
||
class clicker | ||
{ | ||
public: | ||
void work( ); | ||
void click( bool button, int cps, bool &is_first_click ); | ||
void click_mouse( bool is_down, bool button ); | ||
|
||
~clicker( ) = default; | ||
clicker( ) = default; | ||
|
||
private: | ||
int delay = 0; // delay for the sleep | ||
int random = 0; // random cps | ||
|
||
/// <summary> | ||
/// Delay for the sleep | ||
/// </summary> | ||
int delay = 0; | ||
|
||
/// <summary> | ||
/// Random cps values | ||
/// </summary> | ||
int random = 0; | ||
|
||
/// <summary> | ||
/// Has blockhitted at the time | ||
/// </summary> | ||
bool blockhitted = false; | ||
|
||
bool right_mb = false; | ||
bool left_mb = true; | ||
|
||
bool input_down = true; | ||
bool input_up = false; | ||
public: | ||
/// <summary> | ||
/// Initializes main loop | ||
/// </summary> | ||
void init( ); | ||
|
||
/// <summary> | ||
/// Clicks mouse with randomization | ||
/// </summary> | ||
/// <param name="button"></param> | ||
/// <param name="cps"></param> | ||
/// <param name="is_first_click"></param> | ||
void click( bool button, int cps, bool &is_first_click ); | ||
|
||
/// <summary> | ||
/// Clicks a mouse button | ||
/// </summary> | ||
/// <param name="is_down"></param> | ||
/// <param name="button"></param> | ||
void click_mouse( bool is_down, bool button ); | ||
|
||
/// <summary> | ||
/// Separate randomization thread for more accurate randomization algorithm | ||
/// </summary> | ||
/// <param name="delay"></param> | ||
void randomization_thread( int delay ); | ||
|
||
~clicker( ) = default; | ||
clicker( ) = default; | ||
}; | ||
|
||
inline auto g_clicker = std::make_unique<clicker>( ); |
Oops, something went wrong.