-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
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;
}
Последнее редактирование: