I’m trying to use DirectX EndScene to draw BoxChams.
I have 2 issues.
1. They are unproportional as fuck
2. They lag all over the place
class CESPMath
{
public:
bool ScreenTransform(const Vector& point, Vector& screen);
bool WorldToScreen(const Vector& origin, Vector& screen);
}; extern std::unique_ptr g_pESPMath;
std::unique_ptr g_pESPMath = std::make_unique();
bool CESPMath::ScreenTransform(const Vector& point, Vector& screen) // tots not pasted
{
float w;
const VMatrix& worldToScreen = g_EngineClient->WorldToScreenMatrix();
screen.x = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3];
screen.y = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3];
w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];
screen.z = 0.0f;
bool behind = false;
if (w < 0.001f)
{
behind = true;
screen.x *= 100000;
screen.y *= 100000;
}
else
{
behind = false;
float invw = 1.0f / w;
screen.x *= invw;
screen.y *= invw;
}
return behind;
}
bool CESPMath::WorldToScreen(const Vector& origin, Vector& screen)
{
if (!ScreenTransform(origin, screen))
{
int ScreenWidth, ScreenHeight;
g_EngineClient->GetScreenSize(ScreenWidth, ScreenHeight);
float x = ScreenWidth / 2;
float y = ScreenHeight / 2;
x += 0.5 * screen.x * ScreenWidth + 0.5;
y -= 0.5 * screen.y * ScreenHeight + 0.5;
screen.x = x;
screen.y = y;
return true;
}
return false;
}
class CESP
{
public:
int originalfov = 90;
int zoomedfov = 90;
bool scoped = false;
bool inited = false;
bool overridesafe = false;
void ScopeIn(CViewSetup* view);
void ThirdPerson();
void DrawGlow();
void PlayerESP(int index);
bool EntityIsInvalid(C_BaseEntity* Entity);
void PlayerBox(float x, float y, float w, float h, Color clr);
void HealthBar(Vector bot, Vector top, float health);
};
extern std::unique_ptr g_pESP;
std::unique_ptr g_pESP = std::make_unique();
bool CESP::EntityIsInvalid(C_BaseEntity* Entity)
{
if (!Entity)
return true;
auto pEntity = (C_BasePlayer*)Entity;
if (!pEntity)
return true;
if (Entity == g_LocalPlayer)
return true;
if (pEntity->m_iHealth() <= 0)
return true;
if (Entity->IsDormant())
return true;
return false;
}
void CESP::PlayerESP(int index)
{
C_BasePlayer* Entity = (C_BasePlayer*)g_EntityList->GetClientEntity(index);
if (!Entity)
return;
//if (Entity && Vars.Visuals.Info.Name)
if (Entity->GetClientClass()->m_ClassID == 85)
{
if (Entity->IsDormant())
return;
Vector Origin, Screen;
Origin = Entity->m_vecOrigin() + Vector(0, 0, Entity->GetCollideable()->OBBMaxs().z);
if (g_pESPMath->WorldToScreen(Origin, Screen))
g_pDraw->String(Screen.x, Screen.y, FONT_CENTER, g_pDraw->fonts.calibri,true,GREEN(255), charenc("Hostage"));
return;
}
if (EntityIsInvalid(Entity))
return;
if (1 == 1 && !Entity->IsEnemy()) //!Vars.Visuals.Filter.Friendlies
return;
//if (!Vars.Visuals.Filter.Enemies && Entity->IsEnemy())
// return;
//if (Vars.Visuals.Dlights)
//{
// dlight_t* dLight = g_pEffects->CL_AllocDlight(Entity->EntIndex());
// dLight->die = g_GlobalVars->curtime + 0.05f;
// dLight->radius = 200.f;
// if (Entity->IsEnemy())
// {
// dLight->color.r = 200;
// dLight->color.g = 200;
// dLight->color.b = 60;
// }
// else
// {
// dLight->color.r = 2;
// dLight->color.g = 48;
// dLight->color.b = 22;
// }
// dLight->color.exponent = 5;
// dLight->key = Entity->EntIndex();
// dLight->decay = dLight->radius / 5.0f;
// dLight->origin = Entity->m_vecOrigin() + Vector(0, 0, 2);
//}
Vector max = Entity->GetCollideable()->OBBMaxs();
Vector pos, pos3D;
Vector top, top3D;
pos3D = Entity->m_vecOrigin();
top3D = pos3D + Vector(0, 0, max.z);
if (!g_pESPMath->WorldToScreen(pos3D, pos) || !g_pESPMath->WorldToScreen(top3D, top))
return;
float height = (pos.y - top.y);
float width = height / 4.f;
//if (Vars.Visuals.Skeleton)
// Skeleton(Entity, Color::White());
if (Utils::CanSeePlayer(Entity))
PlayerBox(top.x, top.y, width, height, Entity->IsEnemy() ? Color(200, 60, 60) : Color(84, 167, 255));
else if (!Utils::CanSeePlayer(Entity))
PlayerBox(top.x, top.y, width, height, Entity->IsEnemy() ? Color(232, 209, 32) : Color(72, 219, 75));
//if (Vars.Visuals.Info.Name)
g_pDraw->String(top.x, top.y, FONT_CENTER, g_pDraw->fonts.calibri, true, WHITE(255), Entity->GetPlayerInfo().szName);
//if (Vars.Visuals.Info.Health)
HealthBar(pos, top, Entity->m_iHealth());
// if (Vars.Visuals.BulletTrace)
// BulletTrace(Entity, Color(200, 50, 50, 150));
// int bottom = 0;
//if (Vars.Visuals.Info.Weapon)
// D::DrawString(F::ESP, top.x, top.y + height + 8 + (10 * bottom++), Color::White(), FONT_CENTER, "%s", Entity->GetWeapon()->GetWeaponName().c_str());
//
//if (Vars.Visuals.Info.Flashed && Entity->IsFlashed())
// D::DrawString(F::ESP, top.x, top.y + height + 8 + (10 * bottom++), Color::Red(), FONT_CENTER, charenc("FLASHED"));
}
void CESP::PlayerBox(float x, float y, float w, float h, Color clr)
{
g_pDraw->BorderedBoxOutlined(x - w, y, (x + w)/3, (y + h)/3, RED(255), RED(255));
g_pDraw->BorderedBoxOutlined(x - w - 1, y - 1, (x + w + 1)/3, (y + h + 1)/3, RED(255),RED(255));
g_pDraw->BorderedBoxOutlined(x - w + 1, y + 1, (x + w - 1)/3, (y + h - 1)/3, RED(255), RED(255));
}
void CESP::HealthBar(Vector bot, Vector top, float health)
{
float h = (bot.y - top.y);
float offset = (h / 4.f) + 5;
float w = h / 64.f;
UINT hp = h - (UINT)((h * health) / 100); // Percentage
int Red = 255 - (health * 2.55);
int Green = health * 2.55;