Skip to content

Commit

Permalink
Solved #53 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fotonnn committed Oct 10, 2023
1 parent e31eaf3 commit 4429141
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 56 deletions.
37 changes: 18 additions & 19 deletions controller/src/enhancements/player.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const HEALTH_BAR_MAX_HEALTH: f32 = 100.0;

use std::{
ffi::CStr,
sync::Arc,
Expand Down Expand Up @@ -351,11 +353,16 @@ impl Enhancement for PlayerESP {
let bar_height = vmax.y - vmin.y; // height = box height
let bar_x = vmin.x - 5.0; // Left

let max_health = 100.0;
let player_health = entry.player_health;
let health_percentage = player_health as f32 / max_health as f32;
let player_health = entry.player_health as f32;
let clamped_player_health =
player_health.max(0.0).min(HEALTH_BAR_MAX_HEALTH);
let health_percentage =
clamped_player_health / HEALTH_BAR_MAX_HEALTH;
let filled_height = bar_height * health_percentage;
let width = settings.health_bar_width;
let border_bar_y = vmax.y;
let border_thickness = 1.0;
let border_color = [0.0, 0.0, 0.0, 1.0];

let bar_y = vmax.y - filled_height;

Expand All @@ -369,6 +376,10 @@ impl Enhancement for PlayerESP {
filled_height,
width,
rainbow_color,
border_thickness,
border_color,
bar_height,
border_bar_y,
)
} else {
let health_color =
Expand All @@ -380,24 +391,12 @@ impl Enhancement for PlayerESP {
filled_height,
width,
health_color,
border_thickness,
border_color,
bar_height,
border_bar_y,
)
}

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,
)
}
}
}
Expand Down
57 changes: 20 additions & 37 deletions controller/src/view/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,53 +190,36 @@ impl ViewController {
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)
.thickness(5.0)
.build();
}
}

pub fn draw_border(
&self,
draw: &imgui::DrawListMut,
bar_x: f32,
bar_y: f32,
bar_width: f32,
bar_height: f32,
health_color: [f32; 4],
border_thickness: f32,
border_color: [f32; 4],
bar_height: f32,
border_bar_y: f32,
) {
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],
//get fix edge
let border_bottom_y = border_bar_y - border_thickness;
let border_top_y = border_bottom_y - bar_height - border_thickness;

//border
draw.add_rect(
[bar_x - border_thickness, border_top_y],
[bar_x + bar_width + border_thickness, border_bottom_y],
border_color,
)
.thickness(border_thickness)
.build();

draw.add_rect_filled_multicolor(
[bar_x, bar_y],
[bar_x + bar_width, bar_y + filled_height],
health_color,
health_color,
health_color,
health_color,
);
}

// 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] {
let frequency = 0.1;
let r = (frequency * value).sin() * 127.0 + 128.0;
Expand Down

0 comments on commit 4429141

Please sign in to comment.