Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void c_misc::autostrafe(C_CSPlayer* local)
- {
- if (!config::get<bool>(g_cfg.movement_autostrafe)) return;
- enum directions : int
- {
- FORWARDS = 0,
- BACKWARDS = 180,
- LEFT = 90,
- RIGHT = -90
- };
- is_bhopping = g_cl.m_cmd->m_buttons & IN_JUMP;
- if (!is_bhopping && local->flags() & FL_ONGROUND)
- {
- calculated_direction = directions::FORWARDS;
- in_transition = false;
- return;
- }
- vec3_t base;
- g_csgo.m_engine->GetViewAngles(base);
- auto get_rough_direction = [&](float true_direction) -> float
- {
- std::array<float, 4> minimum = { directions::FORWARDS, directions::BACKWARDS, directions::LEFT, directions::RIGHT };
- float best_angle, best_delta = 181.f;
- for (size_t i = 0; i < minimum.size(); ++i)
- {
- float rough_direction = base.y + minimum.at(i);
- float delta = fabsf(math::normalize_angle(true_direction - rough_direction));
- if (delta < best_delta)
- {
- best_angle = rough_direction;
- best_delta = delta;
- }
- }
- return best_angle;
- };
- vec3_t angles;
- math::vector_angle(local->velocity(), angles);
- true_direction = angles.y;
- if (g_cl.m_cmd->m_buttons & IN_FORWARD)
- {
- wish_direction = base.y + directions::FORWARDS;
- }
- else if (g_cl.m_cmd->m_buttons & IN_BACK)
- {
- wish_direction = base.y + directions::BACKWARDS;
- }
- else if (g_cl.m_cmd->m_buttons & IN_MOVELEFT)
- {
- wish_direction = base.y + directions::LEFT;
- }
- else if (g_cl.m_cmd->m_buttons & IN_MOVERIGHT)
- {
- wish_direction = base.y + directions::RIGHT;
- }
- else
- {
- g_cl.m_cmd->m_buttons |= IN_FORWARD;
- wish_direction = base.y + directions::FORWARDS;
- }
- float speed_rotation = math::min(math::rad_to_deg(std::asinf(30.f / local->velocity().length_2d())) * 0.5f, 45.f);
- if (in_transition)
- {
- float ideal_step = speed_rotation + calculated_direction;
- step = fabsf(math::normalize_angle(calculated_direction - ideal_step));
- if (fabsf(math::normalize_angle(wish_direction - calculated_direction)) > step)
- {
- float add = math::normalize_angle(calculated_direction + step);
- float sub = math::normalize_angle(calculated_direction - step);
- if (fabsf(math::normalize_angle(wish_direction - add)) >= fabsf(math::normalize_angle(wish_direction - sub)))
- {
- calculated_direction -= step;
- }
- else
- {
- calculated_direction += step;
- }
- }
- else
- {
- in_transition = false;
- }
- }
- else
- {
- rough_direction = get_rough_direction(true_direction);
- calculated_direction = rough_direction;
- if (rough_direction != wish_direction)
- {
- in_transition = true;
- }
- }
- g_cl.m_cmd->m_forwardmove = 0.f;
- g_cl.m_cmd->m_sidemove = g_cl.m_cmd->m_command_number % 2 ? 450.f : -450.f;
- float direction = (g_cl.m_cmd->m_command_number % 2 ? speed_rotation : -speed_rotation) + calculated_direction;
- float rotation = math::deg_to_rad(base.y - direction);
- float cos_rot = cos(rotation);
- float sin_rot = sin(rotation);
- float forwardmove = (cos_rot * g_cl.m_cmd->m_forwardmove) - (sin_rot * g_cl.m_cmd->m_sidemove);
- float sidemove = (sin_rot * g_cl.m_cmd->m_forwardmove) + (cos_rot * g_cl.m_cmd->m_sidemove);
- g_cl.m_cmd->m_forwardmove = forwardmove;
- g_cl.m_cmd->m_sidemove = sidemove;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement