From 3e4e0199629964f84486275107be3b66b5ffe66b Mon Sep 17 00:00:00 2001 From: felix Date: Tue, 15 Jun 2021 19:21:33 -0300 Subject: [PATCH] cleaned stuff, more performance, cleaner menu --- clicker/clicker.cpp | 92 ++++++++++++++++++--------------- clicker/clicker.hpp | 83 ++++------------------------- clicker/clicker.vcxproj | 1 + clicker/clicker.vcxproj.filters | 6 +++ clicker/config.hpp | 2 +- clicker/main.cpp | 37 ++++++------- clicker/menu.cpp | 91 ++++++++++++++++---------------- clicker/menu.hpp | 5 +- clicker/pch.hpp | 5 +- clicker/threads.hpp | 63 ++++++++++++++++++++++ clicker/utils.hpp | 21 +++++--- clicker/vars.hpp | 3 +- 12 files changed, 211 insertions(+), 198 deletions(-) create mode 100644 clicker/threads.hpp diff --git a/clicker/clicker.cpp b/clicker/clicker.cpp index 1ce196f..5266751 100644 --- a/clicker/clicker.cpp +++ b/clicker/clicker.cpp @@ -8,19 +8,25 @@ void c_clicker::init() if ( !this->m_is_right_clicking || !this->m_is_left_clicking ) std::this_thread::sleep_for( 1ms ); - var::key::clicker_enabled.i_mode = config.clicker.i_key_type; - var::key::clicker_enabled.i_key = config.clicker.i_clicker_key; + vars::key::clicker_enabled.i_mode = config.clicker.i_key_type; + vars::key::clicker_enabled.i_key = config.clicker.i_clicker_key; - static bool first_click = true; - if ( var::key::clicker_enabled.get() ) + static auto first_click = true; + if ( vars::key::clicker_enabled.get() ) { - if ( util::extra::is_window_focused() && util::extra::is_cursor_visible() && !( util::extra::is_application_focused() ) ) + if ( util::extra::is_window_focused() && util::extra::is_cursor_visible() && !util::extra::is_application_focused() ) { - this->m_is_left_clicking = ( config.clicker.b_enable_left_clicker && var::key::left_clicker_down.get() && !var::key::right_clicker_down.get() ); + // left + // + this->m_is_left_clicking = ( config.clicker.b_enable_left_clicker && vars::key::left_clicker_down.get() && !vars::key::right_clicker_down.get() ); + if ( this->m_is_left_clicking ) this->send_click( button_t::left, config.clicker.f_left_cps, first_click ); - this->m_is_right_clicking = ( config.clicker.b_enable_right_clicker && var::key::right_clicker_down.get() ); + // right + // + this->m_is_right_clicking = ( config.clicker.b_enable_right_clicker && vars::key::right_clicker_down.get() ); + if ( this->m_is_right_clicking ) this->send_click( button_t::right, config.clicker.f_right_cps, first_click ); } @@ -32,24 +38,20 @@ void c_clicker::send_click( button_t b_button, float f_cps, bool& b_is_first_cli { const auto start = std::chrono::high_resolution_clock::now(); - // ~~ return if the cps is 0 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 ) f_cps += this->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! */ this->m_delay = ( 1000 / f_cps ) / 2; - // ~~ if blatant is not enabled apply given randomization values if ( !config.clicker.b_enable_blatant ) + { this->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 ( b_is_first_click ) { sleep( this->m_delay ); @@ -57,12 +59,9 @@ void c_clicker::send_click( button_t b_button, float f_cps, bool& b_is_first_cli b_is_first_click = false; } - // ~~ sleep and input down sleep( this->m_delay ); this->send_mouse_input( input_type_t::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. */ if ( config.clicker.b_enable_blockhit && config.clicker.i_blockhit_chance > 0 && std::rand() % ( 100 / config.clicker.i_blockhit_chance ) == 0 ) { @@ -73,14 +72,13 @@ void c_clicker::send_click( button_t b_button, float f_cps, bool& b_is_first_cli sleep( this->m_delay ); this->send_mouse_input( input_type_t::up, b_button ); - // ~~ if we blockhitted, send up input corresponding to the before down input and set variable back to false. if ( this->m_blockhitted ) { send_mouse_input( input_type_t::up, button_t::right ); m_blockhitted = false; } - ++var::stats::i_clicks_this_session; + ++vars::stats::i_clicks_this_session; const auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration elapsed { end - start }; @@ -92,34 +90,42 @@ void c_clicker::update_thread() { while ( true ) { - // ~~ if we should update. - if ( this->m_should_update ) + if ( this->m_is_right_clicking || this->m_is_left_clicking ) { - // ~~ if persistent values is enabled, apply persistent values! - 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 -= 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 += config.clicker.f_cps_spike_add; - - // ~~ set it to false so we only set it one time.. - this->m_should_update = false; - } + auto rate = util::random::number( 0, + config.clicker.f_persistence_update_rate ); - m_persistent_value = util::random::number( config.clicker.f_persistence_update_rate / 2, config.clicker.f_persistence_update_rate ); + if ( this->m_should_update ) + { + log_debug( "update %.3fms", rate ); + + // ~ persistence + if ( config.clicker.b_enable_persistence ) + { + m_random = util::random::number( -config.clicker.f_persistence_value, config.clicker.f_persistence_value ); + } + + // ~ 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 + 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; + } + + this->m_should_update = false; + } - // ~~ wait for the next update... - std::this_thread::sleep_for( floating_ms( config.clicker.f_persistence_update_rate ) ); + sleep( rate ); - // ~~ and start it!... - this->m_random = {}; - this->m_should_update = true; + this->m_random = {}; + this->m_should_update = true; + } } } \ No newline at end of file diff --git a/clicker/clicker.hpp b/clicker/clicker.hpp index bbeeba6..d83aaee 100644 --- a/clicker/clicker.hpp +++ b/clicker/clicker.hpp @@ -1,23 +1,22 @@ #pragma once +// for timeBeginPeriod #include -#pragma comment(lib, "Winmm.lib") +#pragma comment(lib, "winmm.lib") using floating_ms = std::chrono::duration; -enum class button_t: bool +enum button_t: bool { - right = false, - left = true + right, left }; -enum class input_type_t: bool +enum input_type_t: bool { - up = false, - down = true + up, down }; -#define sleep(ms) { timeBeginPeriod(1); clicker.precise_timer_sleep( static_cast( ms / 1000.f ) ); timeEndPeriod(1); } +#define sleep(ms) { timeBeginPeriod(1); g_clicker.precise_timer_sleep( static_cast( ms / 1000 ) ); timeEndPeriod(1); } class c_clicker { @@ -45,9 +44,9 @@ class c_clicker { POINT pos; GetCursorPos( &pos ); - static_cast( i_type ) ? ( static_cast( b_button ) ? PostMessage( GetForegroundWindow(), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM( pos.x, pos.y ) ) : + i_type ? ( b_button ? PostMessage( GetForegroundWindow(), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM( pos.x, pos.y ) ) : PostMessage( GetForegroundWindow(), WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM( pos.x, pos.y ) ) ) : - ( static_cast( b_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 ) ) ); } @@ -61,8 +60,6 @@ class c_clicker bool m_is_left_clicking { false }; bool m_is_right_clicking { false }; - float m_persistent_value { 0.f }; - public: void init(); void update_thread(); @@ -71,64 +68,4 @@ class c_clicker c_clicker() = default; }; -inline auto clicker = c_clicker(); - -namespace thread -{ - namespace click - { - inline void init() - { - clicker.init(); - } - - inline void randomization() - { - clicker.update_thread(); - } - } - - // had to - namespace hooking - { - inline HHOOK h_hook; - - static LRESULT CALLBACK keyboard_callback( int nCode, WPARAM wParam, LPARAM lParam ) - { - static auto* k_hook = reinterpret_cast( lParam ); - - 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 ); - } - - 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 ); - } - - UnhookWindowsHookEx( h_hook ); - } - } -} \ No newline at end of file +inline auto g_clicker = c_clicker(); \ No newline at end of file diff --git a/clicker/clicker.vcxproj b/clicker/clicker.vcxproj index 34a86d9..ac12077 100644 --- a/clicker/clicker.vcxproj +++ b/clicker/clicker.vcxproj @@ -94,6 +94,7 @@ + diff --git a/clicker/clicker.vcxproj.filters b/clicker/clicker.vcxproj.filters index 37d7b21..5f09623 100644 --- a/clicker/clicker.vcxproj.filters +++ b/clicker/clicker.vcxproj.filters @@ -94,6 +94,9 @@ utils\keybind + + utils\threads + @@ -138,5 +141,8 @@ {c87a7cbb-b9a7-4307-b963-a65bc9292368} + + {2fddc2fe-d959-4e3a-b967-7234b06e9dc9} + \ No newline at end of file diff --git a/clicker/config.hpp b/clicker/config.hpp index 1f9c524..299b0be 100644 --- a/clicker/config.hpp +++ b/clicker/config.hpp @@ -2,7 +2,7 @@ #include "archivex.hpp" -#include +#include #include #include diff --git a/clicker/main.cpp b/clicker/main.cpp index 341a106..be61d16 100644 --- a/clicker/main.cpp +++ b/clicker/main.cpp @@ -1,41 +1,36 @@ #include "pch.hpp" -#include "clicker.hpp" -#include "menu.hpp" -// ~ main entrypoint INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd ) { - std::atexit( [] {} ); + std::atexit( [] { threads::hooking::unhook(); } ); config.run( "clicker" ); log_debug( "initializing threads..." ); - if ( !_beginthreadex( nullptr, 0, - reinterpret_cast( thread::click::init ), nullptr, 0, nullptr ) ) + std::vector> functions = { - log_err( "Failed to initialize clicker thread!" ); - return EXIT_FAILURE; - } + { threads::clicker::init, "clicker" }, + { threads::clicker::randomization, "clicker randomization" }, + { threads::hooking::spawn, "hooking" } + }; - if ( !_beginthreadex( nullptr, 0, - reinterpret_cast( thread::click::randomization ), nullptr, 0, nullptr ) ) + for ( auto& [func, name] : functions ) { - log_err( "Failed to initialize clicker randomization thread!" ); - return EXIT_FAILURE; - } + log_debug( "spawning %s thread...", name.c_str() ); - if ( !_beginthreadex( nullptr, 0, - reinterpret_cast( thread::hooking::spawn ), nullptr, 0, nullptr ) ) - { - log_err( "Failed to initialize hooking!" ); - return EXIT_FAILURE; + if ( !_beginthreadex( nullptr, 0, reinterpret_cast( func ), nullptr, 0, nullptr ) ) + { + log_err( "failed to spawn %s thread!", name.c_str() ); + return EXIT_FAILURE; + } } - log_debug( "waiting for program end." ); + log_debug( "calling menu..." ); if ( !menu.initialize( 550, 350 ) ) { - log_err( "Failed to create DirectX9 device!" ); + log_err( "failed to create DirectX9 device!" ); + return EXIT_FAILURE; } return EXIT_SUCCESS; diff --git a/clicker/menu.cpp b/clicker/menu.cpp index a5ac12b..5a2f71c 100644 --- a/clicker/menu.cpp +++ b/clicker/menu.cpp @@ -3,33 +3,35 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height ) { - static auto x = 0, y = 0; + static int x = 0, y = 0; - ImGui::SetNextWindowSize( ImVec2( static_cast( i_width ), static_cast( i_height ) ), ImGuiCond_Always ); - ImGui::SetNextWindowPos( ImVec2( 0, 0 ), ImGuiCond_Always ); + ImGui::SetNextWindowSize( { static_cast( i_width ), static_cast( i_height ) }, ImGuiCond_Always ); + ImGui::SetNextWindowPos( { 0, 0 }, ImGuiCond_Always ); - if ( ImGui::IsMouseClicked( ImGuiMouseButton_Left ) ) - get_mouse_offset( x, y, hwnd ); + vars::key::hide_window.i_key = config.clicker.i_hide_window_key; + vars::key::hide_window.get() ? ShowWindow( hwnd, SW_HIDE ) : ShowWindow( hwnd, SW_SHOW ); - var::key::hide_window.i_key = config.clicker.i_hide_window_key; - var::key::hide_window.get() ? ShowWindow( hwnd, SW_HIDE ) : ShowWindow( hwnd, SW_SHOW ); + static auto b_open = true; - ImGui::Begin( "##var::clicker::begin", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove ); + if ( !b_open ) + std::exit( 0 ); + + if ( ImGui::Begin( "clicker", &b_open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove ) ) { - if ( y >= 0 && y <= ImGui::GetTextLineHeight() + ImGui::GetStyle().FramePadding.y * 4.f && ImGui::IsMouseDragging( ImGuiMouseButton_Left ) ) + if ( ImGui::IsMouseClicked( ImGuiMouseButton_Left ) ) + get_mouse_offset( x, y, hwnd ); + + if ( y >= 0 && y <= ( ImGui::GetTextLineHeight() + ImGui::GetStyle().FramePadding.y * 4 ) && ImGui::IsMouseDragging( ImGuiMouseButton_Left ) ) set_position( x, y, i_width, i_height, hwnd ); if ( ImGui::BeginTabBar( "##var::clicker::tabs" ) ) { - ImGui::SameLine( i_width - 30.f ); - if ( ImGui::Button( "##close", { 15, 15 } ) ) { std::exit( 0 ); } - - if ( ImGui::BeginTabItem( "clicker" ) ) + if ( ImGui::BeginTabItem( "mouse" ) ) { ImGui::Text( "Keybind" ); ImGui::Separator(); - keybind_button( config.clicker.i_clicker_key, 155, 22 ); + keybind_button( config.clicker.i_clicker_key, 150, 22 ); ImGui::SameLine(); @@ -56,33 +58,28 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height ) ImGui::Combo( "##var::clicker::i_version_type", &config.clicker.i_version_type, "Minecraft\0Custom\0\0" ); - if ( config.clicker.i_version_type == 0 ) + switch ( config.clicker.i_version_type ) { - ImGui::Checkbox( "Only playing", &config.clicker.b_only_in_game ); - if ( ImGui::IsItemHovered() ) - ImGui::SetTooltip( "If enabled, clicker will only work while playing.\nUseful for clicking in game menu." ); - - if ( config.clicker.b_only_in_game ) - { - ImGui::Checkbox( "Work in inventory", &config.clicker.b_work_in_inventory ); + case 0: + ImGui::Checkbox( "Only playing", &config.clicker.b_only_in_game ); if ( ImGui::IsItemHovered() ) - ImGui::SetTooltip( "If enabled, clicker will work while playing and with the inventory opened." ); - } - } - else - { - config.clicker.b_only_in_game = false; - config.clicker.b_work_in_inventory = false; - } - - static char buffer[32]; - if ( config.clicker.i_version_type == 1 ) - { - ImGui::InputText( "##var::input::buffer", buffer, IM_ARRAYSIZE( buffer ) ); - if ( ImGui::IsItemHovered() ) - ImGui::SetTooltip( "If you leave it blank it'll work anywhere." ); + ImGui::SetTooltip( "If enabled, clicker will only work while playing.\nUseful for clicking in game menu." ); + + if ( config.clicker.b_only_in_game ) + { + ImGui::Checkbox( "Work in inventory", &config.clicker.b_work_in_inventory ); + if ( ImGui::IsItemHovered() ) + ImGui::SetTooltip( "If enabled, clicker will work while playing and with the inventory opened." ); + } + break; + case 1: + static char buffer[32]; + ImGui::InputText( "##var::input::buffer", buffer, IM_ARRAYSIZE( buffer ) ); + if ( ImGui::IsItemHovered() ) + ImGui::SetTooltip( "If you leave it blank it'll work anywhere." ); - config.clicker.str_window_title = buffer; + config.clicker.str_window_title = buffer; + break; } if ( !config.clicker.b_enable_blatant ) @@ -127,7 +124,7 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height ) ImGui::Checkbox( "Advanced options", &config.clicker.b_enable_advanced_options ); if ( config.clicker.b_enable_advanced_options ) { - ImGui::Text( "Persistence update rate" ); + ImGui::Text( "Maximum update rate delay" ); if ( ImGui::IsItemHovered() ) ImGui::SetTooltip( "Smaller values, faster cps updates." ); @@ -170,13 +167,13 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height ) { ImGui::Text( "Information" ); ImGui::Separator(); - ImGui::Text( "Clicks this session: %d", var::stats::i_clicks_this_session ); - ImGui::Text( "Is left button down: %s", var::key::left_clicker_down.get() ? ICON_FA_CHECK : ICON_FA_TIMES ); - ImGui::Text( "Is right button down: %s", var::key::right_clicker_down.get() ? ICON_FA_CHECK : ICON_FA_TIMES ); - ImGui::Text( "Is hotkey toggled: %s", var::key::clicker_enabled.get() ? ICON_FA_CHECK : ICON_FA_TIMES ); + ImGui::Text( "Clicks this session: %d", vars::stats::i_clicks_this_session ); + ImGui::Text( "Is left button down: %s", vars::key::left_clicker_down.get() ? ICON_FA_CHECK : ICON_FA_TIMES ); + ImGui::Text( "Is right button down: %s", vars::key::right_clicker_down.get() ? 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", util::extra::is_window_focused() ? ICON_FA_CHECK : ICON_FA_TIMES ); - ImGui::Text( "Is cursor visible: %s", util::extra::cursor_handle_status() ? ICON_FA_CHECK : ICON_FA_TIMES ); - ImGui::Text( "Is in inventory: %s", var::key::inventory_opened ? ICON_FA_CHECK : ICON_FA_TIMES ); + ImGui::Text( "Is cursor visible: %s", util::extra::cursor_visible() ? ICON_FA_CHECK : ICON_FA_TIMES ); + ImGui::Text( "Is in inventory: %s", vars::key::inventory_opened ? ICON_FA_CHECK : ICON_FA_TIMES ); ImGui::Text( "Current window name: %ls", util::extra::get_active_window_title().c_str() ); ImGui::Text( "Application average: %.1f ms (%.1f fps)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate ); ImGui::Separator(); @@ -203,7 +200,7 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height ) } constexpr auto& config_items = config.get_configs(); - static int current_config = -1; + static auto current_config = -1; if ( static_cast( current_config ) >= config_items.size() ) current_config = -1; @@ -234,7 +231,7 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height ) ImGui::SameLine(); - if ( current_config != -1 ) + if ( current_config > -1 ) { if ( ImGui::Button( "Load", ImVec2( 60, 25 ) ) ) config.load( current_config ); diff --git a/clicker/menu.hpp b/clicker/menu.hpp index ae72fe9..362a97c 100644 --- a/clicker/menu.hpp +++ b/clicker/menu.hpp @@ -266,7 +266,7 @@ class c_menu io.Fonts->AddFontFromMemoryCompressedTTF( fontawesome_compressed_data, fontawesome_compressed_size, 10.f, &icons_config, icons_ranges ); - style.ScrollbarSize = 5.0f; + style.ScrollbarSize = 10.0f; style.GrabRounding = 5.0f; style.GrabMinSize = 10.0f; style.FrameRounding = 3.0f; @@ -279,7 +279,7 @@ class c_menu const auto clear_color = ImVec4( 0.09f, 0.09f, 0.09f, 0.94f ); - bool done = false; + auto done = false; while ( !done ) { MSG msg; @@ -306,6 +306,7 @@ class c_menu colors[ImGuiCol_PopupBg] = ImVec4( 0.11f, 0.11f, 0.11f, 0.94f ); colors[ImGuiCol_Border] = float_to_imvec4( config.clicker.f_color_accent ); colors[ImGuiCol_FrameBg] = ImVec4( 0.15f, 0.15f, 0.15f, 0.54f ); + colors[ImGuiCol_TitleBgActive] = float_to_imvec4( config.clicker.f_color_accent ); colors[ImGuiCol_FrameBgHovered] = ImVec4( 0.19f, 0.19f, 0.19f, 0.54f ); colors[ImGuiCol_FrameBgActive] = ImVec4( 0.26f, 0.26f, 0.26f, 0.54f ); colors[ImGuiCol_ScrollbarBg] = ImVec4( 0.11f, 0.11f, 0.11f, 0.94f ); diff --git a/clicker/pch.hpp b/clicker/pch.hpp index 92cd0ec..919d6f2 100644 --- a/clicker/pch.hpp +++ b/clicker/pch.hpp @@ -14,4 +14,7 @@ using namespace std::chrono_literals; #include "keybind.hpp" #include "config.hpp" #include "vars.hpp" -#include "utils.hpp" \ No newline at end of file +#include "utils.hpp" +#include "clicker.hpp" +#include "threads.hpp" +#include "menu.hpp" \ No newline at end of file diff --git a/clicker/threads.hpp b/clicker/threads.hpp new file mode 100644 index 0000000..566a6b4 --- /dev/null +++ b/clicker/threads.hpp @@ -0,0 +1,63 @@ +#pragma once + +namespace threads +{ + namespace clicker + { + inline void init() + { + g_clicker.init(); + } + + inline void randomization() + { + g_clicker.update_thread(); + } + } + + namespace hooking + { + inline HHOOK h_hook; + + static LRESULT CALLBACK keyboard_callback( int nCode, WPARAM wParam, LPARAM lParam ) + { + static auto* k_hook = reinterpret_cast( lParam ); + + if ( wParam == WM_KEYDOWN && nCode == HC_ACTION && ( wParam >= WM_KEYFIRST ) && ( wParam <= WM_KEYLAST ) ) + { + if ( util::extra::is_window_focused() ) + { + if ( k_hook->vkCode == 69 /* E */ ) + vars::key::inventory_opened = !vars::key::inventory_opened; + + if ( k_hook->vkCode == VK_ESCAPE ) + vars::key::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 ); + } + } +} \ No newline at end of file diff --git a/clicker/utils.hpp b/clicker/utils.hpp index cd9705b..6c05f39 100644 --- a/clicker/utils.hpp +++ b/clicker/utils.hpp @@ -71,28 +71,29 @@ namespace util { wchar_t title[256]; const auto hwnd = GetForegroundWindow(); - GetWindowText( hwnd, title, sizeof( title ) ); + GetWindowText( hwnd, title, sizeof( title ) / 4 ); return title; } inline bool is_application_focused() { const auto hwnd = GetForegroundWindow(); - if ( !hwnd ) return false; + if ( !hwnd ) + return false; DWORD dw_thread_process_id; GetWindowThreadProcessId( hwnd, &dw_thread_process_id ); return ( GetCurrentProcessId() == dw_thread_process_id ); } - inline bool cursor_handle_status() + inline bool cursor_visible() { CURSORINFO ci { sizeof( CURSORINFO ) }; if ( GetCursorInfo( &ci ) ) { const auto handle = ci.hCursor; - if ( ( handle > (HCURSOR) 50000 ) & ( handle < (HCURSOR) 100000 ) ) + if ( !( ( handle > (HCURSOR) 50000 ) & ( handle < (HCURSOR) 100000 ) ) ) return true; } @@ -105,8 +106,10 @@ namespace util { case 0: return ( GetForegroundWindow() == FindWindow( L"LWJGL", nullptr ) ); + break; case 1: - return get_active_window_title().find( util::string::to_unicode( config.clicker.str_window_title ) ) != std::string::npos; + return ( get_active_window_title().find( util::string::to_unicode( config.clicker.str_window_title ) ) != std::string::npos ); + break; } return false; @@ -117,12 +120,14 @@ namespace util if ( config.clicker.b_only_in_game ) { if ( config.clicker.b_work_in_inventory ) - return !( cursor_handle_status() ) || ( var::key::inventory_opened && cursor_handle_status() ); + { + return cursor_visible() || ( vars::key::inventory_opened && !cursor_visible() ); + } - return !( cursor_handle_status() ); + return cursor_visible(); } - return true; + return false; } } } \ No newline at end of file diff --git a/clicker/vars.hpp b/clicker/vars.hpp index 1d14224..ce42cca 100644 --- a/clicker/vars.hpp +++ b/clicker/vars.hpp @@ -1,7 +1,6 @@ #pragma once -// ~ these variables aren't saved to configuration, only changed at runtime. -namespace var +namespace vars { namespace key {