Skip to content

Commit

Permalink
new clicker algorithm
Browse files Browse the repository at this point in the history
my mind is tired
  • Loading branch information
felix committed Feb 18, 2021
1 parent 11dc5e8 commit 2baed16
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 268 deletions.
11 changes: 6 additions & 5 deletions clicker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<ClInclude Include="def\includes.hpp" />
<ClInclude Include="def\scanner\scanner.hpp" />
<ClInclude Include="def\utils\util.hpp" />
<ClInclude Include="def\utils\vars.hpp" />
<ClInclude Include="def\vars.hpp" />
<ClInclude Include="menu\menu.hpp" />
<ClInclude Include="mouse\mouse.hpp" />
</ItemGroup>
Expand Down Expand Up @@ -115,7 +115,7 @@
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level1</WarningLevel>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
Expand All @@ -131,7 +131,7 @@
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<GenerateMapFile>true</GenerateMapFile>
</Link>
</ItemDefinitionGroup>
Expand All @@ -148,16 +148,17 @@
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>d3d9.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<AdditionalOptions>/DEBUG:NONE /EMITPOGOPHASEINFO %(AdditionalOptions)</AdditionalOptions>
<GenerateMapFile>true</GenerateMapFile>
<GenerateMapFile>false</GenerateMapFile>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
6 changes: 3 additions & 3 deletions clicker.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
<ClInclude Include="def\utils\util.hpp">
<Filter>def\utils</Filter>
</ClInclude>
<ClInclude Include="def\utils\vars.hpp">
<Filter>def\utils</Filter>
</ClInclude>
<ClInclude Include="def\imgui\fonts\font_definitions.hpp">
<Filter>def\include\imgui\fonts</Filter>
</ClInclude>
Expand Down Expand Up @@ -113,5 +110,8 @@
<Filter>menu</Filter>
</ClInclude>
<ClInclude Include="mouse\mouse.hpp" />
<ClInclude Include="def\vars.hpp">
<Filter>def\utils</Filter>
</ClInclude>
</ItemGroup>
</Project>
149 changes: 84 additions & 65 deletions clicker/clicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,97 @@ void clicker::work( )
{
while ( true )
{
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
// Please PR if you found a better way to do this. CPU Usage is high without.
sleep( 1 );

if ( config.clicker.hotkey_enabled && util::get_active_window_title( ).find( config.clicker.window_title ) != std::string::npos )
if ( vars::b_hotkey_enabled && util::get_active_window_title( ).find( config.clicker.window_title ) != std::string::npos ) // if hotkey is enabled, and selected window is active
{
if ( config.clicker.left_enabled && vars::b_l_mouse_down )
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.
{
if ( vars::b_l_first_click )
{
std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) );
g_mouse->left_up( );
vars::b_l_first_click = false;
}
else
{
// Old meth logic, will change to something better later ;c
auto random_delay = util::random_int
(
1000 / ( config.clicker.l_min_cps + config.clicker.l_max_cps * ( int ) 0.2 ),
1000 / ( config.clicker.l_min_cps + config.clicker.l_max_cps * ( int ) 0.48 )
);

if ( ( std::clock( ) - vars::l_last_click_time ) > random_delay )
{
g_mouse->left_down( );
vars::l_last_click_time = std::clock( );

if ( config.clicker.blockhit && config.clicker.blockhit_chance > 0 && std::rand( ) % ( 100 / config.clicker.blockhit_chance ) == 0 )
g_mouse->right_down( );

std::this_thread::sleep_for( std::chrono::milliseconds( util::random_int( 30, 50 ) ) );
g_mouse->left_up( );

if ( config.clicker.blockhit )
g_mouse->right_up( );

vars::i_clicks_this_session++;

_log( LDEBUG, "l_click random_delay %d clock %d last click time %d", random_delay, std::clock( ), vars::l_last_click_time );
}
}
g_clicker->click( LBUTTON, config.clicker.l_cps, &vars::b_l_first_click ); // click!
}

if ( config.clicker.right_enabled && vars::b_r_mouse_down )
if ( config.clicker.right_enabled && vars::b_r_mouse_down ) // if right is enabled, right mouse is down start clicking.
{
if ( vars::b_r_first_click )
{
std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) );
g_mouse->right_up( );
vars::b_r_first_click = false;
}
else
{
auto random_delay = util::random_int
(
1000 / ( config.clicker.r_min_cps + config.clicker.r_max_cps * ( int ) 0.2 ),
1000 / ( config.clicker.r_min_cps + config.clicker.r_max_cps * ( int ) 0.48 )
);

if ( ( std::clock( ) - vars::l_last_click_time ) > random_delay )
{
g_mouse->right_down( );
vars::l_last_click_time = std::clock( );

std::this_thread::sleep_for( std::chrono::milliseconds( util::random_int( 30, 50 ) ) );
g_mouse->right_up( );

vars::i_clicks_this_session++;

_log( LDEBUG, "r_click random_delay %d clock %d last click time %d", random_delay, std::clock( ), vars::l_last_click_time );
}
}
g_clicker->click( RBUTTON, config.clicker.r_cps, &vars::b_r_first_click ); // click!
}
}
}
}

