Skip to content

Commit

Permalink
modern code and more other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Jun 7, 2021
1 parent 23467a9 commit 1444bce
Show file tree
Hide file tree
Showing 21 changed files with 690 additions and 1,435 deletions.
12 changes: 6 additions & 6 deletions clicker/archivex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ template <typename TS>
class archivex final
{
private:
TS &stream;
TS& stream;
public:
constexpr explicit archivex( TS &stream ): stream { stream } {}
constexpr explicit archivex( TS& stream ): stream{ stream } {}

template <typename T>
constexpr const auto &operator<<( const T &item ) const
constexpr const auto& operator<<( const T& item ) const
{
stream.write( reinterpret_cast<const char *>(&item), sizeof( item ) );
stream.write( reinterpret_cast<const char*>( &item ), sizeof( item ) );
return *this;
}

template <typename T>
constexpr const auto &operator>>( T &item ) const
constexpr const auto& operator>>( T& item ) const
{
stream.read( reinterpret_cast<char *>(&item), sizeof( item ) );
stream.read( reinterpret_cast<char*>( &item ), sizeof( item ) );
return *this;
}
};
129 changes: 67 additions & 62 deletions clicker/clicker.cpp
Original file line number Diff line number Diff line change
@@ -1,133 +1,138 @@
#include "pch.hpp"
#include "clicker.hpp"

void clicker::init()
auto c_clicker::init() -> void
{
/* ~~ main thread loop */
while (true)
while ( true )
{
/* ~~ sleep for saving cpu cycles if we're not clicking to accurately click */
if (!is_right_clicking || !is_left_clicking)
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
if ( !m_is_right_clicking || !m_is_left_clicking )
std::this_thread::sleep_for( 1ms );

/* ~~ Changes these variables every time so if we change anything it works */
hooks::keybinds::clicker.i_mode = config.clicker.activation_type;
hooks::keybinds::clicker.i_key = config.clicker.clicker_key;
vars::key::is_hotkey_enabled = hooks::keybinds::clicker.get();
var::key::clicker_enabled.i_mode = config.clicker.i_key_type;
var::key::clicker_enabled.i_key = config.clicker.i_clicker_key;

vars::window::is_focused = utils::other::focused_situation();
vars::window::is_cursor_visible = utils::other::get_cursor_status();
static bool first_click = true;

if (vars::key::is_hotkey_enabled)
if ( var::key::clicker_enabled.get() )
{
if (vars::window::is_focused && vars::window::is_cursor_visible && !utils::other::application_focused())
if ( util::extra::is_window_focused() && util::extra::is_cursor_visible() && !util::extra::is_application_focused() )
{
/* ~~ Left clicker */
if (config.clicker.left_clicker_enabled && vars::mouse::left_mouse_down)
// ~ left
if ( config.clicker.b_enable_left_clicker && var::key::left_clicker_down.get() )
{
send_click( left_mouse_button, config.clicker.left_cps, vars::mouse::left_first_click );
is_left_clicking = true;
send_click( buttons::LEFT, config.clicker.f_left_cps, first_click );
m_is_left_clicking = true;
}
else
is_left_clicking = false;
{
m_is_left_clicking = false;
}

/* ~~ Right clicker */
if (config.clicker.right_clicker_enabled && vars::mouse::right_mouse_down)
// ~ right
if ( config.clicker.b_enable_right_clicker && var::key::right_clicker_down.get() )
{
send_click( right_mouse_button, config.clicker.right_cps, vars::mouse::right_first_click );
is_right_clicking = true;
send_click( buttons::RIGHT, config.clicker.f_right_cps, first_click );
m_is_right_clicking = true;
}
else
is_right_clicking = false;
{
m_is_right_clicking = false;
}
}
}
}
}

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

/* ~~ Return if the cps is 0 */
if (cps <= 0.f)
if ( cps <= 0.f )
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.blatant_enabled)
cps += random;
if ( !config.clicker.b_enable_blatant )
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! */
delay = (1000.f / cps) / 2.f;
m_delay = ( 1000.f / cps ) / 2.f;

