Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Вопрос C++ + Jni ESP

  • Автор темы Автор темы SaNeDs
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
2 Май 2024
Сообщения
124
Реакции
2
Кароче вот пишу есп и не понимаю вроде все нормально,но есп рендериться не на ентети а где то впизде иногда не далеко вмещен а иногда прям в ряльной пизде

ESP.cpp:
Expand Collapse Copy
#include "esp.h"
#include "../../OverrideClient.h"
#include "../../globals/globals.h"
#include "../../gui/GUI.h"
#include <sdk/minecraft/entity/entity.h>
#include <sdk/minecraft/minecraft.h>
#include <sdk/minecraft/util/box.h>
#include <sdk/minecraft/world/world.h>
#include <sdk/classloader.h>
#include <sdk/mappings/mappings.hpp>
#include <OverrideClient/utils/logger.h>
#define NOMINMAX
#include <algorithm>
#include <cmath>
#include <mutex>
#include <vector>

using namespace OverrideClient::modules;

namespace
{
    constexpr float kPi = 3.1415926535f;
    
    struct ent_snap {
        std::string name;
        double minX, minY, minZ;
        double maxX, maxY, maxZ;
        float hp;
        bool is_player;
    };

    struct esp_snap {
        std::vector<ent_snap> entities;
        bool ready = false;
    } g_snap;

    std::mutex g_mutex;

    bool manual_w2s(float dx, float dy, float dz, ImVec2& s, float yaw, float pitch, float fov, const ImVec2& ds)
    {
        float radYaw = (yaw + 180.0f) * (kPi / 180.0f);
        float radPitch = -pitch * (kPi / 180.0f);

        float cosY = cosf(radYaw), sinY = sinf(radYaw);
        float cosP = cosf(radPitch), sinP = sinf(radPitch);

        // Standard W2S transform
        float x1 = dx * cosY - dz * sinY;
        float z1 = dx * sinY + dz * cosY;
        float y1 = dy * cosP - z1 * sinP;
        float viewZ = dy * sinP + z1 * cosP;

        if (viewZ <= 0.1f) return false;

        float aspect = ds.x / ds.y;
        float fovRad = fov * (kPi / 180.0f);
        float tanHalfFov = tanf(fovRad / 2.0f);

        s.x = (ds.x * 0.5f) * (1.0f + (x1 / (viewZ * tanHalfFov * aspect)));
        s.y = (ds.y * 0.5f) * (1.0f - (y1 / (viewZ * tanHalfFov)));

        return true;
    }
}

void esp::run()
{
    if (!globals::box_enabled) return;
    auto env = OverrideClient::instance ? OverrideClient::instance->get_env() : nullptr;
    if (!env) return;
    if (env->PushLocalFrame(128) < 0) return;

    jobject world = sdk::instance->get_world();
    jobject lp = sdk::instance->get_player();
    if (!world || !lp) { env->PopLocalFrame(nullptr); return; }

    sdk::world_client wc(world);
    std::vector<jobject> players = wc.get_players();
    
    esp_snap next;
    jclass living_cls = sdk::classloader::find_class(env, sdk::mappings::living_entity_class_sig);
    jmethodID get_hp = living_cls ? env->GetMethodID(living_cls, sdk::mappings::living_entity_get_health_name, sdk::mappings::living_entity_get_health_sig) : nullptr;
    if (env->ExceptionCheck()) env->ExceptionClear();
    jclass player_cls = sdk::classloader::find_class(env, sdk::mappings::player_entity_class_sig);
    if (env->ExceptionCheck()) env->ExceptionClear();

    for (jobject p : players) {
        if (!p || env->IsSameObject(p, lp)) { if (p) env->DeleteLocalRef(p); continue; }
        
        sdk::entity_client ent(p);
        jobject box_obj = ent.get_bounding_box();
        if (!box_obj) { env->DeleteLocalRef(p); continue; }
        
        sdk::box_client bbox(box_obj);
        ent_snap d;
        d.name = ent.get_name_string();
        d.minX = bbox.get_min_x(); d.minY = bbox.get_min_y(); d.minZ = bbox.get_min_z();
        d.maxX = bbox.get_max_x(); d.maxY = bbox.get_max_y(); d.maxZ = bbox.get_max_z();
        d.is_player = player_cls ? env->IsInstanceOf(p, player_cls) : false;
        if (env->ExceptionCheck()) env->ExceptionClear();
        if (living_cls && env->IsInstanceOf(p, living_cls)) {
            d.hp = get_hp ? env->CallFloatMethod(p, get_hp) : 20.0f;
            if (env->ExceptionCheck()) env->ExceptionClear();
        } else { d.hp = 20.0f; }

        next.entities.push_back(std::move(d));
        env->DeleteLocalRef(box_obj); env->DeleteLocalRef(p);
    }
    next.ready = true;
    { std::lock_guard<std::mutex> lock(g_mutex); g_snap = std::move(next); }
    if (player_cls) env->DeleteLocalRef(player_cls);
    if (living_cls) env->DeleteLocalRef(living_cls);
    env->DeleteLocalRef(world); env->DeleteLocalRef(lp);
    env->PopLocalFrame(nullptr);
}

void esp::draw_boxes()
{
    if (!globals::box_enabled) return;

    sdk::camera_data cam = sdk::instance->get_camera();
    if (!cam.valid) return;

    esp_snap s;
    {
        std::lock_guard<std::mutex> lock(g_mutex);
        if (!g_snap.ready || g_snap.entities.empty()) return;
        s = g_snap;
    }

    ImDrawList* dl = ImGui::GetForegroundDrawList();
    const ImVec2 ds = ImGui::GetIO().DisplaySize;

    for (const auto& p : s.entities) {
        double expand = globals::hitbox_enabled ? globals::hitbox_expand_width : 0.0;
        
        float rminX = (float)(p.minX - expand - cam.x); float rminY = (float)(p.minY - cam.y); float rminZ = (float)(p.minZ - expand - cam.z);
        float rmaxX = (float)(p.maxX + expand - cam.x); float rmaxY = (float)(p.maxY + expand*2.0 - cam.y); float rmaxZ = (float)(p.maxZ + expand - cam.z);

        float cx[8] = {rminX, rmaxX, rmaxX, rminX, rminX, rmaxX, rmaxX, rminX};
        float cy[8] = {rminY, rminY, rminY, rminY, rmaxY, rmaxY, rmaxY, rmaxY};
        float cz[8] = {rminZ, rminZ, rmaxZ, rmaxZ, rminZ, rminZ, rmaxZ, rmaxZ};

        ImVec2 scr[8];
        bool any_v = false;
        float msx = ds.x, msy = ds.y, mxx = -1.0f, mxy = -1.0f;

        for (int j = 0; j < 8; j++) {
            if (manual_w2s(cx[j], cy[j], cz[j], scr[j], cam.yaw, cam.pitch, cam.fov, ds)) {
                msx = (std::min)(msx, scr[j].x); msy = (std::min)(msy, scr[j].y);
                mxx = (std::max)(mxx, scr[j].x); mxy = (std::max)(mxy, scr[j].y);
                any_v = true;
            }
        }
        
        if (!any_v) continue;

        // Constraint box to screen
        msx = std::clamp(msx, -500.0f, ds.x + 500.0f);
        mxx = std::clamp(mxx, -500.0f, ds.x + 500.0f);
        msy = std::clamp(msy, -500.0f, ds.y + 500.0f);
        mxy = std::clamp(mxy, -500.0f, ds.y + 500.0f);

        ImU32 box_color = p.is_player ? IM_COL32(0, 255, 0, 255) : IM_COL32(255, 255, 0, 255);
        dl->AddRect({msx, msy}, {mxx, mxy}, box_color, 0.0f, 0, 1.5f);

        float hpf = std::clamp(p.hp / 20.0f, 0.0f, 1.0f);
        float bar_h = (mxy - msy) * hpf;
        dl->AddRectFilled({msx - 5, mxy - bar_h}, {msx - 2, mxy}, IM_COL32((int)(255 * (1 - hpf)), (int)(255 * hpf), 0, 255));

        ImVec2 tsz = ImGui::CalcTextSize(p.name.c_str());
        dl->AddText({(msx + mxx) * 0.5f - tsz.x * 0.5f, msy - tsz.y - 2}, IM_COL32(255, 255, 255, 255), p.name.c_str());
    }
}

void esp::shutdown() { std::lock_guard<std::mutex> lock(g_mutex); g_snap.ready = false; g_snap.entities.clear(); }







1773877207571.png
 
Кароче вот пишу есп и не понимаю вроде все нормально,но есп рендериться не на ентети а где то впизде иногда не далеко вмещен а иногда прям в ряльной пизде

ESP.cpp:
Expand Collapse Copy
#include "esp.h"
#include "../../OverrideClient.h"
#include "../../globals/globals.h"
#include "../../gui/GUI.h"
#include <sdk/minecraft/entity/entity.h>
#include <sdk/minecraft/minecraft.h>
#include <sdk/minecraft/util/box.h>
#include <sdk/minecraft/world/world.h>
#include <sdk/classloader.h>
#include <sdk/mappings/mappings.hpp>
#include <OverrideClient/utils/logger.h>
#define NOMINMAX
#include <algorithm>
#include <cmath>
#include <mutex>
#include <vector>

using namespace OverrideClient::modules;

namespace
{
    constexpr float kPi = 3.1415926535f;
   
    struct ent_snap {
        std::string name;
        double minX, minY, minZ;
        double maxX, maxY, maxZ;
        float hp;
        bool is_player;
    };

    struct esp_snap {
        std::vector<ent_snap> entities;
        bool ready = false;
    } g_snap;

    std::mutex g_mutex;

    bool manual_w2s(float dx, float dy, float dz, ImVec2& s, float yaw, float pitch, float fov, const ImVec2& ds)
    {
        float radYaw = (yaw + 180.0f) * (kPi / 180.0f);
        float radPitch = -pitch * (kPi / 180.0f);

        float cosY = cosf(radYaw), sinY = sinf(radYaw);
        float cosP = cosf(radPitch), sinP = sinf(radPitch);

        // Standard W2S transform
        float x1 = dx * cosY - dz * sinY;
        float z1 = dx * sinY + dz * cosY;
        float y1 = dy * cosP - z1 * sinP;
        float viewZ = dy * sinP + z1 * cosP;

        if (viewZ <= 0.1f) return false;

        float aspect = ds.x / ds.y;
        float fovRad = fov * (kPi / 180.0f);
        float tanHalfFov = tanf(fovRad / 2.0f);

        s.x = (ds.x * 0.5f) * (1.0f + (x1 / (viewZ * tanHalfFov * aspect)));
        s.y = (ds.y * 0.5f) * (1.0f - (y1 / (viewZ * tanHalfFov)));

        return true;
    }
}

void esp::run()
{
    if (!globals::box_enabled) return;
    auto env = OverrideClient::instance ? OverrideClient::instance->get_env() : nullptr;
    if (!env) return;
    if (env->PushLocalFrame(128) < 0) return;

    jobject world = sdk::instance->get_world();
    jobject lp = sdk::instance->get_player();
    if (!world || !lp) { env->PopLocalFrame(nullptr); return; }

    sdk::world_client wc(world);
    std::vector<jobject> players = wc.get_players();
   
    esp_snap next;
    jclass living_cls = sdk::classloader::find_class(env, sdk::mappings::living_entity_class_sig);
    jmethodID get_hp = living_cls ? env->GetMethodID(living_cls, sdk::mappings::living_entity_get_health_name, sdk::mappings::living_entity_get_health_sig) : nullptr;
    if (env->ExceptionCheck()) env->ExceptionClear();
    jclass player_cls = sdk::classloader::find_class(env, sdk::mappings::player_entity_class_sig);
    if (env->ExceptionCheck()) env->ExceptionClear();

    for (jobject p : players) {
        if (!p || env->IsSameObject(p, lp)) { if (p) env->DeleteLocalRef(p); continue; }
       
        sdk::entity_client ent(p);
        jobject box_obj = ent.get_bounding_box();
        if (!box_obj) { env->DeleteLocalRef(p); continue; }
       
        sdk::box_client bbox(box_obj);
        ent_snap d;
        d.name = ent.get_name_string();
        d.minX = bbox.get_min_x(); d.minY = bbox.get_min_y(); d.minZ = bbox.get_min_z();
        d.maxX = bbox.get_max_x(); d.maxY = bbox.get_max_y(); d.maxZ = bbox.get_max_z();
        d.is_player = player_cls ? env->IsInstanceOf(p, player_cls) : false;
        if (env->ExceptionCheck()) env->ExceptionClear();
        if (living_cls && env->IsInstanceOf(p, living_cls)) {
            d.hp = get_hp ? env->CallFloatMethod(p, get_hp) : 20.0f;
            if (env->ExceptionCheck()) env->ExceptionClear();
        } else { d.hp = 20.0f; }

        next.entities.push_back(std::move(d));
        env->DeleteLocalRef(box_obj); env->DeleteLocalRef(p);
    }
    next.ready = true;
    { std::lock_guard<std::mutex> lock(g_mutex); g_snap = std::move(next); }
    if (player_cls) env->DeleteLocalRef(player_cls);
    if (living_cls) env->DeleteLocalRef(living_cls);
    env->DeleteLocalRef(world); env->DeleteLocalRef(lp);
    env->PopLocalFrame(nullptr);
}

void esp::draw_boxes()
{
    if (!globals::box_enabled) return;

    sdk::camera_data cam = sdk::instance->get_camera();
    if (!cam.valid) return;

    esp_snap s;
    {
        std::lock_guard<std::mutex> lock(g_mutex);
        if (!g_snap.ready || g_snap.entities.empty()) return;
        s = g_snap;
    }

    ImDrawList* dl = ImGui::GetForegroundDrawList();
    const ImVec2 ds = ImGui::GetIO().DisplaySize;

    for (const auto& p : s.entities) {
        double expand = globals::hitbox_enabled ? globals::hitbox_expand_width : 0.0;
       
        float rminX = (float)(p.minX - expand - cam.x); float rminY = (float)(p.minY - cam.y); float rminZ = (float)(p.minZ - expand - cam.z);
        float rmaxX = (float)(p.maxX + expand - cam.x); float rmaxY = (float)(p.maxY + expand*2.0 - cam.y); float rmaxZ = (float)(p.maxZ + expand - cam.z);

        float cx[8] = {rminX, rmaxX, rmaxX, rminX, rminX, rmaxX, rmaxX, rminX};
        float cy[8] = {rminY, rminY, rminY, rminY, rmaxY, rmaxY, rmaxY, rmaxY};
        float cz[8] = {rminZ, rminZ, rmaxZ, rmaxZ, rminZ, rminZ, rmaxZ, rmaxZ};

        ImVec2 scr[8];
        bool any_v = false;
        float msx = ds.x, msy = ds.y, mxx = -1.0f, mxy = -1.0f;

        for (int j = 0; j < 8; j++) {
            if (manual_w2s(cx[j], cy[j], cz[j], scr[j], cam.yaw, cam.pitch, cam.fov, ds)) {
                msx = (std::min)(msx, scr[j].x); msy = (std::min)(msy, scr[j].y);
                mxx = (std::max)(mxx, scr[j].x); mxy = (std::max)(mxy, scr[j].y);
                any_v = true;
            }
        }
       
        if (!any_v) continue;

        // Constraint box to screen
        msx = std::clamp(msx, -500.0f, ds.x + 500.0f);
        mxx = std::clamp(mxx, -500.0f, ds.x + 500.0f);
        msy = std::clamp(msy, -500.0f, ds.y + 500.0f);
        mxy = std::clamp(mxy, -500.0f, ds.y + 500.0f);

        ImU32 box_color = p.is_player ? IM_COL32(0, 255, 0, 255) : IM_COL32(255, 255, 0, 255);
        dl->AddRect({msx, msy}, {mxx, mxy}, box_color, 0.0f, 0, 1.5f);

        float hpf = std::clamp(p.hp / 20.0f, 0.0f, 1.0f);
        float bar_h = (mxy - msy) * hpf;
        dl->AddRectFilled({msx - 5, mxy - bar_h}, {msx - 2, mxy}, IM_COL32((int)(255 * (1 - hpf)), (int)(255 * hpf), 0, 255));

        ImVec2 tsz = ImGui::CalcTextSize(p.name.c_str());
        dl->AddText({(msx + mxx) * 0.5f - tsz.x * 0.5f, msy - tsz.y - 2}, IM_COL32(255, 255, 255, 255), p.name.c_str());
    }
}

void esp::shutdown() { std::lock_guard<std::mutex> lock(g_mutex); g_snap.ready = false; g_snap.entities.clear(); }







Посмотреть вложение 330750
гл матрицу возьми для перевода в 2д кординаты
 
я вообще не ебу в с++ но возьми с enhance если нужно могу скинуть
вот тебе


struct Vec3 { float x, y, z; };

bool WorldToScreen(const Vec3& world, const GLfloat modelview[16],
const GLfloat projection[16], const GLint viewport[4],
GLfloat& screenX, GLfloat& screenY, GLfloat& screenZ) {

GLfloat eyeX = modelview[0]*world.x + modelview[4]*world.y + modelview[8]*world.z + modelview[12];
GLfloat eyeY = modelview[1]*world.x + modelview[5]*world.y + modelview[9]*world.z + modelview[13];
GLfloat eyeZ = modelview[2]*world.x + modelview[6]*world.y + modelview[10]*world.z + modelview[14];
GLfloat eyeW = modelview[3]*world.x + modelview[7]*world.y + modelview[11]*world.z + modelview[15];

GLfloat clipX = projection[0]*eyeX + projection[4]*eyeY + projection[8]*eyeZ + projection[12]*eyeW;
GLfloat clipY = projection[1]*eyeX + projection[5]*eyeY + projection[9]*eyeZ + projection[13]*eyeW;
GLfloat clipZ = projection[2]*eyeX + projection[6]*eyeY + projection[10]*eyeZ + projection[14]*eyeW;
GLfloat clipW = projection[3]*eyeX + projection[7]*eyeY + projection[11]*eyeZ + projection[15]*eyeW;

if (clipW == 0.0f) return false;


GLfloat ndcX = clipX / clipW;
GLfloat ndcY = clipY / clipW;
GLfloat ndcZ = clipZ / clipW;
screenX = (viewport[2] * (ndcX + 1.0f) / 2.0f) + viewport[0];
screenY = (viewport[3] * (ndcY + 1.0f) / 2.0f) + viewport[1];
screenZ = (ndcZ + 1.0f) / 2.0f;

return true;
}
 
с++:
Expand Collapse Copy
#include "esp.h"
#include "../../OverrideClient.h"
#include "../../globals/globals.h"
#include "../../gui/GUI.h"
#include <sdk/minecraft/entity/entity.h>
#include <sdk/minecraft/minecraft.h>
#include <sdk/minecraft/util/box.h>
#include <sdk/minecraft/world/world.h>
#define NOMINMAX
#include <algorithm>
#include <cmath>
#include <mutex>
#include <utility>
#include <vector>

namespace
{
    struct view_matrix_t
    {
        float right[3];
        float up[3];
        float forward[3];
        float cam_pos[3];
        float fov_x;
        float fov_y;
        float half_w;
        float half_h;
        bool valid;
    };

    struct render_snapshot_t
    {
        float partial_ticks;
        esp_camera_data camera;
        int screen_w;
        int screen_height;
        bool valid;
    };

    constexpr float kPi = 3.14159265358979323846f;

    std::vector<esp_player_data> esp_players;
    std::mutex esp_players_mutex;
    render_snapshot_t g_render_snapshot{};
    std::mutex g_snapshot_mutex;
    view_matrix_t g_view_matrix{};

    void update_render_snapshot(float partial_ticks, const esp_camera_data& camera, int w, int h)
    {
        std::lock_guard<std::mutex> lock(g_snapshot_mutex);
        g_render_snapshot.partial_ticks = partial_ticks;
        g_render_snapshot.camera = camera;
        g_render_snapshot.screen_w = w;
        g_render_snapshot.screen_height = h;
        g_render_snapshot.valid = true;
    }

    render_snapshot_t get_snapshot()
    {
        std::lock_guard<std::mutex> lock(g_snapshot_mutex);
        return g_render_snapshot;
    }

    bool is_name_tags_enabled()
    {
        return globals::box_enabled && !globals::is_unloading;
    }

    float sanitize_fov(float fov)
    {
        if (!std::isfinite(fov) || fov <= 1.0f || fov >= 179.0f) return 70.0f;
        return fov;
    }

    float clamp01(float value)
    {
        if (!std::isfinite(value)) return 1.0f;
        if (value < 0.0f) return 0.0f;
        if (value > 1.0f) return 1.0f;
        return value;
    }

    double interpolate_double(double previous, double current, float partial_ticks)
    {
        return previous + (current - previous) * static_cast<double>(partial_ticks);
    }

    esp_player_data interpolate_player(const esp_player_data& player, float partial_ticks)
    {
        esp_player_data interpolated = player;
        const float t = clamp01(partial_ticks);

        interpolated.x = interpolate_double(player.prev_x, player.x, t);
        interpolated.y = interpolate_double(player.prev_y, player.y, t);
        interpolated.z = interpolate_double(player.prev_z, player.z, t);

        const double min_dx = player.min_x - player.x;
        const double min_dy = player.min_y - player.y;
        const double min_dz = player.min_z - player.z;
        const double max_dx = player.max_x - player.x;
        const double max_dy = player.max_y - player.y;
        const double max_dz = player.max_z - player.z;

        interpolated.min_x = interpolated.x + min_dx;
        interpolated.min_y = interpolated.y + min_dy;
        interpolated.min_z = interpolated.z + min_dz;
        interpolated.max_x = interpolated.x + max_dx;
        interpolated.max_y = interpolated.y + max_dy;
        interpolated.max_z = interpolated.z + max_dz;
        return interpolated;
    }

    void clear_esp_state()
    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        esp_players.clear();
    }

    void compute_view_matrix(const esp_camera_data& camera, int screen_width, int screen_height)
    {
        g_view_matrix.valid = false;

        if (screen_width <= 0 || screen_height <= 0) return;
        if (!std::isfinite(camera.cam_x) || !std::isfinite(camera.cam_y) || !std::isfinite(camera.cam_z)) return;
        
        const float fov = sanitize_fov(camera.fov);
        const float yaw_rad = camera.yaw * (kPi / 180.0f);
        const float pitch_rad = camera.pitch * (kPi / 180.0f);

        const float cos_yaw = cosf(yaw_rad);
        const float sin_yaw = sinf(yaw_rad);
        const float cos_pitch = cosf(pitch_rad);
        const float sin_pitch = sinf(pitch_rad);

        g_view_matrix.forward[0] = -sin_yaw * cos_pitch;
        g_view_matrix.forward[1] = -sin_pitch;
        g_view_matrix.forward[2] = cos_yaw * cos_pitch;

        g_view_matrix.right[0] = -cos_yaw;
        g_view_matrix.right[1] = 0.0f;
        g_view_matrix.right[2] = -sin_yaw;

        g_view_matrix.up[0] = g_view_matrix.forward[1] * g_view_matrix.right[2] - g_view_matrix.forward[2] * g_view_matrix.right[1];
        g_view_matrix.up[1] = g_view_matrix.forward[2] * g_view_matrix.right[0] - g_view_matrix.forward[0] * g_view_matrix.right[2];
        g_view_matrix.up[2] = g_view_matrix.forward[0] * g_view_matrix.right[1] - g_view_matrix.forward[1] * g_view_matrix.right[0];

        g_view_matrix.cam_pos[0] = static_cast<float>(camera.cam_x);
        g_view_matrix.cam_pos[1] = static_cast<float>(camera.cam_y);
        g_view_matrix.cam_pos[2] = static_cast<float>(camera.cam_z);

        const float fov_rad = fov * (kPi / 180.0f);
        const float tan_half_fov = tanf(fov_rad * 0.5f);
        
        const float aspect = static_cast<float>(screen_width) / static_cast<float>(screen_height);
        g_view_matrix.fov_x = 1.0f / (tan_half_fov * aspect);
        g_view_matrix.fov_y = 1.0f / tan_half_fov;
        g_view_matrix.half_w = static_cast<float>(screen_width) * 0.5f;
        g_view_matrix.half_h = static_cast<float>(screen_height) * 0.5f;
        g_view_matrix.valid = true;
    }

    bool world_to_screen_fast(float x, float y, float z, float& out_x, float& out_y)
    {
        if (!g_view_matrix.valid) return false;

        const float lx = x - g_view_matrix.cam_pos[0];
        const float ly = y - g_view_matrix.cam_pos[1];
        const float lz = z - g_view_matrix.cam_pos[2];

        const float px = lx * g_view_matrix.right[0] + ly * g_view_matrix.right[1] + lz * g_view_matrix.right[2];
        const float py = lx * g_view_matrix.up[0] + ly * g_view_matrix.up[1] + lz * g_view_matrix.up[2];
        const float pz = lx * g_view_matrix.forward[0] + ly * g_view_matrix.forward[1] + lz * g_view_matrix.forward[2];

        if (pz <= 0.05f) return false;

        const float inv_z = 1.0f / pz;
        out_x = g_view_matrix.half_w + (px * inv_z * g_view_matrix.fov_x) * g_view_matrix.half_w;
        out_y = g_view_matrix.half_h - (py * inv_z * g_view_matrix.fov_y) * g_view_matrix.half_h;

        return std::isfinite(out_x) && std::isfinite(out_y);
    }

    bool project_name_tag(const esp_player_data& player, float partial_ticks, ImVec2& screen_pos)
    {
        const esp_player_data interpolated = interpolate_player(player, partial_ticks);

        const float center_x = static_cast<float>((interpolated.min_x + interpolated.max_x) * 0.5);
        const float center_z = static_cast<float>((interpolated.min_z + interpolated.max_z) * 0.5);
        const float tag_y = static_cast<float>(interpolated.max_y + 0.45f);

        float sx = 0.0f, sy = 0.0f;
        if (world_to_screen_fast(center_x, tag_y, center_z, sx, sy)) {
            screen_pos.x = sx;
            screen_pos.y = sy;
            return true;
        }

        return false;
    }
}

void OverrideClient::modules::esp::run()
{
    auto env = OverrideClient::instance ? OverrideClient::instance->get_env() : nullptr;
    if (!env || !sdk::instance) return;

    if (!is_name_tags_enabled()) {
        clear_esp_state();
        return;
    }

    render_snapshot_t snapshot = get_snapshot();
    if (!snapshot.valid) return;

    jobject world = sdk::instance->get_world();
    jobject local_player = sdk::instance->get_player();
    if (!world || !local_player) {
        if (world) env->DeleteLocalRef(world);
        if (local_player) env->DeleteLocalRef(local_player);
        clear_esp_state();
        return;
    }

    sdk::world_client world_client(world);
    std::vector<jobject> players = world_client.get_players();
    std::vector<esp_player_data> players_data;
    players_data.reserve(players.size());

    compute_view_matrix(snapshot.camera, snapshot.screen_w, snapshot.screen_height);

    for (jobject player : players)
    {
        if (!player) continue;

        sdk::entity_client entity_client(player);
        if (entity_client.is_same_object(local_player)) {
            env->DeleteLocalRef(player);
            continue;
        }

        jobject box = entity_client.get_bounding_box();
        if (!box) {
            env->DeleteLocalRef(player);
            continue;
        }

        sdk::box_client bbox(box);

        esp_player_data data{};
        data.name = entity_client.get_name_string();
        if (data.name.empty()) data.name = "Player";

        data.x = entity_client.get_x();
        data.y = entity_client.get_y();
        data.z = entity_client.get_z();
        data.prev_x = entity_client.get_last_x();
        data.prev_y = entity_client.get_last_y();
        data.prev_z = entity_client.get_last_z();

        data.min_x = bbox.get_min_x();
        data.min_y = bbox.get_min_y();
        data.min_z = bbox.get_min_z();
        data.max_x = bbox.get_max_x();
        data.max_y = bbox.get_max_y();
        data.max_z = bbox.get_max_z();

        ImVec2 screen_pos{};
        if (project_name_tag(data, snapshot.partial_ticks, screen_pos)) {
            data.screen_pos = screen_pos;
            players_data.push_back(std::move(data));
        }

        env->DeleteLocalRef(box);
        env->DeleteLocalRef(player);
    }

    env->DeleteLocalRef(world);
    env->DeleteLocalRef(local_player);

    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        esp_players = std::move(players_data);
    }
}