void clicker::click( bool b_button, int i_cps, bool *b_first_click )
{
if ( i_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( -( i_cps / 5 ), ( i_cps / 5 ) ); // random int between negative 1 / 5 of our cps and 1 / 5 of our cps
i_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.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 / i_cps ) / 2; // delay is half because we'll be calling it two times, on mouse down and up.

if ( *b_first_click ) // if it's our first click, delay and send a up input to our function.
{
sleep( delay );
g_clicker->click_mouse( INPUT_UP, b_button );
*b_first_click = false;
_log( LDEBUG, "[ clicker ] first click" );
}

sleep( delay ); // sleep on input down

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_blockhitted = true; // set blockhitted bool to true
g_clicker->click_mouse( INPUT_DOWN, RBUTTON ); // right click
}

g_clicker->click_mouse( INPUT_DOWN, b_button ); // the actual input down call

sleep( delay ); // sleep on input up

if ( if_blockhitted ) // check if blockhitted bool was true
{
g_clicker->click_mouse( INPUT_UP, RBUTTON ); // right click up
if_blockhitted = false; // set blockhitted variable back to false.
}

g_clicker->click_mouse( INPUT_UP, b_button ); // the actual input up call

_log( LDEBUG, "[ clicker ] i_cps: %d delay %d", i_cps, delay );
}

void clicker::click_mouse( bool down, bool button ) // le button
{
if ( down ) // if our mouse is down
{
if ( button ) // set left down
g_mouse->left_down( );
else // set right down
g_mouse->right_down( );
}
else // if our mouse isn't down
{
if ( button ) // set left up
g_mouse->left_up( );
else // set right up
g_mouse->right_up( );
}

vars::i_clicks_this_session += 1;
}
15 changes: 15 additions & 0 deletions clicker/clicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
#include "../def/includes.hpp"
#include "../mouse/mouse.hpp"

#define sleep(ms) (std::this_thread::sleep_for(std::chrono::milliseconds(ms)));

class clicker
{
public:
void work( );
void click( bool b_button, int i_cps, bool *b_first_click );
void click_mouse( bool down, bool button );

~clicker( ) = default;
clicker( ) = default;

private:
int delay = 0; // delay for the sleep
int random = 0; // random cps
bool if_blockhitted = false;

bool RBUTTON = false;
bool LBUTTON = true;

bool INPUT_UP = false;
bool INPUT_DOWN = true;
};

inline auto g_clicker = std::make_unique<clicker>( );
14 changes: 8 additions & 6 deletions def/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class c_config final
bool left_enabled { false };
bool right_enabled { false };

bool hotkey_enabled { false };
bool blockhit { false };
bool blatant { false };

bool delete_file_on_exit { false };
bool clear_string_on_exit { false };
Expand All @@ -36,13 +36,15 @@ class c_config final
int activation_type { 0 };
int version_type { 0 };

int l_min_cps { 0 };
int l_max_cps { 0 };

int r_min_cps { 0 };
int r_max_cps { 0 };
int l_cps { 0 };
int r_cps { 0 };

