From 66ef51944484dfeb856802675b3d907379de17f7 Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 5 Aug 2024 02:28:47 +0300 Subject: [PATCH] Code cleanup Code cleanup --- Cargo.toml | 10 +- build.rs | 3 - src/draw_utils.rs | 3 +- src/entity.rs | 2 +- src/entrypoint.rs | 420 ++--------------------------------- src/esp.rs | 2 +- src/esp_gdi.rs | 384 ++++++++++++++++++++++++++++++++ src/game.rs | 4 +- src/get_local_player_hook.rs | 10 +- src/get_window_dimensions.rs | 6 +- src/getclosestentity.rs | 2 +- src/hotkey_widget.rs | 10 +- src/key_action.rs | 57 +++-- src/lib.rs | 1 + src/main_thread.rs | 2 +- src/memorypatch.rs | 4 +- src/misc.rs | 25 ++- src/offsets.rs | 3 +- src/pattern_mask.rs | 14 +- src/state/mod.rs | 6 +- src/triggerbot_hook.rs | 34 +-- src/ui.rs | 164 ++++++++++---- src/utils.rs | 19 +- src/vars.rs | 9 +- src/wallhack_hook.rs | 6 +- 25 files changed, 628 insertions(+), 572 deletions(-) create mode 100644 src/esp_gdi.rs diff --git a/Cargo.toml b/Cargo.toml index b794985..a651097 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,13 @@ authors = ["luadebug Lin Evelynn lin@sz.cn.eu.org"] publish = false [dependencies] -windows = { git = "https://github.com/microsoft/windows-rs", features = ["Win32_System_Console", "Win32_System_SystemServices", "Win32_System_LibraryLoader", "Win32_System_Threading", "Win32_Security", "Win32_System_Memory", "Win32_System_Diagnostics", "Win32_System_Diagnostics_Debug", "Win32_Graphics", "Win32_Graphics_OpenGL", "Win32_UI", "Win32_UI_Input", "Win32_UI_Input_KeyboardAndMouse", "Win32_Graphics_Gdi", "Win32_UI_WindowsAndMessaging", "Win32_Globalization", "Win32_System_ProcessStatus"] } -hudhook = { git = "https://github.com/veeenu/hudhook/", features = ["opengl3", "imgui-freetype"] } +windows = { git = "https://github.com/microsoft/windows-rs", features = ["Win32_System_Console", + "Win32_System_SystemServices", "Win32_System_LibraryLoader", "Win32_System_Threading", "Win32_Security", + "Win32_System_Memory", "Win32_System_Diagnostics", "Win32_System_Diagnostics_Debug", "Win32_Graphics", + "Win32_UI", "Win32_UI_Input", "Win32_UI_Input_KeyboardAndMouse", "Win32_Graphics_Gdi", + "Win32_UI_WindowsAndMessaging", "Win32_System_ProcessStatus"] } +hudhook = { git = "https://github.com/veeenu/hudhook/", features = ["opengl3", "imgui-freetype", + "imgui-docking", "imgui-tables-api"] } tracing-subscriber = "0.3.18" once_cell = "1.19.0" ilhook = "2.1.1" @@ -20,6 +25,7 @@ serde_yml = "0.0.11" gnal_tsur = "0.1.0" pkg-config = "0.3.30" imgui-sys = { version = "0.12.0", features = ["use-vcpkg"] } +lazy_static = "1.5.0" [lib] crate-type = ["cdylib"] diff --git a/build.rs b/build.rs index fa4d8c1..df2faf3 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,3 @@ -use std::path::Path; -use vcpkg::Error; - fn main() { match vcpkg::find_package("freetype") { Ok(freetype) => println!("{:?}", freetype.include_paths), diff --git a/src/draw_utils.rs b/src/draw_utils.rs index c658032..bcec97c 100644 --- a/src/draw_utils.rs +++ b/src/draw_utils.rs @@ -1,4 +1,4 @@ -use std::ffi::CString; +/*use std::ffi::CString; use windows::core::PCSTR; use windows::Win32::Foundation::{GetLastError, COLORREF, RECT}; @@ -166,3 +166,4 @@ pub unsafe fn draw_circle(hdc: HDC, center: (f32, f32), radius: f32, color: COLO let _ = DeleteObject(brush); } } +*/ \ No newline at end of file diff --git a/src/entity.rs b/src/entity.rs index d2caadb..f15b4d2 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -1,4 +1,4 @@ -use crate::offsets::offsets::{ +use crate::offsets::{ HEAD_X_FROM_LOCAL_PLAYER, HEAD_Y_FROM_LOCAL_PLAYER, HEAD_Z_FROM_LOCAL_PLAYER, HEALTH_OFFSET_FROM_LOCAL_PLAYER, NAME_OFFSET_FROM_LOCAL_PLAYER, PITCH_OFFSET, POSITION_X_FROM_LOCAL_PLAYER, POSITION_Y_FROM_LOCAL_PLAYER, POSITION_Z_FROM_LOCAL_PLAYER, diff --git a/src/entrypoint.rs b/src/entrypoint.rs index 49e83f0..9f47b9e 100644 --- a/src/entrypoint.rs +++ b/src/entrypoint.rs @@ -1,200 +1,50 @@ -use std::ffi::{c_void, CString}; -use std::ptr::null; +use std::ffi::CString; 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::Foundation::GetLastError; 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 windows::Win32::UI::WindowsAndMessaging::FindWindowA; -use crate::distance; -use crate::draw_utils::{draw_border_box, draw_circle, draw_scaling_bar, draw_text}; +//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::{ +use crate::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::{ENTITY_LIST_PTR, 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, - )) - } -} +use crate::vars::handles::GAME_WINDOW_DIMENSIONS; +use crate::vars::ui_vars::IS_ESP; -pub unsafe fn read_game_data() -> Result<(usize, usize, usize, [f32; 16]), Box> { +pub unsafe fn read_game_data() -> Result<(usize, usize, usize, [f32; 16]), String> { 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)))?; + .map_err(|err| 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)) + 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)))?; + .map_err(|err| 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)))?; + .map_err(|err| format!("Error reading view matrix: {}", err))?; // Return the values as a tuple Ok(( @@ -205,248 +55,8 @@ pub unsafe fn read_game_data() -> Result<(usize, usize, usize, [f32; 16]), Box(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> { +pub unsafe fn entrypoint() -> Result<(), String> { unsafe { // Initialize module handle AC_CLIENT_EXE_HMODULE = { @@ -481,7 +91,7 @@ pub unsafe fn entrypoint() -> Result<(), Box> { 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(std::ptr::null::()), PCSTR(assault_cube_cstring.as_ptr() as *const u8), ); diff --git a/src/esp.rs b/src/esp.rs index 5901cc5..cb7389a 100644 --- a/src/esp.rs +++ b/src/esp.rs @@ -10,7 +10,7 @@ unsafe fn esp_cleanup( red_brush: HBRUSH, blue_brush: HBRUSH, background_brush: HBRUSH, -) -> Result<(), Box> { +) -> Result<(), String> { unsafe { // Attempt to delete the memory bitmap and log the result if DeleteObject(mem_bitmap) == TRUE { diff --git a/src/esp_gdi.rs b/src/esp_gdi.rs new file mode 100644 index 0000000..92f7276 --- /dev/null +++ b/src/esp_gdi.rs @@ -0,0 +1,384 @@ +/*use windows::Win32::Graphics::Gdi::{HBITMAP, HBRUSH, HDC, ReleaseDC}; +use std::ffi::CString; +use windows::Win32::System::LibraryLoader::GetModuleHandleA; +use windows::core::PCSTR; +use windows::Win32::UI::WindowsAndMessaging::FindWindowA; +use crate::utils::read_view_matrix; +use crate::vars::handles::{AC_CLIENT_EXE_HMODULE, GAME_WINDOW_DIMENSIONS, GAME_WINDOW_HANDLE}; + +#[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(std::ptr::null::()), + 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) + &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, + )) + } +} + +#[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(()) +}*/ \ No newline at end of file diff --git a/src/game.rs b/src/game.rs index 4a3c99e..8809c72 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,7 +6,7 @@ use windows::Win32::System::Memory::{ VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS, }; -use crate::offsets::offsets::{BRIGHTNESS, SET_BRIGHTNESS}; +use crate::offsets::{BRIGHTNESS, SET_BRIGHTNESS}; use crate::utils::write_memory; pub unsafe fn c_brightness() -> *mut usize { @@ -67,7 +67,7 @@ pub unsafe fn set_brightness_toggle(is_on: bool) { static mut SET_BRIGHTNESS_FUNCTION: Option ()> = None; // Get the address somewhere in your code - SET_BRIGHTNESS_FUNCTION = core::mem::transmute(set_brightness_func); + SET_BRIGHTNESS_FUNCTION = core::mem::transmute::<*mut usize, Option>(set_brightness_func); // Then call it somewhere else SET_BRIGHTNESS_FUNCTION.unwrap()(); diff --git a/src/get_local_player_hook.rs b/src/get_local_player_hook.rs index 77f16ac..d1e9589 100644 --- a/src/get_local_player_hook.rs +++ b/src/get_local_player_hook.rs @@ -5,7 +5,7 @@ use std::thread; use ilhook::x86::{CallbackOption, HookFlags, HookType, Hooker, Registers}; use crate::entity::Entity; -use crate::offsets::offsets::{ +use crate::offsets::{ AMMO_CARBINE, AMMO_IN_MAGAZINE_CARBINE, AMMO_IN_MAGAZINE_PISTOL, AMMO_IN_MAGAZINE_RIFLE, AMMO_IN_MAGAZINE_SHOTGUN, AMMO_IN_MAGAZINE_SNIPER, AMMO_IN_MAGAZINE_SUBMACHINEGUN, AMMO_PISTOL, AMMO_RIFLE, AMMO_SHOTGUN, AMMO_SNIPER, AMMO_SUBMACHINEGUN, ARMOR_OFFSET_FROM_LOCAL_PLAYER, @@ -27,11 +27,9 @@ pub(crate) unsafe extern "cdecl" fn get_local_player_health(reg: *mut Registers, if reg_val.ebx == 0 { return; } - if LOCAL_PLAYER_FIELDS_ADDR == null_mut() { + if LOCAL_PLAYER_FIELDS_ADDR.is_null() || + LOCAL_PLAYER_FIELDS_ADDR != reg_val.ebx as *mut usize { LOCAL_PLAYER_FIELDS_ADDR = reg_val.ebx as *mut usize; - if LOCAL_PLAYER_FIELDS_ADDR == null_mut() { - return; - } } let mut local_player = match Entity::from_addr(LOCAL_PLAYER_FIELDS_ADDR as usize) { @@ -103,7 +101,7 @@ pub fn setup_invul() { let get_local_player_health_aob = find_pattern( "ac_client.exe", - &*pattern_mask.aob_pattern, + &pattern_mask.aob_pattern, &pattern_mask.mask_to_string(), ); diff --git a/src/get_window_dimensions.rs b/src/get_window_dimensions.rs index 5f3e6fa..ad3b6c2 100644 --- a/src/get_window_dimensions.rs +++ b/src/get_window_dimensions.rs @@ -3,7 +3,7 @@ use windows::Win32::UI::WindowsAndMessaging::{GetWindowInfo, WINDOWINFO}; use crate::window_dimensions::WindowDimensions; -pub(crate) fn get_window_dimensions(window: HWND) -> Result> { +pub(crate) fn get_window_dimensions(window: HWND) -> Result { let mut window_info = WINDOWINFO::default(); window_info.cbSize = std::mem::size_of_val(&window_info) as u32; @@ -13,10 +13,10 @@ pub(crate) fn get_window_dimensions(window: HWND) -> Result Err(Box::new(format!( + Err(_) => Err(format!( "Error getting screen dimensions. last_error={:?}", GetLastError() - ))), + )), } } } diff --git a/src/getclosestentity.rs b/src/getclosestentity.rs index 69ef39f..91f530c 100644 --- a/src/getclosestentity.rs +++ b/src/getclosestentity.rs @@ -5,7 +5,7 @@ use windows::Win32::System::LibraryLoader::GetModuleHandleA; use crate::distance::distance_2d; use crate::entity::Entity; -use crate::offsets::offsets::{ +use crate::offsets::{ ENTITY_LIST_OFFSET, LOCAL_PLAYER_OFFSET, NUMBER_OF_PLAYERS_IN_MATCH_OFFSET, VIEW_MATRIX_ADDR, }; use crate::utils::{read_memory, read_view_matrix}; diff --git a/src/hotkey_widget.rs b/src/hotkey_widget.rs index 4e788a7..df702e7 100644 --- a/src/hotkey_widget.rs +++ b/src/hotkey_widget.rs @@ -224,11 +224,6 @@ pub fn render_button_key( "None".to_string() }; - /* if !label.starts_with("##") { - ui.text(label); - ui.same_line(); - }*/ - let mut updated = false; if optional { if ui.button_with_size(&button_label, [size[0] - 35.0, size[1]]) { @@ -246,11 +241,10 @@ pub fn render_button_key( //*key = None; } }); - } else { - if ui.button_with_size(&button_label, size) { + } else if ui.button_with_size(&button_label, size) { ui.open_popup(label); } - } + ui.modal_popup_config(label) .inputs(true) diff --git a/src/key_action.rs b/src/key_action.rs index a88f94c..d9f677b 100644 --- a/src/key_action.rs +++ b/src/key_action.rs @@ -4,13 +4,11 @@ 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::memorypatch::MemoryPatch; +use crate::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, RADAR_MEMORY_PATCH, RAPID_FIRE_MEMORY_PATCH, -}; use crate::vars::ui_vars::IS_SMOOTH; use crate::vec_structures::Vec3; @@ -48,27 +46,27 @@ pub unsafe fn toggle_infinite_ammo(toggle: &mut bool) { *toggle = !*toggle; } -pub unsafe fn toggle_no_recoil(toggle: &mut bool) { +pub unsafe fn toggle_no_recoil(toggle: &mut bool, mem_patch: &mut MemoryPatch) { *toggle = !*toggle; if *toggle { - NO_RECOIL_MEMORY_PATCH + mem_patch .patch_memory() .expect("[ui] Failed to patch memory no recoil"); } else { - NO_RECOIL_MEMORY_PATCH + mem_patch .unpatch_memory() .expect("[ui] Failed to unpatch memory no recoil"); } } -pub unsafe fn toggle_rapid_fire(toggle: &mut bool) { +pub unsafe fn toggle_rapid_fire(toggle: &mut bool, mem_patch: &mut MemoryPatch) { *toggle = !*toggle; if *toggle { - RAPID_FIRE_MEMORY_PATCH + mem_patch .patch_memory() .expect("[ui] Failed to patch memory rapid fire"); } else { - RAPID_FIRE_MEMORY_PATCH + mem_patch .unpatch_memory() .expect("[ui] Failed to unpatch memory rapid fire"); } @@ -90,27 +88,26 @@ 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"); - RADAR_MEMORY_PATCH - .patch_memory() - .expect("[ui] Failed to patch memory Radar"); - } else { - MAPHACK_MEMORY_PATCH - .unpatch_memory() - .expect("[ui] Failed to unpatch memory Maphack"); - RADAR_MEMORY_PATCH - .unpatch_memory() - .expect("[ui] Failed to unpatch memory Radar"); - } +pub unsafe fn toggle_maphack(toggle: &mut bool, mem_patch: &mut MemoryPatch, mem_patch2: &mut MemoryPatch) { + *toggle = !*toggle; + if *toggle { + mem_patch + .patch_memory() + .expect("[ui] Failed to patch memory Maphack"); + mem_patch2 + .patch_memory() + .expect("[ui] Failed to patch memory Radar"); + } else { + mem_patch + .unpatch_memory() + .expect("[ui] Failed to unpatch memory Maphack"); + mem_patch2 + .unpatch_memory() + .expect("[ui] Failed to unpatch memory Radar"); } } + pub unsafe fn toggle_fullbright(toggle: &mut bool) { *toggle = !*toggle; let set_brightness_func = unsafe { set_brightness() }; @@ -199,7 +196,7 @@ pub unsafe fn aimbot(toggle: &mut bool) { // 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), + (Ok(y), Ok(p)) => (y, p), (Err(err), _) => { println!("Error reading yaw: {}", err); return; @@ -223,8 +220,6 @@ pub unsafe fn aimbot(toggle: &mut bool) { 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); diff --git a/src/lib.rs b/src/lib.rs index ec08a52..bd36ad3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,6 +42,7 @@ mod vec_structures; mod wallhack_hook; mod window_dimensions; mod world_to_screen; +mod esp_gdi; #[no_mangle] #[allow(non_snake_case, unused_variables)] diff --git a/src/main_thread.rs b/src/main_thread.rs index d39a6b3..15b4d39 100644 --- a/src/main_thread.rs +++ b/src/main_thread.rs @@ -50,5 +50,5 @@ pub extern "system" fn MainThread(lpReserved: *mut c_void) -> u32 { } entrypoint().expect("[MainThread] Failed to call esp_entrypoint()"); } - return 1; + 1 } diff --git a/src/memorypatch.rs b/src/memorypatch.rs index f0c68b8..daf316e 100644 --- a/src/memorypatch.rs +++ b/src/memorypatch.rs @@ -87,8 +87,8 @@ impl MemoryPatch { unsafe { ptr::copy_nonoverlapping(buffer_to_patch.as_ptr(), patch_instructions, size_buffer); ptr::copy_nonoverlapping(location as *const u8, original_instructions, size_buffer); - for i in 0..size_buffer { - if mask[i] == b'?' { + for (i, &m) in mask.iter().enumerate().take(size_buffer) { + if m == b'?' { *patch_instructions.add(i) = *original_instructions.add(i); } } diff --git a/src/misc.rs b/src/misc.rs index 544cd62..61872a2 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -8,6 +8,7 @@ use crate::vars::mem_patches::{ }; use crate::wallhack_hook::setup_wallhack; use std::ffi::c_void; +use std::sync::Mutex; use std::thread; pub unsafe fn init_mem_patches() { @@ -18,7 +19,7 @@ pub unsafe fn init_mem_patches() { let no_recoil_aob = find_pattern( "ac_client.exe", - &*pattern_mask.aob_pattern, + &pattern_mask.aob_pattern, &pattern_mask.mask_to_string(), ); let mut no_recoil_res: usize = 0; @@ -31,13 +32,13 @@ pub unsafe fn init_mem_patches() { //83 EC 28 -> C2 08 00 unsafe { - NO_RECOIL_MEMORY_PATCH = MemoryPatch::new( + NO_RECOIL_MEMORY_PATCH = Mutex::new(MemoryPatch::new( &[0xC2, 0x08, 0x00], // return 0008 0x03, no_recoil_res as *mut c_void, 3usize, ) - .expect("Failed to patch No Recoil"); + .expect("Failed to patch No Recoil")); } }); @@ -48,7 +49,7 @@ pub unsafe fn init_mem_patches() { let rapid_fire_aob = find_pattern( "ac_client.exe", - &*pattern_mask.aob_pattern, + &pattern_mask.aob_pattern, &pattern_mask.mask_to_string(), ); let mut rapid_fire_res: usize = 0; @@ -61,13 +62,13 @@ pub unsafe fn init_mem_patches() { //89 08 -> 90 90 unsafe { - RAPID_FIRE_MEMORY_PATCH = MemoryPatch::new( + RAPID_FIRE_MEMORY_PATCH = Mutex::new(MemoryPatch::new( &[0x90, 0x90], // nop nop 0x02, rapid_fire_res as *mut c_void, 2usize, ) - .expect("Failed to patch Rapid Fire"); + .expect("Failed to patch Rapid Fire")); } }); thread::spawn(|| { @@ -77,7 +78,7 @@ pub unsafe fn init_mem_patches() { let maphack_aob = find_pattern( "ac_client.exe", - &*pattern_mask.aob_pattern, + &pattern_mask.aob_pattern, &pattern_mask.mask_to_string(), ); @@ -89,13 +90,13 @@ pub unsafe fn init_mem_patches() { println!("[esp] maphack pattern not found"); } unsafe { - MAPHACK_MEMORY_PATCH = MemoryPatch::new( + MAPHACK_MEMORY_PATCH = Mutex::new(MemoryPatch::new( &[0xE9, 0xCD, 0x00, 0x00, 0x00, 0x90], 0x06, map_res as *mut c_void, 6usize, ) - .expect("Failed to patch map"); + .expect("Failed to patch map")); } let pattern_mask2 = PatternMask::aob_to_pattern_mask("0F 8D ? ? ? ? 85 C9 74 68"); @@ -104,7 +105,7 @@ pub unsafe fn init_mem_patches() { let radarhack_aob = find_pattern( "ac_client.exe", - &*pattern_mask2.aob_pattern, + &pattern_mask2.aob_pattern, &pattern_mask2.mask_to_string(), ); @@ -116,13 +117,13 @@ pub unsafe fn init_mem_patches() { println!("[esp] radarhack pattern not found"); } unsafe { - RADAR_MEMORY_PATCH = MemoryPatch::new( + RADAR_MEMORY_PATCH = Mutex::new(MemoryPatch::new( &[0xE9, 0xD6, 0x00, 0x00, 0x00, 0x90], 0x06, radar_res as *mut c_void, 6usize, ) - .expect("Failed to patch radar"); + .expect("Failed to patch radar")); } }); setup_trigger_bot(); diff --git a/src/offsets.rs b/src/offsets.rs index 9c4d39c..465eab5 100644 --- a/src/offsets.rs +++ b/src/offsets.rs @@ -1,4 +1,4 @@ -pub mod offsets { + pub const LOCAL_PLAYER_OFFSET: usize = 0x18AC00; pub const HEAD_X_FROM_LOCAL_PLAYER: usize = 0x4; pub const HEAD_Y_FROM_LOCAL_PLAYER: usize = 0x8; @@ -46,4 +46,3 @@ pub mod offsets { pub const BRIGHTNESS: usize = 0x182D40; pub const SET_BRIGHTNESS: usize = 0xBA180; -} diff --git a/src/pattern_mask.rs b/src/pattern_mask.rs index 97fe3dc..4ba6f80 100644 --- a/src/pattern_mask.rs +++ b/src/pattern_mask.rs @@ -15,10 +15,10 @@ impl PatternMask { }; d.string_byte_array = search - .trim() .split_whitespace() .map(|s| s.to_string()) .collect(); + let length = d.string_byte_array.len(); d.aob_pattern = vec![0; length]; d.mask = vec![0; length]; @@ -27,16 +27,12 @@ impl PatternMask { if ba == "??" || (ba.len() == 1 && ba == "?") { d.mask[i] = 0x00; d.aob_pattern[i] = 0x00; // Set aob_pattern for wildcards as well - } else if ba.chars().next().unwrap().is_ascii_alphanumeric() - && ba.chars().nth(1) == Some('?') - { + } else if ba.starts_with(|arg0: char| char::is_ascii_alphanumeric(&arg0)) && ba.chars().nth(1) == Some('?') { d.mask[i] = 0xF0; let hex_value = u8::from_str_radix(&format!("{}0", ba.chars().next().unwrap()), 16).unwrap(); d.aob_pattern[i] = hex_value; - } else if ba.chars().next() == Some('?') - && ba.chars().nth(1).unwrap().is_ascii_alphanumeric() - { + } else if ba.starts_with('?') && ba.chars().nth(1).expect("Failed to extract second character").is_ascii_alphanumeric() { d.mask[i] = 0x0F; let hex_value = u8::from_str_radix(&format!("0{}", ba.chars().nth(1).unwrap()), 16).unwrap(); @@ -44,8 +40,8 @@ impl PatternMask { } else { d.mask[i] = 0xFF; // Correctly convert and apply mask to aob_pattern - let hex_value = if ba.starts_with("0x") { - u8::from_str_radix(&ba[2..], 16).unwrap_or(0x00) + let hex_value = if let Some(stripped) = ba.strip_prefix("0x") { + u8::from_str_radix(stripped, 16).unwrap_or(0x00) } else { u8::from_str_radix(ba, 16).unwrap_or(0x00) }; diff --git a/src/state/mod.rs b/src/state/mod.rs index 4efe06e..3655d2e 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -208,8 +208,7 @@ impl StateRegistry { let value = self.states[index] .try_borrow() .ok() - .map(transpose_ref_opt) - .flatten()?; + .and_then(transpose_ref_opt)?; let value = Ref::map(value, |value| { value.value.downcast_ref::().expect("to be type T") @@ -227,8 +226,7 @@ impl StateRegistry { let value = self.states[index] .try_borrow_mut() .ok() - .map(transpose_ref_mut_opt) - .flatten()?; + .and_then(transpose_ref_mut_opt)?; // Use and_then instead of map + flatten let value = RefMut::map(value, |value| { value.value.downcast_mut::().expect("to be type T") diff --git a/src/triggerbot_hook.rs b/src/triggerbot_hook.rs index f828663..da9077c 100644 --- a/src/triggerbot_hook.rs +++ b/src/triggerbot_hook.rs @@ -1,15 +1,12 @@ -use std::ptr::null_mut; -use std::sync::atomic::Ordering::SeqCst; use std::sync::{Arc, Mutex}; +use std::sync::atomic::Ordering::SeqCst; use std::thread; use std::thread::sleep; use std::time::Duration; -use ilhook::x86::{CallbackOption, HookFlags, HookType, Hooker, Registers}; +use ilhook::x86::{CallbackOption, Hooker, HookFlags, HookType, Registers}; use windows::Win32::Foundation::GetLastError; -use windows::Win32::UI::Input::KeyboardAndMouse::{ - SendInput, INPUT, INPUT_MOUSE, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, MOUSE_EVENT_FLAGS, -}; +use windows::Win32::UI::Input::KeyboardAndMouse::{INPUT, INPUT_0, INPUT_MOUSE, MOUSE_EVENT_FLAGS, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, MOUSEINPUT, SendInput}; use crate::entity::Entity; use crate::pattern_mask::PatternMask; @@ -31,7 +28,7 @@ pub(crate) unsafe extern "cdecl" fn get_crosshair_entity(reg: *mut Registers, _: return; } CURRENT_CROSSHAIR_ENTITY_ADDR = reg_val.eax as *mut usize; - if CURRENT_CROSSHAIR_ENTITY_ADDR == null_mut() { + if CURRENT_CROSSHAIR_ENTITY_ADDR.is_null() { return; } @@ -65,14 +62,19 @@ pub(crate) unsafe extern "cdecl" fn get_crosshair_entity(reg: *mut Registers, _: } } unsafe fn trigger_bot() { - let mut input: INPUT = INPUT::default(); - input.r#type = INPUT_MOUSE; - input.Anonymous.mi.dx = 0; - input.Anonymous.mi.dy = 0; - input.Anonymous.mi.mouseData = 0; - input.Anonymous.mi.dwFlags = MOUSE_EVENT_FLAGS(0); - input.Anonymous.mi.time = 0; - input.Anonymous.mi.dwExtraInfo = 0; + let input: INPUT = INPUT { + r#type: INPUT_MOUSE, + Anonymous: INPUT_0 { + mi: MOUSEINPUT { + dx: 0, + dy: 0, + mouseData: 0, + dwFlags: MOUSE_EVENT_FLAGS(0), + time: 0, + dwExtraInfo: 0, + }, + }, + }; // Use a mutex to synchronize access to the input variable let input_mutex = Arc::new(Mutex::new(input)); @@ -115,7 +117,7 @@ pub fn setup_trigger_bot() { let trigger_bot_aob = find_pattern( "ac_client.exe", - &*pattern_mask.aob_pattern, + &pattern_mask.aob_pattern, &pattern_mask.mask_to_string(), ); diff --git a/src/ui.rs b/src/ui.rs index f3735ba..67608a0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -6,32 +6,32 @@ 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, Io}; use once_cell::sync::Lazy; 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::hotkey_widget::{ImGuiKey, KeyboardInputSystem, to_win_key}; 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, + 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::aimbot; 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::{ +use crate::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::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, }; @@ -40,9 +40,7 @@ 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, -}; +use crate::vars::mem_patches::{MAPHACK_MEMORY_PATCH, NO_RECOIL_MEMORY_PATCH, RADAR_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, @@ -56,6 +54,9 @@ 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(); @@ -152,11 +153,11 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { if ui.checkbox(CURRENT_LOCALE_VECTOR[8], IS_NO_RECOIL.get_mut()) { println!("Set No Recoil Toggle to {}", IS_NO_RECOIL.load(SeqCst)); if IS_NO_RECOIL.load(SeqCst) { - NO_RECOIL_MEMORY_PATCH + NO_RECOIL_MEMORY_PATCH.lock().unwrap() .patch_memory() .expect("[ui] Failed to patch memory no recoil"); } else { - NO_RECOIL_MEMORY_PATCH + NO_RECOIL_MEMORY_PATCH.lock().unwrap() .unpatch_memory() .expect("[ui] Failed to unpatch memory no recoil"); } @@ -174,11 +175,11 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { if ui.checkbox(CURRENT_LOCALE_VECTOR[9], IS_RAPID_FIRE.get_mut()) { println!("Set Rapid Fire Toggle to {}", IS_RAPID_FIRE.load(SeqCst)); if IS_RAPID_FIRE.load(SeqCst) { - RAPID_FIRE_MEMORY_PATCH + RAPID_FIRE_MEMORY_PATCH.lock().unwrap() .patch_memory() .expect("[ui] Failed to patch memory rapid fire"); } else { - RAPID_FIRE_MEMORY_PATCH + RAPID_FIRE_MEMORY_PATCH.lock().unwrap() .unpatch_memory() .expect("[ui] Failed to unpatch memory rapid fire"); } @@ -277,11 +278,17 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { if ui.checkbox(CURRENT_LOCALE_VECTOR[17], IS_MAPHACK.get_mut()) { println!("Set Maphack Toggle to {}", IS_MAPHACK.load(SeqCst)); if IS_MAPHACK.load(SeqCst) { - MAPHACK_MEMORY_PATCH + RADAR_MEMORY_PATCH.lock().unwrap() + .patch_memory() + .expect("[ui] Failed to patch memory radarhack"); + MAPHACK_MEMORY_PATCH.lock().unwrap() .patch_memory() .expect("[ui] Failed to patch memory maphack"); } else { - MAPHACK_MEMORY_PATCH + RADAR_MEMORY_PATCH.lock().unwrap() + .unpatch_memory() + .expect("[ui] Failed to unpatch memory radarhack"); + MAPHACK_MEMORY_PATCH.lock().unwrap() .unpatch_memory() .expect("[ui] Failed to unpatch memory maphack"); } @@ -615,6 +622,13 @@ static mut FONTS_STORAGE: Option = Some(FontIDs { normal: unsafe { mem::zeroed() }, big: unsafe { mem::zeroed() }, }); + +static mut FONTS_STORAGE2: Option = Some(FontIDs { + small: unsafe { mem::zeroed() }, + normal: unsafe { mem::zeroed() }, + big: unsafe { mem::zeroed() }, +}); + pub struct RenderLoop; impl RenderLoop { pub fn new() -> Self { @@ -701,11 +715,13 @@ impl hudhook::ImguiRenderLoop for RenderLoop { }, 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())), + action: Box::new(move || toggle_no_recoil(IS_NO_RECOIL.get_mut(), + NO_RECOIL_MEMORY_PATCH.get_mut().unwrap())), }, 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())), + action: Box::new(move || toggle_rapid_fire(IS_RAPID_FIRE.get_mut(), + RAPID_FIRE_MEMORY_PATCH.get_mut().unwrap())), }, KeyAction { key: to_win_key(SETTINGS.deref().aimbot.as_ref().unwrap().key).0 as usize, @@ -725,7 +741,9 @@ impl hudhook::ImguiRenderLoop for RenderLoop { }, 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())), + action: Box::new(move || toggle_maphack(IS_MAPHACK.get_mut(), + RADAR_MEMORY_PATCH.get_mut().unwrap(), + MAPHACK_MEMORY_PATCH.get_mut().unwrap())), }, KeyAction { key: to_win_key(SETTINGS.deref().fullbright.as_ref().unwrap().key).0 as usize, @@ -796,7 +814,6 @@ impl hudhook::ImguiRenderLoop for RenderLoop { _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); - return; } } @@ -804,7 +821,7 @@ impl hudhook::ImguiRenderLoop for RenderLoop { unsafe { if IS_SHOW_UI.load(SeqCst) { MessageFilter::InputAll | // Filter any input that being sent in-game - MessageFilter::WindowFocus // Filter game cursor midpoint window focus + MessageFilter::WindowFocus // Filter game cursor midpoint window focus } else { MessageFilter::WindowFocus // Filter game cursor midpoint window focus } @@ -819,7 +836,7 @@ impl hudhook::ImguiRenderLoop for RenderLoop { Ok(addr) => addr, Err(err) => { println!("Error reading local player address: {}", err); - return (); + return; } }; @@ -831,7 +848,7 @@ impl hudhook::ImguiRenderLoop for RenderLoop { Ok(num) => num as usize, Err(err) => { println!("Error reading number of players in match: {}", err); - return (); + return; } }; NUM_PLAYERS_IN_MATCH = num_players_in_match; @@ -841,7 +858,7 @@ impl hudhook::ImguiRenderLoop for RenderLoop { Ok(ptr) => ptr, Err(err) => { println!("Error reading entity list pointer: {}", err); - return (); + return; } }; ENTITY_LIST_PTR = entity_list_ptr; @@ -934,11 +951,11 @@ impl hudhook::ImguiRenderLoop for RenderLoop { 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 + if SETTINGS.deref().is_draw_trace_lines && + ((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()) + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap())) { let traceline = background_draw_list .add_line( @@ -956,12 +973,11 @@ impl hudhook::ImguiRenderLoop for RenderLoop { .thickness(SETTINGS.deref().trace_line_thickness); traceline.build(); } - } - if SETTINGS.deref().is_draw_boxes { - if (SETTINGS.deref().is_draw_boxes_ally + + if SETTINGS.deref().is_draw_boxes && ((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()) + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap())) { let box_upper_line = background_draw_list .add_line( @@ -1016,12 +1032,11 @@ impl hudhook::ImguiRenderLoop for RenderLoop { box_left_line.build(); box_right_line.build(); } - } - if SETTINGS.deref().is_draw_hp_bar { - if (SETTINGS.deref().is_draw_hp_bar_ally + + if SETTINGS.deref().is_draw_hp_bar && ((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()) + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap())) { if SETTINGS.deref().is_vertical_hp_bar { // Calculate the height of the health bar based on the entity's health @@ -1073,15 +1088,36 @@ impl hudhook::ImguiRenderLoop for RenderLoop { outer_hp_bar.build(); } } - } - if SETTINGS.deref().is_draw_name_text { - if (SETTINGS.deref().is_draw_name_text_ally + + if SETTINGS.deref().is_draw_name_text && ((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()) + && LOCAL_PLAYER.team().unwrap() != entity.team().unwrap())) { + /* sys::ImDrawList_AddText_Vec2( + sys::igGetBackgroundDrawList(), + ImVec2::from([espleft, esptop - 20.0f32]), + 0xFF0000FFu32, + start, + end, + );*/ + let width = ui.io().display_size[0]; + let font_id = FONTS_STORAGE2 + .as_mut() + .map(|fonts| { + if width > 2000. { + fonts.big + } else if width > 1200. { + fonts.normal + } else { + fonts.small + } + }) + .unwrap(); + + let custom_font = ui.push_font(font_id); background_draw_list.add_text( - [espleft, esptop - 20.0f32], + [espleft, esptop - 40.0f32], if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { SETTINGS.deref().ally_name_text_color } else { @@ -1089,8 +1125,9 @@ impl hudhook::ImguiRenderLoop for RenderLoop { }, entity.name().unwrap(), ); + custom_font.pop(); } - } + if IS_AIMBOT.load(SeqCst) && IS_DRAW_FOV.load(SeqCst) { let circle = background_draw_list.add_circle( [ @@ -1142,6 +1179,7 @@ impl hudhook::ImguiRenderLoop for RenderLoop { } } + unsafe fn init_fonts(_ctx: &mut Context) { unsafe { let fonts = _ctx.fonts(); @@ -1158,6 +1196,22 @@ unsafe fn init_fonts(_ctx: &mut Context) { ..Default::default() }; + let fonts_config_small2 = FontConfig { + glyph_ranges: FontGlyphRanges::cyrillic(), + size_pixels: 50.0f32, + ..Default::default() + }; + let fonts_config_normal2 = FontConfig { + glyph_ranges: FontGlyphRanges::cyrillic(), + size_pixels: 50.0f32, + ..Default::default() + }; + let fonts_config_big2 = FontConfig { + glyph_ranges: FontGlyphRanges::cyrillic(), + size_pixels: 50.0f32, + ..Default::default() + }; + let fonts_config_small_cn = FontConfig { glyph_ranges: FontGlyphRanges::chinese_full(), ..Default::default() @@ -1212,7 +1266,29 @@ unsafe fn init_fonts(_ctx: &mut Context) { hebrew_font_file .read_to_end(&mut hebrew_font_file_bytes) .unwrap(); - + FONTS_STORAGE2 = Some(FontIDs { + small: fonts.add_font(&[ + FontSource::TtfData { + data: &crate::fonts::clash_font::CLASH, // &crate::fonts::clash_font::CLASH, + size_pixels: 50., + config: Some(fonts_config_small2), //None, + }, + ]), + normal: fonts.add_font(&[ + FontSource::TtfData { + data: &crate::fonts::clash_font::CLASH, // &crate::fonts::clash_font::CLASH, + size_pixels: 50., + config: Some(fonts_config_normal2), + } + ]), + big: fonts.add_font(&[ + FontSource::TtfData { + data: &crate::fonts::clash_font::CLASH, // &crate::fonts::clash_font::CLASH, + size_pixels: 50., + config: Some(fonts_config_big2), + }, + ]), + }); FONTS_STORAGE = Some(FontIDs { small: fonts.add_font(&[ FontSource::TtfData { diff --git a/src/utils.rs b/src/utils.rs index 35a926a..b2c90a3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -216,8 +216,7 @@ pub unsafe fn write_memory(address: usize, value: T) -> Result<(), String> { ptr::write_unaligned((address as *mut T).cast(), value); // Restore the original memory protection if it was changed - if !is_writable { - if VirtualProtect( + if !is_writable && VirtualProtect( mbi.BaseAddress, mbi.RegionSize, old_protect, @@ -230,7 +229,7 @@ pub unsafe fn write_memory(address: usize, value: T) -> Result<(), String> { address )); } - } + Ok(()) } @@ -298,8 +297,7 @@ pub unsafe fn read_memory(address: usize) -> Result { let value = ptr::read_unaligned((address as *const T).cast()); // Restore the original memory protection if it was changed - if !is_readable { - if VirtualProtect( + if !is_readable && VirtualProtect( mbi.BaseAddress, mbi.RegionSize, old_protect, @@ -312,7 +310,7 @@ pub unsafe fn read_memory(address: usize) -> Result { address )); } - } + Ok(value) } @@ -384,8 +382,7 @@ pub unsafe fn read_vector(address: usize, len: usize) -> Result, Strin } // Restore the original memory protection if it was changed - if !is_readable { - if VirtualProtect( + if !is_readable && VirtualProtect( mbi.BaseAddress, mbi.RegionSize, old_protect, @@ -398,7 +395,7 @@ pub unsafe fn read_vector(address: usize, len: usize) -> Result, Strin address )); } - } + Ok(values) } @@ -481,12 +478,14 @@ pub fn close_console() { FreeConsole().expect("Failed to free console"); } } + + #[allow(unused)] pub fn run_cmd(command: &str) -> String { let mut result = String::new(); let mut child = Command::new("cmd") - .args(&["/C", command]) + .args(["/C", command]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .creation_flags(CREATE_NO_WINDOW.0) diff --git a/src/vars.rs b/src/vars.rs index d24c0b5..d40985f 100644 --- a/src/vars.rs +++ b/src/vars.rs @@ -12,12 +12,13 @@ pub mod hooks { Lazy::new(|| Mutex::new(None)); } pub mod mem_patches { + use std::sync::Mutex; use crate::memorypatch::MemoryPatch; - pub static mut NO_RECOIL_MEMORY_PATCH: MemoryPatch = MemoryPatch::new_empty(); - pub static mut RAPID_FIRE_MEMORY_PATCH: MemoryPatch = MemoryPatch::new_empty(); - pub static mut MAPHACK_MEMORY_PATCH: MemoryPatch = MemoryPatch::new_empty(); - pub static mut RADAR_MEMORY_PATCH: MemoryPatch = MemoryPatch::new_empty(); + pub static mut NO_RECOIL_MEMORY_PATCH: Mutex = Mutex::new(MemoryPatch::new_empty()); + pub static mut RAPID_FIRE_MEMORY_PATCH: Mutex = Mutex::new(MemoryPatch::new_empty()); + pub static mut MAPHACK_MEMORY_PATCH: Mutex = Mutex::new(MemoryPatch::new_empty()); + pub static mut RADAR_MEMORY_PATCH: Mutex = Mutex::new(MemoryPatch::new_empty()); } pub mod ui_vars { use std::sync::atomic::AtomicBool; diff --git a/src/wallhack_hook.rs b/src/wallhack_hook.rs index 9cdade1..1be1d61 100644 --- a/src/wallhack_hook.rs +++ b/src/wallhack_hook.rs @@ -35,8 +35,7 @@ pub(crate) unsafe extern "cdecl" fn wallhack_hooked_func(reg: *mut Registers, _: asm! { "pushad", } - if IS_WALLHACK.load(SeqCst) { - if (*reg).get_arg(7) > 200 && (*reg).get_arg(7) < 10000 { + if IS_WALLHACK.load(SeqCst) && (*reg).get_arg(7) > 200 && (*reg).get_arg(7) < 10000 { //println!("[ESP+0x1C] = {}", (*reg).get_arg(7)); /*GL_DEPTH_RANGE_FN.unwrap()(0.0f64, 0.0f64);*/ @@ -57,7 +56,6 @@ pub(crate) unsafe extern "cdecl" fn wallhack_hooked_func(reg: *mut Registers, _: GL_DISABLE_FN.unwrap()(0x0B57); GL_COLOR4F_FN.unwrap()(1.0f32, 1.0f32, 1.0f32, 1.0f32);*/ }*/ - } asm! { "popad mov esi, dword ptr ds : [esi + 0xA18]", @@ -86,7 +84,7 @@ pub fn setup_wallhack() { gl_depth_func.unwrap() as usize ); - GL_DEPTH_FUNC_FN = core::mem::transmute(gl_depth_func); + GL_DEPTH_FUNC_FN = core::mem::transmute:: isize>, Option>(gl_depth_func); /*