Skip to content

Commit

Permalink
Few things, more customization to clicker
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Jun 9, 2021
1 parent 7f3932f commit 750abc4
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 142 deletions.
58 changes: 28 additions & 30 deletions clicker/clicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,57 @@ auto c_clicker::init() -> void
{
// ~ left
if ( config.clicker.b_enable_left_clicker && var::key::left_clicker_down.get() )
{
send_click( buttons::LEFT, config.clicker.f_left_cps, first_click );
m_is_left_clicking = true;
}
else
{
m_is_left_clicking = false;
}

if ( m_is_left_clicking )
send_click( buttons::LEFT, config.clicker.f_left_cps, first_click );

// ~ right
if ( config.clicker.b_enable_right_clicker && var::key::right_clicker_down.get() )
{
send_click( buttons::RIGHT, config.clicker.f_right_cps, first_click );
m_is_right_clicking = true;
}
else
{
m_is_right_clicking = false;
}

if ( m_is_right_clicking )
send_click( buttons::RIGHT, config.clicker.f_right_cps, first_click );
}
}
}
}

auto c_clicker::send_click( bool button, float cps, bool& is_first_click ) -> void
auto c_clicker::send_click( bool b_button, float f_cps, bool& b_is_first_click ) -> void
{
const auto start = std::chrono::high_resolution_clock::now();

// ~~ return if the cps is 0
if ( cps <= 0.f )
if ( f_cps <= 0 )
return;

/* ~~ If blatant is not enabled and the persistent values are enabled, apply persistent randomization, this applies to drop and spike chance too. */
if ( !config.clicker.b_enable_blatant )
cps += m_random;
f_cps += m_random;

/* ~~ How the delay works is pretty simple, basically the delay is 1000 divided by the cps (because we're working with milliseconds)
* ~~ divided by 2 because the delay will be called both on input down and input up! */
m_delay = ( 1000.f / cps ) / 2.f;
m_delay = ( 1000 / f_cps ) / 2;

// ~~ if blatant is not enabled apply just a little randomization
if ( !config.clicker.b_enable_blatant )
m_delay += util::random::number( -10.f, 10.f );
m_delay += util::random::number( -config.clicker.f_default_timer_randomization, config.clicker.f_default_timer_randomization );

// ~~ if it's our first click, lets wait for the delay, send the input to up and set it back to false.
if ( is_first_click )
if ( b_is_first_click )
{
sleep( m_delay );
send_mouse_input( input_types::UP, button );
is_first_click = false;
send_mouse_input( input_types::UP, b_button );
b_is_first_click = false;
}

// ~~ sleep and input down
sleep( m_delay );
send_mouse_input( input_types::DOWN, button );
send_mouse_input( input_types::DOWN, b_button );

/* ~~ Blockhit
* ~~ If we have blockhit enabled, the chance is higher than 0 and we hit the randomization chance, send a right input down. */
Expand All @@ -85,7 +81,7 @@ auto c_clicker::send_click( bool button, float cps, bool& is_first_click ) -> vo
}

sleep( m_delay );
send_mouse_input( input_types::UP, button );
send_mouse_input( input_types::UP, b_button );

// ~~ if we blockhitted, send up input corresponding to the before down input and set variable back to false.
if ( m_blockhitted )
Expand All @@ -99,10 +95,10 @@ auto c_clicker::send_click( bool button, float cps, bool& is_first_click ) -> vo
const auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed = end - start;

log_debug( "cps: [ %.3f ], delay: [ %.3fms ], button: [ %s ], time elapsed: [ %.3fms ]", cps, m_delay * 2, translate_button( button ).c_str(), elapsed.count() );
log_debug( "cps: [ %.3f ] delay: [ %.3fms ] time elapsed: [ %.3fms ]", f_cps, m_delay * 2, elapsed.count() );
}

auto c_clicker::update_thread( float delay ) -> void
auto c_clicker::update_thread() -> void
{
auto should_update { false };
while ( true )
Expand All @@ -111,25 +107,27 @@ auto c_clicker::update_thread( float delay ) -> void
if ( should_update )
{
// ~~ if persistent values is enabled, apply persistent values!
if ( config.clicker.b_enable_persistency )
m_random = util::random::number( -config.clicker.f_persistency_value, config.clicker.f_persistency_value );
if ( config.clicker.b_enable_persistence )
m_random = util::random::number( -config.clicker.f_persistence_value, config.clicker.f_persistence_value );

// ~~ if drop chance is enabled and the value is higher than 0 and the chance matches, apply it..
if ( config.clicker.b_enable_cps_drops && config.clicker.i_cps_drop_chance > 0 && std::rand() % ( 100 / config.clicker.i_cps_drop_chance ) == 0 )
m_random -= util::random::number( ( config.clicker.f_cps_drop_remove - 1.f ), config.clicker.f_cps_drop_remove );
if ( config.clicker.b_enable_cps_drops &&
config.clicker.i_cps_drop_chance > 0 && ( std::rand() % ( 100 / config.clicker.i_cps_drop_chance ) == 0 ) )
m_random -= config.clicker.f_cps_drop_remove;

// ~~ if spike chance is enabled and the value is higher than 0 and the chance matches, apply it..
if ( config.clicker.b_enable_cps_spikes && config.clicker.i_cps_spike_chance > 0 && std::rand() % ( 100 / config.clicker.i_cps_spike_chance ) == 0 )
m_random += util::random::number( ( config.clicker.f_cps_spike_add - 1.f ), config.clicker.f_cps_spike_add );
if ( config.clicker.b_enable_cps_spikes &&
config.clicker.i_cps_spike_chance > 0 && ( std::rand() % ( 100 / config.clicker.i_cps_spike_chance ) == 0 ) )
m_random += config.clicker.f_cps_spike_add;

// ~~ set it to false so we only set it one time..
should_update = false;
}

auto value = util::random::number( 1.f, delay );
m_persistent_value = util::random::number( config.clicker.f_persistence_update_rate / 2, config.clicker.f_persistence_update_rate );

// ~~ wait for the next update...
std::this_thread::sleep_for( floating_ms( value ) );
std::this_thread::sleep_for( floating_ms( config.clicker.f_persistence_update_rate ) );

// ~~ and start it!...
m_random = {};
Expand Down
127 changes: 62 additions & 65 deletions clicker/clicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,115 +22,112 @@ enum input_types: bool
class c_clicker
{
private:
auto send_click( bool button, float cps, bool& is_first_click ) -> void;
auto send_click( bool b_button, float f_cps, bool& b_is_first_click ) -> void;

auto precise_timer_sleep( double seconds ) -> void
auto precise_timer_sleep( double f_seconds ) -> void
{
while ( seconds > 5e-3 )
while ( f_seconds > 5e-3 )
{
auto start = std::chrono::high_resolution_clock::now();
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
auto end = std::chrono::high_resolution_clock::now();

auto observed = ( end - start ).count() / 1e9;
seconds -= observed;
f_seconds -= observed;
}

/* ~~ spin lock */
auto start = std::chrono::high_resolution_clock::now();
while ( ( std::chrono::high_resolution_clock::now() - start ).count() / 1e9 < seconds );
while ( ( std::chrono::high_resolution_clock::now() - start ).count() / 1e9 < f_seconds );
}

auto translate_button( bool button ) -> std::string
{
switch ( button )
{
case 0:
return "right mouse button";
case 1:
return "left mouse button";
}

return {};
}

void send_mouse_input( bool down, bool button )
void send_mouse_input( bool b_down, bool b_button )
{
POINT pos;
GetCursorPos( &pos );

down ? ( button ? PostMessage( GetForegroundWindow(), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM( pos.x, pos.y ) ) :
b_down ? ( b_button ? PostMessage( GetForegroundWindow(), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM( pos.x, pos.y ) ) :
PostMessage( GetForegroundWindow(), WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM( pos.x, pos.y ) ) ) :
( button ? PostMessage( GetForegroundWindow(), WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM( pos.x, pos.y ) ) :
( b_button ? PostMessage( GetForegroundWindow(), WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM( pos.x, pos.y ) ) :
PostMessage( GetForegroundWindow(), WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM( pos.x, pos.y ) ) );
}

float m_delay = 0.f;
float m_random = 0.f;
float m_delay { 0.f };
float m_random { 0.f };

bool m_blockhitted { false };

bool m_blockhitted = false;
bool m_is_left_clicking { false };
bool m_is_right_clicking { false };

float m_persistent_value { 0.f };

bool m_is_left_clicking = false;
bool m_is_right_clicking = false;
public:
void init();
void update_thread( float delay );
void update_thread();

~c_clicker() = default;
c_clicker() = default;
};

inline auto clicker = c_clicker();

inline auto initialize_clicker_thread() -> void
{
clicker.init();
}

inline auto initialize_clicker_randomization_thread() -> void
namespace thread
{
clicker.update_thread( util::random::number( 1500, 3500 ) );
}
namespace click
{
inline auto init() -> void
{
clicker.init();
}

namespace hooking
{
inline HHOOK h_hook;
inline auto randomization() -> void
{
clicker.update_thread();
}
}

static LRESULT CALLBACK keyboard_callback( int nCode, WPARAM wParam, LPARAM lParam )
// had to
namespace hooking
{
static auto* k_hook = reinterpret_cast<KBDLLHOOKSTRUCT*>( lParam );
inline HHOOK h_hook;

if ( wParam == WM_KEYDOWN && nCode == HC_ACTION && ( wParam >= WM_KEYFIRST ) && ( wParam <= WM_KEYLAST ) )
static LRESULT CALLBACK keyboard_callback( int nCode, WPARAM wParam, LPARAM lParam )
{
if ( util::extra::is_window_focused() )
{
if ( k_hook->vkCode == 69 )
var::key::inventory_opened = !var::key::inventory_opened;
static auto* k_hook = reinterpret_cast<KBDLLHOOKSTRUCT*>( lParam );

if ( k_hook->vkCode == VK_ESCAPE )
var::key::inventory_opened = false;
if ( wParam == WM_KEYDOWN && nCode == HC_ACTION && ( wParam >= WM_KEYFIRST ) && ( wParam <= WM_KEYLAST ) )
{
if ( util::extra::is_window_focused() )
{
if ( k_hook->vkCode == 69 )
var::key::inventory_opened = !var::key::inventory_opened;

if ( k_hook->vkCode == VK_ESCAPE )
var::key::inventory_opened = false;
}
}
}

return CallNextHookEx( h_hook, nCode, wParam, lParam );
}
return CallNextHookEx( h_hook, nCode, wParam, lParam );
}

inline auto spawn() -> void
{
h_hook = SetWindowsHookEx(
WH_KEYBOARD_LL,
keyboard_callback,
nullptr,
NULL
);

MSG msg;
while ( GetMessage( &msg, nullptr, 0, 0 ) )
inline auto spawn() -> void
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
h_hook = SetWindowsHookEx(
WH_KEYBOARD_LL,
keyboard_callback,
nullptr,
NULL
);

MSG msg;
while ( GetMessage( &msg, nullptr, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

UnhookWindowsHookEx( h_hook );
UnhookWindowsHookEx( h_hook );
}
}
}
20 changes: 12 additions & 8 deletions clicker/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class c_config
bool b_enable_left_clicker { false };
bool b_enable_right_clicker { false };

float f_left_cps { 1.f };
float f_right_cps { 1.f };
float f_left_cps { 11.5f };
float f_right_cps { 11.5f };

bool b_enable_blockhit { false };
int i_blockhit_chance { 5 };
Expand All @@ -43,14 +43,18 @@ class c_config

int i_hide_window_key { 0 };

bool b_enable_advanced_options { false };

bool b_enable_persistency { true };
float f_persistency_value { 2.f };
bool b_enable_persistence { false };
float f_persistence_value { 2.5f };

int i_cps_spike_chance { 15 };
float f_cps_spike_add { 3.5f };
float f_persistence_update_rate { 2000.f };
float f_default_timer_randomization { 5.f };

int i_cps_drop_chance { 10 };
int i_cps_spike_chance { 5 };
float f_cps_spike_add { 2.5f };

int i_cps_drop_chance { 15 };
float f_cps_drop_remove { 3.5f };

bool b_enable_cps_spikes { false };
Expand All @@ -64,7 +68,7 @@ class c_config
float f_color_accent_active[4] { 0.40f, 0.39f, 0.90f, 1.00f };
float f_color_accent_text[4] { 0.94f, 0.94f, 0.94f, 1.00f };

std::string window_title;
std::string str_window_title;
} clicker;
};

Expand Down
Loading

0 comments on commit 750abc4

Please sign in to comment.