Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health Bar #53

Merged
merged 18 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions controller/src/enhancements/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,59 @@ impl Enhancement for PlayerESP {
draw.add_rect([vmin.x, vmin.y], [vmax.x, vmax.y], *esp_color)
.thickness(settings.esp_boxes_thickness)
.build();

if settings.esp_health_bar {
let bar_height = vmax.y - vmin.y; // height = box height
let bar_x = vmin.x - 5.0; // Left

let max_health = 100.0;
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
let player_health = entry.player_health;
let health_percentage = player_health as f32 / max_health as f32;
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
let filled_height = bar_height * health_percentage;
let width = settings.health_bar_width;

let bar_y = vmax.y - filled_height;

if settings.rainbow_health_bar {
let rainbow_color =
view.calculate_rainbow_color(player_health as f32);
view.draw_health_bar(
&draw,
bar_x,
bar_y,
filled_height,
width,
rainbow_color,
)
} else {
let health_color =
view.calculate_health_color(health_percentage);
view.draw_health_bar(
&draw,
bar_x,
bar_y,
filled_height,
width,
health_color,
)
}

let bar_x = vmin.x - 5.0;
let bar_y = vmax.y;
let bar_width = width;
let border_thickness = 1.0;
let border_color = [0.0, 0.0, 0.0, 1.0];

view.draw_border(
&draw,
bar_x,
bar_y,
bar_width,
bar_height,
border_thickness,
border_color,
)
}
}
}
EspBoxType::Box3D => {
Expand Down
13 changes: 12 additions & 1 deletion controller/src/settings/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ fn default_esp_skeleton_thickness() -> f32 {
fn default_esp_boxes_thickness() -> f32 {
3.0
}

fn default_health_bar_width() -> f32 {
3.5
}
fn default_u32<const V: u32>() -> u32 {
V
}
Expand Down Expand Up @@ -90,6 +92,15 @@ pub struct AppSettings {
#[serde(default = "bool_false")]
pub esp_info_health: bool,

#[serde(default = "bool_false")]
pub esp_health_bar: bool,

#[serde(default = "default_health_bar_width")]
pub health_bar_width: f32,
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved

#[serde(default = "bool_false")]
pub rainbow_health_bar: bool,

#[serde(default = "bool_false")]
pub esp_info_weapon: bool,

Expand Down
9 changes: 9 additions & 0 deletions controller/src/settings/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ impl SettingsUI {
ui.slider_config(obfstr!("Thickness"), 0.1, 10.0)
.build(&mut settings.esp_boxes_thickness);
}
if settings.esp_box_type == EspBoxType::Box2D {
ui.checkbox(obfstr!("2DBOX: Show Health Bar"), &mut settings.esp_health_bar);
if settings.esp_health_bar {
ui.same_line();
ui.slider_config(obfstr!("Width"), 3.0, 10.0)
.build(&mut settings.health_bar_width);
ui.checkbox(obfstr!("Rainbow Health Bar (Random colors!)"), &mut settings.rainbow_health_bar);
}
}

ui.checkbox(obfstr!("ESP Skeletons"), &mut settings.esp_skeleton);
if settings.esp_skeleton {
Expand Down
77 changes: 77 additions & 0 deletions controller/src/view/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl ViewController {

let mut min2d = Vec2::new(f32::MAX, f32::MAX);
let mut max2d = Vec2::new(-f32::MAX, -f32::MAX);

for point in points {
if let Some(point) = self.world_to_screen(&point, true) {
min2d.x = min2d.x.min(point.x);
Expand Down Expand Up @@ -182,4 +183,80 @@ impl ViewController {
}
}
}

pub fn draw_health_bar(
&self,
draw: &imgui::DrawListMut,
bar_x: f32,
bar_y: f32,
filled_height: f32,
width: f32,
health_color: [f32; 4],
) {
for i in 0..filled_height as i32 {
let y1 = bar_y + i as f32;
let y2 = y1 + 1.0;
let x1 = bar_x;
let x2 = bar_x + width; //width
draw.add_line([x1, y1], [x2, y2], health_color)
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
.thickness(5.0)
.build();
}
}

pub fn draw_border(
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
&self,
draw: &imgui::DrawListMut,
bar_x: f32,
bar_y: f32,
bar_width: f32,
bar_height: f32,
border_thickness: f32,
border_color: [f32; 4],
) {
draw.add_line([bar_x, bar_y], [bar_x + bar_width, bar_y], border_color)
.thickness(border_thickness)
.build();
draw.add_line([bar_x, bar_y], [bar_x, bar_y - bar_height], border_color)
.thickness(border_thickness)
.build();
draw.add_line(
[bar_x + bar_width, bar_y],
[bar_x + bar_width, bar_y - bar_height],
border_color,
)
.thickness(border_thickness)
.build();
draw.add_line(
[bar_x, bar_y - bar_height],
[bar_x + bar_width, bar_y - bar_height],
border_color,
)
.thickness(border_thickness)
.build();
}

// Thanks to https://www.unknowncheats.me/forum/d3d-tutorials-and-source/208799-esp-rainbow-healthbar.html
pub fn calculate_rainbow_color(&self, value: f32) -> [f32; 4] {
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
let frequency = 0.1;
let r = (frequency * value).sin() * 127.0 + 128.0;
let g = (frequency * value + 2.0 * std::f32::consts::PI / 3.0).sin() * 127.0 + 128.0;
let b = (frequency * value + 4.0 * std::f32::consts::PI / 3.0).sin() * 127.0 + 128.0;
[r / 255.0, g / 255.0, b / 255.0, 1.0]
}

pub fn calculate_health_color(&self, health_percentage: f32) -> [f32; 4] {
if health_percentage > 0.6 {
[
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
2.0 - 2.0 * health_percentage,
2.0 * health_percentage,
0.0,
1.0,
]
} else if health_percentage > 0.3 {
[1.0, 1.0, 2.0 - 2.0 * health_percentage, 1.0]
Fotonnn marked this conversation as resolved.
Show resolved Hide resolved
} else {
[1.0, 2.0 * health_percentage, 0.0, 1.0]
}
}
}