From f0da601288d63deb2cbd2cb43c9200e0e29f8121 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sat, 3 Aug 2024 04:00:17 +0300 Subject: [PATCH] Code cleanup Code cleanup --- Cargo.toml | 4 +- build.rs | 21 +- src/entrypoint.rs | 1059 ++++++++++++++++--------------- src/esp.rs | 3 +- src/fonts/mod.rs | 2 +- src/game.rs | 23 +- src/hotkey_widget.rs | 72 ++- src/key_action.rs | 455 ++++++------- src/lib.rs | 14 +- src/locales/cantonese_locale.rs | 33 +- src/locales/chinese_locale.rs | 33 +- src/locales/english_locale.rs | 32 +- src/locales/hebrew_locale.rs | 54 +- src/locales/mod.rs | 12 +- src/locales/russian_locale.rs | 34 +- src/locales/ukrainian_locale.rs | 34 +- src/settings.rs | 4 +- src/state/mod.rs | 2 + src/style.rs | 61 +- src/ui.rs | 895 +++++++++++++++----------- 20 files changed, 1578 insertions(+), 1269 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e376012..b794985 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ cargo-features = ["edition2024", "profile-rustflags"] [package] name = "rusted-assault-cube" -version = "3.0.0" +version = "2.3.0" edition = "2024" authors = ["luadebug Lin Evelynn lin@sz.cn.eu.org"] publish = false @@ -41,4 +41,4 @@ strip = true #rustflags = ["-C", "link-arg=-fuse-ld=mold"] [target.'cfg(target_os="windows")'.build-dependencies] -vcpkg = "0.2.15" +vcpkg = "0.2.15" \ No newline at end of file diff --git a/build.rs b/build.rs index 4f17009..fa4d8c1 100644 --- a/build.rs +++ b/build.rs @@ -1,12 +1,9 @@ -use std::path::Path; -use vcpkg::Error; - -fn main() { - - - - match vcpkg::find_package("freetype") { - Ok(freetype) => println!("{:?}", freetype.include_paths) , - Err(err) => println!("{}", err), - } -} +use std::path::Path; +use vcpkg::Error; + +fn main() { + match vcpkg::find_package("freetype") { + Ok(freetype) => println!("{:?}", freetype.include_paths), + Err(err) => println!("{}", err), + } +} diff --git a/src/entrypoint.rs b/src/entrypoint.rs index 9d90dad..49e83f0 100644 --- a/src/entrypoint.rs +++ b/src/entrypoint.rs @@ -1,524 +1,535 @@ -use windows::Win32::System::LibraryLoader::GetModuleHandleA; -use windows::core::PCSTR; -use crate::vars::handles::{AC_CLIENT_EXE_HMODULE, GAME_WINDOW_HANDLE}; - -use std::ffi::{c_void, CString}; -use std::ptr::null; -use std::result::Result::Ok; -use std::sync::atomic::Ordering::SeqCst; -use std::thread; -use std::time::Duration; - -use windows::Win32::Foundation::{GetLastError, COLORREF, FALSE, HWND, TRUE}; -use windows::Win32::Graphics::Gdi::{ - AddFontMemResourceEx, CreateCompatibleBitmap, CreateCompatibleDC, CreateSolidBrush, DeleteDC, - DeleteObject, GetDC, InvalidateRect, ReleaseDC, SelectObject, TransparentBlt, HBITMAP, -}; -use windows::Win32::UI::WindowsAndMessaging::{ - FindWindowA, GetWindowLongA, SetWindowLongA, GWL_EXSTYLE, WS_EX_TRANSPARENT, -}; -use windows::Win32::{ - Foundation::RECT, - Graphics::Gdi::{FillRect, HBRUSH, HDC}, -}; - -use crate::distance; -use crate::draw_utils::{draw_border_box, draw_circle, draw_scaling_bar, draw_text}; -use crate::entity::Entity; -use crate::get_window_dimensions::get_window_dimensions; -use crate::misc::init_mem_patches; -use crate::offsets::offsets::{ - ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR, -}; -use crate::utils::{read_memory, read_view_matrix}; -use crate::vars::game_vars::LOCAL_PLAYER; -use crate::vars::game_vars::NUM_PLAYERS_IN_MATCH; -use crate::vars::game_vars::{ENTITY_LIST_PTR, FOV, VIEW_MATRIX}; - -use crate::vars::handles::GAME_WINDOW_DIMENSIONS; - -use crate::vars::ui_vars::{IS_DRAW_FOV, IS_ESP}; -use crate::vec_structures::Vec2; -use crate::world_to_screen::world_to_screen; - -pub unsafe fn init_esp_gdi() -> Result<(HDC, HDC, HBITMAP, HBRUSH, HBRUSH, HBRUSH), Box> { - - // Initialize module handle - AC_CLIENT_EXE_HMODULE = { - let ac_client_exe_cstring = CString::new("ac_client.exe").unwrap(); - GetModuleHandleA(PCSTR(ac_client_exe_cstring.as_ptr() as *const u8)) - .map(|hinstance| hinstance.0 as usize) - .expect("[esp] Error getting module handle") - }; - - println!( - "[esp] Module base addr base_address={:#x}", - AC_CLIENT_EXE_HMODULE - ); - - println!("[esp] going to unwrap assaultcube window handle"); - let assault_cube_cstring = CString::new("AssaultCube").unwrap(); - println!("[esp] going to unwrap FindWindowA"); - let window_handle_result = FindWindowA( - PCSTR(0 as *const u8), - PCSTR(assault_cube_cstring.as_ptr() as *const u8), - ); - - if window_handle_result.is_err() { - let error_code = GetLastError(); - println!("[esp] FindWindowA failed with error code: {:?}", error_code); - } else { - GAME_WINDOW_HANDLE = window_handle_result.unwrap(); - println!( - "[esp] FindWindowA succeeded with window handle: {:?}", - GAME_WINDOW_HANDLE.0 - ); - } - - // Set window style to WS_EX_TRANSPARENT - let ex_style = GetWindowLongA(GAME_WINDOW_HANDLE, GWL_EXSTYLE); - SetWindowLongA( - GAME_WINDOW_HANDLE, - GWL_EXSTYLE, - ex_style | WS_EX_TRANSPARENT.0 as i32, - ); - - println!("[esp] Get device context and create a compatible DC"); - // Get device context for the game window - let hdc = GetDC(GAME_WINDOW_HANDLE); - if hdc.0.is_null() { - return Err(Box::new("Failed to get device context".to_string())); - } - - // Create a compatible device context (DC) - let mem_dc = CreateCompatibleDC(hdc); - if mem_dc.0.is_null() { - ReleaseDC(GAME_WINDOW_HANDLE, hdc); - return Err(Box::new("Failed to create compatible DC".to_string())); - } - - // Get window dimensions - println!("[esp] Get window dimensions"); - let dimensions = get_window_dimensions(GAME_WINDOW_HANDLE)?; - GAME_WINDOW_DIMENSIONS.width = dimensions.width; - GAME_WINDOW_DIMENSIONS.height = dimensions.height; - - - - - // Create a compatible bitmap for double buffering - println!("[esp] Create a compatible bitmap for double buffering"); - let mut mem_bitmap = CreateCompatibleBitmap(hdc, - GAME_WINDOW_DIMENSIONS.width, - GAME_WINDOW_DIMENSIONS.height); - SelectObject(mem_dc, mem_bitmap); // Select the bitmap into the DC - - - // Initialize game entity data - println!("[esp] Initialize game entity data"); - match read_view_matrix(VIEW_MATRIX_ADDR) { - Ok(matrix) => { - VIEW_MATRIX.copy_from_slice(&matrix); - } - Err(err) => { - println!("Error reading view matrix: {}", err); - return Err(Box::new(format!("Error reading view matrix: {}", - err).to_string())); - } - }; - - - println!("[esp] Create brushes for drawing"); - // Create brushes for drawing - let red_brush = CreateSolidBrush(COLORREF(0x000000FF)); // Red Enemy - let green_brush = CreateSolidBrush(COLORREF(0x0000FF00)); // Green Ally - let background_brush = CreateSolidBrush(COLORREF(0x00000000)); // Transparent - - // Check if the brushes are created successfully - if red_brush.0.is_null() || green_brush.0.is_null() || background_brush.0.is_null() { - // Cleanup on error - DeleteDC(mem_dc); - ReleaseDC(GAME_WINDOW_HANDLE, hdc); - return Err(Box::new("Failed to create brushes".to_string())); - } - println!("[esp] Create clash font from memory resource"); - // Create a Clash font with the specified size to use later - let mut n_fonts: u32 = 0; - - let font_handle = AddFontMemResourceEx( - crate::fonts::clash_font::CLASH.as_ptr() as *const c_void, // Pointer to the font resource - crate::fonts::clash_font::CLASH.len() as u32, // Size of the font resource - Some(null()), // Reserved (must be NULL) - &mut n_fonts, - ); // Number of fonts installed - - if font_handle.0.is_null() { - println!( - "Failed to add font from memory, error: {:?}", - GetLastError() - ); - return Err(Box::new(format!("Failed to add font from memory, error: {:?}", - GetLastError()).to_string())); - } - - // Return the handles and brushes - Ok((hdc, mem_dc, mem_bitmap, red_brush, green_brush, background_brush)) -} - -pub unsafe fn read_game_data() -> Result<(usize, usize, usize, [f32; 16]), Box> { - // Read the local player address - let local_player_addr = read_memory::(AC_CLIENT_EXE_HMODULE + LOCAL_PLAYER_OFFSET) - .map_err(|err| Box::new(format!("Error reading local player address: {}", err)))?; - - - - // Read the number of players in the match - let num_players_in_match = read_memory::(AC_CLIENT_EXE_HMODULE + NUMBER_OF_PLAYERS_IN_MATCH_OFFSET) - .map_err(|err| Box::new(format!("Error reading number of players in match: {}", err)))? as usize; - - - - // Read the entity list pointer - let entity_list_ptr = read_memory::(AC_CLIENT_EXE_HMODULE + ENTITY_LIST_OFFSET) - .map_err(|err| Box::new(format!("Error reading entity list pointer: {}", err)))?; - - - - // Read the view matrix - let view_matrix = read_view_matrix(VIEW_MATRIX_ADDR) - .map_err(|err| Box::new(format!("Error reading view matrix: {}", err)))?; - - - - // Return the values as a tuple - Ok((local_player_addr, num_players_in_match, entity_list_ptr, view_matrix)) -} - -pub unsafe fn render_esp_gdi( - hdc: HDC, - mem_dc: HDC, - mem_bitmap: HBITMAP, - red_brush: HBRUSH, - green_brush: HBRUSH, - background_brush: HBRUSH, - local_player_addr: usize, - num_players_in_match: usize, - entity_list_ptr: usize, - view_matrix: [f32; 16] -) -{ - // Clear the memory DC before drawing (set to transparent) - FillRect( - mem_dc, - &RECT { - left: 0, - top: 0, - right: GAME_WINDOW_DIMENSIONS.width, - bottom: GAME_WINDOW_DIMENSIONS.height, - }, - background_brush, - ); - - let mut invalidated_area = RECT { - left: 0, - top: 0, - right: GAME_WINDOW_DIMENSIONS.width, - bottom: GAME_WINDOW_DIMENSIONS.height, - }; - - // Process each entity - for i in 1..num_players_in_match { - let entity_addr = match Entity::from_addr(entity_list_ptr).read_value::(i * 0x4) { - Ok(addr) => addr, - Err(err) => { - println!("Error reading entity address: {}", err); - continue; - } - }; - - if entity_addr == 0 { - continue; - } - - let entity = Entity::from_addr(entity_addr); - - // Check if the entity is alive - if !entity.is_alive() { - continue; - } - - let mut feet_screen_pos = Vec2 { x: 0.0, y: 0.0 }; - let mut head_screen_pos = Vec2 { x: 0.0, y: 0.0 }; - - // Use match expressions for error handling with position and head_position - let entity_position = match entity.position() { - Ok(pos) => pos, - Err(err) => { - println!("Error reading entity position: {}", err); - continue; // Skip to the next entity if there's an error - } - }; - - let entity_head_position = match entity.head_position() { - Ok(pos) => pos, - Err(err) => { - println!("Error reading entity head position: {}", err); - continue; // Skip to the next entity if there's an error - } - }; - - // Convert world coordinates to screen coordinates - if !world_to_screen( - entity_position, - &mut feet_screen_pos, - view_matrix, - GAME_WINDOW_DIMENSIONS.width, - GAME_WINDOW_DIMENSIONS.height, - ) { - continue; - } - - if !world_to_screen( - entity_head_position, - &mut head_screen_pos, - view_matrix, - GAME_WINDOW_DIMENSIONS.width, - GAME_WINDOW_DIMENSIONS.height, - ) { - continue; - } - - // Draw box around the entity - let distance = match (LOCAL_PLAYER.position(), entity.position()) { - (Ok(local_pos), Ok(entity_pos)) => distance::distance_3d(local_pos, entity_pos), - (Err(err), _) | (_, Err(err)) => { - println!("Error reading position: {}", err); - continue; - } - }; - - let box_width = (GAME_WINDOW_DIMENSIONS.width as f32 / distance) as i32; - let box_height = (GAME_WINDOW_DIMENSIONS.height as f32 / distance * 3.5) as i32; - let box_left = (feet_screen_pos.x - box_width as f32 / 2.0) as i32; - let box_top = (feet_screen_pos.y - box_height as f32) as i32; - let box_brush_color = if LOCAL_PLAYER.team() == entity.team() { - green_brush - } else { - red_brush - }; - - // Draw the FOV circle if enabled - if IS_DRAW_FOV.load(SeqCst) { - draw_circle( - hdc, - ( - GAME_WINDOW_DIMENSIONS.width as f32 / 2.0, - GAME_WINDOW_DIMENSIONS.height as f32 / 2.0, - ), - FOV.load(SeqCst) as f32, - COLORREF(0x00FFFFFF), - ); - } - - // Draw text and border box for the entity - draw_text(mem_dc, feet_screen_pos.x as i32, feet_screen_pos.y as i32, &entity); - draw_border_box(mem_dc, box_brush_color, box_left, box_top, box_width, box_height, 5); - - // Draw health bar - match entity.health() { - Ok(health) => { - draw_scaling_bar( - mem_dc, - head_screen_pos.x - 55.0, - head_screen_pos.y, - feet_screen_pos.x - 15.0, - feet_screen_pos.y, - health as f32, - 100.0, - COLORREF(0x0000FF00), - ); - } - Err(err) => { - println!("Error reading entity health: {}", err); - } - } - - // Update the invalidated area to encompass all drawn entities - invalidated_area.left = invalidated_area.left.min(box_left); - invalidated_area.top = invalidated_area.top.min(box_top); - invalidated_area.right = invalidated_area.right.max(box_left + box_width); - invalidated_area.bottom = invalidated_area.bottom.max(box_top + box_height); - } - - // Invalidate the combined area of all drawn entities - if InvalidateRect(GAME_WINDOW_HANDLE, Some(&invalidated_area), TRUE) == FALSE { - println!("[esp] InvalidateRect failed {:?}", GetLastError()); - } - - // Perform the transparent blit - if TransparentBlt( - hdc, - 0, - 0, - GAME_WINDOW_DIMENSIONS.width, - GAME_WINDOW_DIMENSIONS.height, - mem_dc, - 0, - 0, - GAME_WINDOW_DIMENSIONS.width, - GAME_WINDOW_DIMENSIONS.height, - 0x00000000, - ) == FALSE { - println!("[esp] TransparentBlt failed {:?}", GetLastError()); - } -} - - -// Function to handle window resize -pub unsafe fn handle_window_resize_gdi( - mem_dc: &mut HDC, // Mutable pointer to the device context - mem_bitmap: &mut HBITMAP, // Mutable pointer to the bitmap -) -> Result<(), &'static str> { - // Check for window resize - if GAME_WINDOW_DIMENSIONS.width - != get_window_dimensions(GAME_WINDOW_HANDLE).unwrap().width - || GAME_WINDOW_DIMENSIONS.height - != get_window_dimensions(GAME_WINDOW_HANDLE).unwrap().height - { - let new_dimensions = get_window_dimensions(GAME_WINDOW_HANDLE).unwrap(); - let new_width = new_dimensions.width; - let new_height = new_dimensions.height; - - // Only recreate if dimensions have actually changed - if new_width != GAME_WINDOW_DIMENSIONS.width - || new_height != GAME_WINDOW_DIMENSIONS.height - { - println!("[esp] Window resized to: {}x{}", new_width, new_height); - - // Cleanup old resources - let _ = DeleteObject(*mem_bitmap); - let _ = DeleteDC(*mem_dc); - - // Create a new compatible DC and bitmap with the new dimensions - let hdc = GetDC(GAME_WINDOW_HANDLE); - *mem_dc = CreateCompatibleDC(hdc); - *mem_bitmap = CreateCompatibleBitmap(hdc, new_width, new_height); - SelectObject(*mem_dc, *mem_bitmap); // Select the new bitmap into the DC - - // Update current dimensions - GAME_WINDOW_DIMENSIONS.width = new_width; - GAME_WINDOW_DIMENSIONS.height = new_height; - - // Release the device context - ReleaseDC(GAME_WINDOW_HANDLE, hdc); - } - } - Ok(()) -} - - - -pub unsafe fn entrypoint() -> Result<(), Box> { - unsafe { - - // Initialize module handle - AC_CLIENT_EXE_HMODULE = { - let ac_client_exe_cstring = CString::new("ac_client.exe").unwrap(); - GetModuleHandleA(PCSTR(ac_client_exe_cstring.as_ptr() as *const u8)) - .map(|hinstance| hinstance.0 as usize) - .expect("[esp] Error getting module handle") - }; - - println!( - "[esp] Module base addr base_address={:#x}", - AC_CLIENT_EXE_HMODULE - ); - - - -/* let mut hdc; - let mut mem_dc; - let mut mem_bitmap; - let mut red_brush; - let mut green_brush; - let mut background_brush; - (hdc, mem_dc, mem_bitmap, red_brush, green_brush, background_brush) = init_esp_gdi()?;*/ - init_mem_patches(); - - - loop { - if !IS_ESP.load(SeqCst) { - println!("[esp] Turning off ESP"); - thread::sleep(Duration::from_millis(1000)); - continue; - } - - - - - - - - /*println!("[esp] going to unwrap assaultcube window handle");*/ - let assault_cube_cstring = CString::new("AssaultCube").unwrap(); -/* println!("[esp] going to unwrap FindWindowA");*/ - let window_handle_result = FindWindowA( - PCSTR(0 as *const u8), - PCSTR(assault_cube_cstring.as_ptr() as *const u8), - ); - - if window_handle_result.is_err() { - let error_code = GetLastError(); - println!("[esp] FindWindowA failed with error code: {:?}", error_code); - } else { - GAME_WINDOW_HANDLE = window_handle_result.unwrap(); -/* println!( - "[esp] FindWindowA succeeded with window handle: {:?}", - GAME_WINDOW_HANDLE.0 - );*/ - } - - // Get window dimensions -/* println!("[esp] Get window dimensions");*/ - let dimensions = get_window_dimensions(GAME_WINDOW_HANDLE)?; - GAME_WINDOW_DIMENSIONS.width = dimensions.width; - GAME_WINDOW_DIMENSIONS.height = dimensions.height; - - - - - - - match read_game_data() { - Ok((local_player_addr, num_players_in_match, entity_list_ptr, view_matrix)) => { - LOCAL_PLAYER = Entity::from_addr(local_player_addr); - NUM_PLAYERS_IN_MATCH = num_players_in_match; - ENTITY_LIST_PTR = entity_list_ptr; - // Copy the view matrix into the global variable - VIEW_MATRIX.copy_from_slice(&view_matrix); -/* render_esp_gdi(hdc, mem_dc, - mem_bitmap, - red_brush, green_brush, background_brush, - local_player_addr, num_players_in_match, entity_list_ptr, view_matrix);*/ - }, - Err(err) => { - println!("{}", err); // Handle the error appropriately - return Ok(()); - } - } - -/* handle_window_resize_gdi(&mut mem_dc, &mut mem_bitmap).unwrap();*/ - - - - // Sleep to reduce CPU usage - thread::sleep(Duration::from_millis(5)); - } - /* - // Cleanup resources at the end of the loop - esp_cleanup(GAME_WINDOW_HANDLE, hdc, mem_dc, mem_bitmap, red_brush, green_brush, background_brush) - .expect("[esp] Failed to deallocate hdcs, brushes, and bitmaps."); - - Ok(())*/ - } -} \ No newline at end of file +use std::ffi::{c_void, CString}; +use std::ptr::null; +use std::result::Result::Ok; +use std::sync::atomic::Ordering::SeqCst; +use std::thread; +use std::time::Duration; + +use windows::core::PCSTR; +use windows::Win32::Foundation::{GetLastError, COLORREF, FALSE, TRUE}; +use windows::Win32::Graphics::Gdi::{ + AddFontMemResourceEx, CreateCompatibleBitmap, CreateCompatibleDC, CreateSolidBrush, DeleteDC, + DeleteObject, GetDC, InvalidateRect, ReleaseDC, SelectObject, TransparentBlt, HBITMAP, +}; +use windows::Win32::System::LibraryLoader::GetModuleHandleA; +use windows::Win32::UI::WindowsAndMessaging::{ + FindWindowA, GetWindowLongA, SetWindowLongA, GWL_EXSTYLE, WS_EX_TRANSPARENT, +}; +use windows::Win32::{ + Foundation::RECT, + Graphics::Gdi::{FillRect, HBRUSH, HDC}, +}; + +use crate::distance; +use crate::draw_utils::{draw_border_box, draw_circle, draw_scaling_bar, draw_text}; +use crate::entity::Entity; +use crate::get_window_dimensions::get_window_dimensions; +use crate::misc::init_mem_patches; +use crate::offsets::offsets::{ + ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR, +}; +use crate::utils::{read_memory, read_view_matrix}; +use crate::vars::game_vars::LOCAL_PLAYER; +use crate::vars::game_vars::NUM_PLAYERS_IN_MATCH; +use crate::vars::game_vars::{ENTITY_LIST_PTR, FOV, VIEW_MATRIX}; +use crate::vars::handles::GAME_WINDOW_DIMENSIONS; +use crate::vars::handles::{AC_CLIENT_EXE_HMODULE, GAME_WINDOW_HANDLE}; +use crate::vars::ui_vars::{IS_DRAW_FOV, IS_ESP}; +use crate::vec_structures::Vec2; +use crate::world_to_screen::world_to_screen; + +#[allow(unused)] +pub unsafe fn init_esp_gdi() -> Result<(HDC, HDC, HBITMAP, HBRUSH, HBRUSH, HBRUSH), Box> { + unsafe { + // Initialize module handle + AC_CLIENT_EXE_HMODULE = { + let ac_client_exe_cstring = CString::new("ac_client.exe").unwrap(); + GetModuleHandleA(PCSTR(ac_client_exe_cstring.as_ptr() as *const u8)) + .map(|hinstance| hinstance.0 as usize) + .expect("[esp] Error getting module handle") + }; + + println!( + "[esp] Module base addr base_address={:#x}", + AC_CLIENT_EXE_HMODULE + ); + + println!("[esp] going to unwrap assaultcube window handle"); + let assault_cube_cstring = CString::new("AssaultCube").unwrap(); + println!("[esp] going to unwrap FindWindowA"); + let window_handle_result = FindWindowA( + PCSTR(0 as *const u8), + PCSTR(assault_cube_cstring.as_ptr() as *const u8), + ); + + if window_handle_result.is_err() { + let error_code = GetLastError(); + println!("[esp] FindWindowA failed with error code: {:?}", error_code); + } else { + GAME_WINDOW_HANDLE = window_handle_result.unwrap(); + println!( + "[esp] FindWindowA succeeded with window handle: {:?}", + GAME_WINDOW_HANDLE.0 + ); + } + + // Set window style to WS_EX_TRANSPARENT + let ex_style = GetWindowLongA(GAME_WINDOW_HANDLE, GWL_EXSTYLE); + SetWindowLongA( + GAME_WINDOW_HANDLE, + GWL_EXSTYLE, + ex_style | WS_EX_TRANSPARENT.0 as i32, + ); + + println!("[esp] Get device context and create a compatible DC"); + // Get device context for the game window + let hdc = GetDC(GAME_WINDOW_HANDLE); + if hdc.0.is_null() { + return Err(Box::new("Failed to get device context".to_string())); + } + + // Create a compatible device context (DC) + let mem_dc = CreateCompatibleDC(hdc); + if mem_dc.0.is_null() { + ReleaseDC(GAME_WINDOW_HANDLE, hdc); + return Err(Box::new("Failed to create compatible DC".to_string())); + } + + // Get window dimensions + println!("[esp] Get window dimensions"); + let dimensions = get_window_dimensions(GAME_WINDOW_HANDLE)?; + GAME_WINDOW_DIMENSIONS.width = dimensions.width; + GAME_WINDOW_DIMENSIONS.height = dimensions.height; + + // Create a compatible bitmap for double buffering + println!("[esp] Create a compatible bitmap for double buffering"); + let mut mem_bitmap = CreateCompatibleBitmap( + hdc, + GAME_WINDOW_DIMENSIONS.width, + GAME_WINDOW_DIMENSIONS.height, + ); + SelectObject(mem_dc, mem_bitmap); // Select the bitmap into the DC + + // Initialize game entity data + println!("[esp] Initialize game entity data"); + match read_view_matrix(VIEW_MATRIX_ADDR) { + Ok(matrix) => { + VIEW_MATRIX.copy_from_slice(&matrix); + } + Err(err) => { + println!("Error reading view matrix: {}", err); + return Err(Box::new( + format!("Error reading view matrix: {}", err).to_string(), + )); + } + }; + + println!("[esp] Create brushes for drawing"); + // Create brushes for drawing + let red_brush = CreateSolidBrush(COLORREF(0x000000FF)); // Red Enemy + let green_brush = CreateSolidBrush(COLORREF(0x0000FF00)); // Green Ally + let background_brush = CreateSolidBrush(COLORREF(0x00000000)); // Transparent + + // Check if the brushes are created successfully + if red_brush.0.is_null() || green_brush.0.is_null() || background_brush.0.is_null() { + // Cleanup on error + let _ = DeleteDC(mem_dc); + ReleaseDC(GAME_WINDOW_HANDLE, hdc); + return Err(Box::new("Failed to create brushes".to_string())); + } + println!("[esp] Create clash font from memory resource"); + // Create a Clash font with the specified size to use later + let mut n_fonts: u32 = 0; + + let font_handle = AddFontMemResourceEx( + crate::fonts::clash_font::CLASH.as_ptr() as *const c_void, // Pointer to the font resource + crate::fonts::clash_font::CLASH.len() as u32, // Size of the font resource + Some(null()), // Reserved (must be NULL) + &mut n_fonts, + ); // Number of fonts installed + + if font_handle.0.is_null() { + println!( + "Failed to add font from memory, error: {:?}", + GetLastError() + ); + return Err(Box::new( + format!( + "Failed to add font from memory, error: {:?}", + GetLastError() + ) + .to_string(), + )); + } + + // Return the handles and brushes + Ok(( + hdc, + mem_dc, + mem_bitmap, + red_brush, + green_brush, + background_brush, + )) + } +} + +pub unsafe fn read_game_data() -> Result<(usize, usize, usize, [f32; 16]), Box> { + unsafe { + // Read the local player address + let local_player_addr = + read_memory::(AC_CLIENT_EXE_HMODULE + LOCAL_PLAYER_OFFSET) + .map_err(|err| Box::new(format!("Error reading local player address: {}", err)))?; + + // Read the number of players in the match + let num_players_in_match = + read_memory::(AC_CLIENT_EXE_HMODULE + NUMBER_OF_PLAYERS_IN_MATCH_OFFSET) + .map_err(|err| { + Box::new(format!("Error reading number of players in match: {}", err)) + })? as usize; + + // Read the entity list pointer + let entity_list_ptr = read_memory::(AC_CLIENT_EXE_HMODULE + ENTITY_LIST_OFFSET) + .map_err(|err| Box::new(format!("Error reading entity list pointer: {}", err)))?; + + // Read the view matrix + let view_matrix = read_view_matrix(VIEW_MATRIX_ADDR) + .map_err(|err| Box::new(format!("Error reading view matrix: {}", err)))?; + + // Return the values as a tuple + Ok(( + local_player_addr, + num_players_in_match, + entity_list_ptr, + view_matrix, + )) + } +} +#[allow(unused)] +pub unsafe fn render_esp_gdi( + hdc: HDC, + mem_dc: HDC, + mem_bitmap: HBITMAP, + red_brush: HBRUSH, + green_brush: HBRUSH, + background_brush: HBRUSH, + local_player_addr: usize, + num_players_in_match: usize, + entity_list_ptr: usize, + view_matrix: [f32; 16], +) { + unsafe { + // Clear the memory DC before drawing (set to transparent) + FillRect( + mem_dc, + &RECT { + left: 0, + top: 0, + right: GAME_WINDOW_DIMENSIONS.width, + bottom: GAME_WINDOW_DIMENSIONS.height, + }, + background_brush, + ); + + let mut invalidated_area = RECT { + left: 0, + top: 0, + right: GAME_WINDOW_DIMENSIONS.width, + bottom: GAME_WINDOW_DIMENSIONS.height, + }; + + // Process each entity + for i in 1..num_players_in_match { + let entity_addr = match Entity::from_addr(entity_list_ptr).read_value::(i * 0x4) + { + Ok(addr) => addr, + Err(err) => { + println!("Error reading entity address: {}", err); + continue; + } + }; + + if entity_addr == 0 { + continue; + } + + let entity = Entity::from_addr(entity_addr); + + // Check if the entity is alive + if !entity.is_alive() { + continue; + } + + let mut feet_screen_pos = Vec2 { x: 0.0, y: 0.0 }; + let mut head_screen_pos = Vec2 { x: 0.0, y: 0.0 }; + + // Use match expressions for error handling with position and head_position + let entity_position = match entity.position() { + Ok(pos) => pos, + Err(err) => { + println!("Error reading entity position: {}", err); + continue; // Skip to the next entity if there's an error + } + }; + + let entity_head_position = match entity.head_position() { + Ok(pos) => pos, + Err(err) => { + println!("Error reading entity head position: {}", err); + continue; // Skip to the next entity if there's an error + } + }; + + // Convert world coordinates to screen coordinates + if !world_to_screen( + entity_position, + &mut feet_screen_pos, + view_matrix, + GAME_WINDOW_DIMENSIONS.width, + GAME_WINDOW_DIMENSIONS.height, + ) { + continue; + } + + if !world_to_screen( + entity_head_position, + &mut head_screen_pos, + view_matrix, + GAME_WINDOW_DIMENSIONS.width, + GAME_WINDOW_DIMENSIONS.height, + ) { + continue; + } + + // Draw box around the entity + let distance = match (LOCAL_PLAYER.position(), entity.position()) { + (Ok(local_pos), Ok(entity_pos)) => distance::distance_3d(local_pos, entity_pos), + (Err(err), _) | (_, Err(err)) => { + println!("Error reading position: {}", err); + continue; + } + }; + + let box_width = (GAME_WINDOW_DIMENSIONS.width as f32 / distance) as i32; + let box_height = (GAME_WINDOW_DIMENSIONS.height as f32 / distance * 3.5) as i32; + let box_left = (feet_screen_pos.x - box_width as f32 / 2.0) as i32; + let box_top = (feet_screen_pos.y - box_height as f32) as i32; + let box_brush_color = if LOCAL_PLAYER.team() == entity.team() { + green_brush + } else { + red_brush + }; + + // Draw the FOV circle if enabled + if IS_DRAW_FOV.load(SeqCst) { + draw_circle( + hdc, + ( + GAME_WINDOW_DIMENSIONS.width as f32 / 2.0, + GAME_WINDOW_DIMENSIONS.height as f32 / 2.0, + ), + FOV.load(SeqCst) as f32, + COLORREF(0x00FFFFFF), + ); + } + + // Draw text and border box for the entity + draw_text( + mem_dc, + feet_screen_pos.x as i32, + feet_screen_pos.y as i32, + &entity, + ); + draw_border_box( + mem_dc, + box_brush_color, + box_left, + box_top, + box_width, + box_height, + 5, + ); + + // Draw health bar + match entity.health() { + Ok(health) => unsafe { + draw_scaling_bar( + mem_dc, + head_screen_pos.x - 55.0, + head_screen_pos.y, + feet_screen_pos.x - 15.0, + feet_screen_pos.y, + health as f32, + 100.0, + COLORREF(0x0000FF00), + ); + }, + Err(err) => { + println!("Error reading entity health: {}", err); + } + } + + // Update the invalidated area to encompass all drawn entities + invalidated_area.left = invalidated_area.left.min(box_left); + invalidated_area.top = invalidated_area.top.min(box_top); + invalidated_area.right = invalidated_area.right.max(box_left + box_width); + invalidated_area.bottom = invalidated_area.bottom.max(box_top + box_height); + } + unsafe { + // Invalidate the combined area of all drawn entities + if InvalidateRect(GAME_WINDOW_HANDLE, Some(&invalidated_area), TRUE) == FALSE { + println!("[esp] InvalidateRect failed {:?}", GetLastError()); + } + + // Perform the transparent blit + if TransparentBlt( + hdc, + 0, + 0, + GAME_WINDOW_DIMENSIONS.width, + GAME_WINDOW_DIMENSIONS.height, + mem_dc, + 0, + 0, + GAME_WINDOW_DIMENSIONS.width, + GAME_WINDOW_DIMENSIONS.height, + 0x00000000, + ) == FALSE + { + println!("[esp] TransparentBlt failed {:?}", GetLastError()); + } + } + } +} + +// Function to handle window resize +#[allow(unused)] +pub unsafe fn handle_window_resize_gdi( + mem_dc: &mut HDC, // Mutable pointer to the device context + mem_bitmap: &mut HBITMAP, // Mutable pointer to the bitmap +) -> Result<(), &'static str> { + unsafe { + // Check for window resize + if GAME_WINDOW_DIMENSIONS.width != get_window_dimensions(GAME_WINDOW_HANDLE).unwrap().width + || GAME_WINDOW_DIMENSIONS.height + != get_window_dimensions(GAME_WINDOW_HANDLE).unwrap().height + { + let new_dimensions = get_window_dimensions(GAME_WINDOW_HANDLE).unwrap(); + let new_width = new_dimensions.width; + let new_height = new_dimensions.height; + + // Only recreate if dimensions have actually changed + if new_width != GAME_WINDOW_DIMENSIONS.width + || new_height != GAME_WINDOW_DIMENSIONS.height + { + println!("[esp] Window resized to: {}x{}", new_width, new_height); + + // Cleanup old resources + let _ = DeleteObject(*mem_bitmap); + let _ = DeleteDC(*mem_dc); + + // Create a new compatible DC and bitmap with the new dimensions + let hdc = GetDC(GAME_WINDOW_HANDLE); + *mem_dc = CreateCompatibleDC(hdc); + *mem_bitmap = CreateCompatibleBitmap(hdc, new_width, new_height); + SelectObject(*mem_dc, *mem_bitmap); // Select the new bitmap into the DC + + // Update current dimensions + GAME_WINDOW_DIMENSIONS.width = new_width; + GAME_WINDOW_DIMENSIONS.height = new_height; + + // Release the device context + ReleaseDC(GAME_WINDOW_HANDLE, hdc); + } + } + } + Ok(()) +} + +pub unsafe fn entrypoint() -> Result<(), Box> { + unsafe { + // Initialize module handle + AC_CLIENT_EXE_HMODULE = { + let ac_client_exe_cstring = CString::new("ac_client.exe").unwrap(); + GetModuleHandleA(PCSTR(ac_client_exe_cstring.as_ptr() as *const u8)) + .map(|hinstance| hinstance.0 as usize) + .expect("[esp] Error getting module handle") + }; + + println!( + "[esp] Module base addr base_address={:#x}", + AC_CLIENT_EXE_HMODULE + ); + + /* let mut hdc; + let mut mem_dc; + let mut mem_bitmap; + let mut red_brush; + let mut green_brush; + let mut background_brush; + (hdc, mem_dc, mem_bitmap, red_brush, green_brush, background_brush) = init_esp_gdi()?;*/ + init_mem_patches(); + + loop { + if !IS_ESP.load(SeqCst) { + println!("[esp] Turning off ESP"); + thread::sleep(Duration::from_millis(1000)); + continue; + } + + /*println!("[esp] going to unwrap assaultcube window handle");*/ + let assault_cube_cstring = CString::new("AssaultCube").unwrap(); + /* println!("[esp] going to unwrap FindWindowA");*/ + let window_handle_result = FindWindowA( + PCSTR(0 as *const u8), + PCSTR(assault_cube_cstring.as_ptr() as *const u8), + ); + + if window_handle_result.is_err() { + let error_code = GetLastError(); + println!("[esp] FindWindowA failed with error code: {:?}", error_code); + } else { + GAME_WINDOW_HANDLE = window_handle_result.unwrap(); + /* println!( + "[esp] FindWindowA succeeded with window handle: {:?}", + GAME_WINDOW_HANDLE.0 + );*/ + } + + // Get window dimensions + /* println!("[esp] Get window dimensions");*/ + let dimensions = get_window_dimensions(GAME_WINDOW_HANDLE)?; + GAME_WINDOW_DIMENSIONS.width = dimensions.width; + GAME_WINDOW_DIMENSIONS.height = dimensions.height; + + match read_game_data() { + Ok((local_player_addr, num_players_in_match, entity_list_ptr, view_matrix)) => { + LOCAL_PLAYER = Entity::from_addr(local_player_addr); + NUM_PLAYERS_IN_MATCH = num_players_in_match; + ENTITY_LIST_PTR = entity_list_ptr; + // Copy the view matrix into the global variable + VIEW_MATRIX.copy_from_slice(&view_matrix); + /* render_esp_gdi(hdc, mem_dc, + mem_bitmap, + red_brush, green_brush, background_brush, + local_player_addr, num_players_in_match, entity_list_ptr, view_matrix);*/ + } + Err(err) => { + println!("{}", err); // Handle the error appropriately + return Ok(()); + } + } + + /* handle_window_resize_gdi(&mut mem_dc, &mut mem_bitmap).unwrap();*/ + + // Sleep to reduce CPU usage + thread::sleep(Duration::from_millis(5)); + } + /* + // Cleanup resources at the end of the loop + esp_cleanup(GAME_WINDOW_HANDLE, hdc, mem_dc, mem_bitmap, red_brush, green_brush, background_brush) + .expect("[esp] Failed to deallocate hdcs, brushes, and bitmaps."); + + Ok(())*/ + } +} diff --git a/src/esp.rs b/src/esp.rs index 52a77a0..5901cc5 100644 --- a/src/esp.rs +++ b/src/esp.rs @@ -1,5 +1,5 @@ use windows::Win32::Foundation::{HWND, TRUE}; -use windows::Win32::Graphics::Gdi::{DeleteDC, DeleteObject, HBITMAP, HBRUSH, HDC, ReleaseDC}; +use windows::Win32::Graphics::Gdi::{DeleteDC, DeleteObject, ReleaseDC, HBITMAP, HBRUSH, HDC}; #[allow(unused)] unsafe fn esp_cleanup( @@ -54,4 +54,3 @@ unsafe fn esp_cleanup( } Ok(()) } - diff --git a/src/fonts/mod.rs b/src/fonts/mod.rs index caa6019..a04e353 100644 --- a/src/fonts/mod.rs +++ b/src/fonts/mod.rs @@ -1,2 +1,2 @@ pub mod clash_font; -pub mod graffiti_font; \ No newline at end of file +pub mod graffiti_font; diff --git a/src/game.rs b/src/game.rs index af71c8b..4a3c99e 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,19 +1,34 @@ -use std::ffi::c_void; +use std::ffi::{c_void, CString}; +use windows::core::PCSTR; +use windows::Win32::System::LibraryLoader::GetModuleHandleA; use windows::Win32::System::Memory::{ VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS, }; use crate::offsets::offsets::{BRIGHTNESS, SET_BRIGHTNESS}; use crate::utils::write_memory; -use crate::vars::handles::AC_CLIENT_EXE_HMODULE; pub unsafe fn c_brightness() -> *mut usize { - unsafe { (AC_CLIENT_EXE_HMODULE + BRIGHTNESS) as *mut usize } + unsafe { + ({ + let ac_client_exe_cstring = CString::new("ac_client.exe").unwrap(); + GetModuleHandleA(PCSTR(ac_client_exe_cstring.as_ptr() as *const u8)) + .map(|hinstance| hinstance.0 as usize) + .expect("[esp] Error getting module handle") + } + BRIGHTNESS) as *mut usize + } } pub unsafe fn set_brightness() -> *mut usize { - unsafe { (AC_CLIENT_EXE_HMODULE + SET_BRIGHTNESS) as *mut usize } + unsafe { + ({ + let ac_client_exe_cstring = CString::new("ac_client.exe").unwrap(); + GetModuleHandleA(PCSTR(ac_client_exe_cstring.as_ptr() as *const u8)) + .map(|hinstance| hinstance.0 as usize) + .expect("[esp] Error getting module handle") + } + SET_BRIGHTNESS) as *mut usize + } } pub unsafe fn set_brightness_toggle(is_on: bool) { diff --git a/src/hotkey_widget.rs b/src/hotkey_widget.rs index 7775d96..4e788a7 100644 --- a/src/hotkey_widget.rs +++ b/src/hotkey_widget.rs @@ -1,11 +1,23 @@ use std::collections::HashSet; -use std::sync::atomic::Ordering::SeqCst; + use hudhook::imgui; -use hudhook::imgui::{Io, MouseButton, Window}; +use hudhook::imgui::{Io, MouseButton}; 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, GetAsyncKeyState}; -use crate::vars::ui_vars::IS_SHOW_UI; +use windows::Win32::UI::Input::KeyboardAndMouse::{ + GetAsyncKeyState, 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_LBUTTON, VK_LCONTROL, VK_LEFT, VK_LMENU, VK_LSHIFT, VK_LWIN, VK_M, + VK_MBUTTON, 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_RBUTTON, + 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_XBUTTON1, VK_XBUTTON2, + VK_Y, VK_Z, +}; #[derive(Clone, Debug)] pub struct HotKey { @@ -144,7 +156,9 @@ impl<'de> Deserialize<'de> for HotKey { } pub trait ImguiUiEx { + #[allow(unused)] fn set_cursor_pos_x(&self, pos: f32); + #[allow(unused)] fn set_cursor_pos_y(&self, pos: f32); } @@ -267,14 +281,10 @@ 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 { @@ -289,7 +299,7 @@ impl KeyboardInputSystem { } } - pub unsafe fn update(&mut self, io: &mut Io) { + pub unsafe fn update(&mut self, io: &mut Io, is_show_ui: bool) { for vkey in 0..VK_KEY_MAX { let key_state = unsafe { GetAsyncKeyState(vkey as i32) as u16 }; let pressed = key_state & 1 == 1; @@ -301,34 +311,34 @@ impl KeyboardInputSystem { 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); + unsafe { + if !is_show_ui + //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); } - } - 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 index 2fbcca0..b8485dc 100644 --- a/src/key_action.rs +++ b/src/key_action.rs @@ -1,226 +1,229 @@ -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 +use std::sync::atomic::Ordering::SeqCst; + +use crate::angle::Angle; +use crate::entity::Entity; +use crate::game::{set_brightness, set_brightness_toggle}; +use crate::getclosestentity::get_closest_entity; +use crate::offsets::offsets::{LOCAL_PLAYER_OFFSET, PITCH_OFFSET, YAW_OFFSET}; +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_SMOOTH; +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: Box, // Closure that takes no parameters +} + +// Define the actions for each key +pub unsafe fn toggle_show_ui(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_wallhack(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_esp(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_infinite_nades(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_no_reload(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_invulnerability(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_infinite_ammo(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_no_recoil(toggle: &mut bool) { + *toggle = !*toggle; + if *toggle { + 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(toggle: &mut bool) { + *toggle = !*toggle; + if *toggle { + 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(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_draw_fov(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_smooth(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_triggerbot(toggle: &mut bool) { + *toggle = !*toggle; +} + +pub unsafe fn toggle_maphack(toggle: &mut bool) { + unsafe { + *toggle = !*toggle; + if *toggle { + 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(toggle: &mut bool) { + *toggle = !*toggle; + let set_brightness_func = unsafe { set_brightness() }; + if !set_brightness_func.is_null() { + unsafe { set_brightness_toggle(*toggle) }; + } else { + println!("Function pointer to set_brightness is null!"); + } +} + +pub unsafe fn aimbot(toggle: &mut bool) { + //app_settings: &AppSettings + unsafe { + if !*toggle { + 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/lib.rs b/src/lib.rs index 9a78fc5..ec08a52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,35 +13,35 @@ use vars::handles::CHEAT_DLL_HMODULE; mod main_thread; -mod esp; -mod offsets; -mod ui; -mod utils; mod angle; mod distance; mod draw_utils; mod entity; +mod entrypoint; +mod esp; mod fonts; mod game; mod get_local_player_hook; mod get_window_dimensions; mod getclosestentity; mod hotkey_widget; +mod key_action; +mod locales; mod memorypatch; mod misc; +mod offsets; mod pattern_mask; mod settings; mod state; mod style; mod triggerbot_hook; +mod ui; +mod utils; mod vars; mod vec_structures; mod wallhack_hook; mod window_dimensions; mod world_to_screen; -mod locales; -mod key_action; -mod entrypoint; #[no_mangle] #[allow(non_snake_case, unused_variables)] diff --git a/src/locales/cantonese_locale.rs b/src/locales/cantonese_locale.rs index 83fc6f1..94d37bd 100644 --- a/src/locales/cantonese_locale.rs +++ b/src/locales/cantonese_locale.rs @@ -1,7 +1,26 @@ -pub static CANTONESE_LOCALE_VECTOR: [&str; 24] = ["[Insert]顯示/隱藏菜單", "作弊", -"[Home]看穿牆壁","[Delete]超感知覺","[F1]無限手榴彈", -"[F2]不裝填武器","[F3]刀槍不入","[F4]無限彈藥", -"[F5]無後坐力","[F6]快速射擊","[F7]自動瞄準", -"[F8]顯示自動瞄準視角","視角","[F9]平滑自動瞄準","平滑度", -"[F10]自動發射","自動發射延遲時間(秒)","[F11]在小地圖上看到所有人", -"[F12]全亮","保存當前設置","主題","主題", "設置","語言"]; \ No newline at end of file +pub static CANTONESE_LOCALE_VECTOR: [&str; 24] = [ + "[Insert]顯示/隱藏菜單", + "作弊", + "[Home]看穿牆壁", + "[Delete]超感知覺", + "[F1]無限手榴彈", + "[F2]不裝填武器", + "[F3]刀槍不入", + "[F4]無限彈藥", + "[F5]無後坐力", + "[F6]快速射擊", + "[F7]自動瞄準", + "[F8]顯示自動瞄準視角", + "視角", + "[F9]平滑自動瞄準", + "平滑度", + "[F10]自動發射", + "自動發射延遲時間(秒)", + "[F11]在小地圖上看到所有人", + "[F12]全亮", + "保存當前設置", + "主題", + "主題", + "設置", + "語言", +]; diff --git a/src/locales/chinese_locale.rs b/src/locales/chinese_locale.rs index 1696995..fbcb14b 100644 --- a/src/locales/chinese_locale.rs +++ b/src/locales/chinese_locale.rs @@ -1,7 +1,26 @@ -pub static MANDARIN_LOCALE_VECTOR: [&str; 24]= ["[Insert]显示/隐藏菜单", "作弊", -"[Home]看穿墙壁","[Delete]超感知觉","[F1]无限手榴弹", -"[F2]不装填武器","[F3]刀枪不入","[F4]无限弹药", -"[F5]无后坐力","[F6]快速射击","[F7]自动瞄准", -"[F8]显示自动瞄准视角","视角","[F9]平滑自动瞄准","平滑度", -"[F10]自动发射","自动发射延迟时间(秒)","[F11]在小地图上看到所有人", -"[F12]全亮","保存当前设置","主题","主题", "设置","语言"]; \ No newline at end of file +pub static MANDARIN_LOCALE_VECTOR: [&str; 24] = [ + "[Insert]显示/隐藏菜单", + "作弊", + "[Home]看穿墙壁", + "[Delete]超感知觉", + "[F1]无限手榴弹", + "[F2]不装填武器", + "[F3]刀枪不入", + "[F4]无限弹药", + "[F5]无后坐力", + "[F6]快速射击", + "[F7]自动瞄准", + "[F8]显示自动瞄准视角", + "视角", + "[F9]平滑自动瞄准", + "平滑度", + "[F10]自动发射", + "自动发射延迟时间(秒)", + "[F11]在小地图上看到所有人", + "[F12]全亮", + "保存当前设置", + "主题", + "主题", + "设置", + "语言", +]; diff --git a/src/locales/english_locale.rs b/src/locales/english_locale.rs index bb1c8fd..b15ad5c 100644 --- a/src/locales/english_locale.rs +++ b/src/locales/english_locale.rs @@ -1,6 +1,26 @@ -pub static ENG_LOCALE_VECTOR: [&str; 24] = ["[Insert] Show/Hide Menu", "Cheats", "[Home] Wallhack", - "[Delete] ESP", "[F1] Infinite Grenades", "[F2] No Reload", "[F3] Invulnerability", - "[F4] Infinite Ammo", "[F5] No Recoil", "[F6] Rapid Fire", "[F7] Aimbot", - "[F8] Aimbot Draw FOV", "FOV", "[F9] Aimbot Smooth", "Smooth", "[F10] Triggerbot", - "Triggerbot Delay ms", "[F11] Maphack", "[F12] Full Bright", "Save current settings", - "Themes", "Theme", "Settings", "Language"]; \ No newline at end of file +pub static ENG_LOCALE_VECTOR: [&str; 24] = [ + "[Insert] Show/Hide Menu", + "Cheats", + "[Home] Wallhack", + "[Delete] ESP", + "[F1] Infinite Grenades", + "[F2] No Reload", + "[F3] Invulnerability", + "[F4] Infinite Ammo", + "[F5] No Recoil", + "[F6] Rapid Fire", + "[F7] Aimbot", + "[F8] Aimbot Draw FOV", + "FOV", + "[F9] Aimbot Smooth", + "Smooth", + "[F10] Triggerbot", + "Triggerbot Delay ms", + "[F11] Maphack", + "[F12] Full Bright", + "Save current settings", + "Themes", + "Theme", + "Settings", + "Language", +]; diff --git a/src/locales/hebrew_locale.rs b/src/locales/hebrew_locale.rs index 2daec4d..8d0c890 100644 --- a/src/locales/hebrew_locale.rs +++ b/src/locales/hebrew_locale.rs @@ -1,27 +1,27 @@ -use gnal_tsur::gnal_tsur; -pub static HEBREW_LOCALE_VECTOR: [&str; 24] = [ - gnal_tsur!("]tresnI[ הצג / הסתר תפריט"), - gnal_tsur!("בגידות"), - gnal_tsur!("]emoH[ לראות דרך קירות"), - gnal_tsur!("]eteleD[ תפיסה חוץ חושית"), - gnal_tsur!("]1F[ רימוני אינסוף"), - gnal_tsur!("]2F[ ללא טעינת נשק מחדש"), - gnal_tsur!("]3F[ פגיעות"), - gnal_tsur!("]4F[ תחמושת אינסופית"), - gnal_tsur!("]5F[ ללא רתיעה"), - gnal_tsur!("]6F[ אש מהירה"), - gnal_tsur!("]7F[ מכוון אוטומטי"), - gnal_tsur!("]8F[ זווית צפייה מכוונת אוטומטית"), - gnal_tsur!("זווית צפייה"), - gnal_tsur!("]9F[ מטרה אוטומטית חלקה"), - gnal_tsur!("חלקות"), - gnal_tsur!("]01F[ ירי אוטומטי"), - gnal_tsur!("עיכוב ירי אוטומטי באלפיות השנייה"), - gnal_tsur!("]11F[ ראה את כולם במפה מינימלית"), - gnal_tsur!("]21F[ בהיר מלא"), - gnal_tsur!("שמור הגדרות נוכחיות"), - gnal_tsur!("ערכות נושא"), - gnal_tsur!("עיצוב נושא"), - gnal_tsur!("הגדרות"), - gnal_tsur!("שפה") -]; \ No newline at end of file +use gnal_tsur::gnal_tsur; +pub static HEBREW_LOCALE_VECTOR: [&str; 24] = [ + gnal_tsur!("]tresnI[ הצג / הסתר תפריט"), + gnal_tsur!("בגידות"), + gnal_tsur!("]emoH[ לראות דרך קירות"), + gnal_tsur!("]eteleD[ תפיסה חוץ חושית"), + gnal_tsur!("]1F[ רימוני אינסוף"), + gnal_tsur!("]2F[ ללא טעינת נשק מחדש"), + gnal_tsur!("]3F[ פגיעות"), + gnal_tsur!("]4F[ תחמושת אינסופית"), + gnal_tsur!("]5F[ ללא רתיעה"), + gnal_tsur!("]6F[ אש מהירה"), + gnal_tsur!("]7F[ מכוון אוטומטי"), + gnal_tsur!("]8F[ זווית צפייה מכוונת אוטומטית"), + gnal_tsur!("זווית צפייה"), + gnal_tsur!("]9F[ מטרה אוטומטית חלקה"), + gnal_tsur!("חלקות"), + gnal_tsur!("]01F[ ירי אוטומטי"), + gnal_tsur!("עיכוב ירי אוטומטי באלפיות השנייה"), + gnal_tsur!("]11F[ ראה את כולם במפה מינימלית"), + gnal_tsur!("]21F[ בהיר מלא"), + gnal_tsur!("שמור הגדרות נוכחיות"), + gnal_tsur!("ערכות נושא"), + gnal_tsur!("עיצוב נושא"), + gnal_tsur!("הגדרות"), + gnal_tsur!("שפה"), +]; diff --git a/src/locales/mod.rs b/src/locales/mod.rs index d16100d..c134328 100644 --- a/src/locales/mod.rs +++ b/src/locales/mod.rs @@ -1,6 +1,6 @@ -pub mod english_locale; -pub mod russian_locale; -pub mod chinese_locale; -pub mod ukrainian_locale; -pub mod cantonese_locale; -pub mod hebrew_locale; \ No newline at end of file +pub mod cantonese_locale; +pub mod chinese_locale; +pub mod english_locale; +pub mod hebrew_locale; +pub mod russian_locale; +pub mod ukrainian_locale; diff --git a/src/locales/russian_locale.rs b/src/locales/russian_locale.rs index 5cbd137..d4ef985 100644 --- a/src/locales/russian_locale.rs +++ b/src/locales/russian_locale.rs @@ -1,8 +1,26 @@ -pub static RUS_LOCALE_VECTOR: [&str; 24] = ["[Insert] Показать/скрыть Меню", "Читы", -"[Home] Видеть сквозь стены", "[Delete] Экстрасенсорное восприятие", "[F1] Бесконечные гранаты", -"[F2] Без перезарядки оружия", "[F3] Неуязвимость", "[F4] Бесконечные боеприпасы", -"[F5] Без отдачи", "[F6] Быстрый огонь", "[F7] Автоприцел", -"[F8] Показывать угол обзора автоприцела", "Угол обзора", "[F9] Плавный автоприцел", "Плавность", -"[F10] Автовыстрел", "Задержка автовыстрела в секундах", "[F11] Видеть всех на миникарте", -"[F12] Полное освещение", "Сохранить текущие настройки", "Темы", "Тема оформления", -"Настройки", "Язык"]; \ No newline at end of file +pub static RUS_LOCALE_VECTOR: [&str; 24] = [ + "[Insert] Показать/скрыть Меню", + "Читы", + "[Home] Видеть сквозь стены", + "[Delete] Экстрасенсорное восприятие", + "[F1] Бесконечные гранаты", + "[F2] Без перезарядки оружия", + "[F3] Неуязвимость", + "[F4] Бесконечные боеприпасы", + "[F5] Без отдачи", + "[F6] Быстрый огонь", + "[F7] Автоприцел", + "[F8] Показывать угол обзора автоприцела", + "Угол обзора", + "[F9] Плавный автоприцел", + "Плавность", + "[F10] Автовыстрел", + "Задержка автовыстрела в секундах", + "[F11] Видеть всех на миникарте", + "[F12] Полное освещение", + "Сохранить текущие настройки", + "Темы", + "Тема оформления", + "Настройки", + "Язык", +]; diff --git a/src/locales/ukrainian_locale.rs b/src/locales/ukrainian_locale.rs index fe428d8..45124d0 100644 --- a/src/locales/ukrainian_locale.rs +++ b/src/locales/ukrainian_locale.rs @@ -1,8 +1,26 @@ -pub static UA_LOCALE_VECTOR: [&str; 24] = ["[Insert] Показати/Приховати Меню","чіти", - "[Home] Бачити крізь стіни", "[Delete] Екстрасенсорне сприйняття", "[F1] Нескінченні гранати", - "[F2] Без перезарядки зброї", "[F3] Невразливість", "[F4] Нескінченні боєприпаси", - "[F5] Без віддачі", "[F6] Швидкий вогонь"," [F7] Автоприцел", - "[F8] Показувати кут огляду автоприцела", "Кут огляду", "[F9] Плавний автоприцел", "Плавність", - "[F10] Автовистріл", "Затримка автовистрілу в секундах", "[F11] Бачити всіх на мінікарті", - "[F12] Повне висвітлення", "Зберегти поточні налаштування", "Теми","Тема оформлення", - "Налаштування","Мова"]; \ No newline at end of file +pub static UA_LOCALE_VECTOR: [&str; 24] = [ + "[Insert] Показати/Приховати Меню", + "чіти", + "[Home] Бачити крізь стіни", + "[Delete] Екстрасенсорне сприйняття", + "[F1] Нескінченні гранати", + "[F2] Без перезарядки зброї", + "[F3] Невразливість", + "[F4] Нескінченні боєприпаси", + "[F5] Без віддачі", + "[F6] Швидкий вогонь", + " [F7] Автоприцел", + "[F8] Показувати кут огляду автоприцела", + "Кут огляду", + "[F9] Плавний автоприцел", + "Плавність", + "[F10] Автовистріл", + "Затримка автовистрілу в секундах", + "[F11] Бачити всіх на мінікарті", + "[F12] Повне висвітлення", + "Зберегти поточні налаштування", + "Теми", + "Тема оформлення", + "Налаштування", + "Мова", +]; diff --git a/src/settings.rs b/src/settings.rs index 2c863ce..9b4cf32 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -52,7 +52,7 @@ pub struct AppSettings { pub is_draw_name_text_enemy: bool, pub ally_name_text_color: [f32; 3], pub enemy_name_text_color: [f32; 3], - pub name_text_thickness: f32 + pub name_text_thickness: f32, } impl AppSettings { @@ -161,7 +161,7 @@ impl Default for AppSettings { is_draw_name_text_enemy: true, ally_name_text_color: [0.0f32, 255.0f32, 0.0f32], enemy_name_text_color: [255.0f32, 0.0f32, 0.0f32], - name_text_thickness: 19.0f32 + name_text_thickness: 19.0f32, } } } diff --git a/src/state/mod.rs b/src/state/mod.rs index 92f7146..4efe06e 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -16,10 +16,12 @@ pub enum StateCacheType { /// The cache entry will be invalidated if not accessed within /// the target durection. + #[allow(unused)] Timed(Duration), /// The state will be removed as soon it get's invalidated. /// The update method will only be called once uppon creation. + #[allow(unused)] Volatile, } diff --git a/src/style.rs b/src/style.rs index 24e266d..1cb57f8 100644 --- a/src/style.rs +++ b/src/style.rs @@ -83,21 +83,21 @@ pub(crate) fn set_style_minty_red(ctx: &mut hudhook::imgui::Context) { // Set colors use hudhook::imgui::sys::{ ImGuiCol_Border, ImGuiCol_BorderShadow, ImGuiCol_Button, ImGuiCol_ButtonActive, - ImGuiCol_ButtonHovered, ImGuiCol_CheckMark, ImGuiCol_ChildBg, ImGuiCol_FrameBg, - ImGuiCol_FrameBgActive, ImGuiCol_FrameBgHovered, ImGuiCol_Header, ImGuiCol_HeaderActive, - ImGuiCol_HeaderHovered, ImGuiCol_MenuBarBg, ImGuiCol_PopupBg, ImGuiCol_ResizeGrip, + ImGuiCol_ButtonHovered, ImGuiCol_CheckMark, ImGuiCol_ChildBg, ImGuiCol_DragDropTarget, + ImGuiCol_FrameBg, ImGuiCol_FrameBgActive, ImGuiCol_FrameBgHovered, ImGuiCol_Header, + ImGuiCol_HeaderActive, ImGuiCol_HeaderHovered, ImGuiCol_MenuBarBg, + ImGuiCol_ModalWindowDimBg, ImGuiCol_NavHighlight, ImGuiCol_NavWindowingDimBg, + ImGuiCol_NavWindowingHighlight, ImGuiCol_PlotHistogram, ImGuiCol_PlotHistogramHovered, + ImGuiCol_PlotLines, ImGuiCol_PlotLinesHovered, ImGuiCol_PopupBg, ImGuiCol_ResizeGrip, ImGuiCol_ResizeGripActive, ImGuiCol_ResizeGripHovered, ImGuiCol_ScrollbarBg, ImGuiCol_ScrollbarGrab, ImGuiCol_ScrollbarGrabActive, ImGuiCol_ScrollbarGrabHovered, ImGuiCol_Separator, ImGuiCol_SeparatorActive, ImGuiCol_SeparatorHovered, ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, ImGuiCol_Tab, ImGuiCol_TabActive, - ImGuiCol_TabHovered, ImGuiCol_Text, ImGuiCol_TextDisabled, ImGuiCol_TitleBg, - ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed, ImGuiCol_WindowBg, - ImGuiCol_DragDropTarget, ImGuiCol_ModalWindowDimBg, ImGuiCol_NavHighlight, - ImGuiCol_NavWindowingDimBg, ImGuiCol_NavWindowingHighlight, ImGuiCol_PlotHistogram, - ImGuiCol_PlotHistogramHovered, ImGuiCol_PlotLines, ImGuiCol_PlotLinesHovered, - ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive, ImGuiCol_TableBorderLight, - ImGuiCol_TableBorderStrong, ImGuiCol_TableHeaderBg, ImGuiCol_TableRowBg, - ImGuiCol_TableRowBgAlt, ImGuiCol_TextSelectedBg + ImGuiCol_TabHovered, ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive, + ImGuiCol_TableBorderLight, ImGuiCol_TableBorderStrong, ImGuiCol_TableHeaderBg, + ImGuiCol_TableRowBg, ImGuiCol_TableRowBgAlt, ImGuiCol_Text, ImGuiCol_TextDisabled, + ImGuiCol_TextSelectedBg, ImGuiCol_TitleBg, ImGuiCol_TitleBgActive, + ImGuiCol_TitleBgCollapsed, ImGuiCol_WindowBg, }; colors[ImGuiCol_Text as usize] = [0.75, 0.75, 0.75, 1.00]; @@ -156,21 +156,20 @@ pub(crate) fn set_style_minty_red(ctx: &mut hudhook::imgui::Context) { } #[allow(unused)] -pub(crate) fn set_style_minty_light(ctx: &mut hudhook::imgui::Context) -{ +pub(crate) fn set_style_minty_light(ctx: &mut hudhook::imgui::Context) { ctx.style_mut().use_light_colors(); let style = ctx.style_mut(); let colors = &mut style.colors; - use hudhook::imgui::sys::{ImGuiCol_Button, ImGuiCol_ButtonActive, ImGuiCol_ButtonHovered, - ImGuiCol_CheckMark, ImGuiCol_FrameBg, ImGuiCol_FrameBgActive, - ImGuiCol_FrameBgHovered, ImGuiCol_Header, ImGuiCol_HeaderActive, - ImGuiCol_HeaderHovered, ImGuiCol_ResizeGrip, - ImGuiCol_ResizeGripActive, ImGuiCol_ResizeGripHovered, - ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, ImGuiCol_Tab, - ImGuiCol_TabActive, ImGuiCol_TabHovered, ImGuiCol_TitleBg, - ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed}; + use hudhook::imgui::sys::{ + ImGuiCol_Button, ImGuiCol_ButtonActive, ImGuiCol_ButtonHovered, ImGuiCol_CheckMark, + ImGuiCol_FrameBg, ImGuiCol_FrameBgActive, ImGuiCol_FrameBgHovered, ImGuiCol_Header, + ImGuiCol_HeaderActive, ImGuiCol_HeaderHovered, ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGripActive, ImGuiCol_ResizeGripHovered, ImGuiCol_SliderGrab, + ImGuiCol_SliderGrabActive, ImGuiCol_Tab, ImGuiCol_TabActive, ImGuiCol_TabHovered, + ImGuiCol_TitleBg, ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed, + }; colors[ImGuiCol_FrameBg as usize] = [0.25, 0.25, 0.25, 1.00]; colors[ImGuiCol_FrameBgHovered as usize] = [0.05, 0.90, 0.54, 1.00]; @@ -196,21 +195,20 @@ pub(crate) fn set_style_minty_light(ctx: &mut hudhook::imgui::Context) } #[allow(unused)] -pub(crate) fn set_style_minty_mint(ctx: &mut hudhook::imgui::Context) -{ +pub(crate) fn set_style_minty_mint(ctx: &mut hudhook::imgui::Context) { ctx.style_mut().use_dark_colors(); let style = ctx.style_mut(); let colors = &mut style.colors; - use hudhook::imgui::sys::{ImGuiCol_Button, ImGuiCol_ButtonActive, ImGuiCol_ButtonHovered, - ImGuiCol_CheckMark, ImGuiCol_FrameBg, ImGuiCol_FrameBgActive, - ImGuiCol_FrameBgHovered, ImGuiCol_Header, ImGuiCol_HeaderActive, - ImGuiCol_HeaderHovered, ImGuiCol_ResizeGrip, - ImGuiCol_ResizeGripActive, ImGuiCol_ResizeGripHovered, - ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, ImGuiCol_Tab, - ImGuiCol_TabActive, ImGuiCol_TabHovered, ImGuiCol_TitleBg, - ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed}; + use hudhook::imgui::sys::{ + ImGuiCol_Button, ImGuiCol_ButtonActive, ImGuiCol_ButtonHovered, ImGuiCol_CheckMark, + ImGuiCol_FrameBg, ImGuiCol_FrameBgActive, ImGuiCol_FrameBgHovered, ImGuiCol_Header, + ImGuiCol_HeaderActive, ImGuiCol_HeaderHovered, ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGripActive, ImGuiCol_ResizeGripHovered, ImGuiCol_SliderGrab, + ImGuiCol_SliderGrabActive, ImGuiCol_Tab, ImGuiCol_TabActive, ImGuiCol_TabHovered, + ImGuiCol_TitleBg, ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed, + }; colors[ImGuiCol_FrameBg as usize] = [0.25, 0.25, 0.25, 1.00]; colors[ImGuiCol_FrameBgHovered as usize] = [0.05, 0.90, 0.54, 1.00]; @@ -234,4 +232,3 @@ pub(crate) fn set_style_minty_mint(ctx: &mut hudhook::imgui::Context) colors[ImGuiCol_TabHovered as usize] = [0.00, 0.75, 0.43, 1.00]; colors[ImGuiCol_TabActive as usize] = [0.00, 0.68, 0.39, 1.00]; } - diff --git a/src/ui.rs b/src/ui.rs index 18b17f0..f3735ba 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -6,27 +6,39 @@ use std::path::PathBuf; use std::sync::atomic::Ordering::SeqCst; use gnal_tsur::gnal_tsur; +use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, Io}; use hudhook::{imgui, MessageFilter, RenderContext}; -use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, ImColor32, Io}; use once_cell::sync::Lazy; -use windows::Win32::UI::Input::KeyboardAndMouse::{VK_INSERT}; +use windows::Win32::UI::Input::KeyboardAndMouse::VK_INSERT; + use crate::distance; use crate::entity::Entity; +use crate::game::{set_brightness, set_brightness_toggle}; +use crate::hotkey_widget::{to_win_key, ImGuiKey, KeyboardInputSystem}; 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::key_action::{ + 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, KeyAction, +}; use crate::locales::cantonese_locale::CANTONESE_LOCALE_VECTOR; use crate::locales::chinese_locale::MANDARIN_LOCALE_VECTOR; use crate::locales::english_locale::ENG_LOCALE_VECTOR; use crate::locales::hebrew_locale::HEBREW_LOCALE_VECTOR; use crate::locales::russian_locale::RUS_LOCALE_VECTOR; use crate::locales::ukrainian_locale::UA_LOCALE_VECTOR; -use crate::offsets::offsets::{ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR}; -use crate::settings::{AppSettings, load_app_settings, save_app_settings}; -use crate::style::{set_style_minty_light, set_style_minty_mint, set_style_minty_red, set_style_unicore}; +use crate::offsets::offsets::{ + ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR, +}; +use crate::settings::{load_app_settings, save_app_settings, AppSettings}; +use crate::style::{ + set_style_minty_light, set_style_minty_mint, set_style_minty_red, set_style_unicore, +}; use crate::utils::{read_memory, read_view_matrix, run_cmd}; -use crate::vars::game_vars::{ENTITY_LIST_PTR, FOV, LOCAL_PLAYER, NUM_PLAYERS_IN_MATCH, SMOOTH, TRIGGER_DELAY, VIEW_MATRIX}; +use crate::vars::game_vars::{ + ENTITY_LIST_PTR, FOV, LOCAL_PLAYER, NUM_PLAYERS_IN_MATCH, SMOOTH, TRIGGER_DELAY, VIEW_MATRIX, +}; use crate::vars::handles::{AC_CLIENT_EXE_HMODULE, GAME_WINDOW_DIMENSIONS}; use crate::vars::mem_patches::{ MAPHACK_MEMORY_PATCH, NO_RECOIL_MEMORY_PATCH, RAPID_FIRE_MEMORY_PATCH, @@ -39,20 +51,17 @@ use crate::vars::ui_vars::{ use crate::vec_structures::Vec2; use crate::world_to_screen::world_to_screen; -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; +pub static mut KEY_INPUT_SYSTEM: KeyboardInputSystem = 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; pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { unsafe { 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]) - { + if let Some(tab) = ui.tab_bar("Main Menu Tab Bar") { + if let Some(item) = ui.tab_item(CURRENT_LOCALE_VECTOR[1]) { if ui.checkbox(CURRENT_LOCALE_VECTOR[2], IS_WALLHACK.get_mut()) { println!("Set WallHack Toggle to {}", IS_WALLHACK.load(SeqCst)); } @@ -257,7 +266,12 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { ) { println!("Binded Triggerbot toggle key!"); } - if ui.slider(CURRENT_LOCALE_VECTOR[16], 100, 1000, TRIGGER_DELAY.get_mut()) { + if ui.slider( + CURRENT_LOCALE_VECTOR[16], + 100, + 1000, + TRIGGER_DELAY.get_mut(), + ) { println!("Set Triggerbot Delay to {} ms", TRIGGER_DELAY.load(SeqCst)); } if ui.checkbox(CURRENT_LOCALE_VECTOR[17], IS_MAPHACK.get_mut()) { @@ -311,200 +325,284 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { } item.end(); } - if let Some(item) = ui.tab_item(CURRENT_LOCALE_VECTOR[20]) - { - if ui.list_box(CURRENT_LOCALE_VECTOR[21], - &mut app_settings.theme_id, - &["Unicore", "Minty Red", "Minty Light", "Minty Mint"], - 10i32) - { + if let Some(item) = ui.tab_item(CURRENT_LOCALE_VECTOR[20]) { + if ui.list_box( + CURRENT_LOCALE_VECTOR[21], + &mut app_settings.theme_id, + &["Unicore", "Minty Red", "Minty Light", "Minty Mint"], + 10i32, + ) { println!("Going to change theme to {}", app_settings.theme_id); IS_NEED_CHANGE_THEME = true; } item.end(); } - if let Some(item) = ui.tab_item(CURRENT_LOCALE_VECTOR[22]) - { - if ui.list_box(CURRENT_LOCALE_VECTOR[23], - &mut app_settings.language_id, - &["English", "Русский", "Українська", - "中文(简体)", "粵語", - gnal_tsur!("עברית")], - 10i32) - { + if let Some(item) = ui.tab_item(CURRENT_LOCALE_VECTOR[22]) { + if ui.list_box( + CURRENT_LOCALE_VECTOR[23], + &mut app_settings.language_id, + &[ + "English", + "Русский", + "Українська", + "中文(简体)", + "粵語", + gnal_tsur!("עברית"), + ], + 10i32, + ) { println!("Going to change locale to {}", app_settings.language_id); IS_NEED_CHANGE_LOCALE = true; } item.end(); } - if let Some(item) = ui.tab_item("ESP settings") - { - if let Some(tab_esp) = ui.tab_bar("ESP Config Tab Bar") - { - if let Some(tab_esp_item) = ui.tab_item("ESP traceline settings") - { + if let Some(item) = ui.tab_item("ESP settings") { + if let Some(tab_esp) = ui.tab_bar("ESP Config Tab Bar") { + if let Some(tab_esp_item) = ui.tab_item("ESP traceline settings") { if ui.checkbox("Draw tracelines", &mut SETTINGS.is_draw_trace_lines) { - println!("Set ESP drawing tracelines Toggle to {}", - SETTINGS.deref().is_draw_trace_lines); + println!( + "Set ESP drawing tracelines Toggle to {}", + SETTINGS.deref().is_draw_trace_lines + ); } - if SETTINGS.is_draw_trace_lines - { - if ui.slider("Traceline thickness", - 0.1f32, 10.0f32, - &mut SETTINGS.trace_line_thickness) - { - println!("Set traceline thickness {}", SETTINGS.deref().trace_line_thickness); + if SETTINGS.is_draw_trace_lines { + if ui.slider( + "Traceline thickness", + 0.1f32, + 10.0f32, + &mut SETTINGS.trace_line_thickness, + ) { + println!( + "Set traceline thickness {}", + SETTINGS.deref().trace_line_thickness + ); } - if ui.checkbox("Show ally traceline", &mut SETTINGS.is_draw_trace_lines_ally) - { - println!("Toggled show ally traceline {}", SETTINGS.deref().is_draw_trace_lines_ally); + if ui.checkbox( + "Show ally traceline", + &mut SETTINGS.is_draw_trace_lines_ally, + ) { + println!( + "Toggled show ally traceline {}", + SETTINGS.deref().is_draw_trace_lines_ally + ); } - if ui.color_edit3("Ally traceline color", - &mut SETTINGS.ally_trace_line_color) - { - println!("Set color for ally traceline {:?}", - SETTINGS.deref().ally_trace_line_color); + if ui.color_edit3( + "Ally traceline color", + &mut SETTINGS.ally_trace_line_color, + ) { + println!( + "Set color for ally traceline {:?}", + SETTINGS.deref().ally_trace_line_color + ); } - if ui.checkbox("Show enemy traceline", &mut SETTINGS.is_draw_trace_lines_enemy) - { - println!("Toggled show enemy traceline {}", SETTINGS.deref().is_draw_trace_lines_enemy); + if ui.checkbox( + "Show enemy traceline", + &mut SETTINGS.is_draw_trace_lines_enemy, + ) { + println!( + "Toggled show enemy traceline {}", + SETTINGS.deref().is_draw_trace_lines_enemy + ); } - if ui.color_edit3("Enemy traceline color", - &mut SETTINGS.enemy_trace_line_color) - { - println!("Set color for enemy traceline {:?}", - SETTINGS.enemy_trace_line_color); + if ui.color_edit3( + "Enemy traceline color", + &mut SETTINGS.enemy_trace_line_color, + ) { + println!( + "Set color for enemy traceline {:?}", + SETTINGS.enemy_trace_line_color + ); } } tab_esp_item.end(); } - if let Some(tab_esp_item) = ui.tab_item("ESP boxes settings") - { - if ui.checkbox("Draw boxes", &mut SETTINGS.is_draw_boxes) - { - println!("Toggled show enemy traceline {}", SETTINGS.deref().is_draw_boxes); + if let Some(tab_esp_item) = ui.tab_item("ESP boxes settings") { + if ui.checkbox("Draw boxes", &mut SETTINGS.is_draw_boxes) { + println!( + "Toggled show enemy traceline {}", + SETTINGS.deref().is_draw_boxes + ); } - if SETTINGS.is_draw_boxes - { - if ui.slider("Boxes thickness", - 0.1f32, 10.0f32, - &mut SETTINGS.box_thickness) - { + if SETTINGS.is_draw_boxes { + if ui.slider( + "Boxes thickness", + 0.1f32, + 10.0f32, + &mut SETTINGS.box_thickness, + ) { println!("Set box thickness {}", SETTINGS.deref().box_thickness); } - if ui.checkbox("Show ally boxes", &mut SETTINGS.is_draw_boxes_ally) - { - println!("Toggled show ally boxes {}", SETTINGS.deref().is_draw_boxes_ally); + if ui.checkbox("Show ally boxes", &mut SETTINGS.is_draw_boxes_ally) { + println!( + "Toggled show ally boxes {}", + SETTINGS.deref().is_draw_boxes_ally + ); } - if ui.color_edit3("Ally boxes color", - &mut SETTINGS.ally_box_color) - { - println!("Set color for ally boxes {:?}", - SETTINGS.deref().ally_box_color); + if ui.color_edit3("Ally boxes color", &mut SETTINGS.ally_box_color) { + println!( + "Set color for ally boxes {:?}", + SETTINGS.deref().ally_box_color + ); } - if ui.checkbox("Show enemy boxes", &mut SETTINGS.is_draw_boxes_enemy) - { - println!("Toggled show enemy boxes {}", SETTINGS.deref().is_draw_boxes_enemy); + if ui.checkbox("Show enemy boxes", &mut SETTINGS.is_draw_boxes_enemy) { + println!( + "Toggled show enemy boxes {}", + SETTINGS.deref().is_draw_boxes_enemy + ); } - if ui.color_edit3("Enemy boxes color", - &mut SETTINGS.enemy_box_color) - { - println!("Set color for enemy boxes {:?}", - SETTINGS.enemy_box_color); + if ui.color_edit3("Enemy boxes color", &mut SETTINGS.enemy_box_color) { + println!( + "Set color for enemy boxes {:?}", + SETTINGS.enemy_box_color + ); } } - tab_esp_item.end(); } - if let Some(tab_esp_item) = ui.tab_item("ESP health bar settings") - { - if ui.checkbox("Draw health bars", &mut SETTINGS.is_draw_hp_bar) - { - println!("Toggled show enemy traceline {}", SETTINGS.deref().is_draw_boxes); + if let Some(tab_esp_item) = ui.tab_item("ESP health bar settings") { + if ui.checkbox("Draw health bars", &mut SETTINGS.is_draw_hp_bar) { + println!( + "Toggled show enemy traceline {}", + SETTINGS.deref().is_draw_boxes + ); } - if SETTINGS.is_draw_hp_bar - { - if ui.checkbox("Show horizontal hp bar", &mut SETTINGS.is_horizontal_hp_bar) - { - println!("Toggled horizontal hp bar {}", SETTINGS.deref().is_horizontal_hp_bar); + if SETTINGS.is_draw_hp_bar { + if ui.checkbox( + "Show horizontal hp bar", + &mut SETTINGS.is_horizontal_hp_bar, + ) { + println!( + "Toggled horizontal hp bar {}", + SETTINGS.deref().is_horizontal_hp_bar + ); } ui.same_line(); if ui.checkbox("Show vertical hp bar", &mut SETTINGS.is_vertical_hp_bar) { - println!("Toggled vertical hp bar {}", SETTINGS.deref().is_vertical_hp_bar); + println!( + "Toggled vertical hp bar {}", + SETTINGS.deref().is_vertical_hp_bar + ); } - if ui.slider("Health bar thickness", - 0.1f32, 10.0f32, - &mut SETTINGS.hp_bar_thickness) - { - println!("Set health bar thickness {}", SETTINGS.deref().hp_bar_thickness); + if ui.slider( + "Health bar thickness", + 0.1f32, + 10.0f32, + &mut SETTINGS.hp_bar_thickness, + ) { + println!( + "Set health bar thickness {}", + SETTINGS.deref().hp_bar_thickness + ); } - if ui.checkbox("Show ally health bar", &mut SETTINGS.is_draw_hp_bar_ally) + if ui + .checkbox("Show ally health bar", &mut SETTINGS.is_draw_hp_bar_ally) { - println!("Toggled show ally health bar {}", SETTINGS.deref().is_draw_hp_bar_ally); + println!( + "Toggled show ally health bar {}", + SETTINGS.deref().is_draw_hp_bar_ally + ); } ui.same_line(); - if ui.checkbox("Show enemy health bar", &mut SETTINGS.is_draw_hp_bar_enemy) - { - println!("Toggled show enemy health bar {}", SETTINGS.deref().is_draw_hp_bar_enemy); + if ui.checkbox( + "Show enemy health bar", + &mut SETTINGS.is_draw_hp_bar_enemy, + ) { + println!( + "Toggled show enemy health bar {}", + SETTINGS.deref().is_draw_hp_bar_enemy + ); } - if ui.color_edit3("Inner health bar color", - &mut SETTINGS.inner_hp_bar_color) - { - println!("Set color for inner health bar {:?}", - SETTINGS.deref().inner_hp_bar_color); + if ui.color_edit3( + "Inner health bar color", + &mut SETTINGS.inner_hp_bar_color, + ) { + println!( + "Set color for inner health bar {:?}", + SETTINGS.deref().inner_hp_bar_color + ); } - if ui.color_edit3("Outer health bar color", - &mut SETTINGS.outer_hp_bar_color) - { - println!("Set color for outer health bar {:?}", - SETTINGS.outer_hp_bar_color); + if ui.color_edit3( + "Outer health bar color", + &mut SETTINGS.outer_hp_bar_color, + ) { + println!( + "Set color for outer health bar {:?}", + SETTINGS.outer_hp_bar_color + ); } } tab_esp_item.end(); } - if let Some(tab_esp_item) = ui.tab_item("ESP text settings") - { - if ui.checkbox("Draw name text", &mut SETTINGS.is_draw_name_text) - { - println!("Toggled draw name text to {}", SETTINGS.deref().is_draw_name_text) + if let Some(tab_esp_item) = ui.tab_item("ESP text settings") { + if ui.checkbox("Draw name text", &mut SETTINGS.is_draw_name_text) { + println!( + "Toggled draw name text to {}", + SETTINGS.deref().is_draw_name_text + ) } - if SETTINGS.deref().is_draw_name_text - { - if ui.checkbox("Draw ally name text", &mut SETTINGS.is_draw_name_text_ally) - { - println!("Toggled draw ally name text to {}", SETTINGS.deref().is_draw_name_text_ally) + if SETTINGS.deref().is_draw_name_text { + if ui.checkbox( + "Draw ally name text", + &mut SETTINGS.is_draw_name_text_ally, + ) { + println!( + "Toggled draw ally name text to {}", + SETTINGS.deref().is_draw_name_text_ally + ) } ui.same_line(); - if ui.checkbox("Draw enemy name text", &mut SETTINGS.is_draw_name_text_enemy) - { - println!("Toggled draw enemy name text to {}", SETTINGS.deref().is_draw_name_text_enemy) + if ui.checkbox( + "Draw enemy name text", + &mut SETTINGS.is_draw_name_text_enemy, + ) { + println!( + "Toggled draw enemy name text to {}", + SETTINGS.deref().is_draw_name_text_enemy + ) } - if ui.slider("Name text size", 10.0f32, 60.0f32, &mut SETTINGS.name_text_thickness) - { - println!("Set name text size to {}", SETTINGS.deref().name_text_thickness) + if ui.slider( + "Name text size", + 10.0f32, + 60.0f32, + &mut SETTINGS.name_text_thickness, + ) { + println!( + "Set name text size to {}", + SETTINGS.deref().name_text_thickness + ) } - if ui.color_edit3("Ally name text color", &mut SETTINGS.ally_name_text_color) - { - println!("Set ally name text color to {:?}", SETTINGS.ally_name_text_color); + if ui.color_edit3( + "Ally name text color", + &mut SETTINGS.ally_name_text_color, + ) { + println!( + "Set ally name text color to {:?}", + SETTINGS.ally_name_text_color + ); } - if ui.color_edit3("Enemy name text color", &mut SETTINGS.enemy_name_text_color) - { - println!("Set ally name text color to {:?}", SETTINGS.enemy_name_text_color); + if ui.color_edit3( + "Enemy name text color", + &mut SETTINGS.enemy_name_text_color, + ) { + println!( + "Set ally name text color to {:?}", + SETTINGS.enemy_name_text_color + ); } } tab_esp_item.end(); } tab_esp.end(); } + item.end(); } tab.end(); } - } } @@ -547,8 +645,6 @@ impl hudhook::ImguiRenderLoop for RenderLoop { _ctx: &mut Context, _render_context: &'a mut dyn RenderContext, ) { - - _ctx.set_ini_filename(None); unsafe { @@ -574,28 +670,74 @@ 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} + KeyAction { + key: VK_INSERT.0 as usize, + action: Box::new(move || toggle_show_ui(IS_SHOW_UI.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().wallhack_key.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_wallhack(IS_WALLHACK.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().esp_key.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_esp(IS_ESP.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().inf_nade.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_infinite_nades(IS_GRENADES_INFINITE.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().no_reload.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_no_reload(IS_NO_RELOAD.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().invul.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_invulnerability(IS_INVULNERABLE.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().inf_ammo.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_infinite_ammo(IS_INFINITE_AMMO.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().no_recoil.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_no_recoil(IS_NO_RECOIL.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().rapid_fire.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_rapid_fire(IS_RAPID_FIRE.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().aimbot.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_aimbot(IS_AIMBOT.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().aim_draw_fov.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_draw_fov(IS_DRAW_FOV.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().aim_smooth.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_smooth(IS_SMOOTH.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().trigger_bot.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_triggerbot(IS_TRIGGERBOT.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().maphack.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_maphack(IS_MAPHACK.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().fullbright.as_ref().unwrap().key).0 as usize, + action: Box::new(move || toggle_fullbright(IS_FULLBRIGHT.get_mut())), + }, + KeyAction { + key: to_win_key(SETTINGS.deref().aim_key.as_ref().unwrap().key).0 as usize, + action: Box::new(move || aimbot(IS_AIMBOT.get_mut())), + }, ]; - - KEY_INPUT_SYSTEM.update(_ctx.io_mut()); + KEY_INPUT_SYSTEM.update(_ctx.io_mut(), IS_SHOW_UI.load(SeqCst)); for key_action in key_actions { match KEY_INPUT_SYSTEM.key_states[key_action.key] { @@ -604,38 +746,53 @@ impl hudhook::ImguiRenderLoop for RenderLoop { } } - if IS_NEED_CHANGE_THEME - { - match SETTINGS.deref_mut().theme_id - { - 0 => {set_style_unicore(_ctx);}, - 1 => {set_style_minty_red(_ctx);} - 2 => {set_style_minty_light(_ctx);} - 3 => {set_style_minty_mint(_ctx);} - _ => {set_style_unicore(_ctx);} + if IS_NEED_CHANGE_THEME { + match SETTINGS.deref_mut().theme_id { + 0 => { + set_style_unicore(_ctx); + } + 1 => { + set_style_minty_red(_ctx); + } + 2 => { + set_style_minty_light(_ctx); + } + 3 => { + set_style_minty_mint(_ctx); + } + _ => { + set_style_unicore(_ctx); + } } println!("Changed theme to {}", SETTINGS.deref_mut().theme_id); IS_NEED_CHANGE_THEME = false; } - if IS_NEED_CHANGE_LOCALE - { - match SETTINGS.deref_mut().language_id - { - 0 => {CURRENT_LOCALE_VECTOR = ENG_LOCALE_VECTOR;}, - 1 => {CURRENT_LOCALE_VECTOR = RUS_LOCALE_VECTOR;}, - 2 => {CURRENT_LOCALE_VECTOR = UA_LOCALE_VECTOR;}, - 3 => {CURRENT_LOCALE_VECTOR = MANDARIN_LOCALE_VECTOR;}, - 4 => {CURRENT_LOCALE_VECTOR = CANTONESE_LOCALE_VECTOR;}, - 5 => {CURRENT_LOCALE_VECTOR = HEBREW_LOCALE_VECTOR}, - _ => {CURRENT_LOCALE_VECTOR = ENG_LOCALE_VECTOR;}, + if IS_NEED_CHANGE_LOCALE { + match SETTINGS.deref_mut().language_id { + 0 => { + CURRENT_LOCALE_VECTOR = ENG_LOCALE_VECTOR; + } + 1 => { + CURRENT_LOCALE_VECTOR = RUS_LOCALE_VECTOR; + } + 2 => { + CURRENT_LOCALE_VECTOR = UA_LOCALE_VECTOR; + } + 3 => { + CURRENT_LOCALE_VECTOR = MANDARIN_LOCALE_VECTOR; + } + 4 => { + CURRENT_LOCALE_VECTOR = CANTONESE_LOCALE_VECTOR; + } + 5 => CURRENT_LOCALE_VECTOR = HEBREW_LOCALE_VECTOR, + _ => { + CURRENT_LOCALE_VECTOR = ENG_LOCALE_VECTOR; + } } println!("Changed locale to {}", SETTINGS.deref_mut().language_id); IS_NEED_CHANGE_LOCALE = false; } - - - _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); @@ -655,15 +812,8 @@ impl hudhook::ImguiRenderLoop for RenderLoop { } fn render(&mut self, ui: &mut imgui::Ui) { - - unsafe { - if IS_ESP.load(SeqCst) { - - - - let local_player_addr = match read_memory::(AC_CLIENT_EXE_HMODULE + LOCAL_PLAYER_OFFSET) { Ok(addr) => addr, @@ -675,15 +825,15 @@ impl hudhook::ImguiRenderLoop for RenderLoop { LOCAL_PLAYER = Entity::from_addr(local_player_addr); - let num_players_in_match = - match read_memory::(AC_CLIENT_EXE_HMODULE + NUMBER_OF_PLAYERS_IN_MATCH_OFFSET) - { - Ok(num) => num as usize, - Err(err) => { - println!("Error reading number of players in match: {}", err); - return (); - } - }; + let num_players_in_match = match read_memory::( + AC_CLIENT_EXE_HMODULE + NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, + ) { + Ok(num) => num as usize, + Err(err) => { + println!("Error reading number of players in match: {}", err); + return (); + } + }; NUM_PLAYERS_IN_MATCH = num_players_in_match; let entity_list_ptr = @@ -706,7 +856,6 @@ impl hudhook::ImguiRenderLoop for RenderLoop { }; for i in 1..NUM_PLAYERS_IN_MATCH { - println!("IMGUI ESP iterating for i={}",i); let entity_addr = match Entity::from_addr(ENTITY_LIST_PTR).read_value::(i * 0x4) { Ok(addr) => addr, @@ -766,84 +915,101 @@ impl hudhook::ImguiRenderLoop for RenderLoop { ) { continue; } - + #[allow(unused)] let distance = match (LOCAL_PLAYER.position(), entity.position()) { - (Ok(local_pos), Ok(entity_pos)) => distance::distance_3d(local_pos, entity_pos), + (Ok(local_pos), Ok(entity_pos)) => { + distance::distance_3d(local_pos, entity_pos) + } (Err(err), _) | (_, Err(err)) => { println!("Error reading position: {}", err); continue; // Skip to the next entity if there's an error } }; - let EntityHeight = head_screen_pos.y - feet_screen_pos.y; - let EntityWidth = EntityHeight / 2.5f32; + let entity_height = head_screen_pos.y - feet_screen_pos.y; + let entity_width = entity_height / 2.5f32; - let ESPBottom = feet_screen_pos.y; - let ESPLeft = feet_screen_pos.x + (EntityWidth / 2.0f32); - let ESPRight = feet_screen_pos.x - (EntityWidth / 2.0f32); - let ESPTop = head_screen_pos.y + (EntityHeight * 0.1f32); + let espbottom = feet_screen_pos.y; + let espleft = feet_screen_pos.x + (entity_width / 2.0f32); + let espright = feet_screen_pos.x - (entity_width / 2.0f32); + let esptop = head_screen_pos.y + (entity_height * 0.1f32); let background_draw_list = ui.get_background_draw_list(); - if SETTINGS.deref().is_draw_trace_lines - { - if (SETTINGS.deref().is_draw_trace_lines_ally && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) || - (SETTINGS.deref().is_draw_trace_lines_enemy && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) + if SETTINGS.deref().is_draw_trace_lines { + if (SETTINGS.deref().is_draw_trace_lines_ally + && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) + || (SETTINGS.deref().is_draw_trace_lines_enemy + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) { - let traceline = background_draw_list.add_line( - [GAME_WINDOW_DIMENSIONS.width as f32 / 2f32, GAME_WINDOW_DIMENSIONS.height as f32], - [(ESPRight + ESPLeft) / 2f32, ESPBottom], - if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { - SETTINGS.deref().ally_trace_line_color // Color for same team - } else { - SETTINGS.deref().enemy_trace_line_color // Color for different team (example) - } - ).thickness(SETTINGS.deref().trace_line_thickness); + let traceline = background_draw_list + .add_line( + [ + GAME_WINDOW_DIMENSIONS.width as f32 / 2f32, + GAME_WINDOW_DIMENSIONS.height as f32, + ], + [(espright + espleft) / 2f32, espbottom], + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + SETTINGS.deref().ally_trace_line_color // Color for same team + } else { + SETTINGS.deref().enemy_trace_line_color // Color for different team (example) + }, + ) + .thickness(SETTINGS.deref().trace_line_thickness); traceline.build(); } } - if SETTINGS.deref().is_draw_boxes - { - if (SETTINGS.deref().is_draw_boxes_ally && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) || - (SETTINGS.deref().is_draw_boxes_enemy && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) + if SETTINGS.deref().is_draw_boxes { + if (SETTINGS.deref().is_draw_boxes_ally + && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) + || (SETTINGS.deref().is_draw_boxes_enemy + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) { - let box_upper_line = background_draw_list.add_line( - [ESPLeft, ESPTop], - [ESPRight, ESPTop], - if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { - SETTINGS.deref().ally_box_color // Color for same team - } else { - SETTINGS.deref().enemy_box_color // Color for different team (example) - } - ).thickness(SETTINGS.deref().box_thickness); - - let box_bottom_line = background_draw_list.add_line( - [ESPLeft, ESPBottom], - [ESPRight, ESPBottom], - if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { - SETTINGS.deref().ally_box_color // Color for same team - } else { - SETTINGS.deref().enemy_box_color // Color for different team (example) - } - ).thickness(SETTINGS.deref().box_thickness); - - let box_left_line = background_draw_list.add_line( - [ESPLeft, ESPTop], - [ESPLeft, ESPBottom], - if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { - SETTINGS.deref().ally_box_color // Color for same team - } else { - SETTINGS.deref().enemy_box_color // Color for different team (example) - } - ).thickness(SETTINGS.deref().box_thickness); - - let box_right_line = background_draw_list.add_line( - [ESPRight, ESPTop], - [ESPRight, ESPBottom], - if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { - SETTINGS.deref().ally_box_color // Color for same team - } else { - SETTINGS.deref().enemy_box_color // Color for different team (example) - } - ).thickness(SETTINGS.deref().box_thickness); + let box_upper_line = background_draw_list + .add_line( + [espleft, esptop], + [espright, esptop], + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + SETTINGS.deref().ally_box_color // Color for same team + } else { + SETTINGS.deref().enemy_box_color // Color for different team (example) + }, + ) + .thickness(SETTINGS.deref().box_thickness); + + let box_bottom_line = background_draw_list + .add_line( + [espleft, espbottom], + [espright, espbottom], + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + SETTINGS.deref().ally_box_color // Color for same team + } else { + SETTINGS.deref().enemy_box_color // Color for different team (example) + }, + ) + .thickness(SETTINGS.deref().box_thickness); + + let box_left_line = background_draw_list + .add_line( + [espleft, esptop], + [espleft, espbottom], + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + SETTINGS.deref().ally_box_color // Color for same team + } else { + SETTINGS.deref().enemy_box_color // Color for different team (example) + }, + ) + .thickness(SETTINGS.deref().box_thickness); + + let box_right_line = background_draw_list + .add_line( + [espright, esptop], + [espright, espbottom], + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + SETTINGS.deref().ally_box_color // Color for same team + } else { + SETTINGS.deref().enemy_box_color // Color for different team (example) + }, + ) + .thickness(SETTINGS.deref().box_thickness); box_upper_line.build(); box_bottom_line.build(); @@ -851,80 +1017,94 @@ impl hudhook::ImguiRenderLoop for RenderLoop { box_right_line.build(); } } - if SETTINGS.deref().is_draw_hp_bar - { - if (SETTINGS.deref().is_draw_hp_bar_ally && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) || - (SETTINGS.deref().is_draw_hp_bar_enemy && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) + if SETTINGS.deref().is_draw_hp_bar { + if (SETTINGS.deref().is_draw_hp_bar_ally + && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) + || (SETTINGS.deref().is_draw_hp_bar_enemy + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) { - if SETTINGS.deref().is_vertical_hp_bar - { + if SETTINGS.deref().is_vertical_hp_bar { // Calculate the height of the health bar based on the entity's health - let HPTop = entity.health().unwrap() as f32 * (ESPTop - ESPBottom) / 100.0f32; + let hptop = entity.health().unwrap() as f32 * (esptop - espbottom) + / 100.0f32; // Draw the background for the health bar - let outer_hp_bar = background_draw_list.add_line( - [ESPLeft - 20.0f32, ESPTop], // Left side of the box - [ESPLeft - 20.0f32, ESPBottom], // Bottom of the box to the top - SETTINGS.deref().outer_hp_bar_color // Outer hp bar color - ).thickness(SETTINGS.deref().hp_bar_thickness); + let outer_hp_bar = background_draw_list + .add_line( + [espleft - 20.0f32, esptop], // Left side of the box + [espleft - 20.0f32, espbottom], // Bottom of the box to the top + SETTINGS.deref().outer_hp_bar_color, // Outer hp bar color + ) + .thickness(SETTINGS.deref().hp_bar_thickness); // Draw the inner health bar - let inner_hp_bar = background_draw_list.add_line( - [ESPLeft - 20.0f32, ESPBottom + HPTop], // Start at the top of the inner health bar - [ESPLeft - 20.0f32, ESPBottom], // End at the bottom of the box - SETTINGS.deref().inner_hp_bar_color // Inner hp bar color - ).thickness(SETTINGS.deref().hp_bar_thickness); + let inner_hp_bar = background_draw_list + .add_line( + [espleft - 20.0f32, espbottom + hptop], // Start at the top of the inner health bar + [espleft - 20.0f32, espbottom], // End at the bottom of the box + SETTINGS.deref().inner_hp_bar_color, // Inner hp bar color + ) + .thickness(SETTINGS.deref().hp_bar_thickness); // Build the lines outer_hp_bar.build(); inner_hp_bar.build(); } - if SETTINGS.deref().is_horizontal_hp_bar - { - let HPRight = entity.health().unwrap() as f32 * (ESPRight - ESPLeft) / 100.0f32; - let inner_hp_bar = background_draw_list.add_line( - [ESPLeft, ESPBottom + 20.0f32], - [ESPRight, ESPBottom + 20.0f32], - SETTINGS.deref().inner_hp_bar_color // Inner hp bar color - ).thickness(SETTINGS.deref().hp_bar_thickness); - let outer_hp_bar = background_draw_list.add_line( - [ESPLeft + HPRight, ESPBottom + 20.0f32], - [ESPRight, ESPBottom + 20.0f32], - SETTINGS.deref().outer_hp_bar_color // Outer hp bar color - ).thickness(SETTINGS.deref().hp_bar_thickness); + if SETTINGS.deref().is_horizontal_hp_bar { + let hpright = entity.health().unwrap() as f32 + * (espright - espleft) + / 100.0f32; + let inner_hp_bar = background_draw_list + .add_line( + [espleft, espbottom + 20.0f32], + [espright, espbottom + 20.0f32], + SETTINGS.deref().inner_hp_bar_color, // Inner hp bar color + ) + .thickness(SETTINGS.deref().hp_bar_thickness); + let outer_hp_bar = background_draw_list + .add_line( + [espleft + hpright, espbottom + 20.0f32], + [espright, espbottom + 20.0f32], + SETTINGS.deref().outer_hp_bar_color, // Outer hp bar color + ) + .thickness(SETTINGS.deref().hp_bar_thickness); inner_hp_bar.build(); outer_hp_bar.build(); } } } - if SETTINGS.deref().is_draw_name_text - { - if (SETTINGS.deref().is_draw_name_text_ally && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) || - (SETTINGS.deref().is_draw_name_text_enemy && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) + if SETTINGS.deref().is_draw_name_text { + if (SETTINGS.deref().is_draw_name_text_ally + && LOCAL_PLAYER.team().unwrap() == entity.team().unwrap()) + || (SETTINGS.deref().is_draw_name_text_enemy + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap()) { - background_draw_list.add_text([ESPLeft, ESPTop - 20.0f32], - if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() - {SETTINGS.deref().ally_name_text_color} else {SETTINGS.deref().enemy_name_text_color}, - entity.name().unwrap()); - + background_draw_list.add_text( + [espleft, esptop - 20.0f32], + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + SETTINGS.deref().ally_name_text_color + } else { + SETTINGS.deref().enemy_name_text_color + }, + entity.name().unwrap(), + ); } } if IS_AIMBOT.load(SeqCst) && IS_DRAW_FOV.load(SeqCst) { - let circle = background_draw_list.add_circle([ - GAME_WINDOW_DIMENSIONS.width as f32 / 2.0f32, - GAME_WINDOW_DIMENSIONS.height as f32 / 2.0f32], + let circle = background_draw_list.add_circle( + [ + GAME_WINDOW_DIMENSIONS.width as f32 / 2.0f32, + GAME_WINDOW_DIMENSIONS.height as f32 / 2.0f32, + ], FOV.load(SeqCst) as f32, - [255.0f32,255.0f32,255.0f32]); + [255.0f32, 255.0f32, 255.0f32], + ); circle.build(); } } - - - } - if !IS_SHOW_UI.load(SeqCst) { ui.set_mouse_cursor(None); return; @@ -947,69 +1127,71 @@ impl hudhook::ImguiRenderLoop for RenderLoop { let custom_font = ui.push_font(font_id); - if let Some(wt) = 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) .begin() - { - unsafe { on_frame(ui, SETTINGS.deref_mut()); } - custom_font.pop(); - wt.end(); - }; + { + on_frame(ui, SETTINGS.deref_mut()); + custom_font.pop(); + wt.end(); + }; } } } - - - - - unsafe fn init_fonts(_ctx: &mut Context) { unsafe { let fonts = _ctx.fonts(); let fonts_config_small = FontConfig { - glyph_ranges:FontGlyphRanges::cyrillic(), - ..Default::default()}; + glyph_ranges: FontGlyphRanges::cyrillic(), + ..Default::default() + }; let fonts_config_normal = FontConfig { - glyph_ranges:FontGlyphRanges::cyrillic(), - ..Default::default()}; + glyph_ranges: FontGlyphRanges::cyrillic(), + ..Default::default() + }; let fonts_config_big = FontConfig { - glyph_ranges:FontGlyphRanges::cyrillic(), - ..Default::default()}; + glyph_ranges: FontGlyphRanges::cyrillic(), + ..Default::default() + }; let fonts_config_small_cn = FontConfig { - glyph_ranges:FontGlyphRanges::chinese_full(), - ..Default::default()}; + glyph_ranges: FontGlyphRanges::chinese_full(), + ..Default::default() + }; let fonts_config_normal_cn = FontConfig { - glyph_ranges:FontGlyphRanges::chinese_full(), - ..Default::default()}; + glyph_ranges: FontGlyphRanges::chinese_full(), + ..Default::default() + }; let fonts_config_big_cn = FontConfig { - glyph_ranges:FontGlyphRanges::chinese_full(), - ..Default::default()}; + glyph_ranges: FontGlyphRanges::chinese_full(), + ..Default::default() + }; let fonts_config_small_hebrew = FontConfig { - glyph_ranges:FontGlyphRanges::from_slice(&[ - 0x0590, 0x05FF, // Main Hebrew block - 0xFB1D, 0xFB4F, // Extended Hebrew characters - 0, // Zero-termination - ]), - ..Default::default() + glyph_ranges: FontGlyphRanges::from_slice(&[ + 0x0590, 0x05FF, // Main Hebrew block + 0xFB1D, 0xFB4F, // Extended Hebrew characters + 0, // Zero-termination + ]), + ..Default::default() }; let fonts_config_normal_hebrew = FontConfig { - glyph_ranges:FontGlyphRanges::from_slice(&[ + glyph_ranges: FontGlyphRanges::from_slice(&[ 0x0590, 0x05FF, // Main Hebrew block 0xFB1D, 0xFB4F, // Extended Hebrew characters - 0, // Zero-termination + 0, // Zero-termination ]), ..Default::default() }; let fonts_config_big_hebrew = FontConfig { - glyph_ranges:FontGlyphRanges::from_slice(&[ + glyph_ranges: FontGlyphRanges::from_slice(&[ 0x0590, 0x05FF, // Main Hebrew block 0xFB1D, 0xFB4F, // Extended Hebrew characters - 0, // Zero-termination + 0, // Zero-termination ]), ..Default::default() }; @@ -1027,8 +1209,9 @@ unsafe fn init_fonts(_ctx: &mut Context) { let mut hebrew_font_file = File::open(&hebrew_font_file_path).unwrap(); let mut hebrew_font_file_bytes = Vec::new(); - hebrew_font_file.read_to_end(&mut hebrew_font_file_bytes).unwrap(); - + hebrew_font_file + .read_to_end(&mut hebrew_font_file_bytes) + .unwrap(); FONTS_STORAGE = Some(FontIDs { small: fonts.add_font(&[ @@ -1065,9 +1248,7 @@ unsafe fn init_fonts(_ctx: &mut Context) { config: Some(fonts_config_normal_hebrew), }, ]), - big: - - fonts.add_font(&[ + big: fonts.add_font(&[ FontSource::TtfData { data: &crate::fonts::graffiti_font::GRAFFITI, // &crate::fonts::clash_font::CLASH, size_pixels: 24.,