void OverrideClient::modules::esp::draw_boxes()
{
    if (!GUI::get_is_init() || !sdk::instance || !is_name_tags_enabled()) return;

    ImDrawList* draw_list = ImGui::GetForegroundDrawList();
    if (!draw_list) return;

    const ImVec2 display_size = ImGui::GetIO().DisplaySize;
    const int screen_width = static_cast<int>(display_size.x);
    const int screen_height = static_cast<int>(display_size.y);
    if (screen_width <= 0 || screen_height <= 0) return;

    const float partial_ticks = clamp01(sdk::instance->get_partial_ticks());
    sdk::camera_data render_camera = sdk::instance->get_camera();
    if (render_camera.valid) {
        esp_camera_data esp_cam{};
        esp_cam.cam_x = render_camera.x;
        esp_cam.cam_y = render_camera.y;
        esp_cam.cam_z = render_camera.z;
        esp_cam.yaw = render_camera.yaw;
        esp_cam.pitch = render_camera.pitch;
        esp_cam.fov = render_camera.fov;
        update_render_snapshot(partial_ticks, esp_cam, screen_width, screen_height);
    }

    std::vector<esp_player_data> players_copy;
    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        players_copy = esp_players;
    }

    for (const esp_player_data& player : players_copy)
    {
        const ImVec2 anchor = player.screen_pos;
        const char* label = player.name.c_str();
        const ImVec2 text_size = ImGui::CalcTextSize(label);
        const float padding_x = 6.0f;
        const float padding_y = 3.0f;
        const float box_height = text_size.y + padding_y * 2.0f;
        const ImVec2 box_min(anchor.x - text_size.x * 0.5f - padding_x, anchor.y - box_height - 8.0f);
        const ImVec2 box_max(anchor.x + text_size.x * 0.5f + padding_x, anchor.y - 8.0f);

        if (box_max.x < 0.0f || box_min.x > display_size.x || box_max.y < 0.0f || box_min.y > display_size.y) {
            continue;
        }

        draw_list->AddRectFilled(box_min, box_max, IM_COL32(10, 10, 10, 185), 4.0f);
        draw_list->AddRect(box_min, box_max, IM_COL32(255, 255, 255, 35), 4.0f);
        draw_list->AddText(ImVec2(anchor.x - text_size.x * 0.5f, box_min.y + padding_y), IM_COL32(255, 255, 255, 255), label);
    }
}

void OverrideClient::modules::esp::shutdown()
{
    clear_esp_state();
}
кароче рендерит на ентети но двигаеться с камерой
 
с++:
Expand Collapse Copy
#include "esp.h"
#include "../../OverrideClient.h"
#include "../../globals/globals.h"
#include "../../gui/GUI.h"
#include <sdk/minecraft/entity/entity.h>
#include <sdk/minecraft/minecraft.h>
#include <sdk/minecraft/util/box.h>
#include <sdk/minecraft/world/world.h>
#define NOMINMAX
#include <algorithm>
#include <cmath>
#include <mutex>
#include <utility>
#include <vector>

namespace
{
    struct view_matrix_t
    {
        float right[3];
        float up[3];
        float forward[3];
        float cam_pos[3];
        float fov_x;
        float fov_y;
        float half_w;
        float half_h;
        bool valid;
    };

    struct render_snapshot_t
    {
        float partial_ticks;
        esp_camera_data camera;
        int screen_w;
        int screen_height;
        bool valid;
    };

    constexpr float kPi = 3.14159265358979323846f;

    std::vector<esp_player_data> esp_players;
    std::mutex esp_players_mutex;
    render_snapshot_t g_render_snapshot{};
    std::mutex g_snapshot_mutex;
    view_matrix_t g_view_matrix{};

    void update_render_snapshot(float partial_ticks, const esp_camera_data& camera, int w, int h)
    {
        std::lock_guard<std::mutex> lock(g_snapshot_mutex);
        g_render_snapshot.partial_ticks = partial_ticks;
        g_render_snapshot.camera = camera;
        g_render_snapshot.screen_w = w;
        g_render_snapshot.screen_height = h;
        g_render_snapshot.valid = true;
    }

    render_snapshot_t get_snapshot()
    {
        std::lock_guard<std::mutex> lock(g_snapshot_mutex);
        return g_render_snapshot;
    }

    bool is_name_tags_enabled()
    {
        return globals::box_enabled && !globals::is_unloading;
    }

    float sanitize_fov(float fov)
    {
        if (!std::isfinite(fov) || fov <= 1.0f || fov >= 179.0f) return 70.0f;
        return fov;
    }

    float clamp01(float value)
    {
        if (!std::isfinite(value)) return 1.0f;
        if (value < 0.0f) return 0.0f;
        if (value > 1.0f) return 1.0f;
        return value;
    }

    double interpolate_double(double previous, double current, float partial_ticks)
    {
        return previous + (current - previous) * static_cast<double>(partial_ticks);
    }

    esp_player_data interpolate_player(const esp_player_data& player, float partial_ticks)
    {
        esp_player_data interpolated = player;
        const float t = clamp01(partial_ticks);

        interpolated.x = interpolate_double(player.prev_x, player.x, t);
        interpolated.y = interpolate_double(player.prev_y, player.y, t);
        interpolated.z = interpolate_double(player.prev_z, player.z, t);

        const double min_dx = player.min_x - player.x;
        const double min_dy = player.min_y - player.y;
        const double min_dz = player.min_z - player.z;
        const double max_dx = player.max_x - player.x;
        const double max_dy = player.max_y - player.y;
        const double max_dz = player.max_z - player.z;

        interpolated.min_x = interpolated.x + min_dx;
        interpolated.min_y = interpolated.y + min_dy;
        interpolated.min_z = interpolated.z + min_dz;
        interpolated.max_x = interpolated.x + max_dx;
        interpolated.max_y = interpolated.y + max_dy;
        interpolated.max_z = interpolated.z + max_dz;
        return interpolated;
    }

