0% found this document useful (0 votes)
5 views8 pages

Message

The document contains C++ code for an ESP (Extra Sensory Perception) feature in a Roblox game, utilizing ImGui for rendering. It includes functions for calculating distances, drawing outlines, and displaying player information such as health, distance, and names on the screen. The code also manages visual settings like field of view and dead zones, enhancing player visibility and interaction within the game environment.

Uploaded by

davierhacks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Message

The document contains C++ code for an ESP (Extra Sensory Perception) feature in a Roblox game, utilizing ImGui for rendering. It includes functions for calculating distances, drawing outlines, and displaying player information such as health, distance, and names on the screen. The code also manages visual settings like field of view and dead zones, enhancing player visibility and interaction within the game environment.

Uploaded by

davierhacks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include "esp.

hpp"

#include "../../utils/overlay/imgui/imgui.h"
#include "../globals/globals.hpp"

#include <Windows.h>
#include <iomanip>
#include <cmath>

float calc_dist_3d(vercetti::roblox::vector3_t first, vercetti::roblox::vector3_t


sec)
{
return sqrtf((first.x - sec.x) * (first.x - sec.x) + (first.y - sec.y) *
(first.y - sec.y) + (first.z - sec.z) * (first.z - sec.z));
}

vercetti::roblox::vector3_t vector_sub(vercetti::roblox::vector3_t one,


vercetti::roblox::vector3_t two)
{
return { one.x - two.x, one.y - two.y, one.z - two.z };
}

float vector3_mag(vercetti::roblox::vector3_t vector)


{
return sqrtf((vector.x * vector.x) + (vector.y * vector.y) + (vector.z *
vector.z));
}

void DrawEsp(int X, int Y, int W, int H, ImColor Color) {


ImVec4 color = ImVec4(globals::box_color[0], globals::box_color[1],
globals::box_color[2], 1.0f);
ImU32 outlineColor = IM_COL32(0, 0, 0, 255);
float lineT = 1.0f;
float outlineThickness = 2.0f;

float lineW = (W / 5);


float lineH = (H / 6);

auto draw = ImGui::GetBackgroundDrawList();

if (globals::outline) {
draw->AddLine(ImVec2(X, Y), ImVec2(X, Y + lineH), outlineColor, lineT +
outlineThickness);
draw->AddLine(ImVec2(X, Y), ImVec2(X + lineW, Y), outlineColor, lineT +
outlineThickness);
draw->AddLine(ImVec2(X + W - lineW, Y), ImVec2(X + W, Y), outlineColor,
lineT + outlineThickness);
draw->AddLine(ImVec2(X + W, Y), ImVec2(X + W, Y + lineH), outlineColor,
lineT + outlineThickness);
draw->AddLine(ImVec2(X, Y + H - lineH), ImVec2(X, Y + H), outlineColor,
lineT + outlineThickness);
draw->AddLine(ImVec2(X, Y + H), ImVec2(X + lineW, Y + H), outlineColor,
lineT + outlineThickness);
draw->AddLine(ImVec2(X + W - lineW, Y + H), ImVec2(X + W, Y + H),
outlineColor, lineT + outlineThickness);
draw->AddLine(ImVec2(X + W, Y + H - lineH), ImVec2(X + W, Y + H),
outlineColor, lineT + outlineThickness);
}
draw->AddLine(ImVec2(X, Y), ImVec2(X, Y + lineH),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X, Y), ImVec2(X + lineW, Y),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X + W - lineW, Y), ImVec2(X + W, Y),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X + W, Y), ImVec2(X + W, Y + lineH),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X, Y + H - lineH), ImVec2(X, Y + H),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X, Y + H), ImVec2(X + lineW, Y + H),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X + W - lineW, Y + H), ImVec2(X + W, Y + H),
ImGui::ColorConvertFloat4ToU32(color), lineT);
draw->AddLine(ImVec2(X + W, Y + H - lineH), ImVec2(X + W, Y + H),
ImGui::ColorConvertFloat4ToU32(color), lineT);
}

void vercetti::roblox::hook_esp()
{
auto players = globals::players;
auto draw = ImGui::GetBackgroundDrawList();

POINT cursor_pos;
GetCursorPos(&cursor_pos);
ScreenToClient(FindWindowA(0, "Roblox"), &cursor_pos);

//silence::roblox::vector3_t camerapos =
globals::visualengine.get_camera_pos();

if (globals::fov_on)
{
ImColor fill_color(0, 0, 0, 51);
ImColor black_outline_color(0, 0, 0);

ImVec4 color = ImVec4(globals::fov_color[0], globals::fov_color[1],


globals::fov_color[2], 1.0f);

ImVec4 fovfill_color = ImVec4(globals::fov_fill_color[0],


globals::fov_fill_color[1], globals::fov_fill_color[2], 0.4f);

draw->AddCircle(ImVec2(cursor_pos.x, cursor_pos.y), globals::fov + 1.0f,


black_outline_color, 64, 1.0f);
draw->AddCircle(ImVec2(cursor_pos.x, cursor_pos.y), globals::fov,
ImGui::ColorConvertFloat4ToU32(color), 64, 1.0f);
draw->AddCircle(ImVec2(cursor_pos.x, cursor_pos.y), globals::fov - 1.0f,
black_outline_color, 64, 1.0f);
if (globals::fov_filled) {
draw->AddCircleFilled(ImVec2(cursor_pos.x, cursor_pos.y), globals::fov
- 1.5f, ImGui::ColorConvertFloat4ToU32(fovfill_color), 64);
}
}

if (globals::show_deadzone)
{
ImColor fill_color(0, 0, 0, 51);
ImColor black_outline_color(0, 0, 0);

ImVec4 color = ImVec4(globals::deadzone_color[0],


globals::deadzone_color[1], globals::deadzone_color[2], 1.0f);

ImVec4 deadzone_fill_color = ImVec4(globals::fov_fill_color[0],


globals::fov_fill_color[1], globals::fov_fill_color[2], 0.4f);

draw->AddCircle(ImVec2(cursor_pos.x, cursor_pos.y), globals::deadzone_value


+ 1.0f, black_outline_color, 64, 1.0f);
draw->AddCircle(ImVec2(cursor_pos.x, cursor_pos.y),
globals::deadzone_value, ImGui::ColorConvertFloat4ToU32(color), 64, 1.0f);
draw->AddCircle(ImVec2(cursor_pos.x, cursor_pos.y), globals::deadzone_value
- 1.0f, black_outline_color, 64, 1.0f);
if (globals::deadzone_fov_filled) {
draw->AddCircleFilled(ImVec2(cursor_pos.x, cursor_pos.y), globals::fov
- 1.5f, ImGui::ColorConvertFloat4ToU32(deadzone_fill_color), 64);
}
}

if (globals::esp)
{
auto dimensions = globals::visualengine.get_dimensions();
auto viewmatrix = globals::visualengine.get_view_matrix();
auto localplayer = players.get_local_player();
auto localplayerHead =
localplayer.get_model_instance().find_first_child("Head");

for (auto player : players.children())


{

if (player.self == localplayer.self && !globals::local_box)


continue;

// localplayer check
if (player.self == localplayer.self)
continue;

auto character = player.get_model_instance();


if (!character.self)
continue;

auto humanoid = character.find_first_child("Humanoid");


if (!humanoid.self)
continue;

auto head = character.find_first_child("Head");


if (!head.self)
continue;

if (humanoid.get_health() <= 4 && globals::knock_check)


{
continue;
}

auto head_position_3d = head.get_part_pos();

auto head_position =
vercetti::roblox::world_to_screen(vector_sub(head_position_3d, { 0, 2, 0 }),
dimensions, viewmatrix);
auto leg_pos =
vercetti::roblox::world_to_screen(vector_sub(head_position_3d, { 0, 5, 0 }),
dimensions, viewmatrix);

auto hrp_pos = humanoid.get_part_pos();


auto headPosY = static_cast<float>(hrp_pos.y + 2.5);
auto legPosY = static_cast<float>(hrp_pos.y - 3.5);
auto top =
vercetti::roblox::world_to_screen({ static_cast<float>(hrp_pos.x), headPosY,
static_cast<float>(hrp_pos.z) }, dimensions, viewmatrix);
auto bottom =
vercetti::roblox::world_to_screen({ static_cast<float>(hrp_pos.x), legPosY,
static_cast<float>(hrp_pos.z) }, dimensions, viewmatrix);

if (leg_pos.x == -1)
continue;

//float distance_from_camera = vector3_mag(vector_sub(camerapos,


head_position_3d));

float height = head_position.y - leg_pos.y;


float width = height / 1.6f;

// tracers -> line


if (globals::tracers)
{
ImVec4 color = ImVec4(globals::tracers_color[0],
globals::tracers_color[1], globals::tracers_color[2], 1.0f);
draw->AddLine(ImVec2(head_position.x, head_position.y),
ImVec2(static_cast<float>(cursor_pos.x), static_cast<float>(cursor_pos.y)),
ImGui::ColorConvertFloat4ToU32(color));
}

if (globals::distance_esp) {
// Calculate the position on screen for the head position
auto distance_position =
vercetti::roblox::world_to_screen(head_position_3d, dimensions, viewmatrix);

// Calculate the distance magnitude


float distanceMagnitude =
vector3_mag(vector_sub(localplayerHead.get_part_pos(), head_position_3d));
// Round the distance magnitude to two decimal places
distanceMagnitude = roundf(distanceMagnitude * 100) / 100;

// Convert the distance magnitude to a string without appending "m"


std::stringstream stream;
stream << std::fixed << std::setprecision(0) << distanceMagnitude;
std::string distanceStr = stream.str();

// Calculate the width of the text


float textWidth = ImGui::CalcTextSize(distanceStr.c_str()).x;
// Calculate the position of the text on the screen
ImVec2 distancePos = ImVec2(distance_position.x - (textWidth / 2),
distance_position.y - ImGui::GetTextLineHeight());

// Draw the text with shadows for better visibility


draw->AddText(ImVec2(distancePos.x, distancePos.y) + ImVec2(-1, -
1), ImColor(0, 0, 0), distanceStr.c_str());
draw->AddText(ImVec2(distancePos.x, distancePos.y) + ImVec2(1, -1),
ImColor(0, 0, 0), distanceStr.c_str());
draw->AddText(ImVec2(distancePos.x, distancePos.y) + ImVec2(-1, 1),
ImColor(0, 0, 0), distanceStr.c_str());
draw->AddText(ImVec2(distancePos.x, distancePos.y) + ImVec2(1, 1),
ImColor(0, 0, 0), distanceStr.c_str());
draw->AddText(ImVec2(distancePos.x, distancePos.y), ImColor(255,
255, 255), distanceStr.c_str());
}

if (globals::name_esp) {
// Calculate the position on screen for the head position
auto name_position =
vercetti::roblox::world_to_screen(vector_sub(head_position_3d, { -0.25, 5.3, 0 }),
dimensions, viewmatrix);

std::string playerName = player.name();


ImVec2 textSize = ImGui::CalcTextSize(playerName.c_str());

// Calculate text position to be at the top-center of the box


(above distance ESP)
ImVec2 textPos = ImVec2(name_position.x - (textSize.x / 2),
name_position.y);

// Draw the text with shadows for better visibility


draw->AddText(ImVec2(textPos.x, textPos.y) + ImVec2(-1, -1),
ImColor(0, 0, 0), playerName.c_str());
draw->AddText(ImVec2(textPos.x, textPos.y) + ImVec2(1, -1),
ImColor(0, 0, 0), playerName.c_str());
draw->AddText(ImVec2(textPos.x, textPos.y) + ImVec2(-1, 1),
ImColor(0, 0, 0), playerName.c_str());
draw->AddText(ImVec2(textPos.x, textPos.y) + ImVec2(1, 1),
ImColor(0, 0, 0), playerName.c_str());
draw->AddText(ImVec2(textPos.x, textPos.y), ImColor(255, 255, 255),
playerName.c_str());
}

if (globals::healthbar)
{
auto humanoid = character.find_first_child("Humanoid");

float health = humanoid.get_health();


int healthPercentage = static_cast<int>((health /
humanoid.get_max_health()) * 100);

ImVec2 barPos = ImVec2(leg_pos.x - (width / 1.20f), leg_pos.y);


ImVec2 barSize = ImVec2(3.5, height * 2);

draw->AddRectFilled(barPos, ImVec2(barPos.x + barSize.x, barPos.y +


barSize.y), ImColor(0, 0, 0, 150));

float healthBarHeight = (static_cast<float>(healthPercentage) /


100) * (barSize.y - 2);

ImVec2 gradientBarPos = barPos + ImVec2(1, 1);


ImVec2 gradientBarEndPos = ImVec2(barPos.x + barSize.x - 1,
barPos.y + healthBarHeight);
ImU32 colorStart = IM_COL32(0, 255, 0, 255);
ImU32 colorEnd = IM_COL32(255, 0, 0, 255);

draw->AddRectFilledMultiColor(gradientBarPos, gradientBarEndPos,
colorStart, colorStart, colorEnd, colorEnd);

// health info -> text


if (globals::healthinfo)
{
auto humanoid = character.find_first_child("Humanoid");
if (humanoid.self)
{
float health = humanoid.get_health();

ImVec4 healthColor;

if (health <= 20)


healthColor = ImVec4(0.9f, 0.1f, 0.1f, 1.0f); // Red
else if (health <= 50)
healthColor = ImVec4(0.9f, 0.5f, 0.1f, 1.0f); // Orange
else
healthColor = ImVec4(0.1f, 0.9f, 0.1f, 1.0f); // Green

std::string text =
std::to_string(static_cast<int>(health));

ImVec2 textSize = ImGui::CalcTextSize(text.c_str());


ImVec2 barPos = ImVec2(leg_pos.x - (width / 1.20f),
leg_pos.y);
ImVec2 textPos = ImVec2(barPos.x + barSize.x / 2 -
textSize.x / 2, barPos.y - textSize.y + 20);

// Draw the health information


draw->AddText(textPos, ImGui::GetColorU32(healthColor),
text.c_str());
}
}
}

if (globals::box)
{
ImVec4 color = ImVec4(globals::box_color[0], globals::box_color[1],
globals::box_color[2], 1.0f);

float outline_offset = 0.1f;

ImVec4 fill_color = ImVec4(globals::fill_color[0],


globals::fill_color[1], globals::fill_color[2], 0.3f);
ImColor black_outline_color(0, 0, 0);
ImColor white_outline_color(255, 255, 255);

switch (globals::boxtype)
{
case 0:
if (globals::filledbox) {
draw->AddRectFilled(ImVec2(leg_pos.x - (width / 1.3f) -
outline_offset, leg_pos.y - outline_offset), ImVec2(head_position.x + width +
outline_offset, head_position.y + height + outline_offset),
ImGui::ColorConvertFloat4ToU32(fill_color));
}
draw->AddRect(ImVec2(leg_pos.x - (width / 1.3f), leg_pos.y),
ImVec2(head_position.x + width, head_position.y + height),
ImGui::ColorConvertFloat4ToU32(color));
if (globals::outline) {
draw->AddRect(ImVec2(leg_pos.x - (width / 1.3f) -
outline_offset - 1.5, leg_pos.y - outline_offset - 1.5), ImVec2(head_position.x +
width + outline_offset + 1.5, head_position.y + height + outline_offset + 1.5),
black_outline_color);
draw->AddRect(ImVec2(leg_pos.x - (width / 1.3f) -
outline_offset + 1.5, leg_pos.y - outline_offset + 1.5), ImVec2(head_position.x +
width + outline_offset - 1.5, head_position.y + height + outline_offset - 1.5),
black_outline_color);
}
if (globals::rainbowbox) {
float rainbow_width = (head_position.x + width +
outline_offset) - (leg_pos.x - (width / 1.3f) - outline_offset);
float rainbow_height = (head_position.y + height +
outline_offset) - (leg_pos.y - outline_offset);

ImU32 col_top_left = IM_COL32(231, 0, 0, 80);


ImU32 col_top_right = IM_COL32(255, 241, 0, 80);
ImU32 col_bottom_right = IM_COL32(0, 129, 31, 80);
ImU32 col_bottom_left = IM_COL32(0, 70, 173, 80);

draw->AddRectFilledMultiColor(
ImVec2(leg_pos.x - (width / 1.3f) - outline_offset,
leg_pos.y - outline_offset),
ImVec2(leg_pos.x - (width / 1.3f) - outline_offset +
rainbow_width, leg_pos.y - outline_offset + rainbow_height),
col_top_left,
col_top_right,
col_bottom_right,
col_bottom_left
);
}
break;
case 1:
if (globals::filledbox) {
draw->AddRectFilled(ImVec2(leg_pos.x - (width / 1.3f) -
outline_offset, leg_pos.y - outline_offset), ImVec2(head_position.x + width +
outline_offset, head_position.y + height + outline_offset),
ImGui::ColorConvertFloat4ToU32(fill_color));
}

if (globals::rainbowbox) {
float rainbow_width = (head_position.x + width +
outline_offset) - (leg_pos.x - (width / 1.3f) - outline_offset);
float rainbow_height = (head_position.y + height +
outline_offset) - (leg_pos.y - outline_offset);

ImU32 col_top_left = IM_COL32(231, 0, 0, 80);


ImU32 col_top_right = IM_COL32(255, 241, 0, 80);
ImU32 col_bottom_right = IM_COL32(0, 129, 31, 80);
ImU32 col_bottom_left = IM_COL32(0, 70, 173, 80);

draw->AddRectFilledMultiColor(
ImVec2(leg_pos.x - (width / 1.3f) - outline_offset,
leg_pos.y - outline_offset),
ImVec2(leg_pos.x - (width / 1.3f) - outline_offset +
rainbow_width, leg_pos.y - outline_offset + rainbow_height),
col_top_left,
col_top_right,
col_bottom_right,
col_bottom_left
);
}

DrawEsp(leg_pos.x - (width / 1.3f), leg_pos.y, head_position.x


+ width - leg_pos.x + (width / 1.3f), head_position.y + height - leg_pos.y,
ImGui::ColorConvertFloat4ToU32(color));
break;

}
}

}
}
}

You might also like