Исходник Slow walk types как в в3 для лв

Забаненный
Статус
Оффлайн
Регистрация
13 Июл 2021
Сообщения
9
Реакции[?]
2
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
C++:
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

#include "slowwalk.h"

void slowwalk::create_move(CUserCmd* m_pcmd, float speed_modifier)
{
    if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND && engineprediction::get().backup_data.flags & FL_ONGROUND))
        return;

    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return;

    if (!key_binds::get().get_key_bind_state(21))
        return;

    if (speed_modifier == -1.0f)
        g_ctx.globals.slowwalking = true;

    if (key_binds::get().get_key_bind_state(21))
        g_ctx.globals.slowwalking = true;

    int iChokedCommands = m_clientstate()->iChokedCommands;
    int handle_chokes = 13;

    m_pcmd->m_buttons &= ~IN_SPEED;

    int choke_difference, v95;
    choke_difference = v95 = 8;

    if (g_cfg.antiaim.slowwalk_type) {

        if (iChokedCommands >= handle_chokes)
        {
            goto full_stop;
        }

        if (!iChokedCommands)
            goto LABEL_11;

        if (g_cfg.antiaim.slowwalk_type == 1)
        {
            if (iChokedCommands > choke_difference + 1) // get best choke difference ( todo: maybe fullreverse this and sort unchoked ticks? )
            {
                slowwalk::get().stop(0.0, m_pcmd);
                return;
            }
            if (iChokedCommands <= v95)
                return;
        LABEL_11:

        full_stop:
            m_pcmd->m_forwardmove = 0;
            m_pcmd->m_sidemove = 0;
            m_pcmd->m_upmove = 0;
            return;
        }

        if (g_cfg.antiaim.slowwalk_type == 2) {

            if (iChokedCommands > choke_difference)
            {
                slowwalk::get().stop(0.0, m_pcmd);
                return;
            }
        }

    }
    else
    {
        float avg_modifier = 0.33000001 * (g_ctx.local()->m_bIsScoped() ? weapon_info->flMaxPlayerSpeedAlt : weapon_info->flMaxPlayerSpeed);

        if (engineprediction::get().backup_data.velocity.Length2D() > avg_modifier) {

            float move_sqrt = std::sqrtf(m_pcmd->m_forwardmove * m_pcmd->m_forwardmove) + (m_pcmd->m_sidemove * m_pcmd->m_sidemove);

            float forward_sqrt = m_pcmd->m_forwardmove / move_sqrt;
            float side_sqrt = m_pcmd->m_sidemove / move_sqrt;

            auto avg_speed = g_ctx.local()->m_vecVelocity().Length2D();

            if (avg_modifier + 1.0 <= avg_speed) {
                m_pcmd->m_forwardmove = 0;
                m_pcmd->m_sidemove = 0;
            }
            else {
                m_pcmd->m_forwardmove = forward_sqrt * avg_modifier;
                m_pcmd->m_sidemove = side_sqrt * avg_modifier;
            }
        }

        return;
    }
}
void slowwalk::autostop(CUserCmd* m_pcmd, float custom_speed)
{
    if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND && engineprediction::get().backup_data.flags & FL_ONGROUND))
        return;

    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return;

    if (key_binds::get().get_key_bind_state(21) && !g_cfg.antiaim.slowwalk_type == 0)
        return;

    auto modifier = custom_speed == -1.0f ? 0.3f : custom_speed; //-V550
    auto max_speed = modifier * (g_ctx.globals.scoped ? weapon_info->flMaxPlayerSpeedAlt : weapon_info->flMaxPlayerSpeed);

    if (!g_ctx.globals.weapon->is_non_aim())
    {
        auto move_length = sqrt(m_pcmd->m_sidemove * m_pcmd->m_sidemove + m_pcmd->m_forwardmove * m_pcmd->m_forwardmove);

        auto forwardmove = m_pcmd->m_forwardmove / move_length;
        auto sidemove = m_pcmd->m_sidemove / move_length;

        if (move_length > max_speed)
        {
            if (max_speed + 1.0f < g_ctx.local()->m_vecVelocity().Length2D())
            {
                m_pcmd->m_forwardmove = 0.0f;
                m_pcmd->m_sidemove = 0.0f;
            }
            else
            {
                m_pcmd->m_sidemove = max_speed * sidemove;
                m_pcmd->m_forwardmove = max_speed * forwardmove;
            }
        }
    }
    else
    {
        auto forwardmove = m_pcmd->m_forwardmove;
        auto sidemove = m_pcmd->m_sidemove;

        auto move_length = sqrt(sidemove * sidemove + forwardmove * forwardmove);
        auto move_length_backup = move_length;

        if (move_length > 110.0f)
        {
            m_pcmd->m_forwardmove = forwardmove / move_length_backup * 110.0f;
            move_length = sidemove / move_length_backup * 110.0f;
            m_pcmd->m_sidemove = sidemove / move_length_backup * 110.0f;
        }
    }
}

void slowwalk::stop(float speed, CUserCmd* m_cmd) {
    auto sv_friction = m_cvar()->FindVar(m_xor_str("sv_friction"));
    auto sv_stopspeed = m_cvar()->FindVar(m_xor_str("sv_stopspeed"));

    auto get_max_friction_acceleration = [&]() {
        Vector v6 = engineprediction::get().backup_data.velocity;
        float v8 = sv_friction->GetFloat() * g_ctx.local()->m_surfaceFriction();
        float v11 = v6.Length();

        if (v11 <= 0.1f)
            goto LABEL_12;

        float v43 = fmax(v11, sv_stopspeed->GetFloat());
        float v23 = v43 * v8 * m_globals()->m_intervalpertick;
        float v19 = fmax(0.f, v11 - v23);

        if (v19 != v11) {
            v19 /= v11;

            v6 *= v19;
        }
    LABEL_12:
        return v6;
    };

    float m_side_move{ }, m_forward_move{ }, v54{ };

    if (get_max_friction_acceleration().Length2D() > speed) {

        QAngle v23{ };
        Vector velocity = get_max_friction_acceleration(), v6;
        math::vectornagles_2d((velocity * -1.f), v23);
        v23.yaw = m_cmd->m_viewangles.y - v23.yaw;
        math::angle_vectors_deg(v23, &v6);

        m_side_move = 450.0;
        m_forward_move = v6.x * velocity.Length2D();
        v54 = v6.y * velocity.Length2D();
        goto LABEL_246;
    }


LABEL_246:
    if (m_forward_move <= 450.0)
    {
        if (m_forward_move < -450.0)
            m_forward_move = -450.0;
    }
    else
    {
        m_forward_move = 450.0;
    }
    if (v54 <= 450.0)
    {
        if (v54 >= -450.0)
            m_side_move = v54;
        else
            m_side_move = -450.0;
    }

    m_cmd->m_forwardmove = m_forward_move;
    m_cmd->m_sidemove = m_side_move;
}
 
Последнее редактирование:
Эксперт
Статус
Оффлайн
Регистрация
30 Дек 2019
Сообщения
1,970
Реакции[?]
958
Поинты[?]
19K
о да, давайте пастить хуету с овнеса, боже блять, как тут поставить фейспалм:rage::rage::rage:
 
Начинающий
Статус
Оффлайн
Регистрация
23 Окт 2020
Сообщения
33
Реакции[?]
20
Поинты[?]
0
definition of vectornagles_2d and angle_vectors_deg?
Код:
    void angle_vectors_deg(const QAngle& angles, Vector* forward, Vector* right, Vector* up)
    {
        float cp = std::cos(DEG2RAD(angles.pitch)), sp = std::sin(DEG2RAD(angles.pitch));
        float cy = std::cos(DEG2RAD(angles.yaw)), sy = std::sin(DEG2RAD(angles.yaw));
        float cr = std::cos(DEG2RAD(angles.roll)), sr = std::sin(DEG2RAD(angles.roll));

        if (forward) {
            forward->x = cp * cy;
            forward->y = cp * sy;
            forward->z = -sp;
        }

        if (right) {
            right->x = -1.f * sr * sp * cy + -1.f * cr * -sy;
            right->y = -1.f * sr * sp * sy + -1.f * cr * cy;
            right->z = -1.f * sr * cp;
        }

        if (up) {
            up->x = cr * sp * cy + -sr * -sy;
            up->y = cr * sp * sy + -sr * cy;
            up->z = cr * cp;
        }
    }
Код:
    void vectornagles_2d(const Vector& forward, QAngle& angles, Vector* up) {
        Vector  left;
        float   len, up_z, pitch, yaw, roll;

        // get 2d length.
        len = forward.Length2D();

        if (up && len > 0.001f) {
            pitch = RAD2DEG(std::atan2(-forward.z, len));
            yaw = RAD2DEG(std::atan2(forward.y, forward.x));

            // get left direction vector using cross product.
            left = (*up).Cross(forward).Normalized();

            // calculate up_z.
            up_z = (left.y * forward.x) - (left.x * forward.y);

            // calculate roll.
            roll = RAD2DEG(std::atan2(left.z, up_z));
        }

        else {
            if (len > 0.f) {
                // calculate pitch and yaw.
                pitch = RAD2DEG(std::atan2(-forward.z, len));
                yaw = RAD2DEG(std::atan2(forward.y, forward.x));
                roll = 0.f;
            }

            else {
                pitch = (forward.z > 0.f) ? -90.f : 90.f;
                yaw = 0.f;
                roll = 0.f;
            }
        }

        // set out angles.
        angles = { pitch, yaw, roll };
    }
 
Сверху Снизу