int blockhit_chance { 0 };
int cps_spike_chance_val { 0 };
int cps_drop_chance_val { 0 };

bool cps_spike_chance { false };
bool cps_drop_chance { false };

std::string window_title;
}
Expand Down
2 changes: 1 addition & 1 deletion def/includes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
// header files

#include "config/config.hpp"
#include "utils/vars.hpp"
#include "utils/util.hpp"
#include "vars.hpp"
#include "console.hpp"
8 changes: 4 additions & 4 deletions def/scanner/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::vector<size_t> scanner::scan_unicode( std::string string )
if ( y == ___length - 1 )
{
_mem_locations.push_back( this->_address + x * 2 );
_log( LDEBUG, "Read unicode: 0x%x", _address + x * 2 );
_log( LDEBUG, "[ string_scan ] Read unicode: 0x%x", _address + x * 2 );
}
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ std::vector<size_t> scanner::scan_multibyte( std::string string )
if ( y == ___length - 1 )
{
_mem_locations.push_back( this->_address + x );
_log( LDEBUG, "Read multibyte: 0x%x", _address + x );
_log( LDEBUG, "[ string_scan ] Read multibyte: 0x%x", _address + x );
}
}
}
Expand All @@ -100,7 +100,7 @@ void scanner::rewrite_unicode( size_t addr, std::string str )
ZwWriteVirtualMemory( this->p_handle, ( LPVOID ) ( addr + x * 2 ), &str[ x ], 1, nullptr );
}

_log( LDEBUG, "Write unicode: 0x%x", addr );
_log( LDEBUG, "[ string_scan ] Write unicode: 0x%x", addr );
}


Expand All @@ -111,5 +111,5 @@ void scanner::rewrite_multibyte( size_t addr, std::string str )
ZwWriteVirtualMemory( this->p_handle, ( LPVOID ) ( addr + x ), &str[ x ], 1, nullptr );
}

_log( LDEBUG, "Write multibyte: 0x%x", addr );
_log( LDEBUG, "[ string_scan ] Write multibyte: 0x%x", addr );
}
19 changes: 1 addition & 18 deletions def/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ std::string util::get_active_window_title( )
return title;
}

std::string util::get_serial( )
{
DWORD disk_serial;
GetVolumeInformationA( R"(C:)", nullptr, 0, &disk_serial, nullptr, nullptr, nullptr, 0 );

return std::to_string( disk_serial );
}

DWORD util::get_process_id_by_name( const std::string &str_proc )
{
if ( str_proc.empty( ) )
Expand Down Expand Up @@ -79,18 +71,9 @@ void util::self_delete( std::string file_path )
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };

StringCbPrintf( szCmd, 2 * MAX_PATH, "cmd.exe /C ping 1.1.1.1 -n 5 > nul & del /f /q \"%s\"", file_path.c_str( ) );
StringCbPrintf( szCmd, 2 * MAX_PATH, "cmd.exe /C timeout /t 5 > nul & del /f /q \"%s\"", file_path.c_str( ) );
CreateProcess( NULL, szCmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi );

CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
}

template<typename ... args>
static std::string util::format( const std::string &format, args ... arg )
{
const size_t size = std::snprintf( nullptr, 0, format.c_str( ), arg ... ) + 1;
std::unique_ptr<char[]> buf( new char[ size ] );
std::snprintf( buf.get( ), size, format.c_str( ), arg ... );
return std::string( buf.get( ), buf.get( ) + size - 1 );
}
5 changes: 1 addition & 4 deletions def/utils/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
#include <strsafe.h>
#include <tchar.h>

#include "vars.hpp"
#include "../vars.hpp"

namespace util
{
std::string to_lower( std::string str );
std::wstring string_to_wstring( std::string str );
int random_int( int i_start, int i_end );
std::string get_active_window_title( );
std::string get_serial( );
DWORD get_process_id_by_name( const std::string &str_proc );
void self_delete( std::string file_path );
template<typename ...args>
static std::string format( const std::string &format, args ...arg );
}
Loading

0 comments on commit 2baed16

Please sign in to comment.