Skip to content

Commit 05e1c82

Browse files
authored
Fixed name font coloring/scaling font size issues.
Fixed name font coloring/scaling font size issues.
1 parent b914833 commit 05e1c82

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

src/settings.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ pub struct AppSettings {
5050
pub is_draw_name_text: bool,
5151
pub is_draw_name_text_ally: bool,
5252
pub is_draw_name_text_enemy: bool,
53-
pub ally_name_text_color: [f32; 3],
54-
pub enemy_name_text_color: [f32; 3],
53+
pub ally_name_text_color: [f32; 4],
54+
pub enemy_name_text_color: [f32; 4],
5555
pub name_text_thickness: f32,
5656
}
5757

@@ -159,9 +159,9 @@ impl Default for AppSettings {
159159
is_draw_name_text: true,
160160
is_draw_name_text_ally: true,
161161
is_draw_name_text_enemy: true,
162-
ally_name_text_color: [0.0f32, 255.0f32, 0.0f32],
163-
enemy_name_text_color: [255.0f32, 0.0f32, 0.0f32],
164-
name_text_thickness: 19.0f32,
162+
ally_name_text_color: [0.0f32, 255.0f32, 0.0f32, 255.0f32],
163+
enemy_name_text_color: [255.0f32, 0.0f32, 0.0f32, 255.0f32],
164+
name_text_thickness: 40.0f32,
165165
}
166166
}
167167
}

src/ui.rs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::{c_char, CString};
12
use std::fs::File;
23
use std::io::Read;
34
use std::mem;
@@ -7,7 +8,8 @@ use std::sync::atomic::Ordering::SeqCst;
78

89
use gnal_tsur::gnal_tsur;
910
use hudhook::{imgui, MessageFilter, RenderContext};
10-
use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, Io};
11+
use hudhook::imgui::{Context, FontConfig, FontGlyphRanges, FontId, FontSource, ImColor32, Io, sys};
12+
use imgui_sys::{igGetFont, ImColor, ImVec2, ImVec4};
1113
use once_cell::sync::Lazy;
1214
use windows::Win32::UI::Input::KeyboardAndMouse::VK_INSERT;
1315

@@ -35,7 +37,7 @@ use crate::settings::{AppSettings, load_app_settings, save_app_settings};
3537
use crate::style::{
3638
set_style_minty_light, set_style_minty_mint, set_style_minty_red, set_style_unicore,
3739
};
38-
use crate::utils::{read_memory, read_view_matrix, run_cmd};
40+
use crate::utils::{f32_to_u8, float_array_to_u32, read_memory, read_view_matrix, run_cmd};
3941
use crate::vars::game_vars::{
4042
ENTITY_LIST_PTR, FOV, LOCAL_PLAYER, NUM_PLAYERS_IN_MATCH, SMOOTH, TRIGGER_DELAY, VIEW_MATRIX,
4143
};
@@ -575,15 +577,15 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) {
575577
if ui.slider(
576578
"Name text size",
577579
10.0f32,
578-
60.0f32,
580+
120.0f32,
579581
&mut SETTINGS.name_text_thickness,
580582
) {
581583
println!(
582584
"Set name text size to {}",
583585
SETTINGS.deref().name_text_thickness
584586
)
585587
}
586-
if ui.color_edit3(
588+
if ui.color_edit4(
587589
"Ally name text color",
588590
&mut SETTINGS.ally_name_text_color,
589591
) {
@@ -592,7 +594,7 @@ pub unsafe fn on_frame(ui: &imgui::Ui, app_settings: &mut AppSettings) {
592594
SETTINGS.ally_name_text_color
593595
);
594596
}
595-
if ui.color_edit3(
597+
if ui.color_edit4(
596598
"Enemy name text color",
597599
&mut SETTINGS.enemy_name_text_color,
598600
) {
@@ -1115,17 +1117,42 @@ impl hudhook::ImguiRenderLoop for RenderLoop {
11151117
})
11161118
.unwrap();
11171119

1118-
let custom_font = ui.push_font(font_id);
1119-
background_draw_list.add_text(
1120-
[espleft, esptop - 40.0f32],
1121-
if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() {
1122-
SETTINGS.deref().ally_name_text_color
1123-
} else {
1124-
SETTINGS.deref().enemy_name_text_color
1125-
},
1126-
entity.name().unwrap(),
1127-
);
1128-
custom_font.pop();
1120+
1121+
unsafe {
1122+
let custom_font = ui.push_font(font_id);
1123+
// Get the entity name and create a CString
1124+
let text = entity.name().unwrap();
1125+
let c_text = CString::new(text).unwrap(); // Convert to C-compatible string
1126+
1127+
let font_handle = igGetFont();
1128+
1129+
// Get the pointer to the C string
1130+
let start: *const c_char = c_text.as_ptr(); // Use CString to ensure null termination
1131+
1132+
// The end pointer is not necessary when using CString, as you can pass the string slice
1133+
let end: *const c_char = start.add(c_text.as_bytes().len());
1134+
1135+
// Call the function
1136+
sys::ImDrawList_AddText_FontPtr(
1137+
sys::igGetBackgroundDrawList_Nil(),
1138+
font_handle,
1139+
SETTINGS.deref().name_text_thickness,
1140+
ImVec2::from([espleft, esptop - 80.0f32]),
1141+
if LOCAL_PLAYER.team().unwrap() == entity.team().unwrap() {
1142+
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()
1143+
} else {
1144+
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()
1145+
},
1146+
start,
1147+
end,
1148+
0.0f32,
1149+
std::ptr::null() // Assuming you don't want to specify a clipping rectangle
1150+
);
1151+
custom_font.pop();
1152+
}
1153+
1154+
1155+
11291156
}
11301157

11311158
if IS_AIMBOT.load(SeqCst) && IS_DRAW_FOV.load(SeqCst) {

src/utils.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,26 @@ pub unsafe fn setup_tracing() {
556556
.with(EnvFilter::from_default_env())
557557
.init();
558558
}
559+
pub fn float_array_to_u32(arr: [f32; 4]) -> u32 {
560+
assert!(arr.len() == 4); // Ensure the array has exactly 4 items
561+
562+
// Initialize a variable to hold the combined u32 value
563+
let mut combined: u32 = 0;
564+
565+
// Iterate through the array, clamp to 0-255, and combine into u32
566+
for (i, &value) in arr.iter().enumerate() {
567+
// Clamp the value to 0-255 and convert to u8
568+
let byte_value = value.clamp(0.0, 255.0) as u8;
569+
570+
// Combine the byte into the combined u32
571+
combined |= (byte_value as u32) << (8 * (3 - i)); // Shift left to the correct position
572+
}
573+
574+
combined
575+
}
576+
577+
pub fn f32_to_u8(value: f32) -> u8 {
578+
// Scale and clamp the value to the range [0, 255]
579+
let scaled = (value * 255.0).clamp(0.0, 255.0);
580+
scaled as u8
581+
}

0 commit comments

Comments
 (0)