From 05e1c8267b0ce6b79316adc8f7680351c313fe3c Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 5 Aug 2024 05:23:26 +0300 Subject: [PATCH] Fixed name font coloring/scaling font size issues. Fixed name font coloring/scaling font size issues. --- src/settings.rs | 10 ++++----- src/ui.rs | 59 +++++++++++++++++++++++++++++++++++-------------- src/utils.rs | 23 +++++++++++++++++++ 3 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/settings.rs b/src/settings.rs index 9b4cf32..caedc8b 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -50,8 +50,8 @@ pub struct AppSettings { pub is_draw_name_text: bool, pub is_draw_name_text_ally: bool, pub is_draw_name_text_enemy: bool, - pub ally_name_text_color: [f32; 3], - pub enemy_name_text_color: [f32; 3], + pub ally_name_text_color: [f32; 4], + pub enemy_name_text_color: [f32; 4], pub name_text_thickness: f32, } @@ -159,9 +159,9 @@ impl Default for AppSettings { is_draw_name_text: true, is_draw_name_text_ally: true, 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, + ally_name_text_color: [0.0f32, 255.0f32, 0.0f32, 255.0f32], + enemy_name_text_color: [255.0f32, 0.0f32, 0.0f32, 255.0f32], + name_text_thickness: 40.0f32, } } } diff --git a/src/ui.rs b/src/ui.rs index 67608a0..03894c9 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,3 +1,4 @@ +use std::ffi::{c_char, CString}; use std::fs::File; use std::io::Read; use std::mem; @@ -7,7 +8,8 @@ use std::sync::atomic::Ordering::SeqCst; use gnal_tsur::gnal_tsur; use hudhook::{imgui, MessageFilter, RenderContext}; -use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, Io}; +use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, ImColor32, Io, sys}; +use imgui_sys::{igGetFont, ImColor, ImVec2, ImVec4}; use once_cell::sync::Lazy; use windows::Win32::UI::Input::KeyboardAndMouse::VK_INSERT; @@ -35,7 +37,7 @@ 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::utils::{read_memory, read_view_matrix, run_cmd}; +use crate::utils::{f32_to_u8, float_array_to_u32, 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, }; @@ -575,7 +577,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { if ui.slider( "Name text size", 10.0f32, - 60.0f32, + 120.0f32, &mut SETTINGS.name_text_thickness, ) { println!( @@ -583,7 +585,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { SETTINGS.deref().name_text_thickness ) } - if ui.color_edit3( + if ui.color_edit4( "Ally name text color", &mut SETTINGS.ally_name_text_color, ) { @@ -592,7 +594,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) { SETTINGS.ally_name_text_color ); } - if ui.color_edit3( + if ui.color_edit4( "Enemy name text color", &mut SETTINGS.enemy_name_text_color, ) { @@ -1115,17 +1117,42 @@ impl hudhook::ImguiRenderLoop for RenderLoop { }) .unwrap(); - let custom_font = ui.push_font(font_id); - background_draw_list.add_text( - [espleft, esptop - 40.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(), - ); - custom_font.pop(); + + unsafe { + let custom_font = ui.push_font(font_id); + // Get the entity name and create a CString + let text = entity.name().unwrap(); + let c_text = CString::new(text).unwrap(); // Convert to C-compatible string + + let font_handle = igGetFont(); + + // Get the pointer to the C string + let start: *const c_char = c_text.as_ptr(); // Use CString to ensure null termination + + // The end pointer is not necessary when using CString, as you can pass the string slice + let end: *const c_char = start.add(c_text.as_bytes().len()); + + // Call the function + sys::ImDrawList_AddText_FontPtr( + sys::igGetBackgroundDrawList_Nil(), + font_handle, + SETTINGS.deref().name_text_thickness, + ImVec2::from([espleft, esptop - 80.0f32]), + if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() { + ImColor32::from_rgba(f32_to_u8(SETTINGS.deref().ally_name_text_color[0]), f32_to_u8(SETTINGS.deref().ally_name_text_color[1]), f32_to_u8(SETTINGS.deref().ally_name_text_color[2]), f32_to_u8(SETTINGS.deref().ally_name_text_color[3])).to_bits() + } else { + ImColor32::from_rgba(f32_to_u8(SETTINGS.deref().enemy_name_text_color[0]), f32_to_u8(SETTINGS.deref().enemy_name_text_color[1]), f32_to_u8(SETTINGS.deref().enemy_name_text_color[2]), f32_to_u8(SETTINGS.deref().enemy_name_text_color[3])).to_bits() + }, + start, + end, + 0.0f32, + std::ptr::null() // Assuming you don't want to specify a clipping rectangle + ); + custom_font.pop(); + } + + + } if IS_AIMBOT.load(SeqCst) && IS_DRAW_FOV.load(SeqCst) { diff --git a/src/utils.rs b/src/utils.rs index b2c90a3..0d9515f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -556,3 +556,26 @@ pub unsafe fn setup_tracing() { .with(EnvFilter::from_default_env()) .init(); } +pub fn float_array_to_u32(arr: [f32; 4]) -> u32 { + assert!(arr.len() == 4); // Ensure the array has exactly 4 items + + // Initialize a variable to hold the combined u32 value + let mut combined: u32 = 0; + + // Iterate through the array, clamp to 0-255, and combine into u32 + for (i, &value) in arr.iter().enumerate() { + // Clamp the value to 0-255 and convert to u8 + let byte_value = value.clamp(0.0, 255.0) as u8; + + // Combine the byte into the combined u32 + combined |= (byte_value as u32) << (8 * (3 - i)); // Shift left to the correct position + } + + combined +} + +pub fn f32_to_u8(value: f32) -> u8 { + // Scale and clamp the value to the range [0, 255] + let scaled = (value * 255.0).clamp(0.0, 255.0); + scaled as u8 +} \ No newline at end of file