From 6e423725cd257c3e1ac9c0118a25dbfdfbb1d4cf Mon Sep 17 00:00:00 2001 From: Saikari Date: Thu, 1 Aug 2024 23:14:32 +0300 Subject: [PATCH] Added key handler system Added key handler system --- Cargo.toml | 2 +- src/aimbot.rs | 127 ------------------------ src/hotkey_widget.rs | 80 ++++++++++++--- src/key_action.rs | 226 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/ui.rs | 195 ++++++++++--------------------------- 6 files changed, 344 insertions(+), 287 deletions(-) create mode 100644 src/key_action.rs diff --git a/Cargo.toml b/Cargo.toml index 7366e5d..e08832c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ cargo-features = ["edition2024", "profile-rustflags"] [package] name = "rusted-assault-cube" -version = "2.2.0" +version = "2.3.0" edition = "2024" authors = ["luadebug Lin Evelynn lin@sz.cn.eu.org"] publish = false diff --git a/src/aimbot.rs b/src/aimbot.rs index 6113cf9..e69de29 100644 --- a/src/aimbot.rs +++ b/src/aimbot.rs @@ -1,127 +0,0 @@ -use std::sync::atomic::Ordering::SeqCst; - -use windows::Win32::UI::Input::KeyboardAndMouse::GetAsyncKeyState; - -use crate::angle::Angle; -use crate::entity::Entity; -use crate::getclosestentity::get_closest_entity; -use crate::hotkey_widget::to_win_key; -use crate::offsets::offsets::{LOCAL_PLAYER_OFFSET, PITCH_OFFSET, YAW_OFFSET}; -use crate::settings::AppSettings; -use crate::utils::{read_memory, write_memory}; -use crate::vars::game_vars::{LOCAL_PLAYER, SMOOTH}; -use crate::vars::handles::AC_CLIENT_EXE_HMODULE; -use crate::vars::ui_vars::{IS_AIMBOT, IS_SMOOTH}; -use crate::vec_structures::Vec3; - -pub unsafe fn aimbot(app_settings: &AppSettings) { - unsafe { - if !IS_AIMBOT.load(SeqCst) { - return; - } - - let local_player_addr = - match read_memory::(AC_CLIENT_EXE_HMODULE + LOCAL_PLAYER_OFFSET) { - Ok(addr) => addr, - Err(err) => { - println!("Error reading local player address: {}", err); - return; - } - }; - - LOCAL_PLAYER = Entity::from_addr(local_player_addr); - - if GetAsyncKeyState(to_win_key(app_settings.aim_key.as_ref().unwrap().key).0 as i32) & 1 - == 1 - { - let enemy = get_closest_entity(); - if LOCAL_PLAYER.entity_starts_at_addr == 0 || enemy.entity_starts_at_addr == 0 { - return; // Didn't find player or enemy - } - - // Handle health and team checks - if enemy.health().unwrap_or(0) < 0 || enemy.team() == LOCAL_PLAYER.team() { - return; // Skipping dead or ally - } - - // Safely read player and enemy positions - let player_head_pos = match LOCAL_PLAYER.head_position() { - Ok(pos) => pos, - Err(err) => { - println!("Error reading player head position: {}", err); - return; - } - }; - - let enemy_head_pos = match enemy.head_position() { - Ok(pos) => pos, - Err(err) => { - println!("Error reading enemy head position: {}", err); - return; - } - }; - - // Calculate angle - let angle = Angle::get_angle( - Vec3::new(player_head_pos.x, player_head_pos.y, player_head_pos.z), - Vec3::new(enemy_head_pos.x, enemy_head_pos.y, enemy_head_pos.z), - ); - - // Safely read and update yaw and pitch - let update_view_angle = |offset: usize, value: f32| { - let address = LOCAL_PLAYER.entity_starts_at_addr + offset; - match read_memory::(address) { - Ok(current_value) => { - // Only write if the value is different to avoid unnecessary writes - if current_value != value { - if let Err(err) = write_memory::(address, value) { - println!( - "Error writing to address {:x} storing value {}: {}", - address, current_value, err - ); - } - } - } - Err(err) => { - println!("Error reading from address {:x}: {}", address, err); - } - } - }; - - // Read yaw and pitch with error handling - let (local_player_yaw, local_player_pitch) = - match (LOCAL_PLAYER.yaw(), LOCAL_PLAYER.pitch()) { - (Ok(y), Ok(p)) => (y as f32, p as f32), - (Err(err), _) => { - println!("Error reading yaw: {}", err); - return; - } - (_, Err(err)) => { - println!("Error reading pitch: {}", err); - return; - } - }; - - // Calculate the angle difference - let angle_diff_yaw = angle.yaw - local_player_yaw; - let angle_diff_pitch = angle.pitch - local_player_pitch; - - let smooth = Angle::new(angle_diff_yaw, angle_diff_pitch); - let smooth_value = SMOOTH.load(SeqCst) as f32; - - if IS_SMOOTH.load(SeqCst) { - if smooth_value > 0.0 { - let new_yaw = local_player_yaw + (smooth.yaw / smooth_value); - let new_pitch = local_player_pitch + (smooth.pitch / smooth_value); - update_view_angle(YAW_OFFSET, new_yaw); - update_view_angle(PITCH_OFFSET, new_pitch); - } else { - return; - } - } else { - update_view_angle(YAW_OFFSET, angle.yaw); - update_view_angle(PITCH_OFFSET, angle.pitch); - } - } - } -} diff --git a/src/hotkey_widget.rs b/src/hotkey_widget.rs index 0749fac..7775d96 100644 --- a/src/hotkey_widget.rs +++ b/src/hotkey_widget.rs @@ -1,21 +1,11 @@ use std::collections::HashSet; - +use std::sync::atomic::Ordering::SeqCst; use hudhook::imgui; +use hudhook::imgui::{Io, MouseButton, Window}; use imgui::Key; use serde::{de::Visitor, Deserialize, Serialize}; -use windows::Win32::UI::Input::KeyboardAndMouse::{ - VK__none_, VIRTUAL_KEY, VK_0, VK_1, VK_2, VK_3, VK_4, VK_5, VK_6, VK_7, VK_8, VK_9, VK_A, - VK_ADD, VK_APPS, VK_B, VK_BACK, VK_C, VK_CAPITAL, VK_CONTROL, VK_D, VK_DECIMAL, VK_DELETE, - VK_DIVIDE, VK_DOWN, VK_E, VK_END, VK_ESCAPE, VK_F, VK_F1, VK_F10, VK_F11, VK_F12, VK_F2, VK_F3, - VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_G, VK_H, VK_HOME, VK_I, VK_INSERT, VK_J, VK_K, - VK_L, VK_LCONTROL, VK_LEFT, VK_LMENU, VK_LSHIFT, VK_LWIN, VK_M, VK_MENU, VK_MULTIPLY, VK_N, - VK_NEXT, VK_NUMLOCK, VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD4, VK_NUMPAD5, - VK_NUMPAD6, VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9, VK_O, VK_OEM_1, VK_OEM_2, VK_OEM_3, VK_OEM_4, - VK_OEM_5, VK_OEM_6, VK_OEM_7, VK_OEM_COMMA, VK_OEM_MINUS, VK_OEM_PERIOD, VK_OEM_PLUS, VK_P, - VK_PAUSE, VK_PRIOR, VK_Q, VK_R, VK_RCONTROL, VK_RETURN, VK_RIGHT, VK_RMENU, VK_RSHIFT, VK_RWIN, - VK_S, VK_SCROLL, VK_SNAPSHOT, VK_SPACE, VK_SUBTRACT, VK_T, VK_TAB, VK_U, VK_UP, VK_V, VK_W, - VK_X, VK_Y, VK_Z, -}; +use windows::Win32::UI::Input::KeyboardAndMouse::{VK__none_, VIRTUAL_KEY, VK_0, VK_1, VK_2, VK_3, VK_4, VK_5, VK_6, VK_7, VK_8, VK_9, VK_A, VK_ADD, VK_APPS, VK_B, VK_BACK, VK_C, VK_CAPITAL, VK_CONTROL, VK_D, VK_DECIMAL, VK_DELETE, VK_DIVIDE, VK_DOWN, VK_E, VK_END, VK_ESCAPE, VK_F, VK_F1, VK_F10, VK_F11, VK_F12, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_G, VK_H, VK_HOME, VK_I, VK_INSERT, VK_J, VK_K, VK_L, VK_LCONTROL, VK_LEFT, VK_LMENU, VK_LSHIFT, VK_LWIN, VK_M, VK_MENU, VK_MULTIPLY, VK_N, VK_NEXT, VK_NUMLOCK, VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9, VK_O, VK_OEM_1, VK_OEM_2, VK_OEM_3, VK_OEM_4, VK_OEM_5, VK_OEM_6, VK_OEM_7, VK_OEM_COMMA, VK_OEM_MINUS, VK_OEM_PERIOD, VK_OEM_PLUS, VK_P, VK_PAUSE, VK_PRIOR, VK_Q, VK_R, VK_RCONTROL, VK_RETURN, VK_RIGHT, VK_RMENU, VK_RSHIFT, VK_RWIN, VK_S, VK_SCROLL, VK_SNAPSHOT, VK_SPACE, VK_SUBTRACT, VK_T, VK_TAB, VK_U, VK_UP, VK_V, VK_W, VK_X, VK_Y, VK_Z, GetAsyncKeyState}; +use crate::vars::ui_vars::IS_SHOW_UI; #[derive(Clone, Debug)] pub struct HotKey { @@ -277,6 +267,68 @@ pub fn render_button_key( updated } + + +/// Simple input system using the global mouse / keyboard state. +/// This does not require the need to process window messages or the imgui overlay to be active. +// Implement Default for [bool; VK_KEY_MAX] + + + +#[derive(Debug)] +#[allow(unused)] +pub struct KeyboardInputSystem { + pub key_states: [bool; VK_KEY_MAX], +} + +#[allow(unused)] +impl KeyboardInputSystem { + pub const fn new() -> Self { + Self { + key_states: [false; VK_KEY_MAX], // Initialize with all false + } + } + + pub unsafe fn update(&mut self, io: &mut Io) { + for vkey in 0..VK_KEY_MAX { + let key_state = unsafe { GetAsyncKeyState(vkey as i32) as u16 }; + let pressed = key_state & 1 == 1; + if self.key_states[vkey] == pressed { + continue; + } + + self.key_states[vkey] = pressed; + let vkey = VIRTUAL_KEY(vkey as u16); + + handle_key_modifier(io, vkey, pressed); + + if !IS_SHOW_UI.load(SeqCst) //Do not handle mouse input in case menu is opened up + { + let mouse_button = match vkey { + VK_LBUTTON => Some(MouseButton::Left), + VK_RBUTTON => Some(MouseButton::Right), + VK_MBUTTON => Some(MouseButton::Middle), + VK_XBUTTON1 => Some(MouseButton::Extra1), + VK_XBUTTON2 => Some(MouseButton::Extra2), + _ => None, + }; + + if let Some(button) = mouse_button { + io.add_mouse_button_event(button, pressed); + } + } + if let Some(key) = to_imgui_key(vkey) { + println!("Key toogle {:?}: {}", key, pressed); + io.add_key_event(key, pressed); + } else { + println!("Missing ImGui key for {:?}", vkey); + } + } + } +} + + + const VK_KEY_MAX: usize = 256; pub fn to_imgui_key(keycode: VIRTUAL_KEY) -> Option { diff --git a/src/key_action.rs b/src/key_action.rs new file mode 100644 index 0000000..2fbcca0 --- /dev/null +++ b/src/key_action.rs @@ -0,0 +1,226 @@ +use std::sync::atomic::Ordering::SeqCst; +use windows::Win32::UI::Input::KeyboardAndMouse::GetAsyncKeyState; +use crate::angle::Angle; +use crate::entity::Entity; +use crate::game::{set_brightness, set_brightness_toggle}; +use crate::getclosestentity::get_closest_entity; +use crate::hotkey_widget::to_win_key; +use crate::offsets::offsets::{LOCAL_PLAYER_OFFSET, PITCH_OFFSET, YAW_OFFSET}; +use crate::settings::AppSettings; +use crate::utils::{read_memory, write_memory}; +use crate::vars::game_vars::{LOCAL_PLAYER, SMOOTH}; +use crate::vars::handles::AC_CLIENT_EXE_HMODULE; +use crate::vars::mem_patches::{MAPHACK_MEMORY_PATCH, NO_RECOIL_MEMORY_PATCH, RAPID_FIRE_MEMORY_PATCH}; +use crate::vars::ui_vars::{IS_AIMBOT, IS_DRAW_FOV, IS_ESP, IS_FULLBRIGHT, IS_GRENADES_INFINITE, IS_INFINITE_AMMO, IS_INVULNERABLE, IS_MAPHACK, IS_NO_RECOIL, IS_NO_RELOAD, IS_RAPID_FIRE, IS_SHOW_UI, IS_SMOOTH, IS_TRIGGERBOT, IS_WALLHACK}; +use crate::vec_structures::Vec3; + +pub struct KeyAction { + pub(crate) key: usize, // The index of the key state in the key_states array + pub(crate) action: unsafe fn(), // The function to call when the key is pressed +} + +// Define the actions for each key +pub unsafe fn toggle_show_ui() { + IS_SHOW_UI.store(!IS_SHOW_UI.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_wallhack() { + IS_WALLHACK.store(!IS_WALLHACK.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_esp() { + IS_ESP.store(!IS_ESP.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_infinite_nades() { + IS_GRENADES_INFINITE.store(!IS_GRENADES_INFINITE.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_no_reload() { + IS_NO_RELOAD.store(!IS_NO_RELOAD.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_invulnerability() { + IS_INVULNERABLE.store(!IS_INVULNERABLE.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_infinite_ammo() { + IS_INFINITE_AMMO.store(!IS_INFINITE_AMMO.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_no_recoil() { + IS_NO_RECOIL.store(!IS_NO_RECOIL.load(SeqCst), SeqCst); + if IS_NO_RECOIL.load(SeqCst) { + NO_RECOIL_MEMORY_PATCH + .patch_memory() + .expect("[ui] Failed to patch memory no recoil"); + } else { + NO_RECOIL_MEMORY_PATCH + .unpatch_memory() + .expect("[ui] Failed to unpatch memory no recoil"); + } +} + +pub unsafe fn toggle_rapid_fire() { + IS_RAPID_FIRE.store(!IS_RAPID_FIRE.load(SeqCst), SeqCst); + if IS_RAPID_FIRE.load(SeqCst) { + RAPID_FIRE_MEMORY_PATCH + .patch_memory() + .expect("[ui] Failed to patch memory rapid fire"); + } else { + RAPID_FIRE_MEMORY_PATCH + .unpatch_memory() + .expect("[ui] Failed to unpatch memory rapid fire"); + } +} + +pub unsafe fn toggle_aimbot() { + IS_AIMBOT.store(!IS_AIMBOT.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_draw_fov() { + IS_DRAW_FOV.store(!IS_DRAW_FOV.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_smooth() { + IS_SMOOTH.store(!IS_SMOOTH.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_triggerbot() { + IS_TRIGGERBOT.store(!IS_TRIGGERBOT.load(SeqCst), SeqCst); +} + +pub unsafe fn toggle_maphack() { + IS_MAPHACK.store(!IS_MAPHACK.load(SeqCst), SeqCst); + if IS_MAPHACK.load(SeqCst) { + MAPHACK_MEMORY_PATCH + .patch_memory() + .expect("[ui] Failed to patch memory Maphack"); + } else { + MAPHACK_MEMORY_PATCH + .unpatch_memory() + .expect("[ui] Failed to unpatch memory Maphack"); + } +} + +pub unsafe fn toggle_fullbright() { + IS_FULLBRIGHT.store(!IS_FULLBRIGHT.load(SeqCst), SeqCst); + let set_brightness_func = set_brightness(); + if !set_brightness_func.is_null() { + set_brightness_toggle(IS_FULLBRIGHT.load(SeqCst)); + } else { + println!("Function pointer to set_brightness is null!"); + } +} + +pub unsafe fn aimbot() { //app_settings: &AppSettings + unsafe { + if !IS_AIMBOT.load(SeqCst) { + return; + } + + let local_player_addr = + match read_memory::(AC_CLIENT_EXE_HMODULE + LOCAL_PLAYER_OFFSET) { + Ok(addr) => addr, + Err(err) => { + println!("Error reading local player address: {}", err); + return; + } + }; + + LOCAL_PLAYER = Entity::from_addr(local_player_addr); + +/* if GetAsyncKeyState(to_win_key(app_settings.aim_key.as_ref().unwrap().key).0 as i32) & 1 + == 1*/ + { + let enemy = get_closest_entity(); + if LOCAL_PLAYER.entity_starts_at_addr == 0 || enemy.entity_starts_at_addr == 0 { + return; // Didn't find player or enemy + } + + // Handle health and team checks + if enemy.health().unwrap_or(0) < 0 || enemy.team() == LOCAL_PLAYER.team() { + return; // Skipping dead or ally + } + + // Safely read player and enemy positions + let player_head_pos = match LOCAL_PLAYER.head_position() { + Ok(pos) => pos, + Err(err) => { + println!("Error reading player head position: {}", err); + return; + } + }; + + let enemy_head_pos = match enemy.head_position() { + Ok(pos) => pos, + Err(err) => { + println!("Error reading enemy head position: {}", err); + return; + } + }; + + // Calculate angle + let angle = Angle::get_angle( + Vec3::new(player_head_pos.x, player_head_pos.y, player_head_pos.z), + Vec3::new(enemy_head_pos.x, enemy_head_pos.y, enemy_head_pos.z), + ); + + // Safely read and update yaw and pitch + let update_view_angle = |offset: usize, value: f32| { + let address = LOCAL_PLAYER.entity_starts_at_addr + offset; + match read_memory::(address) { + Ok(current_value) => { + // Only write if the value is different to avoid unnecessary writes + if current_value != value { + if let Err(err) = write_memory::(address, value) { + println!( + "Error writing to address {:x} storing value {}: {}", + address, current_value, err + ); + } + } + } + Err(err) => { + println!("Error reading from address {:x}: {}", address, err); + } + } + }; + + // Read yaw and pitch with error handling + let (local_player_yaw, local_player_pitch) = + match (LOCAL_PLAYER.yaw(), LOCAL_PLAYER.pitch()) { + (Ok(y), Ok(p)) => (y as f32, p as f32), + (Err(err), _) => { + println!("Error reading yaw: {}", err); + return; + } + (_, Err(err)) => { + println!("Error reading pitch: {}", err); + return; + } + }; + + // Calculate the angle difference + let angle_diff_yaw = angle.yaw - local_player_yaw; + let angle_diff_pitch = angle.pitch - local_player_pitch; + + let smooth = Angle::new(angle_diff_yaw, angle_diff_pitch); + let smooth_value = SMOOTH.load(SeqCst) as f32; + + if IS_SMOOTH.load(SeqCst) { + if smooth_value > 0.0 { + let new_yaw = local_player_yaw + (smooth.yaw / smooth_value); + let new_pitch = local_player_pitch + (smooth.pitch / smooth_value); + update_view_angle(YAW_OFFSET, new_yaw); + update_view_angle(PITCH_OFFSET, new_pitch); + } else { + return; + } + } else { + update_view_angle(YAW_OFFSET, angle.yaw); + update_view_angle(PITCH_OFFSET, angle.pitch); + } + } + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b5735b0..98a482a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,6 +42,7 @@ mod wallhack_hook; mod window_dimensions; mod world_to_screen; mod locales; +mod key_action; #[no_mangle] #[allow(non_snake_case, unused_variables)] diff --git a/src/ui.rs b/src/ui.rs index f1f5fac..2759736 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -9,12 +9,12 @@ use gnal_tsur::gnal_tsur; use hudhook::{imgui, MessageFilter, RenderContext}; use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, Io}; use once_cell::sync::Lazy; -use windows::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_INSERT}; +use windows::Win32::UI::Input::KeyboardAndMouse::{VK_INSERT}; -use crate::aimbot::aimbot; -use crate::game; -use crate::game::set_brightness_toggle; -use crate::hotkey_widget::{ImGuiKey, to_win_key}; +use crate::key_action::aimbot; +use crate::game::{set_brightness_toggle, set_brightness}; +use crate::hotkey_widget::{ImGuiKey, KeyboardInputSystem, to_win_key}; +use crate::key_action::{KeyAction, toggle_aimbot, toggle_draw_fov, toggle_esp, toggle_fullbright, toggle_infinite_ammo, toggle_infinite_nades, toggle_invulnerability, toggle_maphack, toggle_no_recoil, toggle_no_reload, toggle_rapid_fire, toggle_show_ui, toggle_smooth, toggle_triggerbot, toggle_wallhack}; use crate::locales::cantonese_locale::CANTONESE_LOCALE_VECTOR; use crate::locales::chinese_locale::MANDARIN_LOCALE_VECTOR; use crate::locales::english_locale::ENG_LOCALE_VECTOR; @@ -33,7 +33,7 @@ use crate::vars::ui_vars::{ IS_INVULNERABLE, IS_MAPHACK, IS_NO_RECOIL, IS_NO_RELOAD, IS_RAPID_FIRE, IS_SHOW_UI, IS_SMOOTH, IS_TRIGGERBOT, IS_WALLHACK, }; - +pub static mut KEY_INPUT_SYSTEM: KeyboardInputSystem = unsafe { KeyboardInputSystem::new() }; static mut IS_NEED_CHANGE_THEME:bool = true; static mut IS_NEED_CHANGE_LOCALE:bool = true; static mut CURRENT_LOCALE_VECTOR: [&str; 24] = ENG_LOCALE_VECTOR; @@ -43,7 +43,6 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { let set_cl = app_settings.clone(); - if let Some(tab) = ui.tab_bar("Main Menu Tab Bar") { if let Some(item) = ui.tab_item(CURRENT_LOCALE_VECTOR[1]) @@ -193,6 +192,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { println!("Binded aimbot toggle key!"); } if IS_AIMBOT.load(SeqCst) { + ui.text("Aim Hotkey"); ui.same_line(); if ui.button_key_optional( "Aimbot Aim HotKey", @@ -203,6 +203,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { ) { println!("Binded aimbot aim key!"); } + if ui.checkbox(CURRENT_LOCALE_VECTOR[11], IS_DRAW_FOV.get_mut()) { println!("Set Aimbot Draw FOV Toggle to {}", IS_DRAW_FOV.load(SeqCst)); } @@ -279,7 +280,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { println!("Set Full Bright Toggle to {}", IS_FULLBRIGHT.load(SeqCst)); // Get the function pointer after setting the brightness - let set_brightness_func = game::set_brightness(); + let set_brightness_func = set_brightness(); // Ensure the function pointer is valid if !set_brightness_func.is_null() { @@ -376,6 +377,8 @@ impl hudhook::ImguiRenderLoop for RenderLoop { _ctx: &mut Context, _render_context: &'a mut dyn RenderContext, ) { + + _ctx.set_ini_filename(None); unsafe { @@ -401,6 +404,36 @@ impl hudhook::ImguiRenderLoop for RenderLoop { _render_context: &'a mut dyn RenderContext, ) { unsafe { + + let key_actions: Vec = vec![ + KeyAction { key: VK_INSERT.0 as usize, action: toggle_show_ui }, + KeyAction { key: to_win_key(SETTINGS.deref().wallhack_key.as_ref().unwrap().key).0 as usize, action: toggle_wallhack }, + KeyAction { key: to_win_key(SETTINGS.deref().esp_key.as_ref().unwrap().key).0 as usize, action: toggle_esp }, + KeyAction { key: to_win_key(SETTINGS.deref().inf_nade.as_ref().unwrap().key).0 as usize, action: toggle_infinite_nades }, + KeyAction { key: to_win_key(SETTINGS.deref().no_reload.as_ref().unwrap().key).0 as usize, action: toggle_no_reload }, + KeyAction { key: to_win_key(SETTINGS.deref().invul.as_ref().unwrap().key).0 as usize, action: toggle_invulnerability }, + KeyAction { key: to_win_key(SETTINGS.deref().inf_ammo.as_ref().unwrap().key).0 as usize, action: toggle_infinite_ammo }, + KeyAction { key: to_win_key(SETTINGS.deref().no_recoil.as_ref().unwrap().key).0 as usize, action: toggle_no_recoil }, + KeyAction { key: to_win_key(SETTINGS.deref().rapid_fire.as_ref().unwrap().key).0 as usize, action: toggle_rapid_fire }, + KeyAction { key: to_win_key(SETTINGS.deref().aimbot.as_ref().unwrap().key).0 as usize, action: toggle_aimbot }, + KeyAction { key: to_win_key(SETTINGS.deref().aim_draw_fov.as_ref().unwrap().key).0 as usize, action: toggle_draw_fov }, + KeyAction { key: to_win_key(SETTINGS.deref().aim_smooth.as_ref().unwrap().key).0 as usize, action: toggle_smooth }, + KeyAction { key: to_win_key(SETTINGS.deref().trigger_bot.as_ref().unwrap().key).0 as usize, action: toggle_triggerbot }, + KeyAction { key: to_win_key(SETTINGS.deref().maphack.as_ref().unwrap().key).0 as usize, action: toggle_maphack }, + KeyAction { key: to_win_key(SETTINGS.deref().fullbright.as_ref().unwrap().key).0 as usize, action: toggle_fullbright }, + KeyAction { key: to_win_key(SETTINGS.deref().aim_key.as_ref().unwrap().key).0 as usize, action: aimbot} + ]; + + + KEY_INPUT_SYSTEM.update(_ctx.io_mut()); + + for key_action in key_actions { + match KEY_INPUT_SYSTEM.key_states[key_action.key] { + true => (key_action.action)(), // Call the action function if the key is pressed + false => {} + } + } + if IS_NEED_CHANGE_THEME { match SETTINGS.deref_mut().theme_id @@ -431,10 +464,8 @@ impl hudhook::ImguiRenderLoop for RenderLoop { } - if IS_AIMBOT.load(SeqCst) { - aimbot(SETTINGS.deref()); - } - hotkey_handler(); + + _ctx.io_mut().mouse_draw_cursor = IS_SHOW_UI.load(SeqCst); _ctx.io_mut().want_set_mouse_pos = IS_SHOW_UI.load(SeqCst); _ctx.io_mut().want_capture_mouse = IS_SHOW_UI.load(SeqCst); @@ -477,147 +508,21 @@ impl hudhook::ImguiRenderLoop for RenderLoop { let custom_font = ui.push_font(font_id); - ui.window(CURRENT_LOCALE_VECTOR[0]) + if let Some(wt) = ui.window(CURRENT_LOCALE_VECTOR[0]) .title_bar(true) .size([1000.0, 700.0], imgui::Condition::FirstUseEver) .position([300.0, 300.0], imgui::Condition::FirstUseEver) - .build(|| { - on_frame(ui, SETTINGS.deref_mut()); + .begin() + { + unsafe { on_frame(ui, SETTINGS.deref_mut()); } custom_font.pop(); - }); + wt.end(); + }; } } } -unsafe fn hotkey_handler() { - unsafe { - if GetAsyncKeyState(VK_INSERT.0 as i32) & 1 == 1 { - IS_SHOW_UI.store(!IS_SHOW_UI.load(SeqCst), SeqCst); - } - if GetAsyncKeyState( - to_win_key(SETTINGS.deref().wallhack_key.as_ref().unwrap().key).0 as i32, - ) & 1 - == 1 - { - IS_WALLHACK.store(!IS_WALLHACK.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().esp_key.as_ref().unwrap().key).0 as i32) & 1 - == 1 - { - IS_ESP.store(!IS_ESP.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().inf_nade.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - IS_GRENADES_INFINITE.store(!IS_GRENADES_INFINITE.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().no_reload.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - IS_NO_RELOAD.store(!IS_NO_RELOAD.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().invul.as_ref().unwrap().key).0 as i32) & 1 - == 1 - { - IS_INVULNERABLE.store(!IS_INVULNERABLE.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().inf_ammo.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - IS_INFINITE_AMMO.store(!IS_INFINITE_AMMO.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().no_recoil.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - IS_NO_RECOIL.store(!IS_NO_RECOIL.load(SeqCst), SeqCst); - if IS_NO_RECOIL.load(SeqCst) { - NO_RECOIL_MEMORY_PATCH - .patch_memory() - .expect("[ui] Failed to patch memory no recoil"); - } else { - NO_RECOIL_MEMORY_PATCH - .unpatch_memory() - .expect("[ui] Failed to unpatch memory no recoil"); - } - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().rapid_fire.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - IS_RAPID_FIRE.store(!IS_RAPID_FIRE.load(SeqCst), SeqCst); - if IS_RAPID_FIRE.load(SeqCst) { - RAPID_FIRE_MEMORY_PATCH - .patch_memory() - .expect("[ui] Failed to patch memory rapid fire"); - } else { - RAPID_FIRE_MEMORY_PATCH - .unpatch_memory() - .expect("[ui] Failed to unpatch memory rapid fire"); - } - } - //if GetAsyncKeyState(VK_F7.0 as i32) & 1 == 1 - if GetAsyncKeyState(to_win_key(SETTINGS.deref().aimbot.as_ref().unwrap().key).0 as i32) & 1 - == 1 - { - IS_AIMBOT.store(!IS_AIMBOT.load(SeqCst), SeqCst); - } - if GetAsyncKeyState( - to_win_key(SETTINGS.deref().aim_draw_fov.as_ref().unwrap().key).0 as i32, - ) & 1 - == 1 - && IS_AIMBOT.load(SeqCst) - { - IS_DRAW_FOV.store(!IS_DRAW_FOV.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().aim_smooth.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - && IS_AIMBOT.load(SeqCst) - { - IS_SMOOTH.store(!IS_SMOOTH.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().trigger_bot.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - IS_TRIGGERBOT.store(!IS_TRIGGERBOT.load(SeqCst), SeqCst); - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().maphack.as_ref().unwrap().key).0 as i32) & 1 - == 1 - { - IS_MAPHACK.store(!IS_MAPHACK.load(SeqCst), SeqCst); - if IS_MAPHACK.load(SeqCst) { - MAPHACK_MEMORY_PATCH - .patch_memory() - .expect("[ui] Failed to patch memory Maphack"); - } else { - MAPHACK_MEMORY_PATCH - .unpatch_memory() - .expect("[ui] Failed to unpatch memory Maphack"); - } - } - if GetAsyncKeyState(to_win_key(SETTINGS.deref().fullbright.as_ref().unwrap().key).0 as i32) - & 1 - == 1 - { - //IS_FULLBRIGHT = !IS_FULLBRIGHT; - IS_FULLBRIGHT.store(!IS_FULLBRIGHT.load(SeqCst), SeqCst); - // Get the function pointer after setting the brightness - let set_brightness_func = game::set_brightness(); - - // Ensure the function pointer is valid - if !set_brightness_func.is_null() { - set_brightness_toggle(IS_FULLBRIGHT.load(SeqCst)); - } else { - println!("Function pointer to set_brightness is null!"); - } - } - } -} +