    void clear_esp_state()
    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        esp_players.clear();
    }

    void compute_view_matrix(const esp_camera_data& camera, int screen_width, int screen_height)
    {
        g_view_matrix.valid = false;

        if (screen_width <= 0 || screen_height <= 0) return;
        if (!std::isfinite(camera.cam_x) || !std::isfinite(camera.cam_y) || !std::isfinite(camera.cam_z)) return;
       
        const float fov = sanitize_fov(camera.fov);
        const float yaw_rad = camera.yaw * (kPi / 180.0f);
        const float pitch_rad = camera.pitch * (kPi / 180.0f);

        const float cos_yaw = cosf(yaw_rad);
        const float sin_yaw = sinf(yaw_rad);
        const float cos_pitch = cosf(pitch_rad);
        const float sin_pitch = sinf(pitch_rad);

        g_view_matrix.forward[0] = -sin_yaw * cos_pitch;
        g_view_matrix.forward[1] = -sin_pitch;
        g_view_matrix.forward[2] = cos_yaw * cos_pitch;

        g_view_matrix.right[0] = -cos_yaw;
        g_view_matrix.right[1] = 0.0f;
        g_view_matrix.right[2] = -sin_yaw;

        g_view_matrix.up[0] = g_view_matrix.forward[1] * g_view_matrix.right[2] - g_view_matrix.forward[2] * g_view_matrix.right[1];
        g_view_matrix.up[1] = g_view_matrix.forward[2] * g_view_matrix.right[0] - g_view_matrix.forward[0] * g_view_matrix.right[2];
        g_view_matrix.up[2] = g_view_matrix.forward[0] * g_view_matrix.right[1] - g_view_matrix.forward[1] * g_view_matrix.right[0];

        g_view_matrix.cam_pos[0] = static_cast<float>(camera.cam_x);
        g_view_matrix.cam_pos[1] = static_cast<float>(camera.cam_y);
        g_view_matrix.cam_pos[2] = static_cast<float>(camera.cam_z);

        const float fov_rad = fov * (kPi / 180.0f);
        const float tan_half_fov = tanf(fov_rad * 0.5f);
       
        const float aspect = static_cast<float>(screen_width) / static_cast<float>(screen_height);
        g_view_matrix.fov_x = 1.0f / (tan_half_fov * aspect);
        g_view_matrix.fov_y = 1.0f / tan_half_fov;
        g_view_matrix.half_w = static_cast<float>(screen_width) * 0.5f;
        g_view_matrix.half_h = static_cast<float>(screen_height) * 0.5f;
        g_view_matrix.valid = true;
    }

    bool world_to_screen_fast(float x, float y, float z, float& out_x, float& out_y)
    {
        if (!g_view_matrix.valid) return false;

        const float lx = x - g_view_matrix.cam_pos[0];
        const float ly = y - g_view_matrix.cam_pos[1];
        const float lz = z - g_view_matrix.cam_pos[2];

        const float px = lx * g_view_matrix.right[0] + ly * g_view_matrix.right[1] + lz * g_view_matrix.right[2];
        const float py = lx * g_view_matrix.up[0] + ly * g_view_matrix.up[1] + lz * g_view_matrix.up[2];
        const float pz = lx * g_view_matrix.forward[0] + ly * g_view_matrix.forward[1] + lz * g_view_matrix.forward[2];

        if (pz <= 0.05f) return false;

        const float inv_z = 1.0f / pz;
        out_x = g_view_matrix.half_w + (px * inv_z * g_view_matrix.fov_x) * g_view_matrix.half_w;
        out_y = g_view_matrix.half_h - (py * inv_z * g_view_matrix.fov_y) * g_view_matrix.half_h;

        return std::isfinite(out_x) && std::isfinite(out_y);
    }

    bool project_name_tag(const esp_player_data& player, float partial_ticks, ImVec2& screen_pos)
    {
        const esp_player_data interpolated = interpolate_player(player, partial_ticks);

        const float center_x = static_cast<float>((interpolated.min_x + interpolated.max_x) * 0.5);
        const float center_z = static_cast<float>((interpolated.min_z + interpolated.max_z) * 0.5);
        const float tag_y = static_cast<float>(interpolated.max_y + 0.45f);

        float sx = 0.0f, sy = 0.0f;
        if (world_to_screen_fast(center_x, tag_y, center_z, sx, sy)) {
            screen_pos.x = sx;
            screen_pos.y = sy;
            return true;
        }

        return false;
    }
}

void OverrideClient::modules::esp::run()
{
    auto env = OverrideClient::instance ? OverrideClient::instance->get_env() : nullptr;
    if (!env || !sdk::instance) return;

    if (!is_name_tags_enabled()) {
        clear_esp_state();
        return;
    }

    render_snapshot_t snapshot = get_snapshot();
    if (!snapshot.valid) return;

    jobject world = sdk::instance->get_world();
    jobject local_player = sdk::instance->get_player();
    if (!world || !local_player) {
        if (world) env->DeleteLocalRef(world);
        if (local_player) env->DeleteLocalRef(local_player);
        clear_esp_state();
        return;
    }

    sdk::world_client world_client(world);
    std::vector<jobject> players = world_client.get_players();
    std::vector<esp_player_data> players_data;
    players_data.reserve(players.size());

    compute_view_matrix(snapshot.camera, snapshot.screen_w, snapshot.screen_height);

    for (jobject player : players)
    {
        if (!player) continue;

        sdk::entity_client entity_client(player);
        if (entity_client.is_same_object(local_player)) {
            env->DeleteLocalRef(player);
            continue;
        }

        jobject box = entity_client.get_bounding_box();
        if (!box) {
            env->DeleteLocalRef(player);
            continue;
        }

        sdk::box_client bbox(box);

        esp_player_data data{};
        data.name = entity_client.get_name_string();
        if (data.name.empty()) data.name = "Player";

        data.x = entity_client.get_x();
        data.y = entity_client.get_y();
        data.z = entity_client.get_z();
        data.prev_x = entity_client.get_last_x();
        data.prev_y = entity_client.get_last_y();
        data.prev_z = entity_client.get_last_z();

        data.min_x = bbox.get_min_x();
        data.min_y = bbox.get_min_y();
        data.min_z = bbox.get_min_z();
        data.max_x = bbox.get_max_x();
        data.max_y = bbox.get_max_y();
        data.max_z = bbox.get_max_z();

        ImVec2 screen_pos{};
        if (project_name_tag(data, snapshot.partial_ticks, screen_pos)) {
            data.screen_pos = screen_pos;
            players_data.push_back(std::move(data));
        }

        env->DeleteLocalRef(box);
        env->DeleteLocalRef(player);
    }

    env->DeleteLocalRef(world);
    env->DeleteLocalRef(local_player);

    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        esp_players = std::move(players_data);
    }
}

void OverrideClient::modules::esp::draw_boxes()
{
    if (!GUI::get_is_init() || !sdk::instance || !is_name_tags_enabled()) return;

    ImDrawList* draw_list = ImGui::GetForegroundDrawList();
    if (!draw_list) return;

    const ImVec2 display_size = ImGui::GetIO().DisplaySize;
    const int screen_width = static_cast<int>(display_size.x);
    const int screen_height = static_cast<int>(display_size.y);
    if (screen_width <= 0 || screen_height <= 0) return;

    const float partial_ticks = clamp01(sdk::instance->get_partial_ticks());
    sdk::camera_data render_camera = sdk::instance->get_camera();
    if (render_camera.valid) {
        esp_camera_data esp_cam{};
        esp_cam.cam_x = render_camera.x;
        esp_cam.cam_y = render_camera.y;
        esp_cam.cam_z = render_camera.z;
        esp_cam.yaw = render_camera.yaw;
        esp_cam.pitch = render_camera.pitch;
        esp_cam.fov = render_camera.fov;
        update_render_snapshot(partial_ticks, esp_cam, screen_width, screen_height);
    }

    std::vector<esp_player_data> players_copy;
    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        players_copy = esp_players;
    }

    for (const esp_player_data& player : players_copy)
    {
        const ImVec2 anchor = player.screen_pos;
        const char* label = player.name.c_str();
        const ImVec2 text_size = ImGui::CalcTextSize(label);
        const float padding_x = 6.0f;
        const float padding_y = 3.0f;
        const float box_height = text_size.y + padding_y * 2.0f;
        const ImVec2 box_min(anchor.x - text_size.x * 0.5f - padding_x, anchor.y - box_height - 8.0f);
        const ImVec2 box_max(anchor.x + text_size.x * 0.5f + padding_x, anchor.y - 8.0f);

        if (box_max.x < 0.0f || box_min.x > display_size.x || box_max.y < 0.0f || box_min.y > display_size.y) {
            continue;
        }

        draw_list->AddRectFilled(box_min, box_max, IM_COL32(10, 10, 10, 185), 4.0f);
        draw_list->AddRect(box_min, box_max, IM_COL32(255, 255, 255, 35), 4.0f);
        draw_list->AddText(ImVec2(anchor.x - text_size.x * 0.5f, box_min.y + padding_y), IM_COL32(255, 255, 255, 255), label);
    }
}

void OverrideClient::modules::esp::shutdown()
{
    clear_esp_state();
}
кароче рендерит на ентети но двигаеться с камерой
крч жди одобрение модератора я скинул тебе WorldToScreen
и верни то что у тебя было до этого там хотя бы более менее было
 
с++:
Expand Collapse Copy
#include "esp.h"
#include "../../OverrideClient.h"
#include "../../globals/globals.h"
#include "../../gui/GUI.h"
#include <sdk/minecraft/entity/entity.h>
#include <sdk/minecraft/minecraft.h>
#include <sdk/minecraft/util/box.h>
#include <sdk/minecraft/world/world.h>
#define NOMINMAX
#include <algorithm>
#include <cmath>
#include <mutex>
#include <utility>
#include <vector>

namespace
{
    struct view_matrix_t
    {
        float right[3];
        float up[3];
        float forward[3];
        float cam_pos[3];
        float fov_x;
        float fov_y;
        float half_w;
        float half_h;
        bool valid;
    };

    struct render_snapshot_t
    {
        float partial_ticks;
        esp_camera_data camera;
        int screen_w;
        int screen_height;
        bool valid;
    };

    constexpr float kPi = 3.14159265358979323846f;

    std::vector<esp_player_data> esp_players;
    std::mutex esp_players_mutex;
    render_snapshot_t g_render_snapshot{};
    std::mutex g_snapshot_mutex;
    view_matrix_t g_view_matrix{};

    void update_render_snapshot(float partial_ticks, const esp_camera_data& camera, int w, int h)
    {
        std::lock_guard<std::mutex> lock(g_snapshot_mutex);
        g_render_snapshot.partial_ticks = partial_ticks;
        g_render_snapshot.camera = camera;
        g_render_snapshot.screen_w = w;
        g_render_snapshot.screen_height = h;
        g_render_snapshot.valid = true;
    }

    render_snapshot_t get_snapshot()
    {
        std::lock_guard<std::mutex> lock(g_snapshot_mutex);
        return g_render_snapshot;
    }

    bool is_name_tags_enabled()
    {
        return globals::box_enabled && !globals::is_unloading;
    }

    float sanitize_fov(float fov)
    {
        if (!std::isfinite(fov) || fov <= 1.0f || fov >= 179.0f) return 70.0f;
        return fov;
    }

    float clamp01(float value)
    {
        if (!std::isfinite(value)) return 1.0f;
        if (value < 0.0f) return 0.0f;
        if (value > 1.0f) return 1.0f;
        return value;
    }

    double interpolate_double(double previous, double current, float partial_ticks)
    {
        return previous + (current - previous) * static_cast<double>(partial_ticks);
    }

    esp_player_data interpolate_player(const esp_player_data& player, float partial_ticks)
    {
        esp_player_data interpolated = player;
        const float t = clamp01(partial_ticks);

        interpolated.x = interpolate_double(player.prev_x, player.x, t);
        interpolated.y = interpolate_double(player.prev_y, player.y, t);
        interpolated.z = interpolate_double(player.prev_z, player.z, t);

        const double min_dx = player.min_x - player.x;
        const double min_dy = player.min_y - player.y;
        const double min_dz = player.min_z - player.z;
        const double max_dx = player.max_x - player.x;
        const double max_dy = player.max_y - player.y;
        const double max_dz = player.max_z - player.z;

        interpolated.min_x = interpolated.x + min_dx;
        interpolated.min_y = interpolated.y + min_dy;
        interpolated.min_z = interpolated.z + min_dz;
        interpolated.max_x = interpolated.x + max_dx;
        interpolated.max_y = interpolated.y + max_dy;
        interpolated.max_z = interpolated.z + max_dz;
        return interpolated;
    }

    void clear_esp_state()
    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        esp_players.clear();
    }

    void compute_view_matrix(const esp_camera_data& camera, int screen_width, int screen_height)
    {
        g_view_matrix.valid = false;

        if (screen_width <= 0 || screen_height <= 0) return;
        if (!std::isfinite(camera.cam_x) || !std::isfinite(camera.cam_y) || !std::isfinite(camera.cam_z)) return;
       
        const float fov = sanitize_fov(camera.fov);
        const float yaw_rad = camera.yaw * (kPi / 180.0f);
        const float pitch_rad = camera.pitch * (kPi / 180.0f);

        const float cos_yaw = cosf(yaw_rad);
        const float sin_yaw = sinf(yaw_rad);
        const float cos_pitch = cosf(pitch_rad);
        const float sin_pitch = sinf(pitch_rad);

        g_view_matrix.forward[0] = -sin_yaw * cos_pitch;
        g_view_matrix.forward[1] = -sin_pitch;
        g_view_matrix.forward[2] = cos_yaw * cos_pitch;

        g_view_matrix.right[0] = -cos_yaw;
        g_view_matrix.right[1] = 0.0f;
        g_view_matrix.right[2] = -sin_yaw;

        g_view_matrix.up[0] = g_view_matrix.forward[1] * g_view_matrix.right[2] - g_view_matrix.forward[2] * g_view_matrix.right[1];
        g_view_matrix.up[1] = g_view_matrix.forward[2] * g_view_matrix.right[0] - g_view_matrix.forward[0] * g_view_matrix.right[2];
        g_view_matrix.up[2] = g_view_matrix.forward[0] * g_view_matrix.right[1] - g_view_matrix.forward[1] * g_view_matrix.right[0];

        g_view_matrix.cam_pos[0] = static_cast<float>(camera.cam_x);
        g_view_matrix.cam_pos[1] = static_cast<float>(camera.cam_y);
        g_view_matrix.cam_pos[2] = static_cast<float>(camera.cam_z);

        const float fov_rad = fov * (kPi / 180.0f);
        const float tan_half_fov = tanf(fov_rad * 0.5f);
       
        const float aspect = static_cast<float>(screen_width) / static_cast<float>(screen_height);
        g_view_matrix.fov_x = 1.0f / (tan_half_fov * aspect);
        g_view_matrix.fov_y = 1.0f / tan_half_fov;
        g_view_matrix.half_w = static_cast<float>(screen_width) * 0.5f;
        g_view_matrix.half_h = static_cast<float>(screen_height) * 0.5f;
        g_view_matrix.valid = true;
    }

    bool world_to_screen_fast(float x, float y, float z, float& out_x, float& out_y)
    {
        if (!g_view_matrix.valid) return false;

        const float lx = x - g_view_matrix.cam_pos[0];
        const float ly = y - g_view_matrix.cam_pos[1];
        const float lz = z - g_view_matrix.cam_pos[2];

        const float px = lx * g_view_matrix.right[0] + ly * g_view_matrix.right[1] + lz * g_view_matrix.right[2];
        const float py = lx * g_view_matrix.up[0] + ly * g_view_matrix.up[1] + lz * g_view_matrix.up[2];
        const float pz = lx * g_view_matrix.forward[0] + ly * g_view_matrix.forward[1] + lz * g_view_matrix.forward[2];

        if (pz <= 0.05f) return false;

        const float inv_z = 1.0f / pz;
        out_x = g_view_matrix.half_w + (px * inv_z * g_view_matrix.fov_x) * g_view_matrix.half_w;
        out_y = g_view_matrix.half_h - (py * inv_z * g_view_matrix.fov_y) * g_view_matrix.half_h;

        return std::isfinite(out_x) && std::isfinite(out_y);
    }

    bool project_name_tag(const esp_player_data& player, float partial_ticks, ImVec2& screen_pos)
    {
        const esp_player_data interpolated = interpolate_player(player, partial_ticks);

        const float center_x = static_cast<float>((interpolated.min_x + interpolated.max_x) * 0.5);
        const float center_z = static_cast<float>((interpolated.min_z + interpolated.max_z) * 0.5);
        const float tag_y = static_cast<float>(interpolated.max_y + 0.45f);

        float sx = 0.0f, sy = 0.0f;
        if (world_to_screen_fast(center_x, tag_y, center_z, sx, sy)) {
            screen_pos.x = sx;
            screen_pos.y = sy;
            return true;
        }

        return false;
    }
}

void OverrideClient::modules::esp::run()
{
    auto env = OverrideClient::instance ? OverrideClient::instance->get_env() : nullptr;
    if (!env || !sdk::instance) return;

    if (!is_name_tags_enabled()) {
        clear_esp_state();
        return;
    }

    render_snapshot_t snapshot = get_snapshot();
    if (!snapshot.valid) return;

    jobject world = sdk::instance->get_world();
    jobject local_player = sdk::instance->get_player();
    if (!world || !local_player) {
        if (world) env->DeleteLocalRef(world);
        if (local_player) env->DeleteLocalRef(local_player);
        clear_esp_state();
        return;
    }

    sdk::world_client world_client(world);
    std::vector<jobject> players = world_client.get_players();
    std::vector<esp_player_data> players_data;
    players_data.reserve(players.size());

    compute_view_matrix(snapshot.camera, snapshot.screen_w, snapshot.screen_height);

    for (jobject player : players)
    {
        if (!player) continue;

        sdk::entity_client entity_client(player);
        if (entity_client.is_same_object(local_player)) {
            env->DeleteLocalRef(player);
            continue;
        }

        jobject box = entity_client.get_bounding_box();
        if (!box) {
            env->DeleteLocalRef(player);
            continue;
        }

        sdk::box_client bbox(box);

        esp_player_data data{};
        data.name = entity_client.get_name_string();
        if (data.name.empty()) data.name = "Player";

        data.x = entity_client.get_x();
        data.y = entity_client.get_y();
        data.z = entity_client.get_z();
        data.prev_x = entity_client.get_last_x();
        data.prev_y = entity_client.get_last_y();
        data.prev_z = entity_client.get_last_z();

        data.min_x = bbox.get_min_x();
        data.min_y = bbox.get_min_y();
        data.min_z = bbox.get_min_z();
        data.max_x = bbox.get_max_x();
        data.max_y = bbox.get_max_y();
        data.max_z = bbox.get_max_z();

        ImVec2 screen_pos{};
        if (project_name_tag(data, snapshot.partial_ticks, screen_pos)) {
            data.screen_pos = screen_pos;
            players_data.push_back(std::move(data));
        }

        env->DeleteLocalRef(box);
        env->DeleteLocalRef(player);
    }

    env->DeleteLocalRef(world);
    env->DeleteLocalRef(local_player);

    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        esp_players = std::move(players_data);
    }
}

void OverrideClient::modules::esp::draw_boxes()
{
    if (!GUI::get_is_init() || !sdk::instance || !is_name_tags_enabled()) return;

    ImDrawList* draw_list = ImGui::GetForegroundDrawList();
    if (!draw_list) return;

    const ImVec2 display_size = ImGui::GetIO().DisplaySize;
    const int screen_width = static_cast<int>(display_size.x);
    const int screen_height = static_cast<int>(display_size.y);
    if (screen_width <= 0 || screen_height <= 0) return;

    const float partial_ticks = clamp01(sdk::instance->get_partial_ticks());
    sdk::camera_data render_camera = sdk::instance->get_camera();
    if (render_camera.valid) {
        esp_camera_data esp_cam{};
        esp_cam.cam_x = render_camera.x;
        esp_cam.cam_y = render_camera.y;
        esp_cam.cam_z = render_camera.z;
        esp_cam.yaw = render_camera.yaw;
        esp_cam.pitch = render_camera.pitch;
        esp_cam.fov = render_camera.fov;
        update_render_snapshot(partial_ticks, esp_cam, screen_width, screen_height);
    }

    std::vector<esp_player_data> players_copy;
    {
        std::lock_guard<std::mutex> lock(esp_players_mutex);
        players_copy = esp_players;
    }

    for (const esp_player_data& player : players_copy)
    {
        const ImVec2 anchor = player.screen_pos;
        const char* label = player.name.c_str();
        const ImVec2 text_size = ImGui::CalcTextSize(label);
        const float padding_x = 6.0f;
        const float padding_y = 3.0f;
        const float box_height = text_size.y + padding_y * 2.0f;
        const ImVec2 box_min(anchor.x - text_size.x * 0.5f - padding_x, anchor.y - box_height - 8.0f);
        const ImVec2 box_max(anchor.x + text_size.x * 0.5f + padding_x, anchor.y - 8.0f);

        if (box_max.x < 0.0f || box_min.x > display_size.x || box_max.y < 0.0f || box_min.y > display_size.y) {
            continue;
        }

        draw_list->AddRectFilled(box_min, box_max, IM_COL32(10, 10, 10, 185), 4.0f);
        draw_list->AddRect(box_min, box_max, IM_COL32(255, 255, 255, 35), 4.0f);
        draw_list->AddText(ImVec2(anchor.x - text_size.x * 0.5f, box_min.y + padding_y), IM_COL32(255, 255, 255, 255), label);
    }
}

void OverrideClient::modules::esp::shutdown()
{
    clear_esp_state();
}
кароче рендерит на ентети но двигаеться с камерой
посмотри примеры w2screen в интернете
 
вот тебе


struct Vec3 { float x, y, z; };

bool WorldToScreen(const Vec3& world, const GLfloat modelview[16],
const GLfloat projection[16], const GLint viewport[4],
GLfloat& screenX, GLfloat& screenY, GLfloat& screenZ) {

GLfloat eyeX = modelview[0]*world.x + modelview[4]*world.y + modelview[8]*world.z + modelview[12];
GLfloat eyeY = modelview[1]*world.x + modelview[5]*world.y + modelview[9]*world.z + modelview[13];
GLfloat eyeZ = modelview[2]*world.x + modelview[6]*world.y + modelview[10]*world.z + modelview[14];
GLfloat eyeW = modelview[3]*world.x + modelview[7]*world.y + modelview[11]*world.z + modelview[15];

GLfloat clipX = projection[0]*eyeX + projection[4]*eyeY + projection[8]*eyeZ + projection[12]*eyeW;
GLfloat clipY = projection[1]*eyeX + projection[5]*eyeY + projection[9]*eyeZ + projection[13]*eyeW;
GLfloat clipZ = projection[2]*eyeX + projection[6]*eyeY + projection[10]*eyeZ + projection[14]*eyeW;
GLfloat clipW = projection[3]*eyeX + projection[7]*eyeY + projection[11]*eyeZ + projection[15]*eyeW;

if (clipW == 0.0f) return false;


GLfloat ndcX = clipX / clipW;
GLfloat ndcY = clipY / clipW;
GLfloat ndcZ = clipZ / clipW;
screenX = (viewport[2] * (ndcX + 1.0f) / 2.0f) + viewport[0];
screenY = (viewport[3] * (ndcY + 1.0f) / 2.0f) + viewport[1];
screenZ = (ndcZ + 1.0f) / 2.0f;

return true;
}
Спасибо тебе добрий человек
 
Назад
Сверху Снизу