Skip to content

Commit

Permalink
New clicker randomization, new features.
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Mar 16, 2021
1 parent 24abaf9 commit aed6f92
Show file tree
Hide file tree
Showing 46 changed files with 1,104 additions and 699 deletions.
2 changes: 1 addition & 1 deletion clicker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clicker", "clicker.vcxproj", "{25C13AC6-6ACC-42C9-8422-559D75DE0A86}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clicker", "clicker/clicker.vcxproj", "{25C13AC6-6ACC-42C9-8422-559D75DE0A86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
117 changes: 0 additions & 117 deletions clicker.vcxproj.filters

This file was deleted.

File renamed without changes.
121 changes: 79 additions & 42 deletions clicker/clicker.cpp
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;
}
60 changes: 46 additions & 14 deletions clicker/clicker.hpp
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>( );
Loading

0 comments on commit aed6f92

Please sign in to comment.