/* ~~ If blatant is not enabled apply just a little randomization */
if (!config.clicker.blatant_enabled)
delay += utils::floating::random( -5.f, 5.f );
if ( !config.clicker.b_enable_blatant )
m_delay += util::random::number( -10.f, 10.f );

/* ~~ 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 ( is_first_click )
{
sleep_precisely( delay );
send_mouse_input( input_up, button );
sleep( m_delay );
send_mouse_input( input_types::UP, button );
is_first_click = false;
}

/* ~~ Sleep and input down */
sleep_precisely( delay );
send_mouse_input( input_down, button );
sleep( m_delay );
send_mouse_input( input_types::DOWN, button );

/* ~~ Blockhit
* ~~ If we have blockhit enabled, the chance is higher than 0 and we hit the randomization chance, send a right input down. */
if (config.clicker.blockhit_enabled && config.clicker.blockhit_chance > 0
&& std::rand() % (100 / config.clicker.blockhit_chance) == 0)
if ( config.clicker.b_enable_blockhit && config.clicker.i_blockhit_chance > 0
&& std::rand() % ( 100 / config.clicker.i_blockhit_chance ) == 0 )
{
blockhitted = true;
send_mouse_input( input_down, right_mouse_button );
m_blockhitted = true;
send_mouse_input( input_types::DOWN, buttons::RIGHT );
}

sleep_precisely( delay );
send_mouse_input( input_up, button );
sleep( m_delay );
send_mouse_input( input_types::UP, button );

/* ~~ If we blockhitted, send up input corresponding to the before down input and set variable back to false. */
if (blockhitted)
if ( m_blockhitted )
{
send_mouse_input( input_up, right_mouse_button );
blockhitted = false;
send_mouse_input( input_types::UP, buttons::RIGHT );
m_blockhitted = false;
}

log_debug( "cps -> [ %.3f ], delay -> [ %.3fms ], button -> [ %s ]", cps, delay, translate_button( button ).c_str() );
++vars::stats::clicks_this_session;
++var::stats::i_clicks_this_session;

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() );
}

void clicker::update_thread( float delay )
auto c_clicker::update_thread( float delay ) -> void
{
bool should_update { false };
while (true)
auto should_update { false };
while ( true )
{
/* ~~ If we should update. */
if (should_update)
if ( should_update )
{
/* ~~ If persistent values is enabled, apply persistent values! */
if (config.clicker.persistent_values_enabled)
random = utils::floating::random( -config.clicker.default_persistent_randomization, config.clicker.default_persistent_randomization );
if ( config.clicker.b_enable_persistency )
m_random = util::random::number( -config.clicker.f_persistency_value, config.clicker.f_persistency_value );

/* ~~ If drop chance is enabled and the value is higher than 0 and the chance matches, apply it.. */
if (config.clicker.cps_drop_chance && config.clicker.cps_drop_chance_val > 0 && std::rand() % (100 / config.clicker.cps_drop_chance_val) == 0)
random -= utils::floating::random( (config.clicker.cps_drop_chance_value_removal - 1.f), config.clicker.cps_drop_chance_value_removal );
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 spike chance is enabled and the value is higher than 0 and the chance matches, apply it.. */
if (config.clicker.cps_spike_chance && config.clicker.cps_spike_chance_val > 0 && std::rand() % (100 / config.clicker.cps_spike_chance_val) == 0)
random += utils::floating::random( (config.clicker.cps_spike_chance_value_addition - 1.f), config.clicker.cps_spike_chance_value_addition );
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 );

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

auto value = utils::floating::random( 1.f, delay );
// log_debug( "Updating randomization [ %.3fms ] ", value );
auto value = util::random::number( 1.f, delay );

/* ~~ Wait for the next update... */
std::this_thread::sleep_for( fl_ms( value ) );
std::this_thread::sleep_for( floating_ms( value ) );

/* ~~ And start it!... */
random = {};
m_random = {};
should_update = true;
}
}
Loading

0 comments on commit 1444bce

Please sign in to comment.