Гайд Offscreen with weapon icons for supremacy

Начинающий
Статус
Оффлайн
Регистрация
11 Авг 2021
Сообщения
10
Реакции[?]
1
Поинты[?]
0
SS:
Пожалуйста, авторизуйтесь для просмотра ссылки.

This offscreen code is from Haskihook, so i dont claim this as my own code!!

visual.cpp
C++:
void Visuals::OffScreen(Player* player, int alpha) {
    vec3_t view_origin, target_pos, delta;
    vec2_t screen_pos, offscreen_pos;
    float  leeway_x, leeway_y, radius, offscreen_rotation;
    bool   is_on_screen;
    Vertex verts[3], verts_outline[3];
    Color  color, color_outline;

    bool dormant = player->dormant();

    // todo - dex; move this?
    static auto get_offscreen_data = [](const vec3_t& delta, float radius, vec2_t& out_offscreen_pos, float& out_rotation) {
        ang_t  view_angles(g_csgo.m_view_render->m_view.m_angles);
        vec3_t fwd, right, up(0.f, 0.f, 1.f);
        float  front, side, yaw_rad, sa, ca;

        // get viewport angles forward directional vector.
        math::AngleVectors(view_angles, &fwd);

        // convert viewangles forward directional vector to a unit vector.
        fwd.z = 0.f;
        fwd.normalize();

        // calculate front / side positions.
        right = up.cross(fwd);
        front = delta.dot(fwd);
        side = delta.dot(right);

        // setup offscreen position.
        out_offscreen_pos.x = radius * -side;
        out_offscreen_pos.y = radius * -front;

        // get the rotation ( yaw, 0 - 360 ).
        out_rotation = math::rad_to_deg(std::atan2(out_offscreen_pos.x, out_offscreen_pos.y) + math::pi);

        // get needed sine / cosine values.
        yaw_rad = math::deg_to_rad(-out_rotation);
        sa = std :: sin (yaw_rad);
        ca = std::cos(yaw_rad);

        // rotate offscreen position around.
        out_offscreen_pos.x = (int)((g_cl.m_width / 2.f) + (radius * sa));
        out_offscreen_pos.y = (int)((g_cl.m_height / 2.f) - (radius * ca));
    };

    if (!g_menu.main.players.offscreen.get())
        return;

    if (!g_cl.m_processing || !g_cl.m_local->enemy(player))
        return;

    // get the player's center screen position.
    target_pos = player->WorldSpaceCenter();
    is_on_screen = render::WorldToScreen(target_pos, screen_pos);

    // give some extra room for screen position to be off screen.
    leeway_x = g_cl.m_width / 18.f;
    leeway_y = g_cl.m_height / 18.f;

    // origin is not on the screen at all, get offscreen position data and start rendering.
    if (!is_on_screen
        || screen_pos.x < -leeway_x
        || screen_pos.x >(g_cl.m_width + leeway_x)
        || screen_pos.y <-leeway_y
        || screen_pos.y >(g_cl.m_height + leeway_y)) {

        float size = 100.f / 100.f;
        float pos = 250.f;

        // get viewport origin.
        view_origin = g_csgo.m_view_render->m_view.m_origin;

        // get direction to target.
        delta = (target_pos - view_origin).normalized();

        // note - dex; this is the 'YRES' macro from the source sdk.
        radius = pos * (g_cl.m_height / 480.f);

        // get the data we need for rendering.
        get_offscreen_data(delta, radius, offscreen_pos, offscreen_rotation);

        // bring rotation back into range... before rotating verts, sine and cosine needs this value inverted.
        // note - dex; reference:
        // https://github.com/VSES/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/game/client/tf/tf_hud_damageindicator.cpp#L182
        offscreen_rotation = -offscreen_rotation;

        // setup vertices for the triangle.
        verts[0] = { offscreen_pos.x + (1 * size) , offscreen_pos.y + (1 * size) };        // 0,  0
        verts[1] = { offscreen_pos.x - (12.f * size), offscreen_pos.y + (24.f * size) }; // -1, 1
        verts[2] = { offscreen_pos.x + (12.f * size), offscreen_pos.y + (24.f * size) }; // 1,  1

        // setup verts for the triangle's outline.
        verts_outline[0] = { verts[0].m_pos.x - 0.2f, verts[0].m_pos.y - 0.2f };
        verts_outline[1] = { verts[1].m_pos.x - 0.2f, verts[1].m_pos.y + 0.2f };
        verts_outline[2] = { verts[2].m_pos.x + 0.2f, verts[2].m_pos.y + 0.2f };

        Weapon* weapon = player->GetActiveWeapon();
        if (weapon) {
            const auto icon = weapon->getIcon();
            if (g_menu.main.players.offscreen_icon.get()) {
                render::DrawString(F::Icons, offscreen_pos.x - 80 - (1.f * size - 80), offscreen_pos.y - 40 + (24.f * size), Color(255, 255, 255, 255), FONT_CENTER, icon);
            }
        }

        // rotate all vertices to point towards our target.
        verts[0] = render::RotateVertex(offscreen_pos, verts[0], offscreen_rotation);
        verts[1] = render::RotateVertex(offscreen_pos, verts[1], offscreen_rotation);
        verts[2] = render::RotateVertex(offscreen_pos, verts[2], offscreen_rotation);

        verts_outline[0] = render::RotateVertex(offscreen_pos, verts_outline[0], offscreen_rotation);
        verts_outline[1] = render::RotateVertex(offscreen_pos, verts_outline[1], offscreen_rotation);
        verts_outline[2] = render::RotateVertex(offscreen_pos, verts_outline[2], offscreen_rotation);

        // render!
        int alpha1337 = sin(abs(fmod(-math::pi + (g_csgo.m_globals->m_curtime * (2 / .75)), (math::pi * 2)))) * 255;

        if (alpha1337 < 0)
            alpha1337 = alpha1337 * (-1);

        if (!dormant) {
            color = { g_menu.main.players.offscreen_color.get().r(), g_menu.main.players.offscreen_color.get().g(), g_menu.main.players.offscreen_color.get().b(), g_menu.main.players.offscreen_color.get().a() = 88 }; // damage_data.m_color;
            color_outline = { g_menu.main.players.offscreen_color.get().r(), g_menu.main.players.offscreen_color.get().g(), g_menu.main.players.offscreen_color.get().b(), g_menu.main.players.offscreen_color.get().a() = 255 };
        }
        else {
            color =  { 255,255,255,g_menu.main.players.offscreen_color.get().a() = 44 };
            color_outline = { 255,255,255, g_menu.main.players.offscreen_color.get().a() = 120 };
        }

        g_csgo.m_surface->DrawSetColor(color); // filled
        g_csgo.m_surface->DrawTexturedPolygon(3, verts);
        g_csgo.m_surface->DrawSetColor(color_outline); // outline
        g_csgo.m_surface->DrawTexturedPolyLine(3, verts_outline);
    }
}
visual.h
C++:
struct OffScreenDamageData_t {
    float m_time, m_color_step;
    Color m_color;

    __forceinline OffScreenDamageData_t() : m_time{ 0.f }, m_color{ colors::white } {}
    __forceinline OffScreenDamageData_t(float time, float m_color_step, Color color) : m_time{ time }, m_color{ color } {}
};
 

Вложения

Сверху Снизу