Skip to content

Commit

Permalink
Clicker is fixed. New stuff coming soon
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Nov 30, 2021
1 parent b2fbc3f commit fd89657
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 109 deletions.
21 changes: 9 additions & 12 deletions clicker/clicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// TODO: Fix clicker
void c_clicker::init()
{
// Get rid of the inifite loop
while ( true )
{
if ( !this->m_is_right_clicking || !this->m_is_left_clicking )
Expand All @@ -12,24 +13,21 @@ void c_clicker::init()
vars::key::clicker_enabled.i_mode = config.clicker.i_key_type;
vars::key::clicker_enabled.i_key = config.clicker.i_clicker_key;

static auto first_click = true;
if ( vars::key::clicker_enabled.get() )
{
if ( focus::window_think() && focus::cursor_think() && !focus::is_self_focused() )
if ( focus::window_think() && focus::cursor_think() )
{
// left
//
this->m_is_left_clicking = ( config.clicker.b_enable_left_clicker && vars::key::left_mouse.get() && !vars::key::right_mouse.b_is_down);
this->m_is_left_clicking = ( config.clicker.b_enable_left_clicker && vars::key::is_left_down );

if ( this->m_is_left_clicking )
this->send_click(input::mouse_button_t::left, config.clicker.f_left_cps, first_click );
this->send_click(input::mouse_button_t::left, config.clicker.f_left_cps, vars::key::l_is_first_click );

// right
//
this->m_is_right_clicking = ( config.clicker.b_enable_right_clicker && vars::key::right_mouse.get());
this->m_is_right_clicking = ( config.clicker.b_enable_right_clicker && vars::key::is_right_down);

if ( this->m_is_right_clicking )
this->send_click(input::mouse_button_t::right, config.clicker.f_right_cps, first_click );
this->send_click(input::mouse_button_t::right, config.clicker.f_right_cps, vars::key::r_is_first_click );
}
}
}
Expand All @@ -50,7 +48,6 @@ void c_clicker::send_click(input::mouse_button_t b_button, float f_cps, bool& b_
if ( !config.clicker.b_enable_blatant )
this->m_delay += rng::random_real<float>( -config.clicker.f_default_timer_randomization, config.clicker.f_default_timer_randomization );

// TODO: Fudeu!
if ( b_is_first_click )
{
sleep( this->m_delay );
Expand Down Expand Up @@ -100,15 +97,15 @@ void c_clicker::update_thread()
{
log_debug( "Update %.3fms", rate );

// ~ persistence
// persistence
if ( config.clicker.b_enable_persistence )
m_random = rng::random_real<float>( -config.clicker.f_persistence_value, config.clicker.f_persistence_value );

// ~ cps drops
// cps drops
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;

// ~ cps spikes
// cps spikes
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;

Expand Down
1 change: 1 addition & 0 deletions clicker/clicker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="menu.cpp" />
<ClCompile Include="threads.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="clicker.hpp" />
Expand Down
13 changes: 8 additions & 5 deletions clicker/clicker.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Filter>menu</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>utils\pch</Filter>
<Filter>utils\precompiled</Filter>
</ClCompile>
<ClCompile Include="imgui\imgui_impl_dx9.cpp">
<Filter>utils\imgui\impl\dx9</Filter>
Expand All @@ -35,6 +35,9 @@
<ClCompile Include="imgui\imgui_widgets.cpp">
<Filter>utils\imgui</Filter>
</ClCompile>
<ClCompile Include="threads.cpp">
<Filter>utils\threads</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="archivex.hpp">
Expand All @@ -59,7 +62,7 @@
<Filter>utils\vars</Filter>
</ClInclude>
<ClInclude Include="pch.hpp">
<Filter>utils\pch</Filter>
<Filter>utils\precompiled</Filter>
</ClInclude>
<ClInclude Include="imgui\imgui_impl_dx9.h">
<Filter>utils\imgui\impl\dx9</Filter>
Expand Down Expand Up @@ -129,9 +132,6 @@
<Filter Include="utils\imgui\impl\fonts">
<UniqueIdentifier>{e03d8ee1-45d8-48e9-908e-5068534f2c83}</UniqueIdentifier>
</Filter>
<Filter Include="utils\pch">
<UniqueIdentifier>{4b318143-ea30-4b46-875b-edfdf4ad9267}</UniqueIdentifier>
</Filter>
<Filter Include="utils\utils">
<UniqueIdentifier>{40cd9742-07b4-40cf-b1be-d3baf0050cf2}</UniqueIdentifier>
</Filter>
Expand All @@ -147,5 +147,8 @@
<Filter Include="utils\imgui\stb">
<UniqueIdentifier>{64418ae5-488a-44f0-aa10-d31c2dc334ad}</UniqueIdentifier>
</Filter>
<Filter Include="utils\precompiled">
<UniqueIdentifier>{4b318143-ea30-4b46-875b-edfdf4ad9267}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
14 changes: 9 additions & 5 deletions clicker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd )
{
std::atexit( [] { threads::hooks::unhook(); } );
std::atexit( [] {
// Dispose stuff
threads::destroy();
} );

std::srand( std::time( nullptr ) );

// TODO: Custom config folder
config.run( "clicker" );

std::vector<std::pair<std::function<void()>, std::string>> functions = {
{ threads::clicker::spawn, "clicker" },
{ threads::randomization::spawn, "clicker randomization" },
{ threads::hooks::spawn, "hooking" }
{threads::spawn_hooks, "input hooks"},
{threads::spawn_rand, "randomization"},
{threads::spawn_clicker, "clicker"}
};

for ( auto& [func, name] : functions )
std::thread( func ).detach();

log_debug( "Main loop started..." );
log_debug( "Init menu" );
if ( !g_menu.initialize( 550, 350 ) )
{
log_err( "Failed to create DX9 device!" );
Expand Down
4 changes: 2 additions & 2 deletions clicker/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height )
ImGui::Separator();
ImGui::Text( "Clicks this session: %d", vars::stats::i_clicks_this_session );
ImGui::Text( "Average CPS: %.2f", vars::stats::f_average_cps );
ImGui::Text( "Is left button down: %s", vars::key::left_mouse.get() ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is right button down: %s", vars::key::right_mouse.get() ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is left button down: %s", vars::key::is_left_down ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is right button down: %s", vars::key::is_right_down ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is hotkey toggled: %s", vars::key::clicker_enabled.get() ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is window focused: %s", focus::window_think() ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is cursor visible: %s", focus::is_cursor_visible() ? ICON_FA_CHECK : ICON_FA_TIMES );
Expand Down
101 changes: 101 additions & 0 deletions clicker/threads.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "pch.hpp"

#include "threads.hpp"

DWORD WINAPI threads::spawn_hooks()
{
oLowLevelKeyboardProc = SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, nullptr, 0 );
if ( !oLowLevelKeyboardProc )
{
// Failed to setup WH_KEYBOARD_LL
return EXIT_SUCCESS;
}

oLowLevelMouseProc = SetWindowsHookEx( WH_MOUSE_LL, LowLevelMouseProc, nullptr, 0 );
if ( !oLowLevelMouseProc )
{
// Failed to setup WH_MOUSE_LL
return EXIT_SUCCESS;
}

MSG msg {};
ZeroMemory( &msg, sizeof( msg ) );

while ( msg.message != WM_QUIT )
{
if ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
continue;
}

WaitMessage();
}

return EXIT_SUCCESS;
}

LRESULT CALLBACK threads::LowLevelMouseProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if ( nCode == HC_ACTION )
{
auto mi = *( (MSLLHOOKSTRUCT*) lParam );

switch ( wParam )
{
case WM_LBUTTONDOWN:
vars::key::l_is_first_click = true;
vars::key::is_left_down = true;
break;
case WM_LBUTTONUP:
vars::key::is_left_down = false;
break;
case WM_MOUSEMOVE: break;
case WM_MOUSEWHEEL: break;
case WM_MOUSEHWHEEL: break;
case WM_RBUTTONDOWN:
vars::key::r_is_first_click = true;
vars::key::is_right_down = true;
break;
case WM_RBUTTONUP:
vars::key::is_right_down = false;
break;
}
}

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

LRESULT CALLBACK threads::LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if ( nCode == HC_ACTION )
{
auto mi = *( (KBDLLHOOKSTRUCT*) lParam );

switch ( wParam )
{
case WM_KEYDOWN:
if ( focus::window_think() )
{
if ( mi.vkCode == 69 /* E */ )
vars::key::b_inventory_opened = !vars::key::b_inventory_opened;

if ( mi.vkCode == VK_ESCAPE )
vars::key::b_inventory_opened = false;
}
break;
case WM_SYSKEYDOWN: break;
case WM_KEYUP: break;
case WM_SYSKEYUP: break;
}
}

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

void threads::destroy()
{
UnhookWindowsHookEx( oLowLevelMouseProc );
UnhookWindowsHookEx( oLowLevelKeyboardProc );
}
67 changes: 9 additions & 58 deletions clicker/threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,16 @@

namespace threads
{
namespace clicker
{
inline void spawn()
{
g_clicker->init();
}
}
// Find a better way to sort this out
inline void spawn_clicker() { g_clicker->init(); }
inline void spawn_rand() { g_clicker->update_thread(); }

namespace randomization
{
inline void spawn()
{
g_clicker->update_thread();
}
}
inline HHOOK oLowLevelMouseProc = nullptr;
inline HHOOK oLowLevelKeyboardProc = nullptr;

namespace hooks
{
inline HHOOK h_hook;
extern LRESULT CALLBACK LowLevelMouseProc( int nCode, WPARAM wParam, LPARAM lParam );
extern LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );

static LRESULT CALLBACK keyboard_callback( int nCode, WPARAM wParam, LPARAM lParam )
{
static auto* k_hook = (KBDLLHOOKSTRUCT*) ( lParam );

if ( wParam == WM_KEYDOWN && nCode == HC_ACTION && ( wParam >= WM_KEYFIRST ) && ( wParam <= WM_KEYLAST ) )
{
if ( focus::window_think() )
{
if ( k_hook->vkCode == 69 /* E */ )
vars::key::b_inventory_opened = !vars::key::b_inventory_opened;

if ( k_hook->vkCode == VK_ESCAPE )
vars::key::b_inventory_opened = false;
}
}

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

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

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

inline void unhook()
{
UnhookWindowsHookEx( h_hook );
}
}
void destroy();
DWORD WINAPI spawn_hooks();
}
Loading

0 comments on commit fd89657

Please sign in to comment.