Исходник 7 layer rezolver

Начинающий
Статус
Оффлайн
Регистрация
16 Апр 2021
Сообщения
4
Реакции[?]
3
Поинты[?]
0
мой резольвер по анимациям проперный работает хорошо делал 30 лет


C++:
#include "animation_system.h"
#include "..\ragebot\aim.h"

void resolver::initialize(player_t* e, adjust_data* record, const float& goal_feet_yaw, const float& pitch)
{
    player = e;
    player_record = record;

    original_goal_feet_yaw = math::normalize_yaw(goal_feet_yaw);
    original_pitch = math::normalize_pitch(pitch);
}
Vector old_calcangle(Vector dst, Vector src)
{
    Vector angles;

    double delta[3] = { (src.x - dst.x), (src.y - dst.y), (src.z - dst.z) };
    double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
    angles.x = (float)(atan(delta[2] / hyp) * 180.0 / 3.14159265);
    angles.y = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
    angles.z = 0.0f;

    if (delta[0] >= 0.0)
    {
        angles.y += 180.0f;
    }

    return angles;
}

bool find_layer(SDK::CBaseEntity* entity, int act, SDK::CAnimationLayer *set)
{
    for (int i = 0; i < 13; i++)
    {
        SDK::CAnimationLayer layer = entity->GetAnimOverlay(i);
        const int activity = entity->GetSequenceActivity(layer.m_nSequence);
        if (activity == act) {
            *set = layer;
            return true;
        }
    }
    return false;
}

float old_normalize(float Yaw)
{
    if (Yaw > 180)
    {
        Yaw -= (round(Yaw / 360) * 360.f);
    }
    else if (Yaw < -180)
    {
        Yaw += (round(Yaw / 360) * -360.f);
    }
    return Yaw;
}
void resolver::reset()
{
    player = nullptr;
    player_record = nullptr;

    was_first_bruteforce = false;
    was_second_bruteforce = false;

    original_goal_feet_yaw = 0.0f;
    original_pitch = 0.0f;
}

#define TICK_INTERVAL            ( g_pGlobalVarsBase->interval_per_tick )

#define ROUND_TO_TICKS( t )        ( TICK_INTERVAL * TIME_TO_TICKS( t ) )

std::deque<LagRecord> LagCompensation::m_PlayerTrack[MAX_PLAYERS];
std::deque<LagRecord> LagCompensation::m_PlayerTrack_Future[MAX_PLAYERS];
LagRecord LagCompensation::m_RestoreData; //[MAX_PLAYERS];
SDK::CBaseEntity* LagCompensation::m_pCurrentPlayer;
#define LC_NONE                0
#define LC_ALIVE            (1<<0)
#define LC_ORIGIN_CHANGED    (1<<8)
#define LC_ANGLES_CHANGED    (1<<9)
#define LC_SIZE_CHANGED        (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)
static float GetAverageMovementCurve(int entIndex, SDK::CBaseEntity* ent)
{
    Vector p1 = Vector(0, 0, 0);
    Vector p2 = Vector(0, 0, 0);
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
    {
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ROTATION_CALC_TIME && i > 3)
            break;
        else if (i > 2)
        {
            float angle = 0;
            Vector a1, a2;
            MATH::VectorAngles(p1, a1);
            MATH::VectorAngles(p2, a2);
            if (a1.y < 0.0f)
                a1.y += 360.0f;
            if (a2.y < 0.0f)
                a2.y += 360.0f;
            angle = a2.y - a1.y;
            if (angle > 180.0f)
                angle -= 360.0f;
            ret += angle;
            ticks++;
        }
        p1 = p2;
        if (i > 0)
            p2 = (LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecOrigin - LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_vecOrigin);
        p2.z = 0;
        p2.NormalizeInPlace();
    }
    ret /= max(1, ticks);
    return ret;
}

static Vector GetMovementDirection(int entIndex, SDK::CBaseEntity* ent)
{
    Vector ret = Vector(0, 0, 0);
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > DIRECTION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity;
    ret /= max(1, ticks);
    return ret.NormalizeInPlace();
}

static float GetAverageAcceleration(int entIndex, SDK::CBaseEntity* ent)
{
    float vel = ent->GetVelocity().Length2D();
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ACCELERATION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity.Length2D() - vel;
    ret /= max(1, ticks);
    return ret;
}

static void CreateCircles(Circle circles[5], int entIndex)
{
    size_t size = LagCompensation::m_PlayerTrack[entIndex].size();
    if (size >= 3)
    {
        size = 0;
        for (size = 0; size < LagCompensation::m_PlayerTrack[entIndex].size(); size++)
        {
            if (g_GlobalVars->curtime - LagCompensation::m_PlayerTrack[entIndex].at(size).m_flSimulationTime > ROTATION_CALC_TIME && size > 3)
                break;
        }
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at((size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(2 * (size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(size - 1).m_vecOrigin);
    }
    else if (size >= 1) {
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin, 3604207201337.f, 1.f);
    }
}

static float CalculateAverageSimtimeDelta(int entIndex)
{
    float ret = 0;
    for (size_t i = 1; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        ret += LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_flSimulationTime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime;
    ret /= max(1, (int)LagCompensation::m_PlayerTrack[entIndex].size());
    return ret;
}void CBacktrack::run_legit(SDK::CUserCmd* cmd) //phook backtrack muahhahahahaaha
{
    int bestTargetIndex = -1;
    float bestFov = FLT_MAX;
    SDK::player_info_t info;

    auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());

    if (!local_player)
        return;

    for (int i = 1; i < 65; i++)
    {
        auto entity = INTERFACES::ClientEntityList->GetClientEntity(i);

        if (!entity)
            continue;

        if (entity == local_player)
            continue;

        if (!INTERFACES::Engine->GetPlayerInfo(i, &info))
            continue;

        if (entity->GetIsDormant())
            continue;

        if (entity->GetTeam() == local_player->GetTeam())
            continue;

        if (!local_player->GetHealth() > 0)
            return;

        if (entity->GetHealth() > 0)
        {
            float simtime = entity->GetSimTime();
            Vector hitboxPos = aimbot->get_hitbox_pos(entity, 0);

            headPositions[i][cmd->command_number % 12] = legit_backtrackdata{ simtime, hitboxPos };
            Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
            Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();
            float FOVDistance = point_to_line(hitboxPos, local_position, ViewDir);
    c_player_records* log = &records[m_player->entindex() - 1];

    if (previous && !previous->dormant && previous->data_filled && !record->first_after_dormancy)
    {
        m_player->get_animation_state()->m_primary_cycle = previous->m_primary_cycle;
        m_player->get_animation_state()->m_move_weight = previous->m_move_weight;

        m_player->get_animation_state()->m_strafe_sequence = previous->m_strafe_sequence;
        m_player->get_animation_state()->m_strafe_change_weight = previous->m_strafe_change_weight;
        m_player->get_animation_state()->m_strafe_change_cycle = previous->m_strafe_change_cycle;
        m_player->get_animation_state()->m_acceleration_weight = previous->m_acceleration_weight;
#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_START;
#endif // VIRTUALIZER

    const auto backup_flags = m_player->m_fFlags();
    const auto backup_ieflags = m_player->m_iEFlags();
    const auto backup_duckamt = m_player->m_flDuckAmount();
    const auto backup_lowerbody = m_player->m_flLowerBodyYawTarget();
    const auto backup_move_weight = m_player->get_animation_state()->m_move_weight;
    const auto backup_primary_cycle = m_player->get_animation_state()->m_primary_cycle;
    
    //const auto backup_poses = m_player->m_flPoseParameter();
    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));

    resolver_records* resolver_info = &feature::resolver->player_records[m_player->entindex() - 1];
    c_player_records* log = &records[m_player->entindex() - 1];

    //m_player->set_abs_angles(QAngle(0, record->eye_angles.y, 0));
    m_player->m_angEyeAngles() = record->eye_angles;
    m_player->m_angEyeAngles().z = 0.f;

    prepare_player_anim_update(m_player, record, previous, resolver_side);

    m_player->set_abs_angles(QAngle(0, m_player->get_animation_state()->m_abs_yaw, 0));

    if (record->lag > 1 && !log->saved_info.fakeplayer && previous && previous->data_filled)
    {
        const auto velocity_per_tick = (record->velocity - previous->velocity) / record->lag;
        //const auto origin_per_tick = (record->origin - previous->origin) / record->lag;
        //auto ticks_animated = 0;
        //auto velocity_speed_delta = abs(fmaxf(record->velocity.Length2D(),previous->velocity.Length2D()));

        const auto lby_delta = fabsf(Math::angle_diff(record->eye_angles.y, record->lower_body_yaw));

        record->is_landed = false;

        for (auto i = 1; i <= record->lag; i++)
        {
            auto simulated_time = record->animation_update_start_time + TICKS_TO_TIME(i);

            //auto origin = ((origin_per_tick * (float)i) + previous->origin);//Math::interpolate(previous->origin, previous->origin, record->origin, frac);
            auto velocity = /*velocity_speed_delta < 30.f ? */((velocity_per_tick * (float)i) + previous->velocity);//Math::interpolate(previous->velocity, previous->velocity, record->velocity, frac);
            //auto duck_amt = ((duck_amount_per_tick * i) + previous->duck_amt);//Math::interpolate(previous->duck_amt, previous->duck_amt, record->duck_amt, frac);

            if (record->duck_amount_per_tick != 0.0f)
            {
                auto v208 = ((record->duck_amt - m_player->m_flDuckAmount()) * record->duck_amount_per_tick)
                    + m_player->m_flDuckAmount();

                m_player->m_flDuckAmount() = fminf(fmaxf(v208, 0.0f), 1.0f);
            }

            if (i == record->lag)
                simulated_time = record->simulation_time;

            if (record->land_in_cycle && !record->is_landed) // landing animation fix
            {
                if (record->land_time < simulated_time) {
                    record->entity_anim_flags |= 1;
                    record->is_landed = true;
                    auto layer = &m_player->get_animation_layer(4);
                    layer->m_flCycle = 0;
                    layer->m_flWeight = 0;

                }
            }

            //}
            //else
            //    on_ground = record->entity_flags & FL_ONGROUND;

            m_player->m_fFlags() = record->entity_anim_flags;

            record->can_rotate = resolver_side != 0 && !log->saved_info.fakeplayer && i < record->lag && (!record->shot_this_tick || record->shot_this_tick && record->shot_time <= simulated_time);

            /*if (!(record->anim_layers[6].m_flCycle == 0.0f || previous->anim_layers[6].m_flCycle == 0.0f) && velocity.Length2D() <= 1.1f)
            {
                velocity.x = (i & 1 ? -1.1f : 1.1f);   
                velocity.y = 0.f;
                velocity.z = 0.f;
            }*/

            //if (record->shot_this_tick && record->shot_time <= simulated_time)
            //    m_player->m_angEyeAngles().y = resolver_info->last_non_shot_angle.y;
            //else
            //m_player->m_angEyeAngles() = record->eye_angles;

            if (record->shot_this_tick)
            {
                if (record->shot_time <= simulated_time) {
                    m_player->m_flThirdpersonRecoil() = record->thirdperson_recoil;
                    m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                }
            }

            //if (record->shot_this_tick && record->shot_time > simulated_time)

            //m_player->m_vecOrigin() = origin;
            //m_player->set_abs_origin(origin);
            if (i == record->lag)
            {
                m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
                m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                m_player->m_fFlags() = record->entity_flags;
            }

            m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = velocity;
            
            /*if (record->lower_body_yaw != previous->lower_body_yaw)
            {
                auto delta = record->lag - i;

                auto use_new = true;

                if (lby_delta < 1.f)
                    use_new = delta == 0;
                else
                    use_new = delta < 2;

                m_player->m_flLowerBodyYawTarget() = use_new ? record->lower_body_yaw : previous->lower_body_yaw;
            }*/

            //m_player->m_flLowerBodyYawTarget() = record->lby_flicked_time <= simulated_time ? record->lower_body_yaw : previous->lower_body_yaw;

            if (record->can_rotate) {
                auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

                float yaw = m_player->get_animation_state()->m_abs_yaw;

                if (resolver_side <= 0)
                    yaw = record->eye_angles.y - angle;
                else
                    yaw = record->eye_angles.y + angle;

                m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
            }
            
            /* update animations. */
            ctx.updating_resolver = true;
            //m_player->set_abs_origin(origin);
            //m_player->m_vecOrigin() = origin;
            resolver_info->new_velocity = velocity;
            resolver_info->force_velocity = true;

            auto realtime_backup = csgo.m_globals()->realtime;
            auto curtime = csgo.m_globals()->curtime;
            auto frametime = csgo.m_globals()->frametime;
            auto absoluteframetime = csgo.m_globals()->absoluteframetime;
            auto framecount = csgo.m_globals()->framecount;
            auto tickcount = csgo.m_globals()->tickcount;
            auto interpolation_amount = csgo.m_globals()->interpolation_amount;

            int ticks = TIME_TO_TICKS(simulated_time);

            csgo.m_globals()->realtime = simulated_time;
            csgo.m_globals()->curtime = simulated_time;
            csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->framecount = ticks;
            csgo.m_globals()->tickcount = ticks;
            csgo.m_globals()->interpolation_amount = 0.f;

            m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;
            m_player->update_clientside_animations();
            m_player->m_iEFlags() = backup_ieflags;
            resolver_info->force_velocity = false;
            ctx.updating_resolver = false;

            csgo.m_globals()->realtime = realtime_backup;
            csgo.m_globals()->curtime = curtime;
            csgo.m_globals()->frametime = frametime;
            csgo.m_globals()->absoluteframetime = absoluteframetime;
            csgo.m_globals()->framecount = framecount;
            csgo.m_globals()->tickcount = tickcount;
            csgo.m_globals()->interpolation_amount = interpolation_amount;
        }
    }
    else
    {
        m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
        auto vel = record->velocity;
        
        m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
        m_player->m_fFlags() = record->entity_flags;
        m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;

        if (!log->saved_info.fakeplayer && resolver_side != 0)
        {
            float yaw = m_player->get_animation_state()->m_abs_yaw;
            auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

            if (resolver_side <= 0)
                yaw = record->eye_angles.y - angle;
            else
                yaw = record->eye_angles.y + angle;

            m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
        }
        //if (m_player->get_animation_state()->m_abs_yaw < 0)
        //    m_player->get_animation_state()->m_abs_yaw += 360.f;

        auto realtime_backup = csgo.m_globals()->realtime;
        auto curtime = csgo.m_globals()->curtime;
        auto frametime = csgo.m_globals()->frametime;
        auto absoluteframetime = csgo.m_globals()->absoluteframetime;
        auto framecount = csgo.m_globals()->framecount;
        auto tickcount = csgo.m_globals()->tickcount;
        auto interpolation_amount = csgo.m_globals()->interpolation_amount;

        int ticks = TIME_TO_TICKS(record->simulation_time);

        csgo.m_globals()->realtime = record->simulation_time;
        csgo.m_globals()->curtime = record->simulation_time;
        csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->framecount = ticks;
        csgo.m_globals()->tickcount = ticks;
        csgo.m_globals()->interpolation_amount = 0.f;

        m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = vel;

        /* update animations. */
        ctx.updating_resolver = true;
        resolver_info->new_velocity = record->velocity;
        resolver_info->force_velocity = true;
        m_player->update_clientside_animations();
        resolver_info->force_velocity = false;
        ctx.updating_resolver = false;

        csgo.m_globals()->realtime = realtime_backup;
        csgo.m_globals()->curtime = curtime;
        csgo.m_globals()->frametime = frametime;
        csgo.m_globals()->absoluteframetime = absoluteframetime;
        csgo.m_globals()->framecount = framecount;
        csgo.m_globals()->tickcount = tickcount;
        csgo.m_globals()->interpolation_amount = interpolation_amount;
    }

    //m_player->set_abs_origin(abs_origin);
    m_player->m_fFlags() = backup_flags;
    //m_player->m_vecVelocity() = backup_m_velocity;
    m_player->m_flDuckAmount() = backup_duckamt;
    m_player->m_flLowerBodyYawTarget() = backup_lowerbody;
    m_player->m_iEFlags() = backup_ieflags;
    //m_player->m_angEyeAngles() = record->eye_angles;
    //m_player->m_flPoseParameter() = backup_poses;

    m_player->get_animation_state()->m_primary_cycle = backup_primary_cycle;
    m_player->get_animation_state()->m_move_weight = backup_move_weight;

    if (resolver_side != 0) {
        if (resolver_side > 0)
        {
            record->animstate_right_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_right_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_right_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_right_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_right_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_right_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_right_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_right_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
        else
        {
            record->animstate_left_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_left_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_left_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_left_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_left_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_left_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_left_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_left_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
    }

    /*if (previous && !record->first_after_dormancy && !previous->dormant && previous->data_filled)
        fix_jump_fall(m_player, record, previous);*/

    m_player->invalidate_anims(8);

#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;
#endif // VIRTUALIZER
}

void c_lagcomp::recalculate_velocity(C_Tickrecord* record, C_BasePlayer* m_player, C_Tickrecord* previous)
{
    VIRTUALIZER_FISH_LITE_START;

    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));
    static /*const*/ ConVar* sv_enablebunnyhopping = csgo.m_engine_cvars()->FindVar(sxor("sv_enablebunnyhopping"));

    auto log = &records[m_player->entindex() - 1];
    auto r_log = &feature::resolver->player_records[m_player->entindex() - 1];

    /* fix z velocity if enemy is in air. */
    /* https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/shared/gamemovement.cpp#L1697 */

    //auto& old_origin = *(Vector*)(uintptr_t(m_player) + 0x3A4);

    if (record->entity_flags & FL_ONGROUND
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight > 0.0f
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight < 1.0f)
    {
        // float val = clamp ( ( speed - 0.55f ) / ( 0.9f - 0.55f), 0.f, 1.f );
        // layer11_weight = 1.f - val;
        auto val = (1.0f - record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight) * 0.35f;

        if (val > 0.0f && val < 1.0f)
            record->animation_speed = val + 0.55f;
        else
            record->animation_speed = -1.f;
    }

    if (_fdtest(&record->velocity.x) > 0
        || _fdtest(&record->velocity.y) > 0
        || _fdtest(&record->velocity.z) > 0)
        record->velocity.clear();

    if (!record->first_after_dormancy && previous && !previous->dormant && previous->data_filled)
    {
        //
        //    calculate new velocity based on (new_origin - old_origin) / (new_time - old_time) formula.
        //
        if (record->lag > 1 && record->lag <= 20)
            record->velocity = (record->origin - previous->origin) / record->time_delta;
        
        if (abs(record->velocity.x) < 0.001f)
            record->velocity.x = 0.0f;
        if (abs(record->velocity.y) < 0.001f)
            record->velocity.y = 0.0f;
        if (abs(record->velocity.z) < 0.001f)
            record->velocity.z = 0.0f;

        if (_fdtest(&record->velocity.x) > 0
            || _fdtest(&record->velocity.y) > 0
            || _fdtest(&record->velocity.z) > 0)
            record->velocity.clear();

        auto curr_direction = RAD2DEG(std::atan2f(record->velocity.y, record->velocity.x));
        auto prev_direction = previous == nullptr ? FLT_MAX : RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

        auto delta = Math::normalize_angle(curr_direction - prev_direction);

        if (record->velocity.Length2D() > 0.1f) {
            if (previous->velocity.Length2D() > 0.1f && abs(delta) >= 60.f)
                r_log->last_time_changed_direction = csgo.m_globals()->realtime;
        }
        else
            r_log->last_time_changed_direction = 0;

        //
        // these requirements pass only when layer[6].weight is accurate to normalized velocity.
        //
        if (record->entity_flags & FL_ONGROUND
            && record->velocity.Length2D() >= 0.1f
            && std::abs(delta) < 1.0f
            && std::abs(record->duck_amt - previous->duck_amt) <= 0.0f
            && record->anim_layers[6].m_flPlaybackRate > previous->anim_layers[6].m_flPlaybackRate
            && record->anim_layers[6].m_flWeight > previous->anim_layers[6].m_flWeight)
        {
            auto weight_speed = record->anim_layers[6].m_flWeight;

            if (weight_speed <= 0.7f && weight_speed > 0.0f)
            {
                if (record->anim_layers[6].m_flPlaybackRate == 0.0f)
                    record->velocity.clear();
                else
                {
                    const auto m_post_velocity_lenght = record->velocity.Length2D();

                    if (m_post_velocity_lenght != 0.0f)
                    {
                        float mult = 1;
                        if (record->entity_flags & 6)
                            mult = 0.34f;
                        else if (record->fake_walking)
                            mult = 0.52f;

                        record->velocity.x = (record->velocity.x / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                        record->velocity.y = (record->velocity.y / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                    }
                }
            }
        }

        //
        // fix velocity with fakelag.
        //
        if (record->entity_flags & FL_ONGROUND && record->velocity.Length2D() > 0.1f && record->lag > 1)
        {
            //
            // get velocity lenght from 11th layer calc.
            //
            if (record->animation_speed > 0) {
                const auto m_pre_velocity_lenght = record->velocity.Length2D();
                C_WeaponCSBaseGun* weapon = m_player->get_weapon();

                if (weapon) {
                    auto wdata = weapon->GetCSWeaponData();
                    if (wdata) {
                        auto adjusted_velocity = (record->animation_speed * record->max_current_speed) / m_pre_velocity_lenght;
                        record->velocity.x *= adjusted_velocity;
                        record->velocity.y *= adjusted_velocity;
                    }
                }
            }

            /*if (record->entity_flags & FL_ONGROUND && (sv_enablebunnyhopping && !sv_enablebunnyhopping->GetBool() || previous->entity_flags & FL_ONGROUND)) {
                auto max_speed = record->max_current_speed;

                if (record->entity_flags & 6)
                    max_speed *= 0.34f;
                else if (record->fake_walking)
                    max_speed *= 0.52f;

                if (max_speed < m_pre_velocity_lenght)
                    record->velocity *= (max_speed / m_pre_velocity_lenght);

                if (previous->entity_flags & FL_ONGROUND)
                    record->velocity.z = 0.f;
            }*/
        }

        if (log->records_count > 2 && record->lag > 1 && !record->first_after_dormancy
            && previous->velocity.Length() > 0 && !(record->entity_flags & FL_ONGROUND && previous->entity_flags & FL_ONGROUND))
        {
            auto pre_pre_record = &log->tick_records[(log->records_count - 2) & 63];

            if (!pre_pre_record->dormant && pre_pre_record->data_filled) {
                //if (record->velocity.Length2D() > (record->max_current_speed * 0.52f) && previous->velocity.Length2D() > (record->max_current_speed * 0.52f)
                //    || record->velocity.Length2D() <= (record->max_current_speed * 0.52f) && previous->velocity.Length2D() <= (record->max_current_speed * 0.52f))
                //{
                //    auto manually_calculated = log->tick_records[(log->records_count - 2) & 63].stop_to_full_run_frac;
                //    manually_calculated += (record->velocity.Length2D() > (record->max_current_speed * 0.52f) ? (2.f * previous->time_delta) : -(2.f * previous->time_delta));

                //    manually_calculated = Math::clamp(manually_calculated, 0, 1);

                //    if (abs(manually_calculated - previous->stop_to_full_run_frac) >= 0.1f)// {
                //        m_player->get_animation_state()->m_walk_run_transition = manually_calculated;
                //}

                const auto prev_direction = RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

                auto real_velocity = record->velocity.Length2D();

                float delta = curr_direction - prev_direction;

                if (delta <= 180.0f)
                {
                    if (delta < -180.0f)
                        delta = delta + 360.0f;
                }#include "..\misc\misc.h"
#include "..\misc\logs.h"
#include "..\autowall\autowall.h"
#include "..\misc\prediction_system.h"
#include "..\fakewalk\slowwalk.h"
#include "..\lagcompensation\local_animations.h"

void aim::run(CUserCmd* cmd)
{
    backup.clear();
    targets.clear();
    scanned_targets.clear();
    final_target.reset();
    should_stop = false;

    if (!g_cfg.ragebot.enable)
        return;

    automatic_revolver(cmd);
    prepare_targets();

    if (g_ctx.globals.weapon->is_non_aim())
        return;

    if (g_ctx.globals.current_weapon == -1)
        return;

    scan_targets();

    if (!should_stop && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_PREDICTIVE])
    {
        for (auto& target : targets)
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data, g_ctx.globals.eye_pos);

            if (!last_data.valid())
                continue;

            should_stop = true;
            break;
        }
    }

    if (!automatic_stop(cmd))
        return;

    if (scanned_targets.empty())
        return;

    find_best_target();

    if (!final_target.data.valid())
        return;

    fire(cmd);
}

void aim::automatic_revolver(CUserCmd* cmd)
{
    if (!m_engine()->IsActiveApp())
        return;

    if (g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
        return;

    if (cmd->m_buttons & IN_ATTACK)
        return;

    cmd->m_buttons &= ~IN_ATTACK2;

    static auto r8cock_time = 0.0f;
    auto server_time = TICKS_TO_TIME(g_ctx.globals.backup_tickbase);

    if (g_ctx.globals.weapon->can_fire(false))
    {
        if (r8cock_time <= server_time)
        {
            if (g_ctx.globals.weapon->m_flNextSecondaryAttack() <= server_time)
                r8cock_time = server_time + TICKS_TO_TIME(13);
            else
                cmd->m_buttons |= IN_ATTACK2;
        }
        else
            cmd->m_buttons |= IN_ATTACK;
    }
    else
    {
        r8cock_time = server_time + TICKS_TO_TIME(13);
        cmd->m_buttons &= ~IN_ATTACK;
    }

    g_ctx.globals.revolver_working = true;
}

void aim::prepare_targets()
{
    for (auto i = 1; i < m_globals()->m_maxclients; i++)
    {
        if (g_cfg.player_list.white_list[i])
            continue;

        auto e = (player_t*)m_entitylist()->GetClientEntity(i);

        if (!e->valid(true, false))
            continue;

        auto records = &player_records[i];

        if (records->empty())
            continue;
    
        targets.emplace_back(target(e, get_record(records, false), get_record(records, true)));
    }

    for (auto& target : targets)
        backup.emplace_back(adjust_data(target.e));
}

static bool compare_records(const optimized_adjust_data& first, const optimized_adjust_data& second)
{
    if (first.shot != second.shot)
        return first.shot;
    else if (first.speed != second.speed)
        return first.speed > second.speed;

    return first.simulation_time < second.simulation_time;
}

adjust_data* aim::get_record(std::deque <adjust_data>* records, bool history)
{
    if (history)
    {
        std::deque <optimized_adjust_data> optimized_records;

        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);
            optimized_adjust_data optimized_record;

            optimized_record.i = i;
            optimized_record.player = record->player;
            optimized_record.simulation_time = record->simulation_time;
            optimized_record.speed = record->velocity.Length();
            optimized_record.shot = record->shot;

            optimized_records.emplace_back(optimized_record);
        }

        if (optimized_records.size() < 2)
            return nullptr;

        std::sort(optimized_records.begin(), optimized_records.end(), compare_records);

        for (auto& optimized_record : optimized_records)
        {
            auto record = &records->at(optimized_record.i);

            if (!record->valid())
                continue;

            return record;
        }
    }
    else
    {
        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);

            if (!record->valid())
                continue;

            return record;
        }
    }

    return nullptr;
}

int aim::get_minimum_damage(bool visible, int health)
{
    if (key_binds::get().get_key_bind_state(4))
    {
        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage > 100)
            return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage - 100;
        else
            return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage, 1, health);
    }
    else
    {
        if (visible)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage, 1, health);
        }
        else
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage, 1, health);
        }
    }
}

void aim::scan_targets()
{
    if (targets.empty())
        return;

    for (auto& target : targets)
    {
        if (target.history_record->valid())
        {
            scan_data last_data;

            if (target.last_record->valid())
            {
                target.last_record->adjust_player();
                scan(target.last_record, last_data);
            }

            scan_data history_data;

            target.history_record->adjust_player();
            scan(target.history_record, history_data);

            if (last_data.valid() && last_data.damage > history_data.damage)
                scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
            else if (history_data.valid())
                scanned_targets.emplace_back(scanned_target(target.history_record, history_data));
        }
        else
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data);

            if (!last_data.valid())
                continue;

            scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
        }
    }
}

bool aim::automatic_stop(CUserCmd* cmd)
{
    if (!should_stop)
        return true;

    if (g_ctx.globals.slowwalking)
        return true;

    if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND && engineprediction::get().backup_data.flags & FL_ONGROUND))
        return true;

    if (g_ctx.globals.weapon->is_empty())
        return true;

    if (!g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_BETWEEN_SHOTS] && !g_ctx.globals.weapon->can_fire(false))
        return true;

    auto animlayer = g_ctx.local()->get_animlayers()[1];

    if (animlayer.m_nSequence)
    {
        auto activity = g_ctx.local()->sequence_activity(animlayer.m_nSequence);

        if (activity == ACT_CSGO_RELOAD && animlayer.m_flWeight > 0.0f)
            return true;
    }

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

    if (!weapon_info)
        return true;

    auto max_speed = 0.33f * (g_ctx.globals.scoped ? weapon_info->flMaxPlayerSpeedAlt : weapon_info->flMaxPlayerSpeed);

    if (engineprediction::get().backup_data.velocity.Length2D() < max_speed)
        slowwalk::get().create_move(cmd);
    else
    {
        Vector direction;
        Vector real_view;

        math::vector_angles(engineprediction::get().backup_data.velocity, direction);
        m_engine()->GetViewAngles(real_view);

        direction.y = real_view.y - direction.y;

        Vector forward;
        math::angle_vectors(direction, forward);

        static auto cl_forwardspeed = m_cvar()->FindVar(crypt_str("cl_forwardspeed"));
        static auto cl_sidespeed = m_cvar()->FindVar(crypt_str("cl_sidespeed"));

        auto negative_forward_speed = -cl_forwardspeed->GetFloat();
        auto negative_side_speed = -cl_sidespeed->GetFloat();

        auto negative_forward_direction = forward * negative_forward_speed;
        auto negative_side_direction = forward * negative_side_speed;

        cmd->m_forwardmove = negative_forward_direction.x;
        cmd->m_sidemove = negative_side_direction.y;

        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_FORCE_ACCURACY])
            return false;
    }

    return true;
}

void aim::scan(adjust_data* record, scan_data& data, const Vector& shoot_position)
{
    if (!g_ctx.globals.weapon)
        return;

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

    if (!weapon_info)
        return;

    auto hitboxes = get_hitboxes(record);

    if (hitboxes.empty())
        return;

    auto best_damage = 0;

    auto minimum_damage = get_minimum_damage(false, record->player->m_iHealth());
    auto minimum_visible_damage = get_minimum_damage(true, record->player->m_iHealth());

    std::vector <scan_point> points;

    for (auto& hitbox : hitboxes)
    {
        auto current_points = get_points(record, hitbox);

        for (auto& point : current_points)
        {
            if ((g_ctx.globals.eye_pos - final_target.data.point.point).Length() <= weapon_info->flRange)
            {
                point.safe = record->bot || (hitbox_intersection(record->player, record->matrixes_data.positive, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.zero, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.negative, hitbox, shoot_position, point.point));
                if (!(key_binds::get().get_key_bind_state(3) || g_cfg.player_list.force_safe_points[record->i]) || point.safe)
                {
                    points.emplace_back(point);
                }
            }
        }
    }

    if (points.empty())
        return;

    for (auto& point : points)
    {
        if (!point.safe)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INAIR] && !(record->flags & FL_ONGROUND))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INCROUCH] && record->flags & FL_ONGROUND && record->flags & FL_DUCKING)
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_ONLIMBS] && (point.hitbox >= HITBOX_RIGHT_THIGH && point.hitbox < HITBOX_MAX))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_VISIBLE] && util::visible(g_ctx.globals.eye_pos, point.point, record->player, g_ctx.local()))
                continue;
        }

        if (point.hitbox < HITBOX_PELVIS || point.hitbox > HITBOX_UPPER_CHEST)
        {
            if (g_cfg.player_list.force_body_aim[record->i])
                continue;

            if (key_binds::get().get_key_bind_state(22))
                continue;
        }

        auto fire_data = autowall::get().wall_penetration(shoot_position, point.point, record->player);

        if (!fire_data.valid)
            continue;

        if (fire_data.damage < 1)
            continue;

        if (!fire_data.visible && !g_cfg.ragebot.autowall)
            continue;

        auto current_minimum_damage = fire_data.visible ? minimum_visible_damage : minimum_damage;

        if (fire_data.damage >= current_minimum_damage && fire_data.damage >= best_damage)
        {
            if (!should_stop)
            {
                should_stop = true;

                if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_LETHAL] && fire_data.damage < record->player->m_iHealth())
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_VISIBLE] && !fire_data.visible)
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_CENTER] && !point.center)
                    should_stop = false;
            }

            best_damage = fire_data.damage;

            data.point = point;
            data.visible = fire_data.visible;
            data.damage = fire_data.damage;
            data.hitbox = fire_data.hitbox;
        }
    }
}

std::vector <int> aim::get_hitboxes(adjust_data* record)
{
    std::vector <int> hitboxes;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(0))
        hitboxes.emplace_back(HITBOX_HEAD);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(1))
        hitboxes.emplace_back(HITBOX_UPPER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(2))
        hitboxes.emplace_back(HITBOX_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(3))
        hitboxes.emplace_back(HITBOX_LOWER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(4))
        hitboxes.emplace_back(HITBOX_STOMACH);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(5))
        hitboxes.emplace_back(HITBOX_PELVIS);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(6))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_UPPER_ARM);
        hitboxes.emplace_back(HITBOX_LEFT_UPPER_ARM);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(7))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_THIGH);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);

        hitboxes.emplace_back(HITBOX_RIGHT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(8))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_FOOT);
    }

    return hitboxes;
}

std::vector <scan_point> aim::get_points(adjust_data* record, int hitbox, bool from_aim)
{
    std::vector <scan_point> points;
    auto model = record->player->GetModel();

    if (!model)
        return points;

    auto hdr = m_modelinfo()->GetStudioModel(model);

    if (!hdr)
        return points;

    auto set = hdr->pHitboxSet(record->player->m_nHitboxSet());

    if (!set)
        return points;

    auto bbox = set->pHitbox(hitbox);

    if (!bbox)
        return points;

    const auto mod = bbox->radius != -1.0f ? bbox->radius : 0.0f;

    Vector max;
    Vector min;
    math::vector_transform(bbox->bbmax + mod, record->matrixes_data.main[bbox->bone], max);
    math::vector_transform(bbox->bbmin - mod, record->matrixes_data.main[bbox->bone], min);

    const auto center = (min + max) * 0.5f;

    points.emplace_back(scan_point(center, hitbox, true));

    if (!bbox->radius)
        return points;

    if (hitbox == HITBOX_NECK || hitbox == HITBOX_RIGHT_THIGH || hitbox == HITBOX_LEFT_THIGH || hitbox == HITBOX_RIGHT_CALF || hitbox == HITBOX_LEFT_CALF || hitbox == HITBOX_RIGHT_FOOT || hitbox == HITBOX_LEFT_FOOT || hitbox == HITBOX_RIGHT_HAND || hitbox == HITBOX_LEFT_HAND || hitbox == HITBOX_RIGHT_UPPER_ARM || hitbox == HITBOX_LEFT_UPPER_ARM || hitbox == HITBOX_RIGHT_FOREARM || hitbox == HITBOX_LEFT_FOREARM)
        return points;

    const auto cur_angles = math::calculate_angle(center, g_ctx.globals.eye_pos);

    Vector forward;
    math::angle_vectors(cur_angles, forward);

    auto rs = 0.0f;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].static_point_scale)
    {
        rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].body_scale;
        if (hitbox == HITBOX_HEAD)
            rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].head_scale;
    }
    else
    {
        auto transformed_center = center;
        math::vector_transform(transformed_center, record->matrixes_data.main[bbox->bone], transformed_center);

        auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;
        auto distance = transformed_center.DistTo(g_ctx.globals.eye_pos);

        distance /= math::fast_sin(DEG2RAD(90.0f - RAD2DEG(spread)));
        spread = math::fast_sin(spread);

        auto radius = max(bbox->radius - distance * spread, 0.0f);
        rs = bbox->radius * math::clamp(radius / bbox->radius, 0.0f, 1.0f);
    }

    if (rs < 0.2f)
        return points;

    const auto top = Vector(0, 0, 1) * rs;
    const auto right = forward.Cross(Vector(0, 0, 1)) * rs;
    const auto left = Vector(-right.x, -right.y, right.z);

    if (hitbox == HITBOX_HEAD)
        points.emplace_back(scan_point(center + top, hitbox, false));
    points.emplace_back(scan_point(center + right, hitbox, false));
    points.emplace_back(scan_point(center + left, hitbox, false));

    return points;
}

static bool compare_targets(const scanned_target& first, const scanned_target& second)
{
    if (g_cfg.player_list.high_priority[first.record->i] != g_cfg.player_list.high_priority[second.record->i])
        return g_cfg.player_list.high_priority[first.record->i];

    switch (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
    {
    case 1:
        return first.fov < second.fov;
    case 2:
        return first.distance < second.distance;
    case 3:
        return first.health < second.health;
    case 4:
        return first.data.damage > second.data.damage;
    }

    return false;
}

void aim::find_best_target()
{
    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
        std::sort(scanned_targets.begin(), scanned_targets.end(), compare_targets);

    for (auto& target : scanned_targets)
    {
        if (target.fov > (float)g_cfg.ragebot.field_of_view)
            continue;

        final_target = target;
        final_target.record->adjust_player();
        break;
    }
}

void aim::fire(CUserCmd* cmd)
{
    if (!g_ctx.globals.weapon->can_fire(true))
        return;

    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot && !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }

    auto backtrack_ticks = 0;
    auto net_channel_info = m_engine()->GetNetChannelInfo();

    if (net_channel_info)
    {
        auto original_tickbase = g_ctx.globals.backup_tickbase;
        auto max_tickbase_shift = m_gamerules()->m_bIsValveDS() ? 6 : 16;

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap && g_cfg.ragebot.double_tap_key.key > KEY_NONE && g_cfg.ragebot.double_tap_key.key < KEY_MAX && misc::get().double_tap_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().double_tap_enabled && !g_ctx.globals.weapon->is_grenade() && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_TASER && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap_shift_value, max_tickbase_shift);
            }
        }

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots && g_cfg.ragebot.hide_shots_key.key > KEY_NONE && g_cfg.ragebot.hide_shots_key.key < KEY_MAX && misc::get().hide_shots_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().hide_shots_enabled)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots_shift_value, max_tickbase_shift);
            }
        }

        static auto sv_maxunlag = m_cvar()->FindVar(crypt_str("sv_maxunlag"));

        auto correct = math::clamp(net_channel_info->GetLatency(FLOW_OUTGOING) + net_channel_info->GetLatency(FLOW_INCOMING) + util::get_interpolation(), 0.0f, sv_maxunlag->GetFloat());
        auto delta_time = correct - (TICKS_TO_TIME(original_tickbase) - final_target.record->simulation_time);

        backtrack_ticks = TIME_TO_TICKS(fabs(delta_time));
    }

    static auto get_hitbox_name = [](int hitbox) -> std::string
    {
        switch (hitbox)
        {
        case HITBOX_HEAD:
            return crypt_str("Head");
        case HITBOX_LOWER_CHEST:
            return crypt_str("Lower chest");
        case HITBOX_CHEST:
            return crypt_str("Chest");
        case HITBOX_UPPER_CHEST:
            return crypt_str("Upper chest");
        case HITBOX_STOMACH:
            return crypt_str("Stomach");
        case HITBOX_PELVIS:
            return crypt_str("Pelvis");
        case HITBOX_RIGHT_UPPER_ARM:
        case HITBOX_RIGHT_FOREARM:
        case HITBOX_RIGHT_HAND:
            return crypt_str("Left arm");
        case HITBOX_LEFT_UPPER_ARM:
        case HITBOX_LEFT_FOREARM:
        case HITBOX_LEFT_HAND:
            return crypt_str("Right arm");
        case HITBOX_RIGHT_THIGH:
        case HITBOX_RIGHT_CALF:
            return crypt_str("Left leg");
        case HITBOX_LEFT_THIGH:
        case HITBOX_LEFT_CALF:
            return crypt_str("Right leg");
        case HITBOX_RIGHT_FOOT:
            return crypt_str("Left foot");
        case HITBOX_LEFT_FOOT:
            return crypt_str("Right foot");
        }
    };

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                else
                {
                    delta = delta - 360.0f;
                }

        if (resolver_side == 0) {
            m_player->get_animation_state()->m_abs_yaw = previous->animstate.m_abs_yaw;
            m_player->get_animation_state()->m_abs_yaw_last = previous->animstate.m_abs_yaw_last;
            m_player->get_animation_state()->m_move_yaw = previous->animstate.m_move_yaw;
            m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate.m_move_yaw_ideal;
            m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate.m_move_yaw_current_to_ideal;
            m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate.m_move_weight_smoothed;
            m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate.m_in_air_smooth_value;
            m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate.m_time_to_align_lower_body;
        }
        else
        {
            if (resolver_side > 0)
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_right_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_right_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_right_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_right_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_right_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_right_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_right_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_right_params[7];
            }
            else
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_left_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_left_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_left_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_left_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_left_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_left_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_left_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_left_params[7];
            }
        }
            if (bestFov > FOVDistance)
            {
                bestFov = FOVDistance;
                bestTargetIndex = i;
            }
        }
    }bool c_lagcomp::has_firing_animation(C_BasePlayer* m_player, C_Tickrecord* record)
{
    auto weapon = m_player->get_weapon();
    if (weapon)
    {
        int iWeaponIndex = weapon->m_iItemDefinitionIndex();
        auto act = m_player->get_sec_activity(record->anim_layers[1].m_nSequence);
        if (act == ACT_CSGO_FIRE_PRIMARY || ((act == ACT_CSGO_FIRE_SECONDARY || act == ACT_CSGO_FIRE_SECONDARY_OPT_1 || act == ACT_CSGO_FIRE_SECONDARY_OPT_2) && (iWeaponIndex == WEAPON_GLOCK || iWeaponIndex == WEAPON_REVOLVER || iWeaponIndex == WEAPON_FAMAS || weapon->is_knife())))
            return true;
    }
    return false;
}

CBacktrack* backtracking = new CBacktrack();
legit_backtrackdata headPositions[64][12];
    float bestTargetSimTime;
    if (bestTargetIndex != -1)
    {
        float tempFloat = FLT_MAX;
        Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
        Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();

        for (int t = 0; t < 12; ++t)
        {
            float tempFOVDistance = point_to_line(headPositions[bestTargetIndex][t].hitboxPos, local_position, ViewDir);
            if (tempFloat > tempFOVDistance && headPositions[bestTargetIndex][t].simtime > local_player->GetSimTime() - 1)
            {
                tempFloat = tempFOVDistance;
                bestTargetSimTime = headPositions[bestTargetIndex][t].simtime;
            }
        }
        if (cmd->buttons & IN_ATTACK)
        {
            cmd->tick_count = TIME_TO_TICKS(bestTargetSimTime);
        }
    }
}
static void CreateFutureTicks(int entIndex)
{
    SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(entIndex);
    g_PlayerSettings[entIndex].averageSimTimeDelta = CalculateAverageSimtimeDelta(entIndex);
    SDK::INetChannelInfo* nci = INTERFACES::Engine->GetNetChannelInfo();
    if (nci->GetLatency(FLOW_OUTGOING) < g_PlayerSettings[entIndex].averageSimTimeDelta)
    {
        LagCompensation::m_PlayerTrack_Future[entIndex].clear();
        return;
    }
    //int predictAmount = ((nci->GetLatency(FLOW_OUTGOING) + nci->GetLatency(FLOW_INCOMING)) / INTERFACES::Globals->interval_per_tick) + 0.5f;
    //float predictionAngle = GetAverageMovementCurve(entIndex, ent);
    //float acceleration = GetAverageAcceleration(entIndex, ent);
    //Vector currentPosition = ent->GetVecOrigin();
    //Vector currentVelocity = ent->GetVelocity();
    //g_CVar->ConsoleDPrintf("Current velocity: %f %f %f\n", currentVelocity.x, currentVelocity.y, currentVelocity.z);
    SDK::CTraceWorldOnly filter;
    //LagRecord record = LagRecord(ent, nullptr);
    LagCompensation::m_PlayerTrack_Future[entIndex].clear();
    if (LagCompensation::m_PlayerTrack[entIndex].size() < 2)
        return;
    //Circle circles[5];
    //CreateCircles(circ
void C_Tickrecord::store(C_BasePlayer* player, bool backup)
{
    //if (player != nullptr)
    //{
        //auto activity = player->get_sec_activity(player->get_animation_layer(1).m_nSequence);
        //auto shot_bt = ((activity >= ACT_CSGO_FIRE_PRIMARY && activity <= ACT_CSGO_FIRE_SECONDARY_OPT_2) && player->get_animation_layer(1).m_flWeight > 0.01f && player->get_animation_layer(1).m_flCycle < 0.05f) || (player->get_weapon() && player->get_weapon()->m_Activity() == 208);

        //type = RECORD_NORMAL;

        //auto priority = ((activity == ACT_CSGO_RELOAD) && player->get_animation_layer(1).m_flWeight > 0.001f && player->get_animation_layer(1).m_flCycle < 1.f);
        shot_this_tick = false;
        valid = false;
        dormant = false;

        /*if (auto wpn = player->get_weapon(); wpn != nullptr)
            shot_time = wpn->m_flLastShotTime();
        else
            shot_time = 0;*/

        //if (priority)
        //    type = RECORD_PRIORITY;

        bones_count = player->m_bone_count();
        bones_count = Math::clamp(bones_count, 0, 128);

        if (backup) {
            memcpy(matrixes, player->m_CachedBoneData().Base(), bones_count * sizeof(matrix3x4_t));
            valid = false;
            dormant = false;
            animated = true;
            exploit = false;
        }
        //memcpy(leftmatrixes, feature::resolver->player_records[player->entindex() - 1].left_mx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightmatrixes, feature::resolver->player_records[player->entindex() - 1].right_mx, bones_count * sizeof(matrix3x4_t));

        //memcpy(leftlmatrixes, feature::resolver->player_records[player->entindex() - 1].left_lmx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightlmatrixes, feature::resolver->player_records[player->entindex() - 1].right_lmx, bones_count * sizeof(matrix3x4_t));

        //left_side = feature::resolver->player_records[player->entindex() - 1].left_side;
        //right_side = feature::resolver->player_records[player->entindex() - 1].right_side;

        //resolver_index = 0;

        origin = player->m_vecOrigin();
        abs_origin = player->get_abs_origin();
        velocity = player->m_vecVelocity();
        animation_time = feature::lagcomp->get_interpolated_time();
        object_mins = player->OBBMins();
        object_maxs = player->OBBMaxs();
        eye_angles = player->m_angEyeAngles();
        abs_angles = player->get_abs_angles().y;
        entity_flags = player->m_fFlags();
        simulation_time = player->m_flSimulationTime();
        simulation_time_old = player->m_flOldSimulationTime();
        lower_body_yaw = player->m_flLowerBodyYawTarget();
        time_of_last_injury = player->m_flTimeOfLastInjury();
        velocity_modifier = player->m_flVelocityModifier();
        //anim_velocity = player->m_vecVelocity();
        ientity_fl#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;}

void c_lagcomp::build_local_bones(C_BasePlayer* local)
{
    const auto dolboeb = local->m_flPoseParameter();
    local->force_bone_rebuild();
    local->m_flPoseParameter() = ctx.poses[ANGLE_REAL];
    local->set_abs_angles(QAngle(0, ctx.angles[ANGLE_REAL], 0));
    memcpy(ctx.m_local()->animation_layers_ptr(), ctx.local_layers[ANGLE_REAL], 0x38 * ctx.m_local()->get_animation_layers_count());
    /*cheat::main::setuped_bones = */local->SetupBonesEx();
    //memcpy(ctx.matrix, ctx.m_local()->m_CachedBoneData().Base(), min(128, ctx.m_local()->GetBoneCount()) * sizeof(matrix3x4_t));
    local->m_flPoseParameter() = dolboeb;
}

#endif // VIRTUALIZERags = player->m_iEFlags();
        duck_amt = player->m_flDuckAmount();
        ground_accel_last_time = player->m_flGroundAccelLinearFracLastTime();

        if (!backup)
            head_pos = player->get_bone_pos(8);
        if (!backup)
            desync_delta = feature::anti_aim->get_max_desync_delta(player);

        thirdperson_recoil = player->m_flThirdpersonRecoil();
        stop_to_full_run_frac = player->get_animation_state() ? player->get_animation_state()->m_walk_run_transition : 0.f;

        if (auto weapon = player->get_weapon(); weapon != nullptr && weapon)
            shot_time = weapon->m_flLastShotTime();
        else
            shot_time = -1;

        lag = TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime());

        // clamp it so we don't interpolate too far : )
        lag = Math::clamp(lag, 0, 31);

        time_delta = player->m_flSimulationTime() - player->m_flOldSimulationTime();

        if (*(void**)pla{
    //            if (cmd->buttons & IN_JUMP)
    //            {
    //                int sequence = is_moving ? 16 : 15;

    //                if (is_crouched)
    //                    sequence = is_moving ? 18 : 17;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }
    //            else
    //            {
    //                static int sequence = 14;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }

    //            m_flDurationInAir = 0;
    //        }
    //        else if (on_ground && !was_on_ground && !animstate->m_landing)
    //        {
    //            auto sequence = is_moving ? 22 : 20;

    //            if (is_crouched)
    //                sequence = is_moving ? 19 : 21;

    //            if (cmd->buttons & IN_JUMP)
    //                sequence = animstate->m_duration_in_air > 1 ? 24 : 23;

    //            jump_fall->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(jump_fall, sequence);
    //            jump_fall->m_nSequence = sequence;
    //            jump_fall->m_flCycle = jump_fall->m_flWeight = 0.f;

    //            /*anim_state->m_landing = true;
    //            anim_state->m_on_ground = true;
    //            anim_state->m_landed_on_ground_this_frame = true;
    //            anim_state->m_duration_in_air = 0.f;*/
    //            //ctx.fake_state.m_landing = true;
    //        }

    //        if ((!was_on_ground && on_ground) && !(cmd->buttons & IN_JUMP))
    //        {yer && player->get_animation_state())
            memcpy(&animstate, player->get_animation_state(), 0x334);
int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                spread_values[i][0] = a;
                spread_values[i][1] = c;

                auto sin_b = 0.0f, cos_b = 0.0f;
                DirectX::XMScalarSinCos(&sin_b, &cos_b, b);

                auto sin_d = 0.0f, cos_d = 0.0f;
                DirectX::XMScalarSinCos(&sin_d, &cos_d, d);

                spread_values[i][2] = sin_b;
                spread_values[i][3] = cos_b;
                spread_values[i][4] = sin_d;
                spread_values[i][5] = cos_d;
            }
        }

        auto hits = 0;

        for (auto i = 0; i < 256; ++i)
        {
            auto inaccuracy = spread_values[i][0] * g_ctx.globals.inaccuracy;
            auto spread = spread_values[i][1] * g_ctx.globals.spread;

            auto spread_x = spread_values[i][3] * inaccuracy + spread_values[i][5] * spread;
            auto spread_y = spread_values[i][2] * inaccuracy + spread_values[i][4] * spread;

            auto direction = ZERO;

            direction.x = forward.x + right.x * spread_x + up.x * spread_y;
            direction.y = forward.y + right.y * spread_x + up.y * spread_y;
            direction.z = forward.z + right.z * spread_x + up.z * spread_y;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
                ++hits;
        }

        final_hitchance = (int)((float)hits / 2.56f);
    }

    if (g_ctx.globals.double_tap_aim)
        return final_hitchance;

    auto damage = 0;
    auto high_accuracy_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;

    auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;

    for (auto i = 1; i <= 6; ++i)
    {
        for (auto j = 0; j < 8; ++j)
        {
            auto current_spread = spread * ((float)i / 6.0f);

            auto direction_cos = 0.0f;
            auto direction_sin = 0.0f;

            DirectX::XMScalarSinCos(&direction_cos, &direction_sin, (float)j / 8.0f * DirectX::XM_2PI);

            auto spread_x = direction_cos * current_spread;
            auto spread_y = direction_sin * current_spread;

            auto direction = ZERO;

            direction.x = forward.x + spread_x * right.x + spread_y * up.x;
            direction.y = forward.y + spread_x * right.y + spread_y * up.y;
            direction.z = forward.z + spread_x * right.z + spread_y * up.z;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
            {
                auto fire_data = autowall::get().wall_penetration(g_ctx.globals.eye_pos, end, final_target.record->player);
                auto valid_hitbox = true;

                if (final_target.data.hitbox == HITBOX_HEAD && fire_data.hitbox != HITBOX_HEAD)
                    valid_hitbox = false;

                if (fire_data.valid && fire_data.damage >= 1 && valid_hitbox)
                    damage += high_accuracy_weapon ? fire_data.damage : 1;
            }
        }
    }

    if (high_accuracy_weapon)
        return (float)damage / 48.0f >= get_minimum_damage(final_target.data.visible, final_target.health) ? final_hitchance : 0;

    return (float)damage / 48.0f >= (float)g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount * 0.01f ? final_hitchance : 0;
}

        /*pose_paramaters.fill(0);
        left_poses.fill(0);
        right_poses.fill(0);*/
        fill(begin(pose_paramaters), end(pose_paramaters), 0.f);
        if (!backup) {
            fill(begin(left_poses), end(left_poses), 0.f);
            fill(begi    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);&& !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }n(right_poses), end(right_poses), 0.f);
        }

        if (player->get_animation_layers_count() > 0)
            memcpy(anim_layers, player->animation_layers_ptr(), 0x38 * player->get_animation_layers_count());

        //*(&player->get_bone_accessor()->m_WritableBones + 8) = m_writable_bones;
        //readable_bones_count = player->GetBoneAccessor().m_ReadableBones;
        breaking_lc = false;

        tickcount = ctx.current_tickcount;
        simulation_time_delay = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick - TIME_TO_TICKS(player->m_flSimulationTime());

        lc_exploit = simulation_time_delay >= 12;

        if (csgo.m_client_state())
            m_tick = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick;

        latency = ctx.latency[FLOW_INCOMING];

        not_desyncing = false;
        data_filled = true;
    //}
}
les, entIndex);
    Vector deltaVec = Vector(0, 0, 0);
    Vector origin = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin;
    /*for (int o = 0; o < 5; o++)
    {
        Vector movementDirection = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecVelocity;
        movementDirection.z = 0;
        //deltaVec = -circles[o].center + origin;
        //QAngle deltaAngle;
        //Math::VectorAngles(deltaVec, deltaAngle);
        //if (deltaAngle.yaw > 180.f)
        //    deltaAngle.yaw -= 360.f;
        //movementDirection = Math::RotateVectorYaw(Vector(0, 0, 0), deltaAngle.yaw + 180, movementDirection);
        movementDirection.NormalizeInPlace();
        bool isGrounded = ent->GetFlags() & FL_ONGROUND;
        for (int i = 0; i < predictAmount; i++)
        {
            float omega = currentVelocity.Length2D() * circles[o].iRadius;
            float predictionAngle = circles[o].direction * RAD2DEG(omega * g_GlobalVars->interval_per_tick);
            //g_CVar->ConsoleDPrintf("Predicted angle: %f Center: %f %f Rad: %f Vel: %f Accel: %f VelZ: %f \n", predictionAngle, circles[o].center.x, circles[o].center.y, circles[o].radius, currentVelocity.Length(), acceleration, currentVelocity.z);
            currentVelocity = Math::RotateVectorYaw(Vector(0, 0, 0), predictionAngle, currentVelocity);
            movementDirection = currentVelocity;
            movementDirection.z = 0;
            movementDirection.NormalizeInPlace();
            currentVelocity.x += acceleration * movementDirection.x * g_GlobalVars->interval_per_tick;
            currentVelocity.y += acceleration * movementDirection.y * g_GlobalVars->interval_per_tick;
            Movement::PlayerMove(ent, currentPosition, currentVelocity, isGrounded, true, g_GlobalVars->interval_per_tick);
            LagCompensation::m_PlayerTrack_Future[entIndex].push_back(LagRecord(LagRecord(ent, nullptr), currentPosition, (i + 1) * g_GlobalVars->interval_per_tick));
        }*.
        break;
    }
}

void LagCompensation::CreateMove(SDK::CUserCmd* cmd)
{
    if (!INTERFACES::Engine->IsInGame())
        return;
    for (int i = 1; i < 65; ++i)
    {
        SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(i);
        auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
        if (!local_player)
            continue;
        if (!ent
            || ent == local_player
            || ent->GetIsDormant()
            || !ent->GetHealth() > 0) {
            m_PlayerTrack[i].clear();
            continue;
        }
        SDK::player_info_t entityInformation;
        INTERFACES::Engine->GetPlayerInfo(i, &entityInformation);
        if (m_PlayerTrack[i].size() > 0 && m_PlayerTrack[i].at(0).m_flSimulationTime == ent->GetSimTime())
            continue;
        if (m_PlayerTrack[i].size() >= MAX_RECORDS - 1)
            m_PlayerTrack[i].pop_back();
        /*if (m_PlayerTrack[i].size() >= 1) {
            g_PlayerSettings[i].lastSimTimeDelta = ent->GetSimTime() - m_PlayerTrack[i].at(0).m_flSimulationTime;
            g_PlayerSettings[i].breakingLC = (ent->GetVecOrigin() - m_PlayerTrack[i].at(0).m_vecOrigin).Length2DSqr() > 4096;
        }

        /*m_PlayerTrack[i].push_front(LagRecord(ent, cmd));
        if (aim_type == 2)
            CreateFutureTicks(i);
        //if (g_PlayerSettings[i].breakingLC && m_PlayerTrack_Future[i].size() == 0)
            //g_PlayerSettings[i].breakingLC = false;
    }
}
void LagCompensation::StartLagCompensation(SDK::CBaseEntity* player)
{
    if (m_pCurrentPlayer)
        return;
    matrix3x4_t boneMatrix[MAXSTUDIOBONES];
    ((SDK::CBaseAnimating*)player)->GetDirectBoneMatrix(boneMatrix);
    m_pCurrentPlayer = player;
    m_RestoreData = LagRecord(player, NULL);
    SDK::studiohdr_t *hdr = INTERFACES::ModelInfo->GetStudioModel(player->GetModel());
    if (!hdr)
        return;
    int size = hdr->numbones;
    for (int i = 0; i < size; i++)
        memcpy(m_RestoreData.boneMatrix + i, boneMatrix + i, sizeof(matrix3x4_t));
}
void LagCompensation::BacktrackPlayer(SDK::CBaseEntity* player, LagRecord record, bool setAngles)
{
    //Prevent the physics engine from culling the player
    if (setAngles)
    {
        player->SetAbsAngles(record.m_vecAngles);
        player->SetAbsOrigin(record.m_vecOrigin);
    }
    //Screw aiming at air with autowall especially, just tell the game what bonematrix to use
    ((SDK::CBaseAnimating*)player)->SetBoneMatrix(record.boneMatrix);
}
void LagCompensation::EndLagCompensation(SDK::CBaseEntity* player)
{
    m_pCurrentPlayer = nullptr;
    BacktrackPlayer(player, m_RestoreData);
}
template<class T> const T&
clamp(const T& x, const T& upper, const T& lower) { return min(upper, max(x, lower)); }
void resolver::resolve_yaw()
{
    player_info_t player_info;
    auto animstate = player->get_animation_state();

    if (!m_engine()->GetPlayerInfo(player->EntIndex(), &player_info) || !animstate || player_info.fakeplayer || g_cfg.player_list.disable_resolver[player_record->i] || !g_ctx.local()->is_alive() || player->m_iTeamNum() == g_ctx.local()->m_iTeamNum() || abs(TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime()) - 1) || player_record->shot)
    {
        player_record->side = RESOLVER_ORIGINAL;
        return;
    }

    if (g_ctx.globals.missed_shots[player->EntIndex()])
    {
        switch (last_side)
        {
        case RESOLVER_ORIGINAL:
            g_ctx.globals.missed_shots[player->EntIndex()] = 0;
            break;
        case RESOLVER_ZERO:
            player_record->side = RESOLVER_LOW_POSITIVE;

            was_first_bruteforce = false;
            was_second_bruteforce = false;
            return;
        case RESOLVER_POSITIVE:
            player_record->side = was_second_bruteforce ? RESOLVER_ZERO : RESOLVER_NEGATIVE;

            was_first_bruteforce = true;
            return;
        case RESOLVER_NEGATIVE:
            player_record->side = was_first_bruteforce ? RESOLVER_ZERO : RESOLVER_POSITIVE;

            was_second_bruteforce = true;
            return;
        case RESOLVER_LOW_POSITIVE:
            player_record->side = RESOLVER_LOW_NEGATIVE;
            return;
        case RESOLVER_LOW_NEGATIVE:
            player_record->side = RESOLVER_POSITIVE;
            return;
        }
    }

    auto valid_move = true;
    if (animstate->m_velocity > 0.1f)
    {
        valid_move = animstate->m_flTimeSinceStartedMoving < 0.22f;
    }

    if (valid_move && player_record->layers[3].m_flWeight == 0.f && player_record->layers[3].m_flCycle == 0.f && player_record->layers[6].m_flWeight == 0.f)
    {
        auto delta = math::angle_difference(player->m_angEyeAngles().y, zero_goal_feet_yaw);
        auto positive_resolver = (2 * (delta <= 0.0f) - 1) > 0;
        player_record->side = positive_resolver ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
    }
    else if (!valid_move &&    !(static_cast<int>(player_record->layers[12].m_flWeight * 1000.f)) && static_cast<int>(player_record->layers[6].m_flWeight * 1000.f) == static_cast<int>(previous_layers[6].m_flWeight * 1000.f))
    {
        auto delta_negative = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[0][6].m_flPlaybackRate);
        auto delta_zero = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[1][6].m_flPlaybackRate);
        auto delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate);

         if (delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate))

        if (delta_zero < delta_positive || delta_negative <= delta_positive || (delta_positive * 1000.f))
        {
            if (delta_zero >= delta_negative && delta_positive > delta_negative && !(delta_negative * 1000.f))
            {
                player_record->side = RESOLVER_POSITIVE;
            }
        }
        else
        {
            player_record->side = RESOLVER_NEGATIVE;
        }

float v25, v26, v27, v28
      if ( ( v25 - v26 ) <= v27 ) {
         if ( -v27 <= ( v25 - v26 ) )
            v28 = v25;
         else
            v28 = v26 - v27;
      } else {
         v28 = v26 + v27;
         player_record->lock_side = 1;
      }

      std::cout "rezolver mod 1 ";
      m_globals()->m_curtime;
      m_globals()->m_curtime;
      //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);
    }
    else
    {
        autowall::get().wall_penetration = m_globals()->m_curtime; // grenade prediction
        auto lby_update_de
        entity->SetEyeAngles(info.lby); // set final 6 layer lta = abs((((update_delta + 180) % 360 + 360) % 360 - 180));
        if (m_globals()->m_curtime - lock_side > 2.0f)
        {
            auto fire_data_positive = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.positive), player);
            auto fire_data_negative = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.negative), player);

            if (fire_data_positive.visible != fire_data_negative.visible)
            {
                player_record->side = fire_data_negative.visible ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                lock_side = m_globals()->m_curtime;
            }
            else
            {
                if (fire_data_positive.damage != fire_data_negative.damage)
                {
                    player_record->side = fire_data_negative.damage > fire_data_positive.damage ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                }
            }
            else if if if else (
                find_layer(1))
                - 67
            std::regex("final reziolver set4eed hlgjnv ");
            //XIAOMI HOOK MI MIX WARE BETA V4.LUA.JS.CC.COM
float for (std::vector<>::iterator i = .begin(); i != .end(); ++i)
{
    
}
fire_data_positive
was_first_bruteforce
    return;

    bool is_local_player = entity == local_player;
    bool is_teammate = local_player->GetTeam() == entity->GetTeam() && !is_local_player;

    if (is_local_player)
        return;

    if (is_teammate)
        return;

    if (entity->GetHealth() <= 0)
        return;

    if (local_player->GetHealth() <= 0)
        return;

    //--- Variable Declaration ---//;
    auto &info = player_info[entity->GetIndex()];

    //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);

    info.back = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 180.f, 0.f);
    info.right = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 70.f, 0.f);
    info.left = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y - 70.f, 0.f);

    info.backtrack = Vector(entity->GetEyeAngles().x, lby_to_back[entity->GetIndex()], 0.f);

    shots_missed[entity->GetIndex()] = shots_fired[entity->GetIndex()] - shots_hit[entity->GetIndex()];
    info.is_moving = entity->GetVelocity().Length2D() > 0.1 && entity->GetFlags() & FL_ONGROUND && !info.could_be_slowmo;
    info.is_jumping = !entity->GetFlags() & FL_ONGROUND;
    info.could_be_slowmo = entity->GetVelocity().Length2D() > 6 && entity->GetVelocity().Length2D() < 36 && !info.is_crouching;
    info.is_crouching = entity->GetFlags() & FL_DUCKING;
    update_time[entity->GetIndex()] = info.next_lby_update_time;

    static float old_simtime[65];
    if (entity->GetSimTime() != old_simtime[entity->GetIndex()])
    {
        using_fake_angles[entity->GetIndex()] = entity->GetSimTime() - old_simtime[entity->GetIndex()] == INTERFACES::Globals->interval_per_tick; entity->GetSimTime() - old_simtime[entity->GetIndex()] >= TICKS_TO_TIME(2);
        old_simtime[entity->GetIndex()] = entity->GetSimTime();
    }

    //--- Actual Angle Resolving ---//
    if (!using_fake_angles[entity->GetIndex()])
    {
        if (backtrack_tick[entity->GetIndex()])
        {
            resolve_type[entity->GetIndex()] = 7;
            entity->SetEyeAngles(info.backtrack);
        }
        else if (info.stored_lby != entity->GetLowerBodyYaw()) // || entity->GetSimTime() > info.next_lby_update_time) lby prediction
        {
            entity->GetSimTime() > info.next_lby_update_time;
            entity->SetEyeAngles(info.lby);
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            info.stored_lby = entity->GetLowerBodyYaw();
            resolve_type[entity->GetIndex()] = 3;
        }
        else if (info.is_jumping)
        {
            nospread_resolve(entity, entity->GetIndex());
        }
        else if (info.is_moving) //while moving
        {
            entity->SetEyeAngles(info.lby);
            info.last_moving_lby = entity->GetLowerBodyYaw();
            info.stored_missed = shots_missed[entity->GetIndex()];
            resolve_type[entity->GetIndex()] = 1;
        }
        else
        {
            if (shots_missed[entity->GetIndex()] > info.stored_missed) //if we have missed 1 shot since we have stopped moving
            {
                resolve_type[entity->GetIndex()] = 4;
                switch (shots_missed[entity->GetIndex()] % 4)
                {
                case 0: entity->SetEyeAngles(info.inverse); break;
                case 1: entity->SetEyeAngles(info.left); break;
                case 2: entity->SetEyeAngles(info.back); break;
                case 3: entity->SetEyeAngles(info.right); break;
                }
            }
            else //first thing we shoot when they stop
            {
                entity->SetEyeAngles(info.last_lby);
                resolve_type[entity->GetIndex()] = 5;
            }
        }
    }


    SDK::CAnimationLayer layer = entity->GetAnimOverlay(0);
    if (entity->GetSimTime() != info.stored_simtime)
    {
        info.stored_simtime = entity->GetSimTime();
        info.prev_layer = info.backup_layer;
        SDK::CAnimationLayer dummy;
        info.backup_layer = find_layer(entity, 979, &dummy) ? dummy : layer;
    }

    SDK::CAnimationLayer prev = info.prev_layer;
    auto server_time = local_player->GetTickBase() * INTERFACES::Globals->interval_per_tick; //i have a global dedicated to curtime but am using this because lemon is gay

    if (info.is_moving && !info.could_be_slowmo)
    {
        entity->SetEyeAngles(info.lby);
        info.last_moving_lby = entity->GetLowerBodyYaw();
        info.stored_missed = shots_missed[entity->GetIndex()];
        info.last_move_time = server_time;
        info.reset_state = true;
        resolve_type[entity->GetIndex()] = 1;
    }
    else
    {
        if (info.stored_lby != entity->GetLowerBodyYaw())
        {
            entity->SetEyeAngles(info.lby);
            info.stored_lby = entity->GetLowerBodyYaw();
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            resolve_type[entity->GetIndex()] = 7;
        }
        else if (server_time - info.last_move_time < 0.1 && info.reset_state)
        {
            info.pre_anim_lby = entity->GetLowerBodyYaw();
            info.reset_state = false;
            info.breaking_lby = false;
            //std::cout << "reset and lby break is false!" << std::endl;
        }
        auto previous_is_valid = entity->
        }
    }
}

float resolver::resolve_pitch()
{
    return original_pitch;
}
bool aim::hitbox_intersection(player_t* e, matrix3x4_t* matrix, int hitbox, const Vector& start, const Vector& end)
{
    // note: simv0l - pasted from r7 software.
    auto model = e->GetModel();

    if (!model)
        return false;

    auto studio_model = m_modelinfo()->GetStudioModel(model);

    if (!studio_model)
        return false;

    auto studio_set = studio_model->pHitboxSet(e->m_nHitboxSet());

    if (!studio_set)
        return false;

    auto studio_hitbox = studio_set->pHitbox(hitbox);

    if (!studio_hitbox)
        return false;

    Vector min, max;

    const auto is_capsule = studio_hitbox->radius != -1.f;

    if (is_capsule)
    {
        math::vector_transform(studio_hitbox->bbmin, matrix[studio_hitbox->bone], min);
        math::vector_transform(studio_hitbox->bbmax, matrix[studio_hitbox->bone], max);
        const auto dist = math::segment_to_segment(start, end, min, max);

        if (dist < studio_hitbox->radius)
            return true;
    }
    else
    {
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmin, studio_hitbox->rotation), matrix[studio_hitbox->bone], min);
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmax, studio_hitbox->rotation), matrix[studio_hitbox->bone], max);

        math::vector_i_transform(start, matrix[studio_hitbox->bone], min);
        math::vector_i_rotate(end, matrix[studio_hitbox->bone], max);

        if (math::intersect_line_with_bb(min, max, studio_hitbox->bbmin, studio_hitbox->bbmax))
            return true;
    }

    return false;
также девкор сурс
Пожалуйста, авторизуйтесь для просмотра ссылки.
Anko1337
 
09-29-2022 Thu 18:48:59
Эксперт
Статус
Оффлайн
Регистрация
28 Ноя 2019
Сообщения
1,225
Реакции[?]
413
Поинты[?]
110K
мой резольвер по анимациям проперный работает хорошо делал 30 лет


C++:
#include "animation_system.h"
#include "..\ragebot\aim.h"

void resolver::initialize(player_t* e, adjust_data* record, const float& goal_feet_yaw, const float& pitch)
{
    player = e;
    player_record = record;

    original_goal_feet_yaw = math::normalize_yaw(goal_feet_yaw);
    original_pitch = math::normalize_pitch(pitch);
}
Vector old_calcangle(Vector dst, Vector src)
{
    Vector angles;

    double delta[3] = { (src.x - dst.x), (src.y - dst.y), (src.z - dst.z) };
    double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
    angles.x = (float)(atan(delta[2] / hyp) * 180.0 / 3.14159265);
    angles.y = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
    angles.z = 0.0f;

    if (delta[0] >= 0.0)
    {
        angles.y += 180.0f;
    }

    return angles;
}

bool find_layer(SDK::CBaseEntity* entity, int act, SDK::CAnimationLayer *set)
{
    for (int i = 0; i < 13; i++)
    {
        SDK::CAnimationLayer layer = entity->GetAnimOverlay(i);
        const int activity = entity->GetSequenceActivity(layer.m_nSequence);
        if (activity == act) {
            *set = layer;
            return true;
        }
    }
    return false;
}

float old_normalize(float Yaw)
{
    if (Yaw > 180)
    {
        Yaw -= (round(Yaw / 360) * 360.f);
    }
    else if (Yaw < -180)
    {
        Yaw += (round(Yaw / 360) * -360.f);
    }
    return Yaw;
}
void resolver::reset()
{
    player = nullptr;
    player_record = nullptr;

    was_first_bruteforce = false;
    was_second_bruteforce = false;

    original_goal_feet_yaw = 0.0f;
    original_pitch = 0.0f;
}

#define TICK_INTERVAL            ( g_pGlobalVarsBase->interval_per_tick )

#define ROUND_TO_TICKS( t )        ( TICK_INTERVAL * TIME_TO_TICKS( t ) )

std::deque<LagRecord> LagCompensation::m_PlayerTrack[MAX_PLAYERS];
std::deque<LagRecord> LagCompensation::m_PlayerTrack_Future[MAX_PLAYERS];
LagRecord LagCompensation::m_RestoreData; //[MAX_PLAYERS];
SDK::CBaseEntity* LagCompensation::m_pCurrentPlayer;
#define LC_NONE                0
#define LC_ALIVE            (1<<0)
#define LC_ORIGIN_CHANGED    (1<<8)
#define LC_ANGLES_CHANGED    (1<<9)
#define LC_SIZE_CHANGED        (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)
static float GetAverageMovementCurve(int entIndex, SDK::CBaseEntity* ent)
{
    Vector p1 = Vector(0, 0, 0);
    Vector p2 = Vector(0, 0, 0);
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
    {
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ROTATION_CALC_TIME && i > 3)
            break;
        else if (i > 2)
        {
            float angle = 0;
            Vector a1, a2;
            MATH::VectorAngles(p1, a1);
            MATH::VectorAngles(p2, a2);
            if (a1.y < 0.0f)
                a1.y += 360.0f;
            if (a2.y < 0.0f)
                a2.y += 360.0f;
            angle = a2.y - a1.y;
            if (angle > 180.0f)
                angle -= 360.0f;
            ret += angle;
            ticks++;
        }
        p1 = p2;
        if (i > 0)
            p2 = (LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecOrigin - LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_vecOrigin);
        p2.z = 0;
        p2.NormalizeInPlace();
    }
    ret /= max(1, ticks);
    return ret;
}

static Vector GetMovementDirection(int entIndex, SDK::CBaseEntity* ent)
{
    Vector ret = Vector(0, 0, 0);
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > DIRECTION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity;
    ret /= max(1, ticks);
    return ret.NormalizeInPlace();
}

static float GetAverageAcceleration(int entIndex, SDK::CBaseEntity* ent)
{
    float vel = ent->GetVelocity().Length2D();
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ACCELERATION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity.Length2D() - vel;
    ret /= max(1, ticks);
    return ret;
}

static void CreateCircles(Circle circles[5], int entIndex)
{
    size_t size = LagCompensation::m_PlayerTrack[entIndex].size();
    if (size >= 3)
    {
        size = 0;
        for (size = 0; size < LagCompensation::m_PlayerTrack[entIndex].size(); size++)
        {
            if (g_GlobalVars->curtime - LagCompensation::m_PlayerTrack[entIndex].at(size).m_flSimulationTime > ROTATION_CALC_TIME && size > 3)
                break;
        }
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at((size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(2 * (size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(size - 1).m_vecOrigin);
    }
    else if (size >= 1) {
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin, 3604207201337.f, 1.f);
    }
}

static float CalculateAverageSimtimeDelta(int entIndex)
{
    float ret = 0;
    for (size_t i = 1; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        ret += LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_flSimulationTime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime;
    ret /= max(1, (int)LagCompensation::m_PlayerTrack[entIndex].size());
    return ret;
}void CBacktrack::run_legit(SDK::CUserCmd* cmd) //phook backtrack muahhahahahaaha
{
    int bestTargetIndex = -1;
    float bestFov = FLT_MAX;
    SDK::player_info_t info;

    auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());

    if (!local_player)
        return;

    for (int i = 1; i < 65; i++)
    {
        auto entity = INTERFACES::ClientEntityList->GetClientEntity(i);

        if (!entity)
            continue;

        if (entity == local_player)
            continue;

        if (!INTERFACES::Engine->GetPlayerInfo(i, &info))
            continue;

        if (entity->GetIsDormant())
            continue;

        if (entity->GetTeam() == local_player->GetTeam())
            continue;

        if (!local_player->GetHealth() > 0)
            return;

        if (entity->GetHealth() > 0)
        {
            float simtime = entity->GetSimTime();
            Vector hitboxPos = aimbot->get_hitbox_pos(entity, 0);

            headPositions[i][cmd->command_number % 12] = legit_backtrackdata{ simtime, hitboxPos };
            Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
            Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();
            float FOVDistance = point_to_line(hitboxPos, local_position, ViewDir);
    c_player_records* log = &records[m_player->entindex() - 1];

    if (previous && !previous->dormant && previous->data_filled && !record->first_after_dormancy)
    {
        m_player->get_animation_state()->m_primary_cycle = previous->m_primary_cycle;
        m_player->get_animation_state()->m_move_weight = previous->m_move_weight;

        m_player->get_animation_state()->m_strafe_sequence = previous->m_strafe_sequence;
        m_player->get_animation_state()->m_strafe_change_weight = previous->m_strafe_change_weight;
        m_player->get_animation_state()->m_strafe_change_cycle = previous->m_strafe_change_cycle;
        m_player->get_animation_state()->m_acceleration_weight = previous->m_acceleration_weight;
#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_START;
#endif // VIRTUALIZER

    const auto backup_flags = m_player->m_fFlags();
    const auto backup_ieflags = m_player->m_iEFlags();
    const auto backup_duckamt = m_player->m_flDuckAmount();
    const auto backup_lowerbody = m_player->m_flLowerBodyYawTarget();
    const auto backup_move_weight = m_player->get_animation_state()->m_move_weight;
    const auto backup_primary_cycle = m_player->get_animation_state()->m_primary_cycle;
   
    //const auto backup_poses = m_player->m_flPoseParameter();
    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));

    resolver_records* resolver_info = &feature::resolver->player_records[m_player->entindex() - 1];
    c_player_records* log = &records[m_player->entindex() - 1];

    //m_player->set_abs_angles(QAngle(0, record->eye_angles.y, 0));
    m_player->m_angEyeAngles() = record->eye_angles;
    m_player->m_angEyeAngles().z = 0.f;

    prepare_player_anim_update(m_player, record, previous, resolver_side);

    m_player->set_abs_angles(QAngle(0, m_player->get_animation_state()->m_abs_yaw, 0));

    if (record->lag > 1 && !log->saved_info.fakeplayer && previous && previous->data_filled)
    {
        const auto velocity_per_tick = (record->velocity - previous->velocity) / record->lag;
        //const auto origin_per_tick = (record->origin - previous->origin) / record->lag;
        //auto ticks_animated = 0;
        //auto velocity_speed_delta = abs(fmaxf(record->velocity.Length2D(),previous->velocity.Length2D()));

        const auto lby_delta = fabsf(Math::angle_diff(record->eye_angles.y, record->lower_body_yaw));

        record->is_landed = false;

        for (auto i = 1; i <= record->lag; i++)
        {
            auto simulated_time = record->animation_update_start_time + TICKS_TO_TIME(i);

            //auto origin = ((origin_per_tick * (float)i) + previous->origin);//Math::interpolate(previous->origin, previous->origin, record->origin, frac);
            auto velocity = /*velocity_speed_delta < 30.f ? */((velocity_per_tick * (float)i) + previous->velocity);//Math::interpolate(previous->velocity, previous->velocity, record->velocity, frac);
            //auto duck_amt = ((duck_amount_per_tick * i) + previous->duck_amt);//Math::interpolate(previous->duck_amt, previous->duck_amt, record->duck_amt, frac);

            if (record->duck_amount_per_tick != 0.0f)
            {
                auto v208 = ((record->duck_amt - m_player->m_flDuckAmount()) * record->duck_amount_per_tick)
                    + m_player->m_flDuckAmount();

                m_player->m_flDuckAmount() = fminf(fmaxf(v208, 0.0f), 1.0f);
            }

            if (i == record->lag)
                simulated_time = record->simulation_time;

            if (record->land_in_cycle && !record->is_landed) // landing animation fix
            {
                if (record->land_time < simulated_time) {
                    record->entity_anim_flags |= 1;
                    record->is_landed = true;
                    auto layer = &m_player->get_animation_layer(4);
                    layer->m_flCycle = 0;
                    layer->m_flWeight = 0;

                }
            }

            //}
            //else
            //    on_ground = record->entity_flags & FL_ONGROUND;

            m_player->m_fFlags() = record->entity_anim_flags;

            record->can_rotate = resolver_side != 0 && !log->saved_info.fakeplayer && i < record->lag && (!record->shot_this_tick || record->shot_this_tick && record->shot_time <= simulated_time);

            /*if (!(record->anim_layers[6].m_flCycle == 0.0f || previous->anim_layers[6].m_flCycle == 0.0f) && velocity.Length2D() <= 1.1f)
            {
                velocity.x = (i & 1 ? -1.1f : 1.1f);  
                velocity.y = 0.f;
                velocity.z = 0.f;
            }*/

            //if (record->shot_this_tick && record->shot_time <= simulated_time)
            //    m_player->m_angEyeAngles().y = resolver_info->last_non_shot_angle.y;
            //else
            //m_player->m_angEyeAngles() = record->eye_angles;

            if (record->shot_this_tick)
            {
                if (record->shot_time <= simulated_time) {
                    m_player->m_flThirdpersonRecoil() = record->thirdperson_recoil;
                    m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                }
            }

            //if (record->shot_this_tick && record->shot_time > simulated_time)

            //m_player->m_vecOrigin() = origin;
            //m_player->set_abs_origin(origin);
            if (i == record->lag)
            {
                m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
                m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                m_player->m_fFlags() = record->entity_flags;
            }

            m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = velocity;
           
            /*if (record->lower_body_yaw != previous->lower_body_yaw)
            {
                auto delta = record->lag - i;

                auto use_new = true;

                if (lby_delta < 1.f)
                    use_new = delta == 0;
                else
                    use_new = delta < 2;

                m_player->m_flLowerBodyYawTarget() = use_new ? record->lower_body_yaw : previous->lower_body_yaw;
            }*/

            //m_player->m_flLowerBodyYawTarget() = record->lby_flicked_time <= simulated_time ? record->lower_body_yaw : previous->lower_body_yaw;

            if (record->can_rotate) {
                auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

                float yaw = m_player->get_animation_state()->m_abs_yaw;

                if (resolver_side <= 0)
                    yaw = record->eye_angles.y - angle;
                else
                    yaw = record->eye_angles.y + angle;

                m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
            }
           
            /* update animations. */
            ctx.updating_resolver = true;
            //m_player->set_abs_origin(origin);
            //m_player->m_vecOrigin() = origin;
            resolver_info->new_velocity = velocity;
            resolver_info->force_velocity = true;

            auto realtime_backup = csgo.m_globals()->realtime;
            auto curtime = csgo.m_globals()->curtime;
            auto frametime = csgo.m_globals()->frametime;
            auto absoluteframetime = csgo.m_globals()->absoluteframetime;
            auto framecount = csgo.m_globals()->framecount;
            auto tickcount = csgo.m_globals()->tickcount;
            auto interpolation_amount = csgo.m_globals()->interpolation_amount;

            int ticks = TIME_TO_TICKS(simulated_time);

            csgo.m_globals()->realtime = simulated_time;
            csgo.m_globals()->curtime = simulated_time;
            csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->framecount = ticks;
            csgo.m_globals()->tickcount = ticks;
            csgo.m_globals()->interpolation_amount = 0.f;

            m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;
            m_player->update_clientside_animations();
            m_player->m_iEFlags() = backup_ieflags;
            resolver_info->force_velocity = false;
            ctx.updating_resolver = false;

            csgo.m_globals()->realtime = realtime_backup;
            csgo.m_globals()->curtime = curtime;
            csgo.m_globals()->frametime = frametime;
            csgo.m_globals()->absoluteframetime = absoluteframetime;
            csgo.m_globals()->framecount = framecount;
            csgo.m_globals()->tickcount = tickcount;
            csgo.m_globals()->interpolation_amount = interpolation_amount;
        }
    }
    else
    {
        m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
        auto vel = record->velocity;
       
        m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
        m_player->m_fFlags() = record->entity_flags;
        m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;

        if (!log->saved_info.fakeplayer && resolver_side != 0)
        {
            float yaw = m_player->get_animation_state()->m_abs_yaw;
            auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

            if (resolver_side <= 0)
                yaw = record->eye_angles.y - angle;
            else
                yaw = record->eye_angles.y + angle;

            m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
        }
        //if (m_player->get_animation_state()->m_abs_yaw < 0)
        //    m_player->get_animation_state()->m_abs_yaw += 360.f;

        auto realtime_backup = csgo.m_globals()->realtime;
        auto curtime = csgo.m_globals()->curtime;
        auto frametime = csgo.m_globals()->frametime;
        auto absoluteframetime = csgo.m_globals()->absoluteframetime;
        auto framecount = csgo.m_globals()->framecount;
        auto tickcount = csgo.m_globals()->tickcount;
        auto interpolation_amount = csgo.m_globals()->interpolation_amount;

        int ticks = TIME_TO_TICKS(record->simulation_time);

        csgo.m_globals()->realtime = record->simulation_time;
        csgo.m_globals()->curtime = record->simulation_time;
        csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->framecount = ticks;
        csgo.m_globals()->tickcount = ticks;
        csgo.m_globals()->interpolation_amount = 0.f;

        m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = vel;

        /* update animations. */
        ctx.updating_resolver = true;
        resolver_info->new_velocity = record->velocity;
        resolver_info->force_velocity = true;
        m_player->update_clientside_animations();
        resolver_info->force_velocity = false;
        ctx.updating_resolver = false;

        csgo.m_globals()->realtime = realtime_backup;
        csgo.m_globals()->curtime = curtime;
        csgo.m_globals()->frametime = frametime;
        csgo.m_globals()->absoluteframetime = absoluteframetime;
        csgo.m_globals()->framecount = framecount;
        csgo.m_globals()->tickcount = tickcount;
        csgo.m_globals()->interpolation_amount = interpolation_amount;
    }

    //m_player->set_abs_origin(abs_origin);
    m_player->m_fFlags() = backup_flags;
    //m_player->m_vecVelocity() = backup_m_velocity;
    m_player->m_flDuckAmount() = backup_duckamt;
    m_player->m_flLowerBodyYawTarget() = backup_lowerbody;
    m_player->m_iEFlags() = backup_ieflags;
    //m_player->m_angEyeAngles() = record->eye_angles;
    //m_player->m_flPoseParameter() = backup_poses;

    m_player->get_animation_state()->m_primary_cycle = backup_primary_cycle;
    m_player->get_animation_state()->m_move_weight = backup_move_weight;

    if (resolver_side != 0) {
        if (resolver_side > 0)
        {
            record->animstate_right_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_right_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_right_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_right_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_right_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_right_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_right_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_right_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
        else
        {
            record->animstate_left_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_left_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_left_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_left_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_left_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_left_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_left_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_left_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
    }

    /*if (previous && !record->first_after_dormancy && !previous->dormant && previous->data_filled)
        fix_jump_fall(m_player, record, previous);*/

    m_player->invalidate_anims(8);

#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;
#endif // VIRTUALIZER
}

void c_lagcomp::recalculate_velocity(C_Tickrecord* record, C_BasePlayer* m_player, C_Tickrecord* previous)
{
    VIRTUALIZER_FISH_LITE_START;

    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));
    static /*const*/ ConVar* sv_enablebunnyhopping = csgo.m_engine_cvars()->FindVar(sxor("sv_enablebunnyhopping"));

    auto log = &records[m_player->entindex() - 1];
    auto r_log = &feature::resolver->player_records[m_player->entindex() - 1];

    /* fix z velocity if enemy is in air. */
    /* https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/shared/gamemovement.cpp#L1697 */

    //auto& old_origin = *(Vector*)(uintptr_t(m_player) + 0x3A4);

    if (record->entity_flags & FL_ONGROUND
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight > 0.0f
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight < 1.0f)
    {
        // float val = clamp ( ( speed - 0.55f ) / ( 0.9f - 0.55f), 0.f, 1.f );
        // layer11_weight = 1.f - val;
        auto val = (1.0f - record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight) * 0.35f;

        if (val > 0.0f && val < 1.0f)
            record->animation_speed = val + 0.55f;
        else
            record->animation_speed = -1.f;
    }

    if (_fdtest(&record->velocity.x) > 0
        || _fdtest(&record->velocity.y) > 0
        || _fdtest(&record->velocity.z) > 0)
        record->velocity.clear();

    if (!record->first_after_dormancy && previous && !previous->dormant && previous->data_filled)
    {
        //
        //    calculate new velocity based on (new_origin - old_origin) / (new_time - old_time) formula.
        //
        if (record->lag > 1 && record->lag <= 20)
            record->velocity = (record->origin - previous->origin) / record->time_delta;
       
        if (abs(record->velocity.x) < 0.001f)
            record->velocity.x = 0.0f;
        if (abs(record->velocity.y) < 0.001f)
            record->velocity.y = 0.0f;
        if (abs(record->velocity.z) < 0.001f)
            record->velocity.z = 0.0f;

        if (_fdtest(&record->velocity.x) > 0
            || _fdtest(&record->velocity.y) > 0
            || _fdtest(&record->velocity.z) > 0)
            record->velocity.clear();

        auto curr_direction = RAD2DEG(std::atan2f(record->velocity.y, record->velocity.x));
        auto prev_direction = previous == nullptr ? FLT_MAX : RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

        auto delta = Math::normalize_angle(curr_direction - prev_direction);

        if (record->velocity.Length2D() > 0.1f) {
            if (previous->velocity.Length2D() > 0.1f && abs(delta) >= 60.f)
                r_log->last_time_changed_direction = csgo.m_globals()->realtime;
        }
        else
            r_log->last_time_changed_direction = 0;

        //
        // these requirements pass only when layer[6].weight is accurate to normalized velocity.
        //
        if (record->entity_flags & FL_ONGROUND
            && record->velocity.Length2D() >= 0.1f
            && std::abs(delta) < 1.0f
            && std::abs(record->duck_amt - previous->duck_amt) <= 0.0f
            && record->anim_layers[6].m_flPlaybackRate > previous->anim_layers[6].m_flPlaybackRate
            && record->anim_layers[6].m_flWeight > previous->anim_layers[6].m_flWeight)
        {
            auto weight_speed = record->anim_layers[6].m_flWeight;

            if (weight_speed <= 0.7f && weight_speed > 0.0f)
            {
                if (record->anim_layers[6].m_flPlaybackRate == 0.0f)
                    record->velocity.clear();
                else
                {
                    const auto m_post_velocity_lenght = record->velocity.Length2D();

                    if (m_post_velocity_lenght != 0.0f)
                    {
                        float mult = 1;
                        if (record->entity_flags & 6)
                            mult = 0.34f;
                        else if (record->fake_walking)
                            mult = 0.52f;

                        record->velocity.x = (record->velocity.x / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                        record->velocity.y = (record->velocity.y / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                    }
                }
            }
        }

        //
        // fix velocity with fakelag.
        //
        if (record->entity_flags & FL_ONGROUND && record->velocity.Length2D() > 0.1f && record->lag > 1)
        {
            //
            // get velocity lenght from 11th layer calc.
            //
            if (record->animation_speed > 0) {
                const auto m_pre_velocity_lenght = record->velocity.Length2D();
                C_WeaponCSBaseGun* weapon = m_player->get_weapon();

                if (weapon) {
                    auto wdata = weapon->GetCSWeaponData();
                    if (wdata) {
                        auto adjusted_velocity = (record->animation_speed * record->max_current_speed) / m_pre_velocity_lenght;
                        record->velocity.x *= adjusted_velocity;
                        record->velocity.y *= adjusted_velocity;
                    }
                }
            }

            /*if (record->entity_flags & FL_ONGROUND && (sv_enablebunnyhopping && !sv_enablebunnyhopping->GetBool() || previous->entity_flags & FL_ONGROUND)) {
                auto max_speed = record->max_current_speed;

                if (record->entity_flags & 6)
                    max_speed *= 0.34f;
                else if (record->fake_walking)
                    max_speed *= 0.52f;

                if (max_speed < m_pre_velocity_lenght)
                    record->velocity *= (max_speed / m_pre_velocity_lenght);

                if (previous->entity_flags & FL_ONGROUND)
                    record->velocity.z = 0.f;
            }*/
        }

        if (log->records_count > 2 && record->lag > 1 && !record->first_after_dormancy
            && previous->velocity.Length() > 0 && !(record->entity_flags & FL_ONGROUND && previous->entity_flags & FL_ONGROUND))
        {
            auto pre_pre_record = &log->tick_records[(log->records_count - 2) & 63];

            if (!pre_pre_record->dormant && pre_pre_record->data_filled) {
                //if (record->velocity.Length2D() > (record->max_current_speed * 0.52f) && previous->velocity.Length2D() > (record->max_current_speed * 0.52f)
                //    || record->velocity.Length2D() <= (record->max_current_speed * 0.52f) && previous->velocity.Length2D() <= (record->max_current_speed * 0.52f))
                //{
                //    auto manually_calculated = log->tick_records[(log->records_count - 2) & 63].stop_to_full_run_frac;
                //    manually_calculated += (record->velocity.Length2D() > (record->max_current_speed * 0.52f) ? (2.f * previous->time_delta) : -(2.f * previous->time_delta));

                //    manually_calculated = Math::clamp(manually_calculated, 0, 1);

                //    if (abs(manually_calculated - previous->stop_to_full_run_frac) >= 0.1f)// {
                //        m_player->get_animation_state()->m_walk_run_transition = manually_calculated;
                //}

                const auto prev_direction = RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

                auto real_velocity = record->velocity.Length2D();

                float delta = curr_direction - prev_direction;

                if (delta <= 180.0f)
                {
                    if (delta < -180.0f)
                        delta = delta + 360.0f;
                }#include "..\misc\misc.h"
#include "..\misc\logs.h"
#include "..\autowall\autowall.h"
#include "..\misc\prediction_system.h"
#include "..\fakewalk\slowwalk.h"
#include "..\lagcompensation\local_animations.h"

void aim::run(CUserCmd* cmd)
{
    backup.clear();
    targets.clear();
    scanned_targets.clear();
    final_target.reset();
    should_stop = false;

    if (!g_cfg.ragebot.enable)
        return;

    automatic_revolver(cmd);
    prepare_targets();

    if (g_ctx.globals.weapon->is_non_aim())
        return;

    if (g_ctx.globals.current_weapon == -1)
        return;

    scan_targets();

    if (!should_stop && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_PREDICTIVE])
    {
        for (auto& target : targets)
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data, g_ctx.globals.eye_pos);

            if (!last_data.valid())
                continue;

            should_stop = true;
            break;
        }
    }

    if (!automatic_stop(cmd))
        return;

    if (scanned_targets.empty())
        return;

    find_best_target();

    if (!final_target.data.valid())
        return;

    fire(cmd);
}

void aim::automatic_revolver(CUserCmd* cmd)
{
    if (!m_engine()->IsActiveApp())
        return;

    if (g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
        return;

    if (cmd->m_buttons & IN_ATTACK)
        return;

    cmd->m_buttons &= ~IN_ATTACK2;

    static auto r8cock_time = 0.0f;
    auto server_time = TICKS_TO_TIME(g_ctx.globals.backup_tickbase);

    if (g_ctx.globals.weapon->can_fire(false))
    {
        if (r8cock_time <= server_time)
        {
            if (g_ctx.globals.weapon->m_flNextSecondaryAttack() <= server_time)
                r8cock_time = server_time + TICKS_TO_TIME(13);
            else
                cmd->m_buttons |= IN_ATTACK2;
        }
        else
            cmd->m_buttons |= IN_ATTACK;
    }
    else
    {
        r8cock_time = server_time + TICKS_TO_TIME(13);
        cmd->m_buttons &= ~IN_ATTACK;
    }

    g_ctx.globals.revolver_working = true;
}

void aim::prepare_targets()
{
    for (auto i = 1; i < m_globals()->m_maxclients; i++)
    {
        if (g_cfg.player_list.white_list[i])
            continue;

        auto e = (player_t*)m_entitylist()->GetClientEntity(i);

        if (!e->valid(true, false))
            continue;

        auto records = &player_records[i];

        if (records->empty())
            continue;
   
        targets.emplace_back(target(e, get_record(records, false), get_record(records, true)));
    }

    for (auto& target : targets)
        backup.emplace_back(adjust_data(target.e));
}

static bool compare_records(const optimized_adjust_data& first, const optimized_adjust_data& second)
{
    if (first.shot != second.shot)
        return first.shot;
    else if (first.speed != second.speed)
        return first.speed > second.speed;

    return first.simulation_time < second.simulation_time;
}

adjust_data* aim::get_record(std::deque <adjust_data>* records, bool history)
{
    if (history)
    {
        std::deque <optimized_adjust_data> optimized_records;

        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);
            optimized_adjust_data optimized_record;

            optimized_record.i = i;
            optimized_record.player = record->player;
            optimized_record.simulation_time = record->simulation_time;
            optimized_record.speed = record->velocity.Length();
            optimized_record.shot = record->shot;

            optimized_records.emplace_back(optimized_record);
        }

        if (optimized_records.size() < 2)
            return nullptr;

        std::sort(optimized_records.begin(), optimized_records.end(), compare_records);

        for (auto& optimized_record : optimized_records)
        {
            auto record = &records->at(optimized_record.i);

            if (!record->valid())
                continue;

            return record;
        }
    }
    else
    {
        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);

            if (!record->valid())
                continue;

            return record;
        }
    }

    return nullptr;
}

int aim::get_minimum_damage(bool visible, int health)
{
    if (key_binds::get().get_key_bind_state(4))
    {
        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage > 100)
            return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage - 100;
        else
            return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage, 1, health);
    }
    else
    {
        if (visible)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage, 1, health);
        }
        else
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage, 1, health);
        }
    }
}

void aim::scan_targets()
{
    if (targets.empty())
        return;

    for (auto& target : targets)
    {
        if (target.history_record->valid())
        {
            scan_data last_data;

            if (target.last_record->valid())
            {
                target.last_record->adjust_player();
                scan(target.last_record, last_data);
            }

            scan_data history_data;

            target.history_record->adjust_player();
            scan(target.history_record, history_data);

            if (last_data.valid() && last_data.damage > history_data.damage)
                scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
            else if (history_data.valid())
                scanned_targets.emplace_back(scanned_target(target.history_record, history_data));
        }
        else
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data);

            if (!last_data.valid())
                continue;

            scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
        }
    }
}

bool aim::automatic_stop(CUserCmd* cmd)
{
    if (!should_stop)
        return true;

    if (g_ctx.globals.slowwalking)
        return true;

    if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND && engineprediction::get().backup_data.flags & FL_ONGROUND))
        return true;

    if (g_ctx.globals.weapon->is_empty())
        return true;

    if (!g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_BETWEEN_SHOTS] && !g_ctx.globals.weapon->can_fire(false))
        return true;

    auto animlayer = g_ctx.local()->get_animlayers()[1];

    if (animlayer.m_nSequence)
    {
        auto activity = g_ctx.local()->sequence_activity(animlayer.m_nSequence);

        if (activity == ACT_CSGO_RELOAD && animlayer.m_flWeight > 0.0f)
            return true;
    }

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

    if (!weapon_info)
        return true;

    auto max_speed = 0.33f * (g_ctx.globals.scoped ? weapon_info->flMaxPlayerSpeedAlt : weapon_info->flMaxPlayerSpeed);

    if (engineprediction::get().backup_data.velocity.Length2D() < max_speed)
        slowwalk::get().create_move(cmd);
    else
    {
        Vector direction;
        Vector real_view;

        math::vector_angles(engineprediction::get().backup_data.velocity, direction);
        m_engine()->GetViewAngles(real_view);

        direction.y = real_view.y - direction.y;

        Vector forward;
        math::angle_vectors(direction, forward);

        static auto cl_forwardspeed = m_cvar()->FindVar(crypt_str("cl_forwardspeed"));
        static auto cl_sidespeed = m_cvar()->FindVar(crypt_str("cl_sidespeed"));

        auto negative_forward_speed = -cl_forwardspeed->GetFloat();
        auto negative_side_speed = -cl_sidespeed->GetFloat();

        auto negative_forward_direction = forward * negative_forward_speed;
        auto negative_side_direction = forward * negative_side_speed;

        cmd->m_forwardmove = negative_forward_direction.x;
        cmd->m_sidemove = negative_side_direction.y;

        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_FORCE_ACCURACY])
            return false;
    }

    return true;
}

void aim::scan(adjust_data* record, scan_data& data, const Vector& shoot_position)
{
    if (!g_ctx.globals.weapon)
        return;

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

    if (!weapon_info)
        return;

    auto hitboxes = get_hitboxes(record);

    if (hitboxes.empty())
        return;

    auto best_damage = 0;

    auto minimum_damage = get_minimum_damage(false, record->player->m_iHealth());
    auto minimum_visible_damage = get_minimum_damage(true, record->player->m_iHealth());

    std::vector <scan_point> points;

    for (auto& hitbox : hitboxes)
    {
        auto current_points = get_points(record, hitbox);

        for (auto& point : current_points)
        {
            if ((g_ctx.globals.eye_pos - final_target.data.point.point).Length() <= weapon_info->flRange)
            {
                point.safe = record->bot || (hitbox_intersection(record->player, record->matrixes_data.positive, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.zero, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.negative, hitbox, shoot_position, point.point));
                if (!(key_binds::get().get_key_bind_state(3) || g_cfg.player_list.force_safe_points[record->i]) || point.safe)
                {
                    points.emplace_back(point);
                }
            }
        }
    }

    if (points.empty())
        return;

    for (auto& point : points)
    {
        if (!point.safe)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INAIR] && !(record->flags & FL_ONGROUND))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INCROUCH] && record->flags & FL_ONGROUND && record->flags & FL_DUCKING)
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_ONLIMBS] && (point.hitbox >= HITBOX_RIGHT_THIGH && point.hitbox < HITBOX_MAX))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_VISIBLE] && util::visible(g_ctx.globals.eye_pos, point.point, record->player, g_ctx.local()))
                continue;
        }

        if (point.hitbox < HITBOX_PELVIS || point.hitbox > HITBOX_UPPER_CHEST)
        {
            if (g_cfg.player_list.force_body_aim[record->i])
                continue;

            if (key_binds::get().get_key_bind_state(22))
                continue;
        }

        auto fire_data = autowall::get().wall_penetration(shoot_position, point.point, record->player);

        if (!fire_data.valid)
            continue;

        if (fire_data.damage < 1)
            continue;

        if (!fire_data.visible && !g_cfg.ragebot.autowall)
            continue;

        auto current_minimum_damage = fire_data.visible ? minimum_visible_damage : minimum_damage;

        if (fire_data.damage >= current_minimum_damage && fire_data.damage >= best_damage)
        {
            if (!should_stop)
            {
                should_stop = true;

                if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_LETHAL] && fire_data.damage < record->player->m_iHealth())
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_VISIBLE] && !fire_data.visible)
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_CENTER] && !point.center)
                    should_stop = false;
            }

            best_damage = fire_data.damage;

            data.point = point;
            data.visible = fire_data.visible;
            data.damage = fire_data.damage;
            data.hitbox = fire_data.hitbox;
        }
    }
}

std::vector <int> aim::get_hitboxes(adjust_data* record)
{
    std::vector <int> hitboxes;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(0))
        hitboxes.emplace_back(HITBOX_HEAD);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(1))
        hitboxes.emplace_back(HITBOX_UPPER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(2))
        hitboxes.emplace_back(HITBOX_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(3))
        hitboxes.emplace_back(HITBOX_LOWER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(4))
        hitboxes.emplace_back(HITBOX_STOMACH);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(5))
        hitboxes.emplace_back(HITBOX_PELVIS);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(6))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_UPPER_ARM);
        hitboxes.emplace_back(HITBOX_LEFT_UPPER_ARM);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(7))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_THIGH);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);

        hitboxes.emplace_back(HITBOX_RIGHT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(8))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_FOOT);
    }

    return hitboxes;
}

std::vector <scan_point> aim::get_points(adjust_data* record, int hitbox, bool from_aim)
{
    std::vector <scan_point> points;
    auto model = record->player->GetModel();

    if (!model)
        return points;

    auto hdr = m_modelinfo()->GetStudioModel(model);

    if (!hdr)
        return points;

    auto set = hdr->pHitboxSet(record->player->m_nHitboxSet());

    if (!set)
        return points;

    auto bbox = set->pHitbox(hitbox);

    if (!bbox)
        return points;

    const auto mod = bbox->radius != -1.0f ? bbox->radius : 0.0f;

    Vector max;
    Vector min;
    math::vector_transform(bbox->bbmax + mod, record->matrixes_data.main[bbox->bone], max);
    math::vector_transform(bbox->bbmin - mod, record->matrixes_data.main[bbox->bone], min);

    const auto center = (min + max) * 0.5f;

    points.emplace_back(scan_point(center, hitbox, true));

    if (!bbox->radius)
        return points;

    if (hitbox == HITBOX_NECK || hitbox == HITBOX_RIGHT_THIGH || hitbox == HITBOX_LEFT_THIGH || hitbox == HITBOX_RIGHT_CALF || hitbox == HITBOX_LEFT_CALF || hitbox == HITBOX_RIGHT_FOOT || hitbox == HITBOX_LEFT_FOOT || hitbox == HITBOX_RIGHT_HAND || hitbox == HITBOX_LEFT_HAND || hitbox == HITBOX_RIGHT_UPPER_ARM || hitbox == HITBOX_LEFT_UPPER_ARM || hitbox == HITBOX_RIGHT_FOREARM || hitbox == HITBOX_LEFT_FOREARM)
        return points;

    const auto cur_angles = math::calculate_angle(center, g_ctx.globals.eye_pos);

    Vector forward;
    math::angle_vectors(cur_angles, forward);

    auto rs = 0.0f;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].static_point_scale)
    {
        rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].body_scale;
        if (hitbox == HITBOX_HEAD)
            rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].head_scale;
    }
    else
    {
        auto transformed_center = center;
        math::vector_transform(transformed_center, record->matrixes_data.main[bbox->bone], transformed_center);

        auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;
        auto distance = transformed_center.DistTo(g_ctx.globals.eye_pos);

        distance /= math::fast_sin(DEG2RAD(90.0f - RAD2DEG(spread)));
        spread = math::fast_sin(spread);

        auto radius = max(bbox->radius - distance * spread, 0.0f);
        rs = bbox->radius * math::clamp(radius / bbox->radius, 0.0f, 1.0f);
    }

    if (rs < 0.2f)
        return points;

    const auto top = Vector(0, 0, 1) * rs;
    const auto right = forward.Cross(Vector(0, 0, 1)) * rs;
    const auto left = Vector(-right.x, -right.y, right.z);

    if (hitbox == HITBOX_HEAD)
        points.emplace_back(scan_point(center + top, hitbox, false));
    points.emplace_back(scan_point(center + right, hitbox, false));
    points.emplace_back(scan_point(center + left, hitbox, false));

    return points;
}

static bool compare_targets(const scanned_target& first, const scanned_target& second)
{
    if (g_cfg.player_list.high_priority[first.record->i] != g_cfg.player_list.high_priority[second.record->i])
        return g_cfg.player_list.high_priority[first.record->i];

    switch (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
    {
    case 1:
        return first.fov < second.fov;
    case 2:
        return first.distance < second.distance;
    case 3:
        return first.health < second.health;
    case 4:
        return first.data.damage > second.data.damage;
    }

    return false;
}

void aim::find_best_target()
{
    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
        std::sort(scanned_targets.begin(), scanned_targets.end(), compare_targets);

    for (auto& target : scanned_targets)
    {
        if (target.fov > (float)g_cfg.ragebot.field_of_view)
            continue;

        final_target = target;
        final_target.record->adjust_player();
        break;
    }
}

void aim::fire(CUserCmd* cmd)
{
    if (!g_ctx.globals.weapon->can_fire(true))
        return;

    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot && !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }

    auto backtrack_ticks = 0;
    auto net_channel_info = m_engine()->GetNetChannelInfo();

    if (net_channel_info)
    {
        auto original_tickbase = g_ctx.globals.backup_tickbase;
        auto max_tickbase_shift = m_gamerules()->m_bIsValveDS() ? 6 : 16;

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap && g_cfg.ragebot.double_tap_key.key > KEY_NONE && g_cfg.ragebot.double_tap_key.key < KEY_MAX && misc::get().double_tap_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().double_tap_enabled && !g_ctx.globals.weapon->is_grenade() && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_TASER && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap_shift_value, max_tickbase_shift);
            }
        }

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots && g_cfg.ragebot.hide_shots_key.key > KEY_NONE && g_cfg.ragebot.hide_shots_key.key < KEY_MAX && misc::get().hide_shots_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().hide_shots_enabled)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots_shift_value, max_tickbase_shift);
            }
        }

        static auto sv_maxunlag = m_cvar()->FindVar(crypt_str("sv_maxunlag"));

        auto correct = math::clamp(net_channel_info->GetLatency(FLOW_OUTGOING) + net_channel_info->GetLatency(FLOW_INCOMING) + util::get_interpolation(), 0.0f, sv_maxunlag->GetFloat());
        auto delta_time = correct - (TICKS_TO_TIME(original_tickbase) - final_target.record->simulation_time);

        backtrack_ticks = TIME_TO_TICKS(fabs(delta_time));
    }

    static auto get_hitbox_name = [](int hitbox) -> std::string
    {
        switch (hitbox)
        {
        case HITBOX_HEAD:
            return crypt_str("Head");
        case HITBOX_LOWER_CHEST:
            return crypt_str("Lower chest");
        case HITBOX_CHEST:
            return crypt_str("Chest");
        case HITBOX_UPPER_CHEST:
            return crypt_str("Upper chest");
        case HITBOX_STOMACH:
            return crypt_str("Stomach");
        case HITBOX_PELVIS:
            return crypt_str("Pelvis");
        case HITBOX_RIGHT_UPPER_ARM:
        case HITBOX_RIGHT_FOREARM:
        case HITBOX_RIGHT_HAND:
            return crypt_str("Left arm");
        case HITBOX_LEFT_UPPER_ARM:
        case HITBOX_LEFT_FOREARM:
        case HITBOX_LEFT_HAND:
            return crypt_str("Right arm");
        case HITBOX_RIGHT_THIGH:
        case HITBOX_RIGHT_CALF:
            return crypt_str("Left leg");
        case HITBOX_LEFT_THIGH:
        case HITBOX_LEFT_CALF:
            return crypt_str("Right leg");
        case HITBOX_RIGHT_FOOT:
            return crypt_str("Left foot");
        case HITBOX_LEFT_FOOT:
            return crypt_str("Right foot");
        }
    };

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                else
                {
                    delta = delta - 360.0f;
                }

        if (resolver_side == 0) {
            m_player->get_animation_state()->m_abs_yaw = previous->animstate.m_abs_yaw;
            m_player->get_animation_state()->m_abs_yaw_last = previous->animstate.m_abs_yaw_last;
            m_player->get_animation_state()->m_move_yaw = previous->animstate.m_move_yaw;
            m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate.m_move_yaw_ideal;
            m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate.m_move_yaw_current_to_ideal;
            m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate.m_move_weight_smoothed;
            m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate.m_in_air_smooth_value;
            m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate.m_time_to_align_lower_body;
        }
        else
        {
            if (resolver_side > 0)
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_right_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_right_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_right_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_right_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_right_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_right_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_right_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_right_params[7];
            }
            else
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_left_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_left_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_left_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_left_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_left_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_left_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_left_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_left_params[7];
            }
        }
            if (bestFov > FOVDistance)
            {
                bestFov = FOVDistance;
                bestTargetIndex = i;
            }
        }
    }bool c_lagcomp::has_firing_animation(C_BasePlayer* m_player, C_Tickrecord* record)
{
    auto weapon = m_player->get_weapon();
    if (weapon)
    {
        int iWeaponIndex = weapon->m_iItemDefinitionIndex();
        auto act = m_player->get_sec_activity(record->anim_layers[1].m_nSequence);
        if (act == ACT_CSGO_FIRE_PRIMARY || ((act == ACT_CSGO_FIRE_SECONDARY || act == ACT_CSGO_FIRE_SECONDARY_OPT_1 || act == ACT_CSGO_FIRE_SECONDARY_OPT_2) && (iWeaponIndex == WEAPON_GLOCK || iWeaponIndex == WEAPON_REVOLVER || iWeaponIndex == WEAPON_FAMAS || weapon->is_knife())))
            return true;
    }
    return false;
}

CBacktrack* backtracking = new CBacktrack();
legit_backtrackdata headPositions[64][12];
    float bestTargetSimTime;
    if (bestTargetIndex != -1)
    {
        float tempFloat = FLT_MAX;
        Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
        Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();

        for (int t = 0; t < 12; ++t)
        {
            float tempFOVDistance = point_to_line(headPositions[bestTargetIndex][t].hitboxPos, local_position, ViewDir);
            if (tempFloat > tempFOVDistance && headPositions[bestTargetIndex][t].simtime > local_player->GetSimTime() - 1)
            {
                tempFloat = tempFOVDistance;
                bestTargetSimTime = headPositions[bestTargetIndex][t].simtime;
            }
        }
        if (cmd->buttons & IN_ATTACK)
        {
            cmd->tick_count = TIME_TO_TICKS(bestTargetSimTime);
        }
    }
}
static void CreateFutureTicks(int entIndex)
{
    SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(entIndex);
    g_PlayerSettings[entIndex].averageSimTimeDelta = CalculateAverageSimtimeDelta(entIndex);
    SDK::INetChannelInfo* nci = INTERFACES::Engine->GetNetChannelInfo();
    if (nci->GetLatency(FLOW_OUTGOING) < g_PlayerSettings[entIndex].averageSimTimeDelta)
    {
        LagCompensation::m_PlayerTrack_Future[entIndex].clear();
        return;
    }
    //int predictAmount = ((nci->GetLatency(FLOW_OUTGOING) + nci->GetLatency(FLOW_INCOMING)) / INTERFACES::Globals->interval_per_tick) + 0.5f;
    //float predictionAngle = GetAverageMovementCurve(entIndex, ent);
    //float acceleration = GetAverageAcceleration(entIndex, ent);
    //Vector currentPosition = ent->GetVecOrigin();
    //Vector currentVelocity = ent->GetVelocity();
    //g_CVar->ConsoleDPrintf("Current velocity: %f %f %f\n", currentVelocity.x, currentVelocity.y, currentVelocity.z);
    SDK::CTraceWorldOnly filter;
    //LagRecord record = LagRecord(ent, nullptr);
    LagCompensation::m_PlayerTrack_Future[entIndex].clear();
    if (LagCompensation::m_PlayerTrack[entIndex].size() < 2)
        return;
    //Circle circles[5];
    //CreateCircles(circ
void C_Tickrecord::store(C_BasePlayer* player, bool backup)
{
    //if (player != nullptr)
    //{
        //auto activity = player->get_sec_activity(player->get_animation_layer(1).m_nSequence);
        //auto shot_bt = ((activity >= ACT_CSGO_FIRE_PRIMARY && activity <= ACT_CSGO_FIRE_SECONDARY_OPT_2) && player->get_animation_layer(1).m_flWeight > 0.01f && player->get_animation_layer(1).m_flCycle < 0.05f) || (player->get_weapon() && player->get_weapon()->m_Activity() == 208);

        //type = RECORD_NORMAL;

        //auto priority = ((activity == ACT_CSGO_RELOAD) && player->get_animation_layer(1).m_flWeight > 0.001f && player->get_animation_layer(1).m_flCycle < 1.f);
        shot_this_tick = false;
        valid = false;
        dormant = false;

        /*if (auto wpn = player->get_weapon(); wpn != nullptr)
            shot_time = wpn->m_flLastShotTime();
        else
            shot_time = 0;*/

        //if (priority)
        //    type = RECORD_PRIORITY;

        bones_count = player->m_bone_count();
        bones_count = Math::clamp(bones_count, 0, 128);

        if (backup) {
            memcpy(matrixes, player->m_CachedBoneData().Base(), bones_count * sizeof(matrix3x4_t));
            valid = false;
            dormant = false;
            animated = true;
            exploit = false;
        }
        //memcpy(leftmatrixes, feature::resolver->player_records[player->entindex() - 1].left_mx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightmatrixes, feature::resolver->player_records[player->entindex() - 1].right_mx, bones_count * sizeof(matrix3x4_t));

        //memcpy(leftlmatrixes, feature::resolver->player_records[player->entindex() - 1].left_lmx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightlmatrixes, feature::resolver->player_records[player->entindex() - 1].right_lmx, bones_count * sizeof(matrix3x4_t));

        //left_side = feature::resolver->player_records[player->entindex() - 1].left_side;
        //right_side = feature::resolver->player_records[player->entindex() - 1].right_side;

        //resolver_index = 0;

        origin = player->m_vecOrigin();
        abs_origin = player->get_abs_origin();
        velocity = player->m_vecVelocity();
        animation_time = feature::lagcomp->get_interpolated_time();
        object_mins = player->OBBMins();
        object_maxs = player->OBBMaxs();
        eye_angles = player->m_angEyeAngles();
        abs_angles = player->get_abs_angles().y;
        entity_flags = player->m_fFlags();
        simulation_time = player->m_flSimulationTime();
        simulation_time_old = player->m_flOldSimulationTime();
        lower_body_yaw = player->m_flLowerBodyYawTarget();
        time_of_last_injury = player->m_flTimeOfLastInjury();
        velocity_modifier = player->m_flVelocityModifier();
        //anim_velocity = player->m_vecVelocity();
        ientity_fl#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;}

void c_lagcomp::build_local_bones(C_BasePlayer* local)
{
    const auto dolboeb = local->m_flPoseParameter();
    local->force_bone_rebuild();
    local->m_flPoseParameter() = ctx.poses[ANGLE_REAL];
    local->set_abs_angles(QAngle(0, ctx.angles[ANGLE_REAL], 0));
    memcpy(ctx.m_local()->animation_layers_ptr(), ctx.local_layers[ANGLE_REAL], 0x38 * ctx.m_local()->get_animation_layers_count());
    /*cheat::main::setuped_bones = */local->SetupBonesEx();
    //memcpy(ctx.matrix, ctx.m_local()->m_CachedBoneData().Base(), min(128, ctx.m_local()->GetBoneCount()) * sizeof(matrix3x4_t));
    local->m_flPoseParameter() = dolboeb;
}

#endif // VIRTUALIZERags = player->m_iEFlags();
        duck_amt = player->m_flDuckAmount();
        ground_accel_last_time = player->m_flGroundAccelLinearFracLastTime();

        if (!backup)
            head_pos = player->get_bone_pos(8);
        if (!backup)
            desync_delta = feature::anti_aim->get_max_desync_delta(player);

        thirdperson_recoil = player->m_flThirdpersonRecoil();
        stop_to_full_run_frac = player->get_animation_state() ? player->get_animation_state()->m_walk_run_transition : 0.f;

        if (auto weapon = player->get_weapon(); weapon != nullptr && weapon)
            shot_time = weapon->m_flLastShotTime();
        else
            shot_time = -1;

        lag = TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime());

        // clamp it so we don't interpolate too far : )
        lag = Math::clamp(lag, 0, 31);

        time_delta = player->m_flSimulationTime() - player->m_flOldSimulationTime();

        if (*(void**)pla{
    //            if (cmd->buttons & IN_JUMP)
    //            {
    //                int sequence = is_moving ? 16 : 15;

    //                if (is_crouched)
    //                    sequence = is_moving ? 18 : 17;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }
    //            else
    //            {
    //                static int sequence = 14;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }

    //            m_flDurationInAir = 0;
    //        }
    //        else if (on_ground && !was_on_ground && !animstate->m_landing)
    //        {
    //            auto sequence = is_moving ? 22 : 20;

    //            if (is_crouched)
    //                sequence = is_moving ? 19 : 21;

    //            if (cmd->buttons & IN_JUMP)
    //                sequence = animstate->m_duration_in_air > 1 ? 24 : 23;

    //            jump_fall->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(jump_fall, sequence);
    //            jump_fall->m_nSequence = sequence;
    //            jump_fall->m_flCycle = jump_fall->m_flWeight = 0.f;

    //            /*anim_state->m_landing = true;
    //            anim_state->m_on_ground = true;
    //            anim_state->m_landed_on_ground_this_frame = true;
    //            anim_state->m_duration_in_air = 0.f;*/
    //            //ctx.fake_state.m_landing = true;
    //        }

    //        if ((!was_on_ground && on_ground) && !(cmd->buttons & IN_JUMP))
    //        {yer && player->get_animation_state())
            memcpy(&animstate, player->get_animation_state(), 0x334);
int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                spread_values[i][0] = a;
                spread_values[i][1] = c;

                auto sin_b = 0.0f, cos_b = 0.0f;
                DirectX::XMScalarSinCos(&sin_b, &cos_b, b);

                auto sin_d = 0.0f, cos_d = 0.0f;
                DirectX::XMScalarSinCos(&sin_d, &cos_d, d);

                spread_values[i][2] = sin_b;
                spread_values[i][3] = cos_b;
                spread_values[i][4] = sin_d;
                spread_values[i][5] = cos_d;
            }
        }

        auto hits = 0;

        for (auto i = 0; i < 256; ++i)
        {
            auto inaccuracy = spread_values[i][0] * g_ctx.globals.inaccuracy;
            auto spread = spread_values[i][1] * g_ctx.globals.spread;

            auto spread_x = spread_values[i][3] * inaccuracy + spread_values[i][5] * spread;
            auto spread_y = spread_values[i][2] * inaccuracy + spread_values[i][4] * spread;

            auto direction = ZERO;

            direction.x = forward.x + right.x * spread_x + up.x * spread_y;
            direction.y = forward.y + right.y * spread_x + up.y * spread_y;
            direction.z = forward.z + right.z * spread_x + up.z * spread_y;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
                ++hits;
        }

        final_hitchance = (int)((float)hits / 2.56f);
    }

    if (g_ctx.globals.double_tap_aim)
        return final_hitchance;

    auto damage = 0;
    auto high_accuracy_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;

    auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;

    for (auto i = 1; i <= 6; ++i)
    {
        for (auto j = 0; j < 8; ++j)
        {
            auto current_spread = spread * ((float)i / 6.0f);

            auto direction_cos = 0.0f;
            auto direction_sin = 0.0f;

            DirectX::XMScalarSinCos(&direction_cos, &direction_sin, (float)j / 8.0f * DirectX::XM_2PI);

            auto spread_x = direction_cos * current_spread;
            auto spread_y = direction_sin * current_spread;

            auto direction = ZERO;

            direction.x = forward.x + spread_x * right.x + spread_y * up.x;
            direction.y = forward.y + spread_x * right.y + spread_y * up.y;
            direction.z = forward.z + spread_x * right.z + spread_y * up.z;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
            {
                auto fire_data = autowall::get().wall_penetration(g_ctx.globals.eye_pos, end, final_target.record->player);
                auto valid_hitbox = true;

                if (final_target.data.hitbox == HITBOX_HEAD && fire_data.hitbox != HITBOX_HEAD)
                    valid_hitbox = false;

                if (fire_data.valid && fire_data.damage >= 1 && valid_hitbox)
                    damage += high_accuracy_weapon ? fire_data.damage : 1;
            }
        }
    }

    if (high_accuracy_weapon)
        return (float)damage / 48.0f >= get_minimum_damage(final_target.data.visible, final_target.health) ? final_hitchance : 0;

    return (float)damage / 48.0f >= (float)g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount * 0.01f ? final_hitchance : 0;
}

        /*pose_paramaters.fill(0);
        left_poses.fill(0);
        right_poses.fill(0);*/
        fill(begin(pose_paramaters), end(pose_paramaters), 0.f);
        if (!backup) {
            fill(begin(left_poses), end(left_poses), 0.f);
            fill(begi    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);&& !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }n(right_poses), end(right_poses), 0.f);
        }

        if (player->get_animation_layers_count() > 0)
            memcpy(anim_layers, player->animation_layers_ptr(), 0x38 * player->get_animation_layers_count());

        //*(&player->get_bone_accessor()->m_WritableBones + 8) = m_writable_bones;
        //readable_bones_count = player->GetBoneAccessor().m_ReadableBones;
        breaking_lc = false;

        tickcount = ctx.current_tickcount;
        simulation_time_delay = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick - TIME_TO_TICKS(player->m_flSimulationTime());

        lc_exploit = simulation_time_delay >= 12;

        if (csgo.m_client_state())
            m_tick = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick;

        latency = ctx.latency[FLOW_INCOMING];

        not_desyncing = false;
        data_filled = true;
    //}
}
les, entIndex);
    Vector deltaVec = Vector(0, 0, 0);
    Vector origin = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin;
    /*for (int o = 0; o < 5; o++)
    {
        Vector movementDirection = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecVelocity;
        movementDirection.z = 0;
        //deltaVec = -circles[o].center + origin;
        //QAngle deltaAngle;
        //Math::VectorAngles(deltaVec, deltaAngle);
        //if (deltaAngle.yaw > 180.f)
        //    deltaAngle.yaw -= 360.f;
        //movementDirection = Math::RotateVectorYaw(Vector(0, 0, 0), deltaAngle.yaw + 180, movementDirection);
        movementDirection.NormalizeInPlace();
        bool isGrounded = ent->GetFlags() & FL_ONGROUND;
        for (int i = 0; i < predictAmount; i++)
        {
            float omega = currentVelocity.Length2D() * circles[o].iRadius;
            float predictionAngle = circles[o].direction * RAD2DEG(omega * g_GlobalVars->interval_per_tick);
            //g_CVar->ConsoleDPrintf("Predicted angle: %f Center: %f %f Rad: %f Vel: %f Accel: %f VelZ: %f \n", predictionAngle, circles[o].center.x, circles[o].center.y, circles[o].radius, currentVelocity.Length(), acceleration, currentVelocity.z);
            currentVelocity = Math::RotateVectorYaw(Vector(0, 0, 0), predictionAngle, currentVelocity);
            movementDirection = currentVelocity;
            movementDirection.z = 0;
            movementDirection.NormalizeInPlace();
            currentVelocity.x += acceleration * movementDirection.x * g_GlobalVars->interval_per_tick;
            currentVelocity.y += acceleration * movementDirection.y * g_GlobalVars->interval_per_tick;
            Movement::PlayerMove(ent, currentPosition, currentVelocity, isGrounded, true, g_GlobalVars->interval_per_tick);
            LagCompensation::m_PlayerTrack_Future[entIndex].push_back(LagRecord(LagRecord(ent, nullptr), currentPosition, (i + 1) * g_GlobalVars->interval_per_tick));
        }*.
        break;
    }
}

void LagCompensation::CreateMove(SDK::CUserCmd* cmd)
{
    if (!INTERFACES::Engine->IsInGame())
        return;
    for (int i = 1; i < 65; ++i)
    {
        SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(i);
        auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
        if (!local_player)
            continue;
        if (!ent
            || ent == local_player
            || ent->GetIsDormant()
            || !ent->GetHealth() > 0) {
            m_PlayerTrack[i].clear();
            continue;
        }
        SDK::player_info_t entityInformation;
        INTERFACES::Engine->GetPlayerInfo(i, &entityInformation);
        if (m_PlayerTrack[i].size() > 0 && m_PlayerTrack[i].at(0).m_flSimulationTime == ent->GetSimTime())
            continue;
        if (m_PlayerTrack[i].size() >= MAX_RECORDS - 1)
            m_PlayerTrack[i].pop_back();
        /*if (m_PlayerTrack[i].size() >= 1) {
            g_PlayerSettings[i].lastSimTimeDelta = ent->GetSimTime() - m_PlayerTrack[i].at(0).m_flSimulationTime;
            g_PlayerSettings[i].breakingLC = (ent->GetVecOrigin() - m_PlayerTrack[i].at(0).m_vecOrigin).Length2DSqr() > 4096;
        }

        /*m_PlayerTrack[i].push_front(LagRecord(ent, cmd));
        if (aim_type == 2)
            CreateFutureTicks(i);
        //if (g_PlayerSettings[i].breakingLC && m_PlayerTrack_Future[i].size() == 0)
            //g_PlayerSettings[i].breakingLC = false;
    }
}
void LagCompensation::StartLagCompensation(SDK::CBaseEntity* player)
{
    if (m_pCurrentPlayer)
        return;
    matrix3x4_t boneMatrix[MAXSTUDIOBONES];
    ((SDK::CBaseAnimating*)player)->GetDirectBoneMatrix(boneMatrix);
    m_pCurrentPlayer = player;
    m_RestoreData = LagRecord(player, NULL);
    SDK::studiohdr_t *hdr = INTERFACES::ModelInfo->GetStudioModel(player->GetModel());
    if (!hdr)
        return;
    int size = hdr->numbones;
    for (int i = 0; i < size; i++)
        memcpy(m_RestoreData.boneMatrix + i, boneMatrix + i, sizeof(matrix3x4_t));
}
void LagCompensation::BacktrackPlayer(SDK::CBaseEntity* player, LagRecord record, bool setAngles)
{
    //Prevent the physics engine from culling the player
    if (setAngles)
    {
        player->SetAbsAngles(record.m_vecAngles);
        player->SetAbsOrigin(record.m_vecOrigin);
    }
    //Screw aiming at air with autowall especially, just tell the game what bonematrix to use
    ((SDK::CBaseAnimating*)player)->SetBoneMatrix(record.boneMatrix);
}
void LagCompensation::EndLagCompensation(SDK::CBaseEntity* player)
{
    m_pCurrentPlayer = nullptr;
    BacktrackPlayer(player, m_RestoreData);
}
template<class T> const T&
clamp(const T& x, const T& upper, const T& lower) { return min(upper, max(x, lower)); }
void resolver::resolve_yaw()
{
    player_info_t player_info;
    auto animstate = player->get_animation_state();

    if (!m_engine()->GetPlayerInfo(player->EntIndex(), &player_info) || !animstate || player_info.fakeplayer || g_cfg.player_list.disable_resolver[player_record->i] || !g_ctx.local()->is_alive() || player->m_iTeamNum() == g_ctx.local()->m_iTeamNum() || abs(TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime()) - 1) || player_record->shot)
    {
        player_record->side = RESOLVER_ORIGINAL;
        return;
    }

    if (g_ctx.globals.missed_shots[player->EntIndex()])
    {
        switch (last_side)
        {
        case RESOLVER_ORIGINAL:
            g_ctx.globals.missed_shots[player->EntIndex()] = 0;
            break;
        case RESOLVER_ZERO:
            player_record->side = RESOLVER_LOW_POSITIVE;

            was_first_bruteforce = false;
            was_second_bruteforce = false;
            return;
        case RESOLVER_POSITIVE:
            player_record->side = was_second_bruteforce ? RESOLVER_ZERO : RESOLVER_NEGATIVE;

            was_first_bruteforce = true;
            return;
        case RESOLVER_NEGATIVE:
            player_record->side = was_first_bruteforce ? RESOLVER_ZERO : RESOLVER_POSITIVE;

            was_second_bruteforce = true;
            return;
        case RESOLVER_LOW_POSITIVE:
            player_record->side = RESOLVER_LOW_NEGATIVE;
            return;
        case RESOLVER_LOW_NEGATIVE:
            player_record->side = RESOLVER_POSITIVE;
            return;
        }
    }

    auto valid_move = true;
    if (animstate->m_velocity > 0.1f)
    {
        valid_move = animstate->m_flTimeSinceStartedMoving < 0.22f;
    }

    if (valid_move && player_record->layers[3].m_flWeight == 0.f && player_record->layers[3].m_flCycle == 0.f && player_record->layers[6].m_flWeight == 0.f)
    {
        auto delta = math::angle_difference(player->m_angEyeAngles().y, zero_goal_feet_yaw);
        auto positive_resolver = (2 * (delta <= 0.0f) - 1) > 0;
        player_record->side = positive_resolver ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
    }
    else if (!valid_move &&    !(static_cast<int>(player_record->layers[12].m_flWeight * 1000.f)) && static_cast<int>(player_record->layers[6].m_flWeight * 1000.f) == static_cast<int>(previous_layers[6].m_flWeight * 1000.f))
    {
        auto delta_negative = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[0][6].m_flPlaybackRate);
        auto delta_zero = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[1][6].m_flPlaybackRate);
        auto delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate);

         if (delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate))

        if (delta_zero < delta_positive || delta_negative <= delta_positive || (delta_positive * 1000.f))
        {
            if (delta_zero >= delta_negative && delta_positive > delta_negative && !(delta_negative * 1000.f))
            {
                player_record->side = RESOLVER_POSITIVE;
            }
        }
        else
        {
            player_record->side = RESOLVER_NEGATIVE;
        }

float v25, v26, v27, v28
      if ( ( v25 - v26 ) <= v27 ) {
         if ( -v27 <= ( v25 - v26 ) )
            v28 = v25;
         else
            v28 = v26 - v27;
      } else {
         v28 = v26 + v27;
         player_record->lock_side = 1;
      }

      std::cout "rezolver mod 1 ";
      m_globals()->m_curtime;
      m_globals()->m_curtime;
      //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);
    }
    else
    {
        autowall::get().wall_penetration = m_globals()->m_curtime; // grenade prediction
        auto lby_update_de
        entity->SetEyeAngles(info.lby); // set final 6 layer lta = abs((((update_delta + 180) % 360 + 360) % 360 - 180));
        if (m_globals()->m_curtime - lock_side > 2.0f)
        {
            auto fire_data_positive = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.positive), player);
            auto fire_data_negative = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.negative), player);

            if (fire_data_positive.visible != fire_data_negative.visible)
            {
                player_record->side = fire_data_negative.visible ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                lock_side = m_globals()->m_curtime;
            }
            else
            {
                if (fire_data_positive.damage != fire_data_negative.damage)
                {
                    player_record->side = fire_data_negative.damage > fire_data_positive.damage ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                }
            }
            else if if if else (
                find_layer(1))
                - 67
            std::regex("final reziolver set4eed hlgjnv ");
            //XIAOMI HOOK MI MIX WARE BETA V4.LUA.JS.CC.COM
float for (std::vector<>::iterator i = .begin(); i != .end(); ++i)
{
   
}
fire_data_positive
was_first_bruteforce
    return;

    bool is_local_player = entity == local_player;
    bool is_teammate = local_player->GetTeam() == entity->GetTeam() && !is_local_player;

    if (is_local_player)
        return;

    if (is_teammate)
        return;

    if (entity->GetHealth() <= 0)
        return;

    if (local_player->GetHealth() <= 0)
        return;

    //--- Variable Declaration ---//;
    auto &info = player_info[entity->GetIndex()];

    //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);

    info.back = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 180.f, 0.f);
    info.right = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 70.f, 0.f);
    info.left = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y - 70.f, 0.f);

    info.backtrack = Vector(entity->GetEyeAngles().x, lby_to_back[entity->GetIndex()], 0.f);

    shots_missed[entity->GetIndex()] = shots_fired[entity->GetIndex()] - shots_hit[entity->GetIndex()];
    info.is_moving = entity->GetVelocity().Length2D() > 0.1 && entity->GetFlags() & FL_ONGROUND && !info.could_be_slowmo;
    info.is_jumping = !entity->GetFlags() & FL_ONGROUND;
    info.could_be_slowmo = entity->GetVelocity().Length2D() > 6 && entity->GetVelocity().Length2D() < 36 && !info.is_crouching;
    info.is_crouching = entity->GetFlags() & FL_DUCKING;
    update_time[entity->GetIndex()] = info.next_lby_update_time;

    static float old_simtime[65];
    if (entity->GetSimTime() != old_simtime[entity->GetIndex()])
    {
        using_fake_angles[entity->GetIndex()] = entity->GetSimTime() - old_simtime[entity->GetIndex()] == INTERFACES::Globals->interval_per_tick; entity->GetSimTime() - old_simtime[entity->GetIndex()] >= TICKS_TO_TIME(2);
        old_simtime[entity->GetIndex()] = entity->GetSimTime();
    }

    //--- Actual Angle Resolving ---//
    if (!using_fake_angles[entity->GetIndex()])
    {
        if (backtrack_tick[entity->GetIndex()])
        {
            resolve_type[entity->GetIndex()] = 7;
            entity->SetEyeAngles(info.backtrack);
        }
        else if (info.stored_lby != entity->GetLowerBodyYaw()) // || entity->GetSimTime() > info.next_lby_update_time) lby prediction
        {
            entity->GetSimTime() > info.next_lby_update_time;
            entity->SetEyeAngles(info.lby);
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            info.stored_lby = entity->GetLowerBodyYaw();
            resolve_type[entity->GetIndex()] = 3;
        }
        else if (info.is_jumping)
        {
            nospread_resolve(entity, entity->GetIndex());
        }
        else if (info.is_moving) //while moving
        {
            entity->SetEyeAngles(info.lby);
            info.last_moving_lby = entity->GetLowerBodyYaw();
            info.stored_missed = shots_missed[entity->GetIndex()];
            resolve_type[entity->GetIndex()] = 1;
        }
        else
        {
            if (shots_missed[entity->GetIndex()] > info.stored_missed) //if we have missed 1 shot since we have stopped moving
            {
                resolve_type[entity->GetIndex()] = 4;
                switch (shots_missed[entity->GetIndex()] % 4)
                {
                case 0: entity->SetEyeAngles(info.inverse); break;
                case 1: entity->SetEyeAngles(info.left); break;
                case 2: entity->SetEyeAngles(info.back); break;
                case 3: entity->SetEyeAngles(info.right); break;
                }
            }
            else //first thing we shoot when they stop
            {
                entity->SetEyeAngles(info.last_lby);
                resolve_type[entity->GetIndex()] = 5;
            }
        }
    }


    SDK::CAnimationLayer layer = entity->GetAnimOverlay(0);
    if (entity->GetSimTime() != info.stored_simtime)
    {
        info.stored_simtime = entity->GetSimTime();
        info.prev_layer = info.backup_layer;
        SDK::CAnimationLayer dummy;
        info.backup_layer = find_layer(entity, 979, &dummy) ? dummy : layer;
    }

    SDK::CAnimationLayer prev = info.prev_layer;
    auto server_time = local_player->GetTickBase() * INTERFACES::Globals->interval_per_tick; //i have a global dedicated to curtime but am using this because lemon is gay

    if (info.is_moving && !info.could_be_slowmo)
    {
        entity->SetEyeAngles(info.lby);
        info.last_moving_lby = entity->GetLowerBodyYaw();
        info.stored_missed = shots_missed[entity->GetIndex()];
        info.last_move_time = server_time;
        info.reset_state = true;
        resolve_type[entity->GetIndex()] = 1;
    }
    else
    {
        if (info.stored_lby != entity->GetLowerBodyYaw())
        {
            entity->SetEyeAngles(info.lby);
            info.stored_lby = entity->GetLowerBodyYaw();
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            resolve_type[entity->GetIndex()] = 7;
        }
        else if (server_time - info.last_move_time < 0.1 && info.reset_state)
        {
            info.pre_anim_lby = entity->GetLowerBodyYaw();
            info.reset_state = false;
            info.breaking_lby = false;
            //std::cout << "reset and lby break is false!" << std::endl;
        }
        auto previous_is_valid = entity->
        }
    }
}

float resolver::resolve_pitch()
{
    return original_pitch;
}
bool aim::hitbox_intersection(player_t* e, matrix3x4_t* matrix, int hitbox, const Vector& start, const Vector& end)
{
    // note: simv0l - pasted from r7 software.
    auto model = e->GetModel();

    if (!model)
        return false;

    auto studio_model = m_modelinfo()->GetStudioModel(model);

    if (!studio_model)
        return false;

    auto studio_set = studio_model->pHitboxSet(e->m_nHitboxSet());

    if (!studio_set)
        return false;

    auto studio_hitbox = studio_set->pHitbox(hitbox);

    if (!studio_hitbox)
        return false;

    Vector min, max;

    const auto is_capsule = studio_hitbox->radius != -1.f;

    if (is_capsule)
    {
        math::vector_transform(studio_hitbox->bbmin, matrix[studio_hitbox->bone], min);
        math::vector_transform(studio_hitbox->bbmax, matrix[studio_hitbox->bone], max);
        const auto dist = math::segment_to_segment(start, end, min, max);

        if (dist < studio_hitbox->radius)
            return true;
    }
    else
    {
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmin, studio_hitbox->rotation), matrix[studio_hitbox->bone], min);
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmax, studio_hitbox->rotation), matrix[studio_hitbox->bone], max);

        math::vector_i_transform(start, matrix[studio_hitbox->bone], min);
        math::vector_i_rotate(end, matrix[studio_hitbox->bone], max);

        if (math::intersect_line_with_bb(min, max, studio_hitbox->bbmin, studio_hitbox->bbmax))
            return true;
    }

    return false;
также девкор сурс
Пожалуйста, авторизуйтесь для просмотра ссылки.
Anko1337
ресольвер на Visual Basic
 
Забаненный
Статус
Оффлайн
Регистрация
8 Июл 2021
Сообщения
45
Реакции[?]
26
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
мой резольвер по анимациям проперный работает хорошо делал 30 лет


C++:
#include "animation_system.h"
#include "..\ragebot\aim.h"

void resolver::initialize(player_t* e, adjust_data* record, const float& goal_feet_yaw, const float& pitch)
{
    player = e;
    player_record = record;

    original_goal_feet_yaw = math::normalize_yaw(goal_feet_yaw);
    original_pitch = math::normalize_pitch(pitch);
}
Vector old_calcangle(Vector dst, Vector src)
{
    Vector angles;

    double delta[3] = { (src.x - dst.x), (src.y - dst.y), (src.z - dst.z) };
    double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
    angles.x = (float)(atan(delta[2] / hyp) * 180.0 / 3.14159265);
    angles.y = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
    angles.z = 0.0f;

    if (delta[0] >= 0.0)
    {
        angles.y += 180.0f;
    }

    return angles;
}

bool find_layer(SDK::CBaseEntity* entity, int act, SDK::CAnimationLayer *set)
{
    for (int i = 0; i < 13; i++)
    {
        SDK::CAnimationLayer layer = entity->GetAnimOverlay(i);
        const int activity = entity->GetSequenceActivity(layer.m_nSequence);
        if (activity == act) {
            *set = layer;
            return true;
        }
    }
    return false;
}

float old_normalize(float Yaw)
{
    if (Yaw > 180)
    {
        Yaw -= (round(Yaw / 360) * 360.f);
    }
    else if (Yaw < -180)
    {
        Yaw += (round(Yaw / 360) * -360.f);
    }
    return Yaw;
}
void resolver::reset()
{
    player = nullptr;
    player_record = nullptr;

    was_first_bruteforce = false;
    was_second_bruteforce = false;

    original_goal_feet_yaw = 0.0f;
    original_pitch = 0.0f;
}

#define TICK_INTERVAL            ( g_pGlobalVarsBase->interval_per_tick )

#define ROUND_TO_TICKS( t )        ( TICK_INTERVAL * TIME_TO_TICKS( t ) )

std::deque<LagRecord> LagCompensation::m_PlayerTrack[MAX_PLAYERS];
std::deque<LagRecord> LagCompensation::m_PlayerTrack_Future[MAX_PLAYERS];
LagRecord LagCompensation::m_RestoreData; //[MAX_PLAYERS];
SDK::CBaseEntity* LagCompensation::m_pCurrentPlayer;
#define LC_NONE                0
#define LC_ALIVE            (1<<0)
#define LC_ORIGIN_CHANGED    (1<<8)
#define LC_ANGLES_CHANGED    (1<<9)
#define LC_SIZE_CHANGED        (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)
static float GetAverageMovementCurve(int entIndex, SDK::CBaseEntity* ent)
{
    Vector p1 = Vector(0, 0, 0);
    Vector p2 = Vector(0, 0, 0);
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
    {
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ROTATION_CALC_TIME && i > 3)
            break;
        else if (i > 2)
        {
            float angle = 0;
            Vector a1, a2;
            MATH::VectorAngles(p1, a1);
            MATH::VectorAngles(p2, a2);
            if (a1.y < 0.0f)
                a1.y += 360.0f;
            if (a2.y < 0.0f)
                a2.y += 360.0f;
            angle = a2.y - a1.y;
            if (angle > 180.0f)
                angle -= 360.0f;
            ret += angle;
            ticks++;
        }
        p1 = p2;
        if (i > 0)
            p2 = (LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecOrigin - LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_vecOrigin);
        p2.z = 0;
        p2.NormalizeInPlace();
    }
    ret /= max(1, ticks);
    return ret;
}

static Vector GetMovementDirection(int entIndex, SDK::CBaseEntity* ent)
{
    Vector ret = Vector(0, 0, 0);
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > DIRECTION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity;
    ret /= max(1, ticks);
    return ret.NormalizeInPlace();
}

static float GetAverageAcceleration(int entIndex, SDK::CBaseEntity* ent)
{
    float vel = ent->GetVelocity().Length2D();
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ACCELERATION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity.Length2D() - vel;
    ret /= max(1, ticks);
    return ret;
}

static void CreateCircles(Circle circles[5], int entIndex)
{
    size_t size = LagCompensation::m_PlayerTrack[entIndex].size();
    if (size >= 3)
    {
        size = 0;
        for (size = 0; size < LagCompensation::m_PlayerTrack[entIndex].size(); size++)
        {
            if (g_GlobalVars->curtime - LagCompensation::m_PlayerTrack[entIndex].at(size).m_flSimulationTime > ROTATION_CALC_TIME && size > 3)
                break;
        }
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at((size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(2 * (size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(size - 1).m_vecOrigin);
    }
    else if (size >= 1) {
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin, 3604207201337.f, 1.f);
    }
}

static float CalculateAverageSimtimeDelta(int entIndex)
{
    float ret = 0;
    for (size_t i = 1; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        ret += LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_flSimulationTime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime;
    ret /= max(1, (int)LagCompensation::m_PlayerTrack[entIndex].size());
    return ret;
}void CBacktrack::run_legit(SDK::CUserCmd* cmd) //phook backtrack muahhahahahaaha
{
    int bestTargetIndex = -1;
    float bestFov = FLT_MAX;
    SDK::player_info_t info;

    auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());

    if (!local_player)
        return;

    for (int i = 1; i < 65; i++)
    {
        auto entity = INTERFACES::ClientEntityList->GetClientEntity(i);

        if (!entity)
            continue;

        if (entity == local_player)
            continue;

        if (!INTERFACES::Engine->GetPlayerInfo(i, &info))
            continue;

        if (entity->GetIsDormant())
            continue;

        if (entity->GetTeam() == local_player->GetTeam())
            continue;

        if (!local_player->GetHealth() > 0)
            return;

        if (entity->GetHealth() > 0)
        {
            float simtime = entity->GetSimTime();
            Vector hitboxPos = aimbot->get_hitbox_pos(entity, 0);

            headPositions[i][cmd->command_number % 12] = legit_backtrackdata{ simtime, hitboxPos };
            Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
            Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();
            float FOVDistance = point_to_line(hitboxPos, local_position, ViewDir);
    c_player_records* log = &records[m_player->entindex() - 1];

    if (previous && !previous->dormant && previous->data_filled && !record->first_after_dormancy)
    {
        m_player->get_animation_state()->m_primary_cycle = previous->m_primary_cycle;
        m_player->get_animation_state()->m_move_weight = previous->m_move_weight;

        m_player->get_animation_state()->m_strafe_sequence = previous->m_strafe_sequence;
        m_player->get_animation_state()->m_strafe_change_weight = previous->m_strafe_change_weight;
        m_player->get_animation_state()->m_strafe_change_cycle = previous->m_strafe_change_cycle;
        m_player->get_animation_state()->m_acceleration_weight = previous->m_acceleration_weight;
#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_START;
#endif // VIRTUALIZER

    const auto backup_flags = m_player->m_fFlags();
    const auto backup_ieflags = m_player->m_iEFlags();
    const auto backup_duckamt = m_player->m_flDuckAmount();
    const auto backup_lowerbody = m_player->m_flLowerBodyYawTarget();
    const auto backup_move_weight = m_player->get_animation_state()->m_move_weight;
    const auto backup_primary_cycle = m_player->get_animation_state()->m_primary_cycle;
   
    //const auto backup_poses = m_player->m_flPoseParameter();
    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));

    resolver_records* resolver_info = &feature::resolver->player_records[m_player->entindex() - 1];
    c_player_records* log = &records[m_player->entindex() - 1];

    //m_player->set_abs_angles(QAngle(0, record->eye_angles.y, 0));
    m_player->m_angEyeAngles() = record->eye_angles;
    m_player->m_angEyeAngles().z = 0.f;

    prepare_player_anim_update(m_player, record, previous, resolver_side);

    m_player->set_abs_angles(QAngle(0, m_player->get_animation_state()->m_abs_yaw, 0));

    if (record->lag > 1 && !log->saved_info.fakeplayer && previous && previous->data_filled)
    {
        const auto velocity_per_tick = (record->velocity - previous->velocity) / record->lag;
        //const auto origin_per_tick = (record->origin - previous->origin) / record->lag;
        //auto ticks_animated = 0;
        //auto velocity_speed_delta = abs(fmaxf(record->velocity.Length2D(),previous->velocity.Length2D()));

        const auto lby_delta = fabsf(Math::angle_diff(record->eye_angles.y, record->lower_body_yaw));

        record->is_landed = false;

        for (auto i = 1; i <= record->lag; i++)
        {
            auto simulated_time = record->animation_update_start_time + TICKS_TO_TIME(i);

            //auto origin = ((origin_per_tick * (float)i) + previous->origin);//Math::interpolate(previous->origin, previous->origin, record->origin, frac);
            auto velocity = /*velocity_speed_delta < 30.f ? */((velocity_per_tick * (float)i) + previous->velocity);//Math::interpolate(previous->velocity, previous->velocity, record->velocity, frac);
            //auto duck_amt = ((duck_amount_per_tick * i) + previous->duck_amt);//Math::interpolate(previous->duck_amt, previous->duck_amt, record->duck_amt, frac);

            if (record->duck_amount_per_tick != 0.0f)
            {
                auto v208 = ((record->duck_amt - m_player->m_flDuckAmount()) * record->duck_amount_per_tick)
                    + m_player->m_flDuckAmount();

                m_player->m_flDuckAmount() = fminf(fmaxf(v208, 0.0f), 1.0f);
            }

            if (i == record->lag)
                simulated_time = record->simulation_time;

            if (record->land_in_cycle && !record->is_landed) // landing animation fix
            {
                if (record->land_time < simulated_time) {
                    record->entity_anim_flags |= 1;
                    record->is_landed = true;
                    auto layer = &m_player->get_animation_layer(4);
                    layer->m_flCycle = 0;
                    layer->m_flWeight = 0;

                }
            }

            //}
            //else
            //    on_ground = record->entity_flags & FL_ONGROUND;

            m_player->m_fFlags() = record->entity_anim_flags;

            record->can_rotate = resolver_side != 0 && !log->saved_info.fakeplayer && i < record->lag && (!record->shot_this_tick || record->shot_this_tick && record->shot_time <= simulated_time);

            /*if (!(record->anim_layers[6].m_flCycle == 0.0f || previous->anim_layers[6].m_flCycle == 0.0f) && velocity.Length2D() <= 1.1f)
            {
                velocity.x = (i & 1 ? -1.1f : 1.1f);  
                velocity.y = 0.f;
                velocity.z = 0.f;
            }*/

            //if (record->shot_this_tick && record->shot_time <= simulated_time)
            //    m_player->m_angEyeAngles().y = resolver_info->last_non_shot_angle.y;
            //else
            //m_player->m_angEyeAngles() = record->eye_angles;

            if (record->shot_this_tick)
            {
                if (record->shot_time <= simulated_time) {
                    m_player->m_flThirdpersonRecoil() = record->thirdperson_recoil;
                    m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                }
            }

            //if (record->shot_this_tick && record->shot_time > simulated_time)

            //m_player->m_vecOrigin() = origin;
            //m_player->set_abs_origin(origin);
            if (i == record->lag)
            {
                m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
                m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                m_player->m_fFlags() = record->entity_flags;
            }

            m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = velocity;
           
            /*if (record->lower_body_yaw != previous->lower_body_yaw)
            {
                auto delta = record->lag - i;

                auto use_new = true;

                if (lby_delta < 1.f)
                    use_new = delta == 0;
                else
                    use_new = delta < 2;

                m_player->m_flLowerBodyYawTarget() = use_new ? record->lower_body_yaw : previous->lower_body_yaw;
            }*/

            //m_player->m_flLowerBodyYawTarget() = record->lby_flicked_time <= simulated_time ? record->lower_body_yaw : previous->lower_body_yaw;

            if (record->can_rotate) {
                auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

                float yaw = m_player->get_animation_state()->m_abs_yaw;

                if (resolver_side <= 0)
                    yaw = record->eye_angles.y - angle;
                else
                    yaw = record->eye_angles.y + angle;

                m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
            }
           
            /* update animations. */
            ctx.updating_resolver = true;
            //m_player->set_abs_origin(origin);
            //m_player->m_vecOrigin() = origin;
            resolver_info->new_velocity = velocity;
            resolver_info->force_velocity = true;

            auto realtime_backup = csgo.m_globals()->realtime;
            auto curtime = csgo.m_globals()->curtime;
            auto frametime = csgo.m_globals()->frametime;
            auto absoluteframetime = csgo.m_globals()->absoluteframetime;
            auto framecount = csgo.m_globals()->framecount;
            auto tickcount = csgo.m_globals()->tickcount;
            auto interpolation_amount = csgo.m_globals()->interpolation_amount;

            int ticks = TIME_TO_TICKS(simulated_time);

            csgo.m_globals()->realtime = simulated_time;
            csgo.m_globals()->curtime = simulated_time;
            csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->framecount = ticks;
            csgo.m_globals()->tickcount = ticks;
            csgo.m_globals()->interpolation_amount = 0.f;

            m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;
            m_player->update_clientside_animations();
            m_player->m_iEFlags() = backup_ieflags;
            resolver_info->force_velocity = false;
            ctx.updating_resolver = false;

            csgo.m_globals()->realtime = realtime_backup;
            csgo.m_globals()->curtime = curtime;
            csgo.m_globals()->frametime = frametime;
            csgo.m_globals()->absoluteframetime = absoluteframetime;
            csgo.m_globals()->framecount = framecount;
            csgo.m_globals()->tickcount = tickcount;
            csgo.m_globals()->interpolation_amount = interpolation_amount;
        }
    }
    else
    {
        m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
        auto vel = record->velocity;
       
        m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
        m_player->m_fFlags() = record->entity_flags;
        m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;

        if (!log->saved_info.fakeplayer && resolver_side != 0)
        {
            float yaw = m_player->get_animation_state()->m_abs_yaw;
            auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

            if (resolver_side <= 0)
                yaw = record->eye_angles.y - angle;
            else
                yaw = record->eye_angles.y + angle;

            m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
        }
        //if (m_player->get_animation_state()->m_abs_yaw < 0)
        //    m_player->get_animation_state()->m_abs_yaw += 360.f;

        auto realtime_backup = csgo.m_globals()->realtime;
        auto curtime = csgo.m_globals()->curtime;
        auto frametime = csgo.m_globals()->frametime;
        auto absoluteframetime = csgo.m_globals()->absoluteframetime;
        auto framecount = csgo.m_globals()->framecount;
        auto tickcount = csgo.m_globals()->tickcount;
        auto interpolation_amount = csgo.m_globals()->interpolation_amount;

        int ticks = TIME_TO_TICKS(record->simulation_time);

        csgo.m_globals()->realtime = record->simulation_time;
        csgo.m_globals()->curtime = record->simulation_time;
        csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->framecount = ticks;
        csgo.m_globals()->tickcount = ticks;
        csgo.m_globals()->interpolation_amount = 0.f;

        m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = vel;

        /* update animations. */
        ctx.updating_resolver = true;
        resolver_info->new_velocity = record->velocity;
        resolver_info->force_velocity = true;
        m_player->update_clientside_animations();
        resolver_info->force_velocity = false;
        ctx.updating_resolver = false;

        csgo.m_globals()->realtime = realtime_backup;
        csgo.m_globals()->curtime = curtime;
        csgo.m_globals()->frametime = frametime;
        csgo.m_globals()->absoluteframetime = absoluteframetime;
        csgo.m_globals()->framecount = framecount;
        csgo.m_globals()->tickcount = tickcount;
        csgo.m_globals()->interpolation_amount = interpolation_amount;
    }

    //m_player->set_abs_origin(abs_origin);
    m_player->m_fFlags() = backup_flags;
    //m_player->m_vecVelocity() = backup_m_velocity;
    m_player->m_flDuckAmount() = backup_duckamt;
    m_player->m_flLowerBodyYawTarget() = backup_lowerbody;
    m_player->m_iEFlags() = backup_ieflags;
    //m_player->m_angEyeAngles() = record->eye_angles;
    //m_player->m_flPoseParameter() = backup_poses;

    m_player->get_animation_state()->m_primary_cycle = backup_primary_cycle;
    m_player->get_animation_state()->m_move_weight = backup_move_weight;

    if (resolver_side != 0) {
        if (resolver_side > 0)
        {
            record->animstate_right_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_right_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_right_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_right_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_right_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_right_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_right_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_right_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
        else
        {
            record->animstate_left_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_left_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_left_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_left_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_left_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_left_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_left_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_left_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
    }

    /*if (previous && !record->first_after_dormancy && !previous->dormant && previous->data_filled)
        fix_jump_fall(m_player, record, previous);*/

    m_player->invalidate_anims(8);

#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;
#endif // VIRTUALIZER
}

void c_lagcomp::recalculate_velocity(C_Tickrecord* record, C_BasePlayer* m_player, C_Tickrecord* previous)
{
    VIRTUALIZER_FISH_LITE_START;

    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));
    static /*const*/ ConVar* sv_enablebunnyhopping = csgo.m_engine_cvars()->FindVar(sxor("sv_enablebunnyhopping"));

    auto log = &records[m_player->entindex() - 1];
    auto r_log = &feature::resolver->player_records[m_player->entindex() - 1];

    /* fix z velocity if enemy is in air. */
    /* https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/shared/gamemovement.cpp#L1697 */

    //auto& old_origin = *(Vector*)(uintptr_t(m_player) + 0x3A4);

    if (record->entity_flags & FL_ONGROUND
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight > 0.0f
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight < 1.0f)
    {
        // float val = clamp ( ( speed - 0.55f ) / ( 0.9f - 0.55f), 0.f, 1.f );
        // layer11_weight = 1.f - val;
        auto val = (1.0f - record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight) * 0.35f;

        if (val > 0.0f && val < 1.0f)
            record->animation_speed = val + 0.55f;
        else
            record->animation_speed = -1.f;
    }

    if (_fdtest(&record->velocity.x) > 0
        || _fdtest(&record->velocity.y) > 0
        || _fdtest(&record->velocity.z) > 0)
        record->velocity.clear();

    if (!record->first_after_dormancy && previous && !previous->dormant && previous->data_filled)
    {
        //
        //    calculate new velocity based on (new_origin - old_origin) / (new_time - old_time) formula.
        //
        if (record->lag > 1 && record->lag <= 20)
            record->velocity = (record->origin - previous->origin) / record->time_delta;
       
        if (abs(record->velocity.x) < 0.001f)
            record->velocity.x = 0.0f;
        if (abs(record->velocity.y) < 0.001f)
            record->velocity.y = 0.0f;
        if (abs(record->velocity.z) < 0.001f)
            record->velocity.z = 0.0f;

        if (_fdtest(&record->velocity.x) > 0
            || _fdtest(&record->velocity.y) > 0
            || _fdtest(&record->velocity.z) > 0)
            record->velocity.clear();

        auto curr_direction = RAD2DEG(std::atan2f(record->velocity.y, record->velocity.x));
        auto prev_direction = previous == nullptr ? FLT_MAX : RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

        auto delta = Math::normalize_angle(curr_direction - prev_direction);

        if (record->velocity.Length2D() > 0.1f) {
            if (previous->velocity.Length2D() > 0.1f && abs(delta) >= 60.f)
                r_log->last_time_changed_direction = csgo.m_globals()->realtime;
        }
        else
            r_log->last_time_changed_direction = 0;

        //
        // these requirements pass only when layer[6].weight is accurate to normalized velocity.
        //
        if (record->entity_flags & FL_ONGROUND
            && record->velocity.Length2D() >= 0.1f
            && std::abs(delta) < 1.0f
            && std::abs(record->duck_amt - previous->duck_amt) <= 0.0f
            && record->anim_layers[6].m_flPlaybackRate > previous->anim_layers[6].m_flPlaybackRate
            && record->anim_layers[6].m_flWeight > previous->anim_layers[6].m_flWeight)
        {
            auto weight_speed = record->anim_layers[6].m_flWeight;

            if (weight_speed <= 0.7f && weight_speed > 0.0f)
            {
                if (record->anim_layers[6].m_flPlaybackRate == 0.0f)
                    record->velocity.clear();
                else
                {
                    const auto m_post_velocity_lenght = record->velocity.Length2D();

                    if (m_post_velocity_lenght != 0.0f)
                    {
                        float mult = 1;
                        if (record->entity_flags & 6)
                            mult = 0.34f;
                        else if (record->fake_walking)
                            mult = 0.52f;

                        record->velocity.x = (record->velocity.x / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                        record->velocity.y = (record->velocity.y / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                    }
                }
            }
        }

        //
        // fix velocity with fakelag.
        //
        if (record->entity_flags & FL_ONGROUND && record->velocity.Length2D() > 0.1f && record->lag > 1)
        {
            //
            // get velocity lenght from 11th layer calc.
            //
            if (record->animation_speed > 0) {
                const auto m_pre_velocity_lenght = record->velocity.Length2D();
                C_WeaponCSBaseGun* weapon = m_player->get_weapon();

                if (weapon) {
                    auto wdata = weapon->GetCSWeaponData();
                    if (wdata) {
                        auto adjusted_velocity = (record->animation_speed * record->max_current_speed) / m_pre_velocity_lenght;
                        record->velocity.x *= adjusted_velocity;
                        record->velocity.y *= adjusted_velocity;
                    }
                }
            }

            /*if (record->entity_flags & FL_ONGROUND && (sv_enablebunnyhopping && !sv_enablebunnyhopping->GetBool() || previous->entity_flags & FL_ONGROUND)) {
                auto max_speed = record->max_current_speed;

                if (record->entity_flags & 6)
                    max_speed *= 0.34f;
                else if (record->fake_walking)
                    max_speed *= 0.52f;

                if (max_speed < m_pre_velocity_lenght)
                    record->velocity *= (max_speed / m_pre_velocity_lenght);

                if (previous->entity_flags & FL_ONGROUND)
                    record->velocity.z = 0.f;
            }*/
        }

        if (log->records_count > 2 && record->lag > 1 && !record->first_after_dormancy
            && previous->velocity.Length() > 0 && !(record->entity_flags & FL_ONGROUND && previous->entity_flags & FL_ONGROUND))
        {
            auto pre_pre_record = &log->tick_records[(log->records_count - 2) & 63];

            if (!pre_pre_record->dormant && pre_pre_record->data_filled) {
                //if (record->velocity.Length2D() > (record->max_current_speed * 0.52f) && previous->velocity.Length2D() > (record->max_current_speed * 0.52f)
                //    || record->velocity.Length2D() <= (record->max_current_speed * 0.52f) && previous->velocity.Length2D() <= (record->max_current_speed * 0.52f))
                //{
                //    auto manually_calculated = log->tick_records[(log->records_count - 2) & 63].stop_to_full_run_frac;
                //    manually_calculated += (record->velocity.Length2D() > (record->max_current_speed * 0.52f) ? (2.f * previous->time_delta) : -(2.f * previous->time_delta));

                //    manually_calculated = Math::clamp(manually_calculated, 0, 1);

                //    if (abs(manually_calculated - previous->stop_to_full_run_frac) >= 0.1f)// {
                //        m_player->get_animation_state()->m_walk_run_transition = manually_calculated;
                //}

                const auto prev_direction = RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

                auto real_velocity = record->velocity.Length2D();

                float delta = curr_direction - prev_direction;

                if (delta <= 180.0f)
                {
                    if (delta < -180.0f)
                        delta = delta + 360.0f;
                }#include "..\misc\misc.h"
#include "..\misc\logs.h"
#include "..\autowall\autowall.h"
#include "..\misc\prediction_system.h"
#include "..\fakewalk\slowwalk.h"
#include "..\lagcompensation\local_animations.h"

void aim::run(CUserCmd* cmd)
{
    backup.clear();
    targets.clear();
    scanned_targets.clear();
    final_target.reset();
    should_stop = false;

    if (!g_cfg.ragebot.enable)
        return;

    automatic_revolver(cmd);
    prepare_targets();

    if (g_ctx.globals.weapon->is_non_aim())
        return;

    if (g_ctx.globals.current_weapon == -1)
        return;

    scan_targets();

    if (!should_stop && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_PREDICTIVE])
    {
        for (auto& target : targets)
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data, g_ctx.globals.eye_pos);

            if (!last_data.valid())
                continue;

            should_stop = true;
            break;
        }
    }

    if (!automatic_stop(cmd))
        return;

    if (scanned_targets.empty())
        return;

    find_best_target();

    if (!final_target.data.valid())
        return;

    fire(cmd);
}

void aim::automatic_revolver(CUserCmd* cmd)
{
    if (!m_engine()->IsActiveApp())
        return;

    if (g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
        return;

    if (cmd->m_buttons & IN_ATTACK)
        return;

    cmd->m_buttons &= ~IN_ATTACK2;

    static auto r8cock_time = 0.0f;
    auto server_time = TICKS_TO_TIME(g_ctx.globals.backup_tickbase);

    if (g_ctx.globals.weapon->can_fire(false))
    {
        if (r8cock_time <= server_time)
        {
            if (g_ctx.globals.weapon->m_flNextSecondaryAttack() <= server_time)
                r8cock_time = server_time + TICKS_TO_TIME(13);
            else
                cmd->m_buttons |= IN_ATTACK2;
        }
        else
            cmd->m_buttons |= IN_ATTACK;
    }
    else
    {
        r8cock_time = server_time + TICKS_TO_TIME(13);
        cmd->m_buttons &= ~IN_ATTACK;
    }

    g_ctx.globals.revolver_working = true;
}

void aim::prepare_targets()
{
    for (auto i = 1; i < m_globals()->m_maxclients; i++)
    {
        if (g_cfg.player_list.white_list[i])
            continue;

        auto e = (player_t*)m_entitylist()->GetClientEntity(i);

        if (!e->valid(true, false))
            continue;

        auto records = &player_records[i];

        if (records->empty())
            continue;
   
        targets.emplace_back(target(e, get_record(records, false), get_record(records, true)));
    }

    for (auto& target : targets)
        backup.emplace_back(adjust_data(target.e));
}

static bool compare_records(const optimized_adjust_data& first, const optimized_adjust_data& second)
{
    if (first.shot != second.shot)
        return first.shot;
    else if (first.speed != second.speed)
        return first.speed > second.speed;

    return first.simulation_time < second.simulation_time;
}

adjust_data* aim::get_record(std::deque <adjust_data>* records, bool history)
{
    if (history)
    {
        std::deque <optimized_adjust_data> optimized_records;

        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);
            optimized_adjust_data optimized_record;

            optimized_record.i = i;
            optimized_record.player = record->player;
            optimized_record.simulation_time = record->simulation_time;
            optimized_record.speed = record->velocity.Length();
            optimized_record.shot = record->shot;

            optimized_records.emplace_back(optimized_record);
        }

        if (optimized_records.size() < 2)
            return nullptr;

        std::sort(optimized_records.begin(), optimized_records.end(), compare_records);

        for (auto& optimized_record : optimized_records)
        {
            auto record = &records->at(optimized_record.i);

            if (!record->valid())
                continue;

            return record;
        }
    }
    else
    {
        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);

            if (!record->valid())
                continue;

            return record;
        }
    }

    return nullptr;
}

int aim::get_minimum_damage(bool visible, int health)
{
    if (key_binds::get().get_key_bind_state(4))
    {
        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage > 100)
            return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage - 100;
        else
            return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage, 1, health);
    }
    else
    {
        if (visible)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage, 1, health);
        }
        else
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage, 1, health);
        }
    }
}

void aim::scan_targets()
{
    if (targets.empty())
        return;

    for (auto& target : targets)
    {
        if (target.history_record->valid())
        {
            scan_data last_data;

            if (target.last_record->valid())
            {
                target.last_record->adjust_player();
                scan(target.last_record, last_data);
            }

            scan_data history_data;

            target.history_record->adjust_player();
            scan(target.history_record, history_data);

            if (last_data.valid() && last_data.damage > history_data.damage)
                scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
            else if (history_data.valid())
                scanned_targets.emplace_back(scanned_target(target.history_record, history_data));
        }
        else
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data);

            if (!last_data.valid())
                continue;

            scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
        }
    }
}

bool aim::automatic_stop(CUserCmd* cmd)
{
    if (!should_stop)
        return true;

    if (g_ctx.globals.slowwalking)
        return true;

    if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND && engineprediction::get().backup_data.flags & FL_ONGROUND))
        return true;

    if (g_ctx.globals.weapon->is_empty())
        return true;

    if (!g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_BETWEEN_SHOTS] && !g_ctx.globals.weapon->can_fire(false))
        return true;

    auto animlayer = g_ctx.local()->get_animlayers()[1];

    if (animlayer.m_nSequence)
    {
        auto activity = g_ctx.local()->sequence_activity(animlayer.m_nSequence);

        if (activity == ACT_CSGO_RELOAD && animlayer.m_flWeight > 0.0f)
            return true;
    }

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

    if (!weapon_info)
        return true;

    auto max_speed = 0.33f * (g_ctx.globals.scoped ? weapon_info->flMaxPlayerSpeedAlt : weapon_info->flMaxPlayerSpeed);

    if (engineprediction::get().backup_data.velocity.Length2D() < max_speed)
        slowwalk::get().create_move(cmd);
    else
    {
        Vector direction;
        Vector real_view;

        math::vector_angles(engineprediction::get().backup_data.velocity, direction);
        m_engine()->GetViewAngles(real_view);

        direction.y = real_view.y - direction.y;

        Vector forward;
        math::angle_vectors(direction, forward);

        static auto cl_forwardspeed = m_cvar()->FindVar(crypt_str("cl_forwardspeed"));
        static auto cl_sidespeed = m_cvar()->FindVar(crypt_str("cl_sidespeed"));

        auto negative_forward_speed = -cl_forwardspeed->GetFloat();
        auto negative_side_speed = -cl_sidespeed->GetFloat();

        auto negative_forward_direction = forward * negative_forward_speed;
        auto negative_side_direction = forward * negative_side_speed;

        cmd->m_forwardmove = negative_forward_direction.x;
        cmd->m_sidemove = negative_side_direction.y;

        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_FORCE_ACCURACY])
            return false;
    }

    return true;
}

void aim::scan(adjust_data* record, scan_data& data, const Vector& shoot_position)
{
    if (!g_ctx.globals.weapon)
        return;

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

    if (!weapon_info)
        return;

    auto hitboxes = get_hitboxes(record);

    if (hitboxes.empty())
        return;

    auto best_damage = 0;

    auto minimum_damage = get_minimum_damage(false, record->player->m_iHealth());
    auto minimum_visible_damage = get_minimum_damage(true, record->player->m_iHealth());

    std::vector <scan_point> points;

    for (auto& hitbox : hitboxes)
    {
        auto current_points = get_points(record, hitbox);

        for (auto& point : current_points)
        {
            if ((g_ctx.globals.eye_pos - final_target.data.point.point).Length() <= weapon_info->flRange)
            {
                point.safe = record->bot || (hitbox_intersection(record->player, record->matrixes_data.positive, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.zero, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.negative, hitbox, shoot_position, point.point));
                if (!(key_binds::get().get_key_bind_state(3) || g_cfg.player_list.force_safe_points[record->i]) || point.safe)
                {
                    points.emplace_back(point);
                }
            }
        }
    }

    if (points.empty())
        return;

    for (auto& point : points)
    {
        if (!point.safe)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INAIR] && !(record->flags & FL_ONGROUND))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INCROUCH] && record->flags & FL_ONGROUND && record->flags & FL_DUCKING)
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_ONLIMBS] && (point.hitbox >= HITBOX_RIGHT_THIGH && point.hitbox < HITBOX_MAX))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_VISIBLE] && util::visible(g_ctx.globals.eye_pos, point.point, record->player, g_ctx.local()))
                continue;
        }

        if (point.hitbox < HITBOX_PELVIS || point.hitbox > HITBOX_UPPER_CHEST)
        {
            if (g_cfg.player_list.force_body_aim[record->i])
                continue;

            if (key_binds::get().get_key_bind_state(22))
                continue;
        }

        auto fire_data = autowall::get().wall_penetration(shoot_position, point.point, record->player);

        if (!fire_data.valid)
            continue;

        if (fire_data.damage < 1)
            continue;

        if (!fire_data.visible && !g_cfg.ragebot.autowall)
            continue;

        auto current_minimum_damage = fire_data.visible ? minimum_visible_damage : minimum_damage;

        if (fire_data.damage >= current_minimum_damage && fire_data.damage >= best_damage)
        {
            if (!should_stop)
            {
                should_stop = true;

                if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_LETHAL] && fire_data.damage < record->player->m_iHealth())
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_VISIBLE] && !fire_data.visible)
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_CENTER] && !point.center)
                    should_stop = false;
            }

            best_damage = fire_data.damage;

            data.point = point;
            data.visible = fire_data.visible;
            data.damage = fire_data.damage;
            data.hitbox = fire_data.hitbox;
        }
    }
}

std::vector <int> aim::get_hitboxes(adjust_data* record)
{
    std::vector <int> hitboxes;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(0))
        hitboxes.emplace_back(HITBOX_HEAD);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(1))
        hitboxes.emplace_back(HITBOX_UPPER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(2))
        hitboxes.emplace_back(HITBOX_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(3))
        hitboxes.emplace_back(HITBOX_LOWER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(4))
        hitboxes.emplace_back(HITBOX_STOMACH);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(5))
        hitboxes.emplace_back(HITBOX_PELVIS);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(6))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_UPPER_ARM);
        hitboxes.emplace_back(HITBOX_LEFT_UPPER_ARM);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(7))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_THIGH);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);

        hitboxes.emplace_back(HITBOX_RIGHT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(8))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_FOOT);
    }

    return hitboxes;
}

std::vector <scan_point> aim::get_points(adjust_data* record, int hitbox, bool from_aim)
{
    std::vector <scan_point> points;
    auto model = record->player->GetModel();

    if (!model)
        return points;

    auto hdr = m_modelinfo()->GetStudioModel(model);

    if (!hdr)
        return points;

    auto set = hdr->pHitboxSet(record->player->m_nHitboxSet());

    if (!set)
        return points;

    auto bbox = set->pHitbox(hitbox);

    if (!bbox)
        return points;

    const auto mod = bbox->radius != -1.0f ? bbox->radius : 0.0f;

    Vector max;
    Vector min;
    math::vector_transform(bbox->bbmax + mod, record->matrixes_data.main[bbox->bone], max);
    math::vector_transform(bbox->bbmin - mod, record->matrixes_data.main[bbox->bone], min);

    const auto center = (min + max) * 0.5f;

    points.emplace_back(scan_point(center, hitbox, true));

    if (!bbox->radius)
        return points;

    if (hitbox == HITBOX_NECK || hitbox == HITBOX_RIGHT_THIGH || hitbox == HITBOX_LEFT_THIGH || hitbox == HITBOX_RIGHT_CALF || hitbox == HITBOX_LEFT_CALF || hitbox == HITBOX_RIGHT_FOOT || hitbox == HITBOX_LEFT_FOOT || hitbox == HITBOX_RIGHT_HAND || hitbox == HITBOX_LEFT_HAND || hitbox == HITBOX_RIGHT_UPPER_ARM || hitbox == HITBOX_LEFT_UPPER_ARM || hitbox == HITBOX_RIGHT_FOREARM || hitbox == HITBOX_LEFT_FOREARM)
        return points;

    const auto cur_angles = math::calculate_angle(center, g_ctx.globals.eye_pos);

    Vector forward;
    math::angle_vectors(cur_angles, forward);

    auto rs = 0.0f;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].static_point_scale)
    {
        rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].body_scale;
        if (hitbox == HITBOX_HEAD)
            rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].head_scale;
    }
    else
    {
        auto transformed_center = center;
        math::vector_transform(transformed_center, record->matrixes_data.main[bbox->bone], transformed_center);

        auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;
        auto distance = transformed_center.DistTo(g_ctx.globals.eye_pos);

        distance /= math::fast_sin(DEG2RAD(90.0f - RAD2DEG(spread)));
        spread = math::fast_sin(spread);

        auto radius = max(bbox->radius - distance * spread, 0.0f);
        rs = bbox->radius * math::clamp(radius / bbox->radius, 0.0f, 1.0f);
    }

    if (rs < 0.2f)
        return points;

    const auto top = Vector(0, 0, 1) * rs;
    const auto right = forward.Cross(Vector(0, 0, 1)) * rs;
    const auto left = Vector(-right.x, -right.y, right.z);

    if (hitbox == HITBOX_HEAD)
        points.emplace_back(scan_point(center + top, hitbox, false));
    points.emplace_back(scan_point(center + right, hitbox, false));
    points.emplace_back(scan_point(center + left, hitbox, false));

    return points;
}

static bool compare_targets(const scanned_target& first, const scanned_target& second)
{
    if (g_cfg.player_list.high_priority[first.record->i] != g_cfg.player_list.high_priority[second.record->i])
        return g_cfg.player_list.high_priority[first.record->i];

    switch (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
    {
    case 1:
        return first.fov < second.fov;
    case 2:
        return first.distance < second.distance;
    case 3:
        return first.health < second.health;
    case 4:
        return first.data.damage > second.data.damage;
    }

    return false;
}

void aim::find_best_target()
{
    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
        std::sort(scanned_targets.begin(), scanned_targets.end(), compare_targets);

    for (auto& target : scanned_targets)
    {
        if (target.fov > (float)g_cfg.ragebot.field_of_view)
            continue;

        final_target = target;
        final_target.record->adjust_player();
        break;
    }
}

void aim::fire(CUserCmd* cmd)
{
    if (!g_ctx.globals.weapon->can_fire(true))
        return;

    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot && !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }

    auto backtrack_ticks = 0;
    auto net_channel_info = m_engine()->GetNetChannelInfo();

    if (net_channel_info)
    {
        auto original_tickbase = g_ctx.globals.backup_tickbase;
        auto max_tickbase_shift = m_gamerules()->m_bIsValveDS() ? 6 : 16;

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap && g_cfg.ragebot.double_tap_key.key > KEY_NONE && g_cfg.ragebot.double_tap_key.key < KEY_MAX && misc::get().double_tap_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().double_tap_enabled && !g_ctx.globals.weapon->is_grenade() && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_TASER && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap_shift_value, max_tickbase_shift);
            }
        }

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots && g_cfg.ragebot.hide_shots_key.key > KEY_NONE && g_cfg.ragebot.hide_shots_key.key < KEY_MAX && misc::get().hide_shots_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().hide_shots_enabled)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots_shift_value, max_tickbase_shift);
            }
        }

        static auto sv_maxunlag = m_cvar()->FindVar(crypt_str("sv_maxunlag"));

        auto correct = math::clamp(net_channel_info->GetLatency(FLOW_OUTGOING) + net_channel_info->GetLatency(FLOW_INCOMING) + util::get_interpolation(), 0.0f, sv_maxunlag->GetFloat());
        auto delta_time = correct - (TICKS_TO_TIME(original_tickbase) - final_target.record->simulation_time);

        backtrack_ticks = TIME_TO_TICKS(fabs(delta_time));
    }

    static auto get_hitbox_name = [](int hitbox) -> std::string
    {
        switch (hitbox)
        {
        case HITBOX_HEAD:
            return crypt_str("Head");
        case HITBOX_LOWER_CHEST:
            return crypt_str("Lower chest");
        case HITBOX_CHEST:
            return crypt_str("Chest");
        case HITBOX_UPPER_CHEST:
            return crypt_str("Upper chest");
        case HITBOX_STOMACH:
            return crypt_str("Stomach");
        case HITBOX_PELVIS:
            return crypt_str("Pelvis");
        case HITBOX_RIGHT_UPPER_ARM:
        case HITBOX_RIGHT_FOREARM:
        case HITBOX_RIGHT_HAND:
            return crypt_str("Left arm");
        case HITBOX_LEFT_UPPER_ARM:
        case HITBOX_LEFT_FOREARM:
        case HITBOX_LEFT_HAND:
            return crypt_str("Right arm");
        case HITBOX_RIGHT_THIGH:
        case HITBOX_RIGHT_CALF:
            return crypt_str("Left leg");
        case HITBOX_LEFT_THIGH:
        case HITBOX_LEFT_CALF:
            return crypt_str("Right leg");
        case HITBOX_RIGHT_FOOT:
            return crypt_str("Left foot");
        case HITBOX_LEFT_FOOT:
            return crypt_str("Right foot");
        }
    };

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                else
                {
                    delta = delta - 360.0f;
                }

        if (resolver_side == 0) {
            m_player->get_animation_state()->m_abs_yaw = previous->animstate.m_abs_yaw;
            m_player->get_animation_state()->m_abs_yaw_last = previous->animstate.m_abs_yaw_last;
            m_player->get_animation_state()->m_move_yaw = previous->animstate.m_move_yaw;
            m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate.m_move_yaw_ideal;
            m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate.m_move_yaw_current_to_ideal;
            m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate.m_move_weight_smoothed;
            m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate.m_in_air_smooth_value;
            m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate.m_time_to_align_lower_body;
        }
        else
        {
            if (resolver_side > 0)
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_right_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_right_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_right_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_right_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_right_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_right_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_right_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_right_params[7];
            }
            else
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_left_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_left_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_left_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_left_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_left_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_left_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_left_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_left_params[7];
            }
        }
            if (bestFov > FOVDistance)
            {
                bestFov = FOVDistance;
                bestTargetIndex = i;
            }
        }
    }bool c_lagcomp::has_firing_animation(C_BasePlayer* m_player, C_Tickrecord* record)
{
    auto weapon = m_player->get_weapon();
    if (weapon)
    {
        int iWeaponIndex = weapon->m_iItemDefinitionIndex();
        auto act = m_player->get_sec_activity(record->anim_layers[1].m_nSequence);
        if (act == ACT_CSGO_FIRE_PRIMARY || ((act == ACT_CSGO_FIRE_SECONDARY || act == ACT_CSGO_FIRE_SECONDARY_OPT_1 || act == ACT_CSGO_FIRE_SECONDARY_OPT_2) && (iWeaponIndex == WEAPON_GLOCK || iWeaponIndex == WEAPON_REVOLVER || iWeaponIndex == WEAPON_FAMAS || weapon->is_knife())))
            return true;
    }
    return false;
}

CBacktrack* backtracking = new CBacktrack();
legit_backtrackdata headPositions[64][12];
    float bestTargetSimTime;
    if (bestTargetIndex != -1)
    {
        float tempFloat = FLT_MAX;
        Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
        Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();

        for (int t = 0; t < 12; ++t)
        {
            float tempFOVDistance = point_to_line(headPositions[bestTargetIndex][t].hitboxPos, local_position, ViewDir);
            if (tempFloat > tempFOVDistance && headPositions[bestTargetIndex][t].simtime > local_player->GetSimTime() - 1)
            {
                tempFloat = tempFOVDistance;
                bestTargetSimTime = headPositions[bestTargetIndex][t].simtime;
            }
        }
        if (cmd->buttons & IN_ATTACK)
        {
            cmd->tick_count = TIME_TO_TICKS(bestTargetSimTime);
        }
    }
}
static void CreateFutureTicks(int entIndex)
{
    SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(entIndex);
    g_PlayerSettings[entIndex].averageSimTimeDelta = CalculateAverageSimtimeDelta(entIndex);
    SDK::INetChannelInfo* nci = INTERFACES::Engine->GetNetChannelInfo();
    if (nci->GetLatency(FLOW_OUTGOING) < g_PlayerSettings[entIndex].averageSimTimeDelta)
    {
        LagCompensation::m_PlayerTrack_Future[entIndex].clear();
        return;
    }
    //int predictAmount = ((nci->GetLatency(FLOW_OUTGOING) + nci->GetLatency(FLOW_INCOMING)) / INTERFACES::Globals->interval_per_tick) + 0.5f;
    //float predictionAngle = GetAverageMovementCurve(entIndex, ent);
    //float acceleration = GetAverageAcceleration(entIndex, ent);
    //Vector currentPosition = ent->GetVecOrigin();
    //Vector currentVelocity = ent->GetVelocity();
    //g_CVar->ConsoleDPrintf("Current velocity: %f %f %f\n", currentVelocity.x, currentVelocity.y, currentVelocity.z);
    SDK::CTraceWorldOnly filter;
    //LagRecord record = LagRecord(ent, nullptr);
    LagCompensation::m_PlayerTrack_Future[entIndex].clear();
    if (LagCompensation::m_PlayerTrack[entIndex].size() < 2)
        return;
    //Circle circles[5];
    //CreateCircles(circ
void C_Tickrecord::store(C_BasePlayer* player, bool backup)
{
    //if (player != nullptr)
    //{
        //auto activity = player->get_sec_activity(player->get_animation_layer(1).m_nSequence);
        //auto shot_bt = ((activity >= ACT_CSGO_FIRE_PRIMARY && activity <= ACT_CSGO_FIRE_SECONDARY_OPT_2) && player->get_animation_layer(1).m_flWeight > 0.01f && player->get_animation_layer(1).m_flCycle < 0.05f) || (player->get_weapon() && player->get_weapon()->m_Activity() == 208);

        //type = RECORD_NORMAL;

        //auto priority = ((activity == ACT_CSGO_RELOAD) && player->get_animation_layer(1).m_flWeight > 0.001f && player->get_animation_layer(1).m_flCycle < 1.f);
        shot_this_tick = false;
        valid = false;
        dormant = false;

        /*if (auto wpn = player->get_weapon(); wpn != nullptr)
            shot_time = wpn->m_flLastShotTime();
        else
            shot_time = 0;*/

        //if (priority)
        //    type = RECORD_PRIORITY;

        bones_count = player->m_bone_count();
        bones_count = Math::clamp(bones_count, 0, 128);

        if (backup) {
            memcpy(matrixes, player->m_CachedBoneData().Base(), bones_count * sizeof(matrix3x4_t));
            valid = false;
            dormant = false;
            animated = true;
            exploit = false;
        }
        //memcpy(leftmatrixes, feature::resolver->player_records[player->entindex() - 1].left_mx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightmatrixes, feature::resolver->player_records[player->entindex() - 1].right_mx, bones_count * sizeof(matrix3x4_t));

        //memcpy(leftlmatrixes, feature::resolver->player_records[player->entindex() - 1].left_lmx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightlmatrixes, feature::resolver->player_records[player->entindex() - 1].right_lmx, bones_count * sizeof(matrix3x4_t));

        //left_side = feature::resolver->player_records[player->entindex() - 1].left_side;
        //right_side = feature::resolver->player_records[player->entindex() - 1].right_side;

        //resolver_index = 0;

        origin = player->m_vecOrigin();
        abs_origin = player->get_abs_origin();
        velocity = player->m_vecVelocity();
        animation_time = feature::lagcomp->get_interpolated_time();
        object_mins = player->OBBMins();
        object_maxs = player->OBBMaxs();
        eye_angles = player->m_angEyeAngles();
        abs_angles = player->get_abs_angles().y;
        entity_flags = player->m_fFlags();
        simulation_time = player->m_flSimulationTime();
        simulation_time_old = player->m_flOldSimulationTime();
        lower_body_yaw = player->m_flLowerBodyYawTarget();
        time_of_last_injury = player->m_flTimeOfLastInjury();
        velocity_modifier = player->m_flVelocityModifier();
        //anim_velocity = player->m_vecVelocity();
        ientity_fl#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;}

void c_lagcomp::build_local_bones(C_BasePlayer* local)
{
    const auto dolboeb = local->m_flPoseParameter();
    local->force_bone_rebuild();
    local->m_flPoseParameter() = ctx.poses[ANGLE_REAL];
    local->set_abs_angles(QAngle(0, ctx.angles[ANGLE_REAL], 0));
    memcpy(ctx.m_local()->animation_layers_ptr(), ctx.local_layers[ANGLE_REAL], 0x38 * ctx.m_local()->get_animation_layers_count());
    /*cheat::main::setuped_bones = */local->SetupBonesEx();
    //memcpy(ctx.matrix, ctx.m_local()->m_CachedBoneData().Base(), min(128, ctx.m_local()->GetBoneCount()) * sizeof(matrix3x4_t));
    local->m_flPoseParameter() = dolboeb;
}

#endif // VIRTUALIZERags = player->m_iEFlags();
        duck_amt = player->m_flDuckAmount();
        ground_accel_last_time = player->m_flGroundAccelLinearFracLastTime();

        if (!backup)
            head_pos = player->get_bone_pos(8);
        if (!backup)
            desync_delta = feature::anti_aim->get_max_desync_delta(player);

        thirdperson_recoil = player->m_flThirdpersonRecoil();
        stop_to_full_run_frac = player->get_animation_state() ? player->get_animation_state()->m_walk_run_transition : 0.f;

        if (auto weapon = player->get_weapon(); weapon != nullptr && weapon)
            shot_time = weapon->m_flLastShotTime();
        else
            shot_time = -1;

        lag = TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime());

        // clamp it so we don't interpolate too far : )
        lag = Math::clamp(lag, 0, 31);

        time_delta = player->m_flSimulationTime() - player->m_flOldSimulationTime();

        if (*(void**)pla{
    //            if (cmd->buttons & IN_JUMP)
    //            {
    //                int sequence = is_moving ? 16 : 15;

    //                if (is_crouched)
    //                    sequence = is_moving ? 18 : 17;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }
    //            else
    //            {
    //                static int sequence = 14;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }

    //            m_flDurationInAir = 0;
    //        }
    //        else if (on_ground && !was_on_ground && !animstate->m_landing)
    //        {
    //            auto sequence = is_moving ? 22 : 20;

    //            if (is_crouched)
    //                sequence = is_moving ? 19 : 21;

    //            if (cmd->buttons & IN_JUMP)
    //                sequence = animstate->m_duration_in_air > 1 ? 24 : 23;

    //            jump_fall->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(jump_fall, sequence);
    //            jump_fall->m_nSequence = sequence;
    //            jump_fall->m_flCycle = jump_fall->m_flWeight = 0.f;

    //            /*anim_state->m_landing = true;
    //            anim_state->m_on_ground = true;
    //            anim_state->m_landed_on_ground_this_frame = true;
    //            anim_state->m_duration_in_air = 0.f;*/
    //            //ctx.fake_state.m_landing = true;
    //        }

    //        if ((!was_on_ground && on_ground) && !(cmd->buttons & IN_JUMP))
    //        {yer && player->get_animation_state())
            memcpy(&animstate, player->get_animation_state(), 0x334);
int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                spread_values[i][0] = a;
                spread_values[i][1] = c;

                auto sin_b = 0.0f, cos_b = 0.0f;
                DirectX::XMScalarSinCos(&sin_b, &cos_b, b);

                auto sin_d = 0.0f, cos_d = 0.0f;
                DirectX::XMScalarSinCos(&sin_d, &cos_d, d);

                spread_values[i][2] = sin_b;
                spread_values[i][3] = cos_b;
                spread_values[i][4] = sin_d;
                spread_values[i][5] = cos_d;
            }
        }

        auto hits = 0;

        for (auto i = 0; i < 256; ++i)
        {
            auto inaccuracy = spread_values[i][0] * g_ctx.globals.inaccuracy;
            auto spread = spread_values[i][1] * g_ctx.globals.spread;

            auto spread_x = spread_values[i][3] * inaccuracy + spread_values[i][5] * spread;
            auto spread_y = spread_values[i][2] * inaccuracy + spread_values[i][4] * spread;

            auto direction = ZERO;

            direction.x = forward.x + right.x * spread_x + up.x * spread_y;
            direction.y = forward.y + right.y * spread_x + up.y * spread_y;
            direction.z = forward.z + right.z * spread_x + up.z * spread_y;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
                ++hits;
        }

        final_hitchance = (int)((float)hits / 2.56f);
    }

    if (g_ctx.globals.double_tap_aim)
        return final_hitchance;

    auto damage = 0;
    auto high_accuracy_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;

    auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;

    for (auto i = 1; i <= 6; ++i)
    {
        for (auto j = 0; j < 8; ++j)
        {
            auto current_spread = spread * ((float)i / 6.0f);

            auto direction_cos = 0.0f;
            auto direction_sin = 0.0f;

            DirectX::XMScalarSinCos(&direction_cos, &direction_sin, (float)j / 8.0f * DirectX::XM_2PI);

            auto spread_x = direction_cos * current_spread;
            auto spread_y = direction_sin * current_spread;

            auto direction = ZERO;

            direction.x = forward.x + spread_x * right.x + spread_y * up.x;
            direction.y = forward.y + spread_x * right.y + spread_y * up.y;
            direction.z = forward.z + spread_x * right.z + spread_y * up.z;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
            {
                auto fire_data = autowall::get().wall_penetration(g_ctx.globals.eye_pos, end, final_target.record->player);
                auto valid_hitbox = true;

                if (final_target.data.hitbox == HITBOX_HEAD && fire_data.hitbox != HITBOX_HEAD)
                    valid_hitbox = false;

                if (fire_data.valid && fire_data.damage >= 1 && valid_hitbox)
                    damage += high_accuracy_weapon ? fire_data.damage : 1;
            }
        }
    }

    if (high_accuracy_weapon)
        return (float)damage / 48.0f >= get_minimum_damage(final_target.data.visible, final_target.health) ? final_hitchance : 0;

    return (float)damage / 48.0f >= (float)g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount * 0.01f ? final_hitchance : 0;
}

        /*pose_paramaters.fill(0);
        left_poses.fill(0);
        right_poses.fill(0);*/
        fill(begin(pose_paramaters), end(pose_paramaters), 0.f);
        if (!backup) {
            fill(begin(left_poses), end(left_poses), 0.f);
            fill(begi    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);&& !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }n(right_poses), end(right_poses), 0.f);
        }

        if (player->get_animation_layers_count() > 0)
            memcpy(anim_layers, player->animation_layers_ptr(), 0x38 * player->get_animation_layers_count());

        //*(&player->get_bone_accessor()->m_WritableBones + 8) = m_writable_bones;
        //readable_bones_count = player->GetBoneAccessor().m_ReadableBones;
        breaking_lc = false;

        tickcount = ctx.current_tickcount;
        simulation_time_delay = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick - TIME_TO_TICKS(player->m_flSimulationTime());

        lc_exploit = simulation_time_delay >= 12;

        if (csgo.m_client_state())
            m_tick = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick;

        latency = ctx.latency[FLOW_INCOMING];

        not_desyncing = false;
        data_filled = true;
    //}
}
les, entIndex);
    Vector deltaVec = Vector(0, 0, 0);
    Vector origin = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin;
    /*for (int o = 0; o < 5; o++)
    {
        Vector movementDirection = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecVelocity;
        movementDirection.z = 0;
        //deltaVec = -circles[o].center + origin;
        //QAngle deltaAngle;
        //Math::VectorAngles(deltaVec, deltaAngle);
        //if (deltaAngle.yaw > 180.f)
        //    deltaAngle.yaw -= 360.f;
        //movementDirection = Math::RotateVectorYaw(Vector(0, 0, 0), deltaAngle.yaw + 180, movementDirection);
        movementDirection.NormalizeInPlace();
        bool isGrounded = ent->GetFlags() & FL_ONGROUND;
        for (int i = 0; i < predictAmount; i++)
        {
            float omega = currentVelocity.Length2D() * circles[o].iRadius;
            float predictionAngle = circles[o].direction * RAD2DEG(omega * g_GlobalVars->interval_per_tick);
            //g_CVar->ConsoleDPrintf("Predicted angle: %f Center: %f %f Rad: %f Vel: %f Accel: %f VelZ: %f \n", predictionAngle, circles[o].center.x, circles[o].center.y, circles[o].radius, currentVelocity.Length(), acceleration, currentVelocity.z);
            currentVelocity = Math::RotateVectorYaw(Vector(0, 0, 0), predictionAngle, currentVelocity);
            movementDirection = currentVelocity;
            movementDirection.z = 0;
            movementDirection.NormalizeInPlace();
            currentVelocity.x += acceleration * movementDirection.x * g_GlobalVars->interval_per_tick;
            currentVelocity.y += acceleration * movementDirection.y * g_GlobalVars->interval_per_tick;
            Movement::PlayerMove(ent, currentPosition, currentVelocity, isGrounded, true, g_GlobalVars->interval_per_tick);
            LagCompensation::m_PlayerTrack_Future[entIndex].push_back(LagRecord(LagRecord(ent, nullptr), currentPosition, (i + 1) * g_GlobalVars->interval_per_tick));
        }*.
        break;
    }
}

void LagCompensation::CreateMove(SDK::CUserCmd* cmd)
{
    if (!INTERFACES::Engine->IsInGame())
        return;
    for (int i = 1; i < 65; ++i)
    {
        SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(i);
        auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
        if (!local_player)
            continue;
        if (!ent
            || ent == local_player
            || ent->GetIsDormant()
            || !ent->GetHealth() > 0) {
            m_PlayerTrack[i].clear();
            continue;
        }
        SDK::player_info_t entityInformation;
        INTERFACES::Engine->GetPlayerInfo(i, &entityInformation);
        if (m_PlayerTrack[i].size() > 0 && m_PlayerTrack[i].at(0).m_flSimulationTime == ent->GetSimTime())
            continue;
        if (m_PlayerTrack[i].size() >= MAX_RECORDS - 1)
            m_PlayerTrack[i].pop_back();
        /*if (m_PlayerTrack[i].size() >= 1) {
            g_PlayerSettings[i].lastSimTimeDelta = ent->GetSimTime() - m_PlayerTrack[i].at(0).m_flSimulationTime;
            g_PlayerSettings[i].breakingLC = (ent->GetVecOrigin() - m_PlayerTrack[i].at(0).m_vecOrigin).Length2DSqr() > 4096;
        }

        /*m_PlayerTrack[i].push_front(LagRecord(ent, cmd));
        if (aim_type == 2)
            CreateFutureTicks(i);
        //if (g_PlayerSettings[i].breakingLC && m_PlayerTrack_Future[i].size() == 0)
            //g_PlayerSettings[i].breakingLC = false;
    }
}
void LagCompensation::StartLagCompensation(SDK::CBaseEntity* player)
{
    if (m_pCurrentPlayer)
        return;
    matrix3x4_t boneMatrix[MAXSTUDIOBONES];
    ((SDK::CBaseAnimating*)player)->GetDirectBoneMatrix(boneMatrix);
    m_pCurrentPlayer = player;
    m_RestoreData = LagRecord(player, NULL);
    SDK::studiohdr_t *hdr = INTERFACES::ModelInfo->GetStudioModel(player->GetModel());
    if (!hdr)
        return;
    int size = hdr->numbones;
    for (int i = 0; i < size; i++)
        memcpy(m_RestoreData.boneMatrix + i, boneMatrix + i, sizeof(matrix3x4_t));
}
void LagCompensation::BacktrackPlayer(SDK::CBaseEntity* player, LagRecord record, bool setAngles)
{
    //Prevent the physics engine from culling the player
    if (setAngles)
    {
        player->SetAbsAngles(record.m_vecAngles);
        player->SetAbsOrigin(record.m_vecOrigin);
    }
    //Screw aiming at air with autowall especially, just tell the game what bonematrix to use
    ((SDK::CBaseAnimating*)player)->SetBoneMatrix(record.boneMatrix);
}
void LagCompensation::EndLagCompensation(SDK::CBaseEntity* player)
{
    m_pCurrentPlayer = nullptr;
    BacktrackPlayer(player, m_RestoreData);
}
template<class T> const T&
clamp(const T& x, const T& upper, const T& lower) { return min(upper, max(x, lower)); }
void resolver::resolve_yaw()
{
    player_info_t player_info;
    auto animstate = player->get_animation_state();

    if (!m_engine()->GetPlayerInfo(player->EntIndex(), &player_info) || !animstate || player_info.fakeplayer || g_cfg.player_list.disable_resolver[player_record->i] || !g_ctx.local()->is_alive() || player->m_iTeamNum() == g_ctx.local()->m_iTeamNum() || abs(TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime()) - 1) || player_record->shot)
    {
        player_record->side = RESOLVER_ORIGINAL;
        return;
    }

    if (g_ctx.globals.missed_shots[player->EntIndex()])
    {
        switch (last_side)
        {
        case RESOLVER_ORIGINAL:
            g_ctx.globals.missed_shots[player->EntIndex()] = 0;
            break;
        case RESOLVER_ZERO:
            player_record->side = RESOLVER_LOW_POSITIVE;

            was_first_bruteforce = false;
            was_second_bruteforce = false;
            return;
        case RESOLVER_POSITIVE:
            player_record->side = was_second_bruteforce ? RESOLVER_ZERO : RESOLVER_NEGATIVE;

            was_first_bruteforce = true;
            return;
        case RESOLVER_NEGATIVE:
            player_record->side = was_first_bruteforce ? RESOLVER_ZERO : RESOLVER_POSITIVE;

            was_second_bruteforce = true;
            return;
        case RESOLVER_LOW_POSITIVE:
            player_record->side = RESOLVER_LOW_NEGATIVE;
            return;
        case RESOLVER_LOW_NEGATIVE:
            player_record->side = RESOLVER_POSITIVE;
            return;
        }
    }

    auto valid_move = true;
    if (animstate->m_velocity > 0.1f)
    {
        valid_move = animstate->m_flTimeSinceStartedMoving < 0.22f;
    }

    if (valid_move && player_record->layers[3].m_flWeight == 0.f && player_record->layers[3].m_flCycle == 0.f && player_record->layers[6].m_flWeight == 0.f)
    {
        auto delta = math::angle_difference(player->m_angEyeAngles().y, zero_goal_feet_yaw);
        auto positive_resolver = (2 * (delta <= 0.0f) - 1) > 0;
        player_record->side = positive_resolver ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
    }
    else if (!valid_move &&    !(static_cast<int>(player_record->layers[12].m_flWeight * 1000.f)) && static_cast<int>(player_record->layers[6].m_flWeight * 1000.f) == static_cast<int>(previous_layers[6].m_flWeight * 1000.f))
    {
        auto delta_negative = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[0][6].m_flPlaybackRate);
        auto delta_zero = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[1][6].m_flPlaybackRate);
        auto delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate);

         if (delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate))

        if (delta_zero < delta_positive || delta_negative <= delta_positive || (delta_positive * 1000.f))
        {
            if (delta_zero >= delta_negative && delta_positive > delta_negative && !(delta_negative * 1000.f))
            {
                player_record->side = RESOLVER_POSITIVE;
            }
        }
        else
        {
            player_record->side = RESOLVER_NEGATIVE;
        }

float v25, v26, v27, v28
      if ( ( v25 - v26 ) <= v27 ) {
         if ( -v27 <= ( v25 - v26 ) )
            v28 = v25;
         else
            v28 = v26 - v27;
      } else {
         v28 = v26 + v27;
         player_record->lock_side = 1;
      }

      std::cout "rezolver mod 1 ";
      m_globals()->m_curtime;
      m_globals()->m_curtime;
      //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);
    }
    else
    {
        autowall::get().wall_penetration = m_globals()->m_curtime; // grenade prediction
        auto lby_update_de
        entity->SetEyeAngles(info.lby); // set final 6 layer lta = abs((((update_delta + 180) % 360 + 360) % 360 - 180));
        if (m_globals()->m_curtime - lock_side > 2.0f)
        {
            auto fire_data_positive = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.positive), player);
            auto fire_data_negative = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.negative), player);

            if (fire_data_positive.visible != fire_data_negative.visible)
            {
                player_record->side = fire_data_negative.visible ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                lock_side = m_globals()->m_curtime;
            }
            else
            {
                if (fire_data_positive.damage != fire_data_negative.damage)
                {
                    player_record->side = fire_data_negative.damage > fire_data_positive.damage ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                }
            }
            else if if if else (
                find_layer(1))
                - 67
            std::regex("final reziolver set4eed hlgjnv ");
            //XIAOMI HOOK MI MIX WARE BETA V4.LUA.JS.CC.COM
float for (std::vector<>::iterator i = .begin(); i != .end(); ++i)
{
   
}
fire_data_positive
was_first_bruteforce
    return;

    bool is_local_player = entity == local_player;
    bool is_teammate = local_player->GetTeam() == entity->GetTeam() && !is_local_player;

    if (is_local_player)
        return;

    if (is_teammate)
        return;

    if (entity->GetHealth() <= 0)
        return;

    if (local_player->GetHealth() <= 0)
        return;

    //--- Variable Declaration ---//;
    auto &info = player_info[entity->GetIndex()];

    //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);

    info.back = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 180.f, 0.f);
    info.right = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 70.f, 0.f);
    info.left = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y - 70.f, 0.f);

    info.backtrack = Vector(entity->GetEyeAngles().x, lby_to_back[entity->GetIndex()], 0.f);

    shots_missed[entity->GetIndex()] = shots_fired[entity->GetIndex()] - shots_hit[entity->GetIndex()];
    info.is_moving = entity->GetVelocity().Length2D() > 0.1 && entity->GetFlags() & FL_ONGROUND && !info.could_be_slowmo;
    info.is_jumping = !entity->GetFlags() & FL_ONGROUND;
    info.could_be_slowmo = entity->GetVelocity().Length2D() > 6 && entity->GetVelocity().Length2D() < 36 && !info.is_crouching;
    info.is_crouching = entity->GetFlags() & FL_DUCKING;
    update_time[entity->GetIndex()] = info.next_lby_update_time;

    static float old_simtime[65];
    if (entity->GetSimTime() != old_simtime[entity->GetIndex()])
    {
        using_fake_angles[entity->GetIndex()] = entity->GetSimTime() - old_simtime[entity->GetIndex()] == INTERFACES::Globals->interval_per_tick; entity->GetSimTime() - old_simtime[entity->GetIndex()] >= TICKS_TO_TIME(2);
        old_simtime[entity->GetIndex()] = entity->GetSimTime();
    }

    //--- Actual Angle Resolving ---//
    if (!using_fake_angles[entity->GetIndex()])
    {
        if (backtrack_tick[entity->GetIndex()])
        {
            resolve_type[entity->GetIndex()] = 7;
            entity->SetEyeAngles(info.backtrack);
        }
        else if (info.stored_lby != entity->GetLowerBodyYaw()) // || entity->GetSimTime() > info.next_lby_update_time) lby prediction
        {
            entity->GetSimTime() > info.next_lby_update_time;
            entity->SetEyeAngles(info.lby);
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            info.stored_lby = entity->GetLowerBodyYaw();
            resolve_type[entity->GetIndex()] = 3;
        }
        else if (info.is_jumping)
        {
            nospread_resolve(entity, entity->GetIndex());
        }
        else if (info.is_moving) //while moving
        {
            entity->SetEyeAngles(info.lby);
            info.last_moving_lby = entity->GetLowerBodyYaw();
            info.stored_missed = shots_missed[entity->GetIndex()];
            resolve_type[entity->GetIndex()] = 1;
        }
        else
        {
            if (shots_missed[entity->GetIndex()] > info.stored_missed) //if we have missed 1 shot since we have stopped moving
            {
                resolve_type[entity->GetIndex()] = 4;
                switch (shots_missed[entity->GetIndex()] % 4)
                {
                case 0: entity->SetEyeAngles(info.inverse); break;
                case 1: entity->SetEyeAngles(info.left); break;
                case 2: entity->SetEyeAngles(info.back); break;
                case 3: entity->SetEyeAngles(info.right); break;
                }
            }
            else //first thing we shoot when they stop
            {
                entity->SetEyeAngles(info.last_lby);
                resolve_type[entity->GetIndex()] = 5;
            }
        }
    }


    SDK::CAnimationLayer layer = entity->GetAnimOverlay(0);
    if (entity->GetSimTime() != info.stored_simtime)
    {
        info.stored_simtime = entity->GetSimTime();
        info.prev_layer = info.backup_layer;
        SDK::CAnimationLayer dummy;
        info.backup_layer = find_layer(entity, 979, &dummy) ? dummy : layer;
    }

    SDK::CAnimationLayer prev = info.prev_layer;
    auto server_time = local_player->GetTickBase() * INTERFACES::Globals->interval_per_tick; //i have a global dedicated to curtime but am using this because lemon is gay

    if (info.is_moving && !info.could_be_slowmo)
    {
        entity->SetEyeAngles(info.lby);
        info.last_moving_lby = entity->GetLowerBodyYaw();
        info.stored_missed = shots_missed[entity->GetIndex()];
        info.last_move_time = server_time;
        info.reset_state = true;
        resolve_type[entity->GetIndex()] = 1;
    }
    else
    {
        if (info.stored_lby != entity->GetLowerBodyYaw())
        {
            entity->SetEyeAngles(info.lby);
            info.stored_lby = entity->GetLowerBodyYaw();
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            resolve_type[entity->GetIndex()] = 7;
        }
        else if (server_time - info.last_move_time < 0.1 && info.reset_state)
        {
            info.pre_anim_lby = entity->GetLowerBodyYaw();
            info.reset_state = false;
            info.breaking_lby = false;
            //std::cout << "reset and lby break is false!" << std::endl;
        }
        auto previous_is_valid = entity->
        }
    }
}

float resolver::resolve_pitch()
{
    return original_pitch;
}
bool aim::hitbox_intersection(player_t* e, matrix3x4_t* matrix, int hitbox, const Vector& start, const Vector& end)
{
    // note: simv0l - pasted from r7 software.
    auto model = e->GetModel();

    if (!model)
        return false;

    auto studio_model = m_modelinfo()->GetStudioModel(model);

    if (!studio_model)
        return false;

    auto studio_set = studio_model->pHitboxSet(e->m_nHitboxSet());

    if (!studio_set)
        return false;

    auto studio_hitbox = studio_set->pHitbox(hitbox);

    if (!studio_hitbox)
        return false;

    Vector min, max;

    const auto is_capsule = studio_hitbox->radius != -1.f;

    if (is_capsule)
    {
        math::vector_transform(studio_hitbox->bbmin, matrix[studio_hitbox->bone], min);
        math::vector_transform(studio_hitbox->bbmax, matrix[studio_hitbox->bone], max);
        const auto dist = math::segment_to_segment(start, end, min, max);

        if (dist < studio_hitbox->radius)
            return true;
    }
    else
    {
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmin, studio_hitbox->rotation), matrix[studio_hitbox->bone], min);
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmax, studio_hitbox->rotation), matrix[studio_hitbox->bone], max);

        math::vector_i_transform(start, matrix[studio_hitbox->bone], min);
        math::vector_i_rotate(end, matrix[studio_hitbox->bone], max);

        if (math::intersect_line_with_bb(min, max, studio_hitbox->bbmin, studio_hitbox->bbmax))
            return true;
    }

    return false;
также девкор сурс
Пожалуйста, авторизуйтесь для просмотра ссылки.
Anko1337
зачем девкор сдк слил
 
desolver.dev
Участник
Статус
Оффлайн
Регистрация
21 Май 2017
Сообщения
465
Реакции[?]
397
Поинты[?]
1K
мой резольвер по анимациям проперный работает хорошо делал 30 лет


C++:
#include "animation_system.h"
#include "..\ragebot\aim.h"

void resolver::initialize(player_t* e, adjust_data* record, const float& goal_feet_yaw, const float& pitch)
{
    player = e;
    player_record = record;

    original_goal_feet_yaw = math::normalize_yaw(goal_feet_yaw);
    original_pitch = math::normalize_pitch(pitch);
}
Vector old_calcangle(Vector dst, Vector src)
{
    Vector angles;

    double delta[3] = { (src.x - dst.x), (src.y - dst.y), (src.z - dst.z) };
    double hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
    angles.x = (float)(atan(delta[2] / hyp) * 180.0 / 3.14159265);
    angles.y = (float)(atanf(delta[1] / delta[0]) * 57.295779513082f);
    angles.z = 0.0f;

    if (delta[0] >= 0.0)
    {
        angles.y += 180.0f;
    }

    return angles;
}

bool find_layer(SDK::CBaseEntity* entity, int act, SDK::CAnimationLayer *set)
{
    for (int i = 0; i < 13; i++)
    {
        SDK::CAnimationLayer layer = entity->GetAnimOverlay(i);
        const int activity = entity->GetSequenceActivity(layer.m_nSequence);
        if (activity == act) {
            *set = layer;
            return true;
        }
    }
    return false;
}

float old_normalize(float Yaw)
{
    if (Yaw > 180)
    {
        Yaw -= (round(Yaw / 360) * 360.f);
    }
    else if (Yaw < -180)
    {
        Yaw += (round(Yaw / 360) * -360.f);
    }
    return Yaw;
}
void resolver::reset()
{
    player = nullptr;
    player_record = nullptr;

    was_first_bruteforce = false;
    was_second_bruteforce = false;

    original_goal_feet_yaw = 0.0f;
    original_pitch = 0.0f;
}

#define TICK_INTERVAL            ( g_pGlobalVarsBase->interval_per_tick )

#define ROUND_TO_TICKS( t )        ( TICK_INTERVAL * TIME_TO_TICKS( t ) )

std::deque<LagRecord> LagCompensation::m_PlayerTrack[MAX_PLAYERS];
std::deque<LagRecord> LagCompensation::m_PlayerTrack_Future[MAX_PLAYERS];
LagRecord LagCompensation::m_RestoreData; //[MAX_PLAYERS];
SDK::CBaseEntity* LagCompensation::m_pCurrentPlayer;
#define LC_NONE                0
#define LC_ALIVE            (1<<0)
#define LC_ORIGIN_CHANGED    (1<<8)
#define LC_ANGLES_CHANGED    (1<<9)
#define LC_SIZE_CHANGED        (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)
static float GetAverageMovementCurve(int entIndex, SDK::CBaseEntity* ent)
{
    Vector p1 = Vector(0, 0, 0);
    Vector p2 = Vector(0, 0, 0);
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
    {
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ROTATION_CALC_TIME && i > 3)
            break;
        else if (i > 2)
        {
            float angle = 0;
            Vector a1, a2;
            MATH::VectorAngles(p1, a1);
            MATH::VectorAngles(p2, a2);
            if (a1.y < 0.0f)
                a1.y += 360.0f;
            if (a2.y < 0.0f)
                a2.y += 360.0f;
            angle = a2.y - a1.y;
            if (angle > 180.0f)
                angle -= 360.0f;
            ret += angle;
            ticks++;
        }
        p1 = p2;
        if (i > 0)
            p2 = (LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecOrigin - LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_vecOrigin);
        p2.z = 0;
        p2.NormalizeInPlace();
    }
    ret /= max(1, ticks);
    return ret;
}

static Vector GetMovementDirection(int entIndex, SDK::CBaseEntity* ent)
{
    Vector ret = Vector(0, 0, 0);
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > DIRECTION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity;
    ret /= max(1, ticks);
    return ret.NormalizeInPlace();
}

static float GetAverageAcceleration(int entIndex, SDK::CBaseEntity* ent)
{
    float vel = ent->GetVelocity().Length2D();
    float ret = 0;
    int ticks = 0;
    for (size_t i = 0; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        if (INTERFACES::Globals->curtime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime > ACCELERATION_CALC_TIME && ticks++ > 1)
            break;
        else
            ret += LagCompensation::m_PlayerTrack[entIndex].at(i).m_vecVelocity.Length2D() - vel;
    ret /= max(1, ticks);
    return ret;
}

static void CreateCircles(Circle circles[5], int entIndex)
{
    size_t size = LagCompensation::m_PlayerTrack[entIndex].size();
    if (size >= 3)
    {
        size = 0;
        for (size = 0; size < LagCompensation::m_PlayerTrack[entIndex].size(); size++)
        {
            if (g_GlobalVars->curtime - LagCompensation::m_PlayerTrack[entIndex].at(size).m_flSimulationTime > ROTATION_CALC_TIME && size > 3)
                break;
        }
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at((size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(2 * (size - 1) / 3).m_vecOrigin, LagCompensation::m_PlayerTrack[entIndex].at(size - 1).m_vecOrigin);
    }
    else if (size >= 1) {
        circles[0] = Circle(LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin, 3604207201337.f, 1.f);
    }
}

static float CalculateAverageSimtimeDelta(int entIndex)
{
    float ret = 0;
    for (size_t i = 1; i < LagCompensation::m_PlayerTrack[entIndex].size(); i++)
        ret += LagCompensation::m_PlayerTrack[entIndex].at(i - 1).m_flSimulationTime - LagCompensation::m_PlayerTrack[entIndex].at(i).m_flSimulationTime;
    ret /= max(1, (int)LagCompensation::m_PlayerTrack[entIndex].size());
    return ret;
}void CBacktrack::run_legit(SDK::CUserCmd* cmd) //phook backtrack muahhahahahaaha
{
    int bestTargetIndex = -1;
    float bestFov = FLT_MAX;
    SDK::player_info_t info;

    auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());

    if (!local_player)
        return;

    for (int i = 1; i < 65; i++)
    {
        auto entity = INTERFACES::ClientEntityList->GetClientEntity(i);

        if (!entity)
            continue;

        if (entity == local_player)
            continue;

        if (!INTERFACES::Engine->GetPlayerInfo(i, &info))
            continue;

        if (entity->GetIsDormant())
            continue;

        if (entity->GetTeam() == local_player->GetTeam())
            continue;

        if (!local_player->GetHealth() > 0)
            return;

        if (entity->GetHealth() > 0)
        {
            float simtime = entity->GetSimTime();
            Vector hitboxPos = aimbot->get_hitbox_pos(entity, 0);

            headPositions[i][cmd->command_number % 12] = legit_backtrackdata{ simtime, hitboxPos };
            Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
            Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();
            float FOVDistance = point_to_line(hitboxPos, local_position, ViewDir);
    c_player_records* log = &records[m_player->entindex() - 1];

    if (previous && !previous->dormant && previous->data_filled && !record->first_after_dormancy)
    {
        m_player->get_animation_state()->m_primary_cycle = previous->m_primary_cycle;
        m_player->get_animation_state()->m_move_weight = previous->m_move_weight;

        m_player->get_animation_state()->m_strafe_sequence = previous->m_strafe_sequence;
        m_player->get_animation_state()->m_strafe_change_weight = previous->m_strafe_change_weight;
        m_player->get_animation_state()->m_strafe_change_cycle = previous->m_strafe_change_cycle;
        m_player->get_animation_state()->m_acceleration_weight = previous->m_acceleration_weight;
#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_START;
#endif // VIRTUALIZER

    const auto backup_flags = m_player->m_fFlags();
    const auto backup_ieflags = m_player->m_iEFlags();
    const auto backup_duckamt = m_player->m_flDuckAmount();
    const auto backup_lowerbody = m_player->m_flLowerBodyYawTarget();
    const auto backup_move_weight = m_player->get_animation_state()->m_move_weight;
    const auto backup_primary_cycle = m_player->get_animation_state()->m_primary_cycle;
   
    //const auto backup_poses = m_player->m_flPoseParameter();
    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));

    resolver_records* resolver_info = &feature::resolver->player_records[m_player->entindex() - 1];
    c_player_records* log = &records[m_player->entindex() - 1];

    //m_player->set_abs_angles(QAngle(0, record->eye_angles.y, 0));
    m_player->m_angEyeAngles() = record->eye_angles;
    m_player->m_angEyeAngles().z = 0.f;

    prepare_player_anim_update(m_player, record, previous, resolver_side);

    m_player->set_abs_angles(QAngle(0, m_player->get_animation_state()->m_abs_yaw, 0));

    if (record->lag > 1 && !log->saved_info.fakeplayer && previous && previous->data_filled)
    {
        const auto velocity_per_tick = (record->velocity - previous->velocity) / record->lag;
        //const auto origin_per_tick = (record->origin - previous->origin) / record->lag;
        //auto ticks_animated = 0;
        //auto velocity_speed_delta = abs(fmaxf(record->velocity.Length2D(),previous->velocity.Length2D()));

        const auto lby_delta = fabsf(Math::angle_diff(record->eye_angles.y, record->lower_body_yaw));

        record->is_landed = false;

        for (auto i = 1; i <= record->lag; i++)
        {
            auto simulated_time = record->animation_update_start_time + TICKS_TO_TIME(i);

            //auto origin = ((origin_per_tick * (float)i) + previous->origin);//Math::interpolate(previous->origin, previous->origin, record->origin, frac);
            auto velocity = /*velocity_speed_delta < 30.f ? */((velocity_per_tick * (float)i) + previous->velocity);//Math::interpolate(previous->velocity, previous->velocity, record->velocity, frac);
            //auto duck_amt = ((duck_amount_per_tick * i) + previous->duck_amt);//Math::interpolate(previous->duck_amt, previous->duck_amt, record->duck_amt, frac);

            if (record->duck_amount_per_tick != 0.0f)
            {
                auto v208 = ((record->duck_amt - m_player->m_flDuckAmount()) * record->duck_amount_per_tick)
                    + m_player->m_flDuckAmount();

                m_player->m_flDuckAmount() = fminf(fmaxf(v208, 0.0f), 1.0f);
            }

            if (i == record->lag)
                simulated_time = record->simulation_time;

            if (record->land_in_cycle && !record->is_landed) // landing animation fix
            {
                if (record->land_time < simulated_time) {
                    record->entity_anim_flags |= 1;
                    record->is_landed = true;
                    auto layer = &m_player->get_animation_layer(4);
                    layer->m_flCycle = 0;
                    layer->m_flWeight = 0;

                }
            }

            //}
            //else
            //    on_ground = record->entity_flags & FL_ONGROUND;

            m_player->m_fFlags() = record->entity_anim_flags;

            record->can_rotate = resolver_side != 0 && !log->saved_info.fakeplayer && i < record->lag && (!record->shot_this_tick || record->shot_this_tick && record->shot_time <= simulated_time);

            /*if (!(record->anim_layers[6].m_flCycle == 0.0f || previous->anim_layers[6].m_flCycle == 0.0f) && velocity.Length2D() <= 1.1f)
            {
                velocity.x = (i & 1 ? -1.1f : 1.1f);  
                velocity.y = 0.f;
                velocity.z = 0.f;
            }*/

            //if (record->shot_this_tick && record->shot_time <= simulated_time)
            //    m_player->m_angEyeAngles().y = resolver_info->last_non_shot_angle.y;
            //else
            //m_player->m_angEyeAngles() = record->eye_angles;

            if (record->shot_this_tick)
            {
                if (record->shot_time <= simulated_time) {
                    m_player->m_flThirdpersonRecoil() = record->thirdperson_recoil;
                    m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                }
            }

            //if (record->shot_this_tick && record->shot_time > simulated_time)

            //m_player->m_vecOrigin() = origin;
            //m_player->set_abs_origin(origin);
            if (i == record->lag)
            {
                m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
                m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
                m_player->m_fFlags() = record->entity_flags;
            }

            m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = velocity;
           
            /*if (record->lower_body_yaw != previous->lower_body_yaw)
            {
                auto delta = record->lag - i;

                auto use_new = true;

                if (lby_delta < 1.f)
                    use_new = delta == 0;
                else
                    use_new = delta < 2;

                m_player->m_flLowerBodyYawTarget() = use_new ? record->lower_body_yaw : previous->lower_body_yaw;
            }*/

            //m_player->m_flLowerBodyYawTarget() = record->lby_flicked_time <= simulated_time ? record->lower_body_yaw : previous->lower_body_yaw;

            if (record->can_rotate) {
                auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

                float yaw = m_player->get_animation_state()->m_abs_yaw;

                if (resolver_side <= 0)
                    yaw = record->eye_angles.y - angle;
                else
                    yaw = record->eye_angles.y + angle;

                m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
            }
           
            /* update animations. */
            ctx.updating_resolver = true;
            //m_player->set_abs_origin(origin);
            //m_player->m_vecOrigin() = origin;
            resolver_info->new_velocity = velocity;
            resolver_info->force_velocity = true;

            auto realtime_backup = csgo.m_globals()->realtime;
            auto curtime = csgo.m_globals()->curtime;
            auto frametime = csgo.m_globals()->frametime;
            auto absoluteframetime = csgo.m_globals()->absoluteframetime;
            auto framecount = csgo.m_globals()->framecount;
            auto tickcount = csgo.m_globals()->tickcount;
            auto interpolation_amount = csgo.m_globals()->interpolation_amount;

            int ticks = TIME_TO_TICKS(simulated_time);

            csgo.m_globals()->realtime = simulated_time;
            csgo.m_globals()->curtime = simulated_time;
            csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
            csgo.m_globals()->framecount = ticks;
            csgo.m_globals()->tickcount = ticks;
            csgo.m_globals()->interpolation_amount = 0.f;

            m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;
            m_player->update_clientside_animations();
            m_player->m_iEFlags() = backup_ieflags;
            resolver_info->force_velocity = false;
            ctx.updating_resolver = false;

            csgo.m_globals()->realtime = realtime_backup;
            csgo.m_globals()->curtime = curtime;
            csgo.m_globals()->frametime = frametime;
            csgo.m_globals()->absoluteframetime = absoluteframetime;
            csgo.m_globals()->framecount = framecount;
            csgo.m_globals()->tickcount = tickcount;
            csgo.m_globals()->interpolation_amount = interpolation_amount;
        }
    }
    else
    {
        m_player->m_flLowerBodyYawTarget() = record->lower_body_yaw;
        auto vel = record->velocity;
       
        m_player->m_flDuckAmount() = fminf(fmaxf(record->duck_amt, 0.0f), 1.0f);
        m_player->m_fFlags() = record->entity_flags;
        m_player->m_iEFlags() &= ~EFL_DIRTY_ABSVELOCITY;

        if (!log->saved_info.fakeplayer && resolver_side != 0)
        {
            float yaw = m_player->get_animation_state()->m_abs_yaw;
            auto angle = feature::anti_aim->get_max_desync_delta(m_player) * record->resolver_delta_multiplier;

            if (resolver_side <= 0)
                yaw = record->eye_angles.y - angle;
            else
                yaw = record->eye_angles.y + angle;

            m_player->get_animation_state()->m_abs_yaw = Math::normalize_angle(yaw);
        }
        //if (m_player->get_animation_state()->m_abs_yaw < 0)
        //    m_player->get_animation_state()->m_abs_yaw += 360.f;

        auto realtime_backup = csgo.m_globals()->realtime;
        auto curtime = csgo.m_globals()->curtime;
        auto frametime = csgo.m_globals()->frametime;
        auto absoluteframetime = csgo.m_globals()->absoluteframetime;
        auto framecount = csgo.m_globals()->framecount;
        auto tickcount = csgo.m_globals()->tickcount;
        auto interpolation_amount = csgo.m_globals()->interpolation_amount;

        int ticks = TIME_TO_TICKS(record->simulation_time);

        csgo.m_globals()->realtime = record->simulation_time;
        csgo.m_globals()->curtime = record->simulation_time;
        csgo.m_globals()->frametime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->absoluteframetime = csgo.m_globals()->interval_per_tick;
        csgo.m_globals()->framecount = ticks;
        csgo.m_globals()->tickcount = ticks;
        csgo.m_globals()->interpolation_amount = 0.f;

        m_player->m_vecAbsVelocity() = m_player->m_vecVelocity() = vel;

        /* update animations. */
        ctx.updating_resolver = true;
        resolver_info->new_velocity = record->velocity;
        resolver_info->force_velocity = true;
        m_player->update_clientside_animations();
        resolver_info->force_velocity = false;
        ctx.updating_resolver = false;

        csgo.m_globals()->realtime = realtime_backup;
        csgo.m_globals()->curtime = curtime;
        csgo.m_globals()->frametime = frametime;
        csgo.m_globals()->absoluteframetime = absoluteframetime;
        csgo.m_globals()->framecount = framecount;
        csgo.m_globals()->tickcount = tickcount;
        csgo.m_globals()->interpolation_amount = interpolation_amount;
    }

    //m_player->set_abs_origin(abs_origin);
    m_player->m_fFlags() = backup_flags;
    //m_player->m_vecVelocity() = backup_m_velocity;
    m_player->m_flDuckAmount() = backup_duckamt;
    m_player->m_flLowerBodyYawTarget() = backup_lowerbody;
    m_player->m_iEFlags() = backup_ieflags;
    //m_player->m_angEyeAngles() = record->eye_angles;
    //m_player->m_flPoseParameter() = backup_poses;

    m_player->get_animation_state()->m_primary_cycle = backup_primary_cycle;
    m_player->get_animation_state()->m_move_weight = backup_move_weight;

    if (resolver_side != 0) {
        if (resolver_side > 0)
        {
            record->animstate_right_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_right_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_right_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_right_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_right_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_right_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_right_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_right_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
        else
        {
            record->animstate_left_params[0] = m_player->get_animation_state()->m_abs_yaw;
            record->animstate_left_params[1] = m_player->get_animation_state()->m_abs_yaw_last;
            record->animstate_left_params[2] = m_player->get_animation_state()->m_move_yaw;
            record->animstate_left_params[3] = m_player->get_animation_state()->m_move_yaw_ideal;
            record->animstate_left_params[4] = m_player->get_animation_state()->m_move_yaw_current_to_ideal;
            record->animstate_left_params[5] = m_player->get_animation_state()->m_move_weight_smoothed;
            record->animstate_left_params[6] = m_player->get_animation_state()->m_in_air_smooth_value;
            record->animstate_left_params[7] = m_player->get_animation_state()->m_time_to_align_lower_body;
        }
    }

    /*if (previous && !record->first_after_dormancy && !previous->dormant && previous->data_filled)
        fix_jump_fall(m_player, record, previous);*/

    m_player->invalidate_anims(8);

#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;
#endif // VIRTUALIZER
}

void c_lagcomp::recalculate_velocity(C_Tickrecord* record, C_BasePlayer* m_player, C_Tickrecord* previous)
{
    VIRTUALIZER_FISH_LITE_START;

    static /*const*/ ConVar* sv_gravity = csgo.m_engine_cvars()->FindVar(sxor("sv_gravity"));
    static /*const*/ ConVar* sv_jump_impulse = csgo.m_engine_cvars()->FindVar(sxor("sv_jump_impulse"));
    static /*const*/ ConVar* sv_enablebunnyhopping = csgo.m_engine_cvars()->FindVar(sxor("sv_enablebunnyhopping"));

    auto log = &records[m_player->entindex() - 1];
    auto r_log = &feature::resolver->player_records[m_player->entindex() - 1];

    /* fix z velocity if enemy is in air. */
    /* https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/shared/gamemovement.cpp#L1697 */

    //auto& old_origin = *(Vector*)(uintptr_t(m_player) + 0x3A4);

    if (record->entity_flags & FL_ONGROUND
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight > 0.0f
        && record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight < 1.0f)
    {
        // float val = clamp ( ( speed - 0.55f ) / ( 0.9f - 0.55f), 0.f, 1.f );
        // layer11_weight = 1.f - val;
        auto val = (1.0f - record->anim_layers[ANIMATION_LAYER_ALIVELOOP].m_flWeight) * 0.35f;

        if (val > 0.0f && val < 1.0f)
            record->animation_speed = val + 0.55f;
        else
            record->animation_speed = -1.f;
    }

    if (_fdtest(&record->velocity.x) > 0
        || _fdtest(&record->velocity.y) > 0
        || _fdtest(&record->velocity.z) > 0)
        record->velocity.clear();

    if (!record->first_after_dormancy && previous && !previous->dormant && previous->data_filled)
    {
        //
        //    calculate new velocity based on (new_origin - old_origin) / (new_time - old_time) formula.
        //
        if (record->lag > 1 && record->lag <= 20)
            record->velocity = (record->origin - previous->origin) / record->time_delta;
       
        if (abs(record->velocity.x) < 0.001f)
            record->velocity.x = 0.0f;
        if (abs(record->velocity.y) < 0.001f)
            record->velocity.y = 0.0f;
        if (abs(record->velocity.z) < 0.001f)
            record->velocity.z = 0.0f;

        if (_fdtest(&record->velocity.x) > 0
            || _fdtest(&record->velocity.y) > 0
            || _fdtest(&record->velocity.z) > 0)
            record->velocity.clear();

        auto curr_direction = RAD2DEG(std::atan2f(record->velocity.y, record->velocity.x));
        auto prev_direction = previous == nullptr ? FLT_MAX : RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

        auto delta = Math::normalize_angle(curr_direction - prev_direction);

        if (record->velocity.Length2D() > 0.1f) {
            if (previous->velocity.Length2D() > 0.1f && abs(delta) >= 60.f)
                r_log->last_time_changed_direction = csgo.m_globals()->realtime;
        }
        else
            r_log->last_time_changed_direction = 0;

        //
        // these requirements pass only when layer[6].weight is accurate to normalized velocity.
        //
        if (record->entity_flags & FL_ONGROUND
            && record->velocity.Length2D() >= 0.1f
            && std::abs(delta) < 1.0f
            && std::abs(record->duck_amt - previous->duck_amt) <= 0.0f
            && record->anim_layers[6].m_flPlaybackRate > previous->anim_layers[6].m_flPlaybackRate
            && record->anim_layers[6].m_flWeight > previous->anim_layers[6].m_flWeight)
        {
            auto weight_speed = record->anim_layers[6].m_flWeight;

            if (weight_speed <= 0.7f && weight_speed > 0.0f)
            {
                if (record->anim_layers[6].m_flPlaybackRate == 0.0f)
                    record->velocity.clear();
                else
                {
                    const auto m_post_velocity_lenght = record->velocity.Length2D();

                    if (m_post_velocity_lenght != 0.0f)
                    {
                        float mult = 1;
                        if (record->entity_flags & 6)
                            mult = 0.34f;
                        else if (record->fake_walking)
                            mult = 0.52f;

                        record->velocity.x = (record->velocity.x / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                        record->velocity.y = (record->velocity.y / m_post_velocity_lenght) * (weight_speed * (record->max_current_speed * mult));
                    }
                }
            }
        }

        //
        // fix velocity with fakelag.
        //
        if (record->entity_flags & FL_ONGROUND && record->velocity.Length2D() > 0.1f && record->lag > 1)
        {
            //
            // get velocity lenght from 11th layer calc.
            //
            if (record->animation_speed > 0) {
                const auto m_pre_velocity_lenght = record->velocity.Length2D();
                C_WeaponCSBaseGun* weapon = m_player->get_weapon();

                if (weapon) {
                    auto wdata = weapon->GetCSWeaponData();
                    if (wdata) {
                        auto adjusted_velocity = (record->animation_speed * record->max_current_speed) / m_pre_velocity_lenght;
                        record->velocity.x *= adjusted_velocity;
                        record->velocity.y *= adjusted_velocity;
                    }
                }
            }

            /*if (record->entity_flags & FL_ONGROUND && (sv_enablebunnyhopping && !sv_enablebunnyhopping->GetBool() || previous->entity_flags & FL_ONGROUND)) {
                auto max_speed = record->max_current_speed;

                if (record->entity_flags & 6)
                    max_speed *= 0.34f;
                else if (record->fake_walking)
                    max_speed *= 0.52f;

                if (max_speed < m_pre_velocity_lenght)
                    record->velocity *= (max_speed / m_pre_velocity_lenght);

                if (previous->entity_flags & FL_ONGROUND)
                    record->velocity.z = 0.f;
            }*/
        }

        if (log->records_count > 2 && record->lag > 1 && !record->first_after_dormancy
            && previous->velocity.Length() > 0 && !(record->entity_flags & FL_ONGROUND && previous->entity_flags & FL_ONGROUND))
        {
            auto pre_pre_record = &log->tick_records[(log->records_count - 2) & 63];

            if (!pre_pre_record->dormant && pre_pre_record->data_filled) {
                //if (record->velocity.Length2D() > (record->max_current_speed * 0.52f) && previous->velocity.Length2D() > (record->max_current_speed * 0.52f)
                //    || record->velocity.Length2D() <= (record->max_current_speed * 0.52f) && previous->velocity.Length2D() <= (record->max_current_speed * 0.52f))
                //{
                //    auto manually_calculated = log->tick_records[(log->records_count - 2) & 63].stop_to_full_run_frac;
                //    manually_calculated += (record->velocity.Length2D() > (record->max_current_speed * 0.52f) ? (2.f * previous->time_delta) : -(2.f * previous->time_delta));

                //    manually_calculated = Math::clamp(manually_calculated, 0, 1);

                //    if (abs(manually_calculated - previous->stop_to_full_run_frac) >= 0.1f)// {
                //        m_player->get_animation_state()->m_walk_run_transition = manually_calculated;
                //}

                const auto prev_direction = RAD2DEG(std::atan2f(previous->velocity.y, previous->velocity.x));

                auto real_velocity = record->velocity.Length2D();

                float delta = curr_direction - prev_direction;

                if (delta <= 180.0f)
                {
                    if (delta < -180.0f)
                        delta = delta + 360.0f;
                }#include "..\misc\misc.h"
#include "..\misc\logs.h"
#include "..\autowall\autowall.h"
#include "..\misc\prediction_system.h"
#include "..\fakewalk\slowwalk.h"
#include "..\lagcompensation\local_animations.h"

void aim::run(CUserCmd* cmd)
{
    backup.clear();
    targets.clear();
    scanned_targets.clear();
    final_target.reset();
    should_stop = false;

    if (!g_cfg.ragebot.enable)
        return;

    automatic_revolver(cmd);
    prepare_targets();

    if (g_ctx.globals.weapon->is_non_aim())
        return;

    if (g_ctx.globals.current_weapon == -1)
        return;

    scan_targets();

    if (!should_stop && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_PREDICTIVE])
    {
        for (auto& target : targets)
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data, g_ctx.globals.eye_pos);

            if (!last_data.valid())
                continue;

            should_stop = true;
            break;
        }
    }

    if (!automatic_stop(cmd))
        return;

    if (scanned_targets.empty())
        return;

    find_best_target();

    if (!final_target.data.valid())
        return;

    fire(cmd);
}

void aim::automatic_revolver(CUserCmd* cmd)
{
    if (!m_engine()->IsActiveApp())
        return;

    if (g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
        return;

    if (cmd->m_buttons & IN_ATTACK)
        return;

    cmd->m_buttons &= ~IN_ATTACK2;

    static auto r8cock_time = 0.0f;
    auto server_time = TICKS_TO_TIME(g_ctx.globals.backup_tickbase);

    if (g_ctx.globals.weapon->can_fire(false))
    {
        if (r8cock_time <= server_time)
        {
            if (g_ctx.globals.weapon->m_flNextSecondaryAttack() <= server_time)
                r8cock_time = server_time + TICKS_TO_TIME(13);
            else
                cmd->m_buttons |= IN_ATTACK2;
        }
        else
            cmd->m_buttons |= IN_ATTACK;
    }
    else
    {
        r8cock_time = server_time + TICKS_TO_TIME(13);
        cmd->m_buttons &= ~IN_ATTACK;
    }

    g_ctx.globals.revolver_working = true;
}

void aim::prepare_targets()
{
    for (auto i = 1; i < m_globals()->m_maxclients; i++)
    {
        if (g_cfg.player_list.white_list[i])
            continue;

        auto e = (player_t*)m_entitylist()->GetClientEntity(i);

        if (!e->valid(true, false))
            continue;

        auto records = &player_records[i];

        if (records->empty())
            continue;
   
        targets.emplace_back(target(e, get_record(records, false), get_record(records, true)));
    }

    for (auto& target : targets)
        backup.emplace_back(adjust_data(target.e));
}

static bool compare_records(const optimized_adjust_data& first, const optimized_adjust_data& second)
{
    if (first.shot != second.shot)
        return first.shot;
    else if (first.speed != second.speed)
        return first.speed > second.speed;

    return first.simulation_time < second.simulation_time;
}

adjust_data* aim::get_record(std::deque <adjust_data>* records, bool history)
{
    if (history)
    {
        std::deque <optimized_adjust_data> optimized_records;

        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);
            optimized_adjust_data optimized_record;

            optimized_record.i = i;
            optimized_record.player = record->player;
            optimized_record.simulation_time = record->simulation_time;
            optimized_record.speed = record->velocity.Length();
            optimized_record.shot = record->shot;

            optimized_records.emplace_back(optimized_record);
        }

        if (optimized_records.size() < 2)
            return nullptr;

        std::sort(optimized_records.begin(), optimized_records.end(), compare_records);

        for (auto& optimized_record : optimized_records)
        {
            auto record = &records->at(optimized_record.i);

            if (!record->valid())
                continue;

            return record;
        }
    }
    else
    {
        for (auto i = 0; i < records->size(); ++i)
        {
            auto record = &records->at(i);

            if (!record->valid())
                continue;

            return record;
        }
    }

    return nullptr;
}

int aim::get_minimum_damage(bool visible, int health)
{
    if (key_binds::get().get_key_bind_state(4))
    {
        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage > 100)
            return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage - 100;
        else
            return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_override_damage, 1, health);
    }
    else
    {
        if (visible)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_visible_damage, 1, health);
        }
        else
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage > 100)
                return health + g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage - 100;
            else
                return math::clamp(g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].minimum_damage, 1, health);
        }
    }
}

void aim::scan_targets()
{
    if (targets.empty())
        return;

    for (auto& target : targets)
    {
        if (target.history_record->valid())
        {
            scan_data last_data;

            if (target.last_record->valid())
            {
                target.last_record->adjust_player();
                scan(target.last_record, last_data);
            }

            scan_data history_data;

            target.history_record->adjust_player();
            scan(target.history_record, history_data);

            if (last_data.valid() && last_data.damage > history_data.damage)
                scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
            else if (history_data.valid())
                scanned_targets.emplace_back(scanned_target(target.history_record, history_data));
        }
        else
        {
            if (!target.last_record->valid())
                continue;

            scan_data last_data;

            target.last_record->adjust_player();
            scan(target.last_record, last_data);

            if (!last_data.valid())
                continue;

            scanned_targets.emplace_back(scanned_target(target.last_record, last_data));
        }
    }
}

bool aim::automatic_stop(CUserCmd* cmd)
{
    if (!should_stop)
        return true;

    if (g_ctx.globals.slowwalking)
        return true;

    if (!(g_ctx.local()->m_fFlags() & FL_ONGROUND && engineprediction::get().backup_data.flags & FL_ONGROUND))
        return true;

    if (g_ctx.globals.weapon->is_empty())
        return true;

    if (!g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_BETWEEN_SHOTS] && !g_ctx.globals.weapon->can_fire(false))
        return true;

    auto animlayer = g_ctx.local()->get_animlayers()[1];

    if (animlayer.m_nSequence)
    {
        auto activity = g_ctx.local()->sequence_activity(animlayer.m_nSequence);

        if (activity == ACT_CSGO_RELOAD && animlayer.m_flWeight > 0.0f)
            return true;
    }

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

    if (!weapon_info)
        return true;

    auto max_speed = 0.33f * (g_ctx.globals.scoped ? weapon_info->flMaxPlayerSpeedAlt : weapon_info->flMaxPlayerSpeed);

    if (engineprediction::get().backup_data.velocity.Length2D() < max_speed)
        slowwalk::get().create_move(cmd);
    else
    {
        Vector direction;
        Vector real_view;

        math::vector_angles(engineprediction::get().backup_data.velocity, direction);
        m_engine()->GetViewAngles(real_view);

        direction.y = real_view.y - direction.y;

        Vector forward;
        math::angle_vectors(direction, forward);

        static auto cl_forwardspeed = m_cvar()->FindVar(crypt_str("cl_forwardspeed"));
        static auto cl_sidespeed = m_cvar()->FindVar(crypt_str("cl_sidespeed"));

        auto negative_forward_speed = -cl_forwardspeed->GetFloat();
        auto negative_side_speed = -cl_sidespeed->GetFloat();

        auto negative_forward_direction = forward * negative_forward_speed;
        auto negative_side_direction = forward * negative_side_speed;

        cmd->m_forwardmove = negative_forward_direction.x;
        cmd->m_sidemove = negative_side_direction.y;

        if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_FORCE_ACCURACY])
            return false;
    }

    return true;
}

void aim::scan(adjust_data* record, scan_data& data, const Vector& shoot_position)
{
    if (!g_ctx.globals.weapon)
        return;

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

    if (!weapon_info)
        return;

    auto hitboxes = get_hitboxes(record);

    if (hitboxes.empty())
        return;

    auto best_damage = 0;

    auto minimum_damage = get_minimum_damage(false, record->player->m_iHealth());
    auto minimum_visible_damage = get_minimum_damage(true, record->player->m_iHealth());

    std::vector <scan_point> points;

    for (auto& hitbox : hitboxes)
    {
        auto current_points = get_points(record, hitbox);

        for (auto& point : current_points)
        {
            if ((g_ctx.globals.eye_pos - final_target.data.point.point).Length() <= weapon_info->flRange)
            {
                point.safe = record->bot || (hitbox_intersection(record->player, record->matrixes_data.positive, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.zero, hitbox, shoot_position, point.point) && hitbox_intersection(record->player, record->matrixes_data.negative, hitbox, shoot_position, point.point));
                if (!(key_binds::get().get_key_bind_state(3) || g_cfg.player_list.force_safe_points[record->i]) || point.safe)
                {
                    points.emplace_back(point);
                }
            }
        }
    }

    if (points.empty())
        return;

    for (auto& point : points)
    {
        if (!point.safe)
        {
            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INAIR] && !(record->flags & FL_ONGROUND))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_INCROUCH] && record->flags & FL_ONGROUND && record->flags & FL_DUCKING)
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_ONLIMBS] && (point.hitbox >= HITBOX_RIGHT_THIGH && point.hitbox < HITBOX_MAX))
                continue;

            if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].safe_points_conditions[SAFEPOINTS_VISIBLE] && util::visible(g_ctx.globals.eye_pos, point.point, record->player, g_ctx.local()))
                continue;
        }

        if (point.hitbox < HITBOX_PELVIS || point.hitbox > HITBOX_UPPER_CHEST)
        {
            if (g_cfg.player_list.force_body_aim[record->i])
                continue;

            if (key_binds::get().get_key_bind_state(22))
                continue;
        }

        auto fire_data = autowall::get().wall_penetration(shoot_position, point.point, record->player);

        if (!fire_data.valid)
            continue;

        if (fire_data.damage < 1)
            continue;

        if (!fire_data.visible && !g_cfg.ragebot.autowall)
            continue;

        auto current_minimum_damage = fire_data.visible ? minimum_visible_damage : minimum_damage;

        if (fire_data.damage >= current_minimum_damage && fire_data.damage >= best_damage)
        {
            if (!should_stop)
            {
                should_stop = true;

                if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_LETHAL] && fire_data.damage < record->player->m_iHealth())
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_VISIBLE] && !fire_data.visible)
                    should_stop = false;
                else if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].automatic_stop_conditions[AUTOSTOP_CENTER] && !point.center)
                    should_stop = false;
            }

            best_damage = fire_data.damage;

            data.point = point;
            data.visible = fire_data.visible;
            data.damage = fire_data.damage;
            data.hitbox = fire_data.hitbox;
        }
    }
}

std::vector <int> aim::get_hitboxes(adjust_data* record)
{
    std::vector <int> hitboxes;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(0))
        hitboxes.emplace_back(HITBOX_HEAD);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(1))
        hitboxes.emplace_back(HITBOX_UPPER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(2))
        hitboxes.emplace_back(HITBOX_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(3))
        hitboxes.emplace_back(HITBOX_LOWER_CHEST);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(4))
        hitboxes.emplace_back(HITBOX_STOMACH);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(5))
        hitboxes.emplace_back(HITBOX_PELVIS);

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(6))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_UPPER_ARM);
        hitboxes.emplace_back(HITBOX_LEFT_UPPER_ARM);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(7))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_THIGH);
        hitboxes.emplace_back(HITBOX_LEFT_THIGH);

        hitboxes.emplace_back(HITBOX_RIGHT_CALF);
        hitboxes.emplace_back(HITBOX_LEFT_CALF);
    }

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitboxes.at(8))
    {
        hitboxes.emplace_back(HITBOX_RIGHT_FOOT);
        hitboxes.emplace_back(HITBOX_LEFT_FOOT);
    }

    return hitboxes;
}

std::vector <scan_point> aim::get_points(adjust_data* record, int hitbox, bool from_aim)
{
    std::vector <scan_point> points;
    auto model = record->player->GetModel();

    if (!model)
        return points;

    auto hdr = m_modelinfo()->GetStudioModel(model);

    if (!hdr)
        return points;

    auto set = hdr->pHitboxSet(record->player->m_nHitboxSet());

    if (!set)
        return points;

    auto bbox = set->pHitbox(hitbox);

    if (!bbox)
        return points;

    const auto mod = bbox->radius != -1.0f ? bbox->radius : 0.0f;

    Vector max;
    Vector min;
    math::vector_transform(bbox->bbmax + mod, record->matrixes_data.main[bbox->bone], max);
    math::vector_transform(bbox->bbmin - mod, record->matrixes_data.main[bbox->bone], min);

    const auto center = (min + max) * 0.5f;

    points.emplace_back(scan_point(center, hitbox, true));

    if (!bbox->radius)
        return points;

    if (hitbox == HITBOX_NECK || hitbox == HITBOX_RIGHT_THIGH || hitbox == HITBOX_LEFT_THIGH || hitbox == HITBOX_RIGHT_CALF || hitbox == HITBOX_LEFT_CALF || hitbox == HITBOX_RIGHT_FOOT || hitbox == HITBOX_LEFT_FOOT || hitbox == HITBOX_RIGHT_HAND || hitbox == HITBOX_LEFT_HAND || hitbox == HITBOX_RIGHT_UPPER_ARM || hitbox == HITBOX_LEFT_UPPER_ARM || hitbox == HITBOX_RIGHT_FOREARM || hitbox == HITBOX_LEFT_FOREARM)
        return points;

    const auto cur_angles = math::calculate_angle(center, g_ctx.globals.eye_pos);

    Vector forward;
    math::angle_vectors(cur_angles, forward);

    auto rs = 0.0f;

    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].static_point_scale)
    {
        rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].body_scale;
        if (hitbox == HITBOX_HEAD)
            rs = bbox->radius * g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].head_scale;
    }
    else
    {
        auto transformed_center = center;
        math::vector_transform(transformed_center, record->matrixes_data.main[bbox->bone], transformed_center);

        auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;
        auto distance = transformed_center.DistTo(g_ctx.globals.eye_pos);

        distance /= math::fast_sin(DEG2RAD(90.0f - RAD2DEG(spread)));
        spread = math::fast_sin(spread);

        auto radius = max(bbox->radius - distance * spread, 0.0f);
        rs = bbox->radius * math::clamp(radius / bbox->radius, 0.0f, 1.0f);
    }

    if (rs < 0.2f)
        return points;

    const auto top = Vector(0, 0, 1) * rs;
    const auto right = forward.Cross(Vector(0, 0, 1)) * rs;
    const auto left = Vector(-right.x, -right.y, right.z);

    if (hitbox == HITBOX_HEAD)
        points.emplace_back(scan_point(center + top, hitbox, false));
    points.emplace_back(scan_point(center + right, hitbox, false));
    points.emplace_back(scan_point(center + left, hitbox, false));

    return points;
}

static bool compare_targets(const scanned_target& first, const scanned_target& second)
{
    if (g_cfg.player_list.high_priority[first.record->i] != g_cfg.player_list.high_priority[second.record->i])
        return g_cfg.player_list.high_priority[first.record->i];

    switch (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
    {
    case 1:
        return first.fov < second.fov;
    case 2:
        return first.distance < second.distance;
    case 3:
        return first.health < second.health;
    case 4:
        return first.data.damage > second.data.damage;
    }

    return false;
}

void aim::find_best_target()
{
    if (g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].selection_type)
        std::sort(scanned_targets.begin(), scanned_targets.end(), compare_targets);

    for (auto& target : scanned_targets)
    {
        if (target.fov > (float)g_cfg.ragebot.field_of_view)
            continue;

        final_target = target;
        final_target.record->adjust_player();
        break;
    }
}

void aim::fire(CUserCmd* cmd)
{
    if (!g_ctx.globals.weapon->can_fire(true))
        return;

    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot && !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }

    auto backtrack_ticks = 0;
    auto net_channel_info = m_engine()->GetNetChannelInfo();

    if (net_channel_info)
    {
        auto original_tickbase = g_ctx.globals.backup_tickbase;
        auto max_tickbase_shift = m_gamerules()->m_bIsValveDS() ? 6 : 16;

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap && g_cfg.ragebot.double_tap_key.key > KEY_NONE && g_cfg.ragebot.double_tap_key.key < KEY_MAX && misc::get().double_tap_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().double_tap_enabled && !g_ctx.globals.weapon->is_grenade() && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_TASER && g_ctx.globals.weapon->m_iItemDefinitionIndex() != WEAPON_REVOLVER)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].double_tap_shift_value, max_tickbase_shift);
            }
        }

        if (g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots && g_cfg.ragebot.hide_shots_key.key > KEY_NONE && g_cfg.ragebot.hide_shots_key.key < KEY_MAX && misc::get().hide_shots_key)
        {
            if (!g_ctx.local()->m_bGunGameImmunity() && !(g_ctx.local()->m_fFlags() & FL_FROZEN) && !antiaim::get().freeze_check && misc::get().hide_shots_enabled)
            {
                original_tickbase += min(g_cfg.ragebot.weapon[hooks::rage_weapon].hide_shots_shift_value, max_tickbase_shift);
            }
        }

        static auto sv_maxunlag = m_cvar()->FindVar(crypt_str("sv_maxunlag"));

        auto correct = math::clamp(net_channel_info->GetLatency(FLOW_OUTGOING) + net_channel_info->GetLatency(FLOW_INCOMING) + util::get_interpolation(), 0.0f, sv_maxunlag->GetFloat());
        auto delta_time = correct - (TICKS_TO_TIME(original_tickbase) - final_target.record->simulation_time);

        backtrack_ticks = TIME_TO_TICKS(fabs(delta_time));
    }

    static auto get_hitbox_name = [](int hitbox) -> std::string
    {
        switch (hitbox)
        {
        case HITBOX_HEAD:
            return crypt_str("Head");
        case HITBOX_LOWER_CHEST:
            return crypt_str("Lower chest");
        case HITBOX_CHEST:
            return crypt_str("Chest");
        case HITBOX_UPPER_CHEST:
            return crypt_str("Upper chest");
        case HITBOX_STOMACH:
            return crypt_str("Stomach");
        case HITBOX_PELVIS:
            return crypt_str("Pelvis");
        case HITBOX_RIGHT_UPPER_ARM:
        case HITBOX_RIGHT_FOREARM:
        case HITBOX_RIGHT_HAND:
            return crypt_str("Left arm");
        case HITBOX_LEFT_UPPER_ARM:
        case HITBOX_LEFT_FOREARM:
        case HITBOX_LEFT_HAND:
            return crypt_str("Right arm");
        case HITBOX_RIGHT_THIGH:
        case HITBOX_RIGHT_CALF:
            return crypt_str("Left leg");
        case HITBOX_LEFT_THIGH:
        case HITBOX_LEFT_CALF:
            return crypt_str("Right leg");
        case HITBOX_RIGHT_FOOT:
            return crypt_str("Left foot");
        case HITBOX_LEFT_FOOT:
            return crypt_str("Right foot");
        }
    };

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                else
                {
                    delta = delta - 360.0f;
                }

        if (resolver_side == 0) {
            m_player->get_animation_state()->m_abs_yaw = previous->animstate.m_abs_yaw;
            m_player->get_animation_state()->m_abs_yaw_last = previous->animstate.m_abs_yaw_last;
            m_player->get_animation_state()->m_move_yaw = previous->animstate.m_move_yaw;
            m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate.m_move_yaw_ideal;
            m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate.m_move_yaw_current_to_ideal;
            m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate.m_move_weight_smoothed;
            m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate.m_in_air_smooth_value;
            m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate.m_time_to_align_lower_body;
        }
        else
        {
            if (resolver_side > 0)
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_right_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_right_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_right_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_right_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_right_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_right_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_right_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_right_params[7];
            }
            else
            {
                m_player->get_animation_state()->m_abs_yaw = previous->animstate_left_params[0];
                m_player->get_animation_state()->m_abs_yaw_last = previous->animstate_left_params[1];
                m_player->get_animation_state()->m_move_yaw = previous->animstate_left_params[2];
                m_player->get_animation_state()->m_move_yaw_ideal = previous->animstate_left_params[3];
                m_player->get_animation_state()->m_move_yaw_current_to_ideal = previous->animstate_left_params[4];
                m_player->get_animation_state()->m_move_weight_smoothed = previous->animstate_left_params[5];
                m_player->get_animation_state()->m_in_air_smooth_value = previous->animstate_left_params[6];
                m_player->get_animation_state()->m_time_to_align_lower_body = previous->animstate_left_params[7];
            }
        }
            if (bestFov > FOVDistance)
            {
                bestFov = FOVDistance;
                bestTargetIndex = i;
            }
        }
    }bool c_lagcomp::has_firing_animation(C_BasePlayer* m_player, C_Tickrecord* record)
{
    auto weapon = m_player->get_weapon();
    if (weapon)
    {
        int iWeaponIndex = weapon->m_iItemDefinitionIndex();
        auto act = m_player->get_sec_activity(record->anim_layers[1].m_nSequence);
        if (act == ACT_CSGO_FIRE_PRIMARY || ((act == ACT_CSGO_FIRE_SECONDARY || act == ACT_CSGO_FIRE_SECONDARY_OPT_1 || act == ACT_CSGO_FIRE_SECONDARY_OPT_2) && (iWeaponIndex == WEAPON_GLOCK || iWeaponIndex == WEAPON_REVOLVER || iWeaponIndex == WEAPON_FAMAS || weapon->is_knife())))
            return true;
    }
    return false;
}

CBacktrack* backtracking = new CBacktrack();
legit_backtrackdata headPositions[64][12];
    float bestTargetSimTime;
    if (bestTargetIndex != -1)
    {
        float tempFloat = FLT_MAX;
        Vector ViewDir = angle_vector(cmd->viewangles + (local_player->GetPunchAnglesRec() * 2.f));
        Vector local_position = local_player->GetVecOrigin() + local_player->GetViewOffset();

        for (int t = 0; t < 12; ++t)
        {
            float tempFOVDistance = point_to_line(headPositions[bestTargetIndex][t].hitboxPos, local_position, ViewDir);
            if (tempFloat > tempFOVDistance && headPositions[bestTargetIndex][t].simtime > local_player->GetSimTime() - 1)
            {
                tempFloat = tempFOVDistance;
                bestTargetSimTime = headPositions[bestTargetIndex][t].simtime;
            }
        }
        if (cmd->buttons & IN_ATTACK)
        {
            cmd->tick_count = TIME_TO_TICKS(bestTargetSimTime);
        }
    }
}
static void CreateFutureTicks(int entIndex)
{
    SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(entIndex);
    g_PlayerSettings[entIndex].averageSimTimeDelta = CalculateAverageSimtimeDelta(entIndex);
    SDK::INetChannelInfo* nci = INTERFACES::Engine->GetNetChannelInfo();
    if (nci->GetLatency(FLOW_OUTGOING) < g_PlayerSettings[entIndex].averageSimTimeDelta)
    {
        LagCompensation::m_PlayerTrack_Future[entIndex].clear();
        return;
    }
    //int predictAmount = ((nci->GetLatency(FLOW_OUTGOING) + nci->GetLatency(FLOW_INCOMING)) / INTERFACES::Globals->interval_per_tick) + 0.5f;
    //float predictionAngle = GetAverageMovementCurve(entIndex, ent);
    //float acceleration = GetAverageAcceleration(entIndex, ent);
    //Vector currentPosition = ent->GetVecOrigin();
    //Vector currentVelocity = ent->GetVelocity();
    //g_CVar->ConsoleDPrintf("Current velocity: %f %f %f\n", currentVelocity.x, currentVelocity.y, currentVelocity.z);
    SDK::CTraceWorldOnly filter;
    //LagRecord record = LagRecord(ent, nullptr);
    LagCompensation::m_PlayerTrack_Future[entIndex].clear();
    if (LagCompensation::m_PlayerTrack[entIndex].size() < 2)
        return;
    //Circle circles[5];
    //CreateCircles(circ
void C_Tickrecord::store(C_BasePlayer* player, bool backup)
{
    //if (player != nullptr)
    //{
        //auto activity = player->get_sec_activity(player->get_animation_layer(1).m_nSequence);
        //auto shot_bt = ((activity >= ACT_CSGO_FIRE_PRIMARY && activity <= ACT_CSGO_FIRE_SECONDARY_OPT_2) && player->get_animation_layer(1).m_flWeight > 0.01f && player->get_animation_layer(1).m_flCycle < 0.05f) || (player->get_weapon() && player->get_weapon()->m_Activity() == 208);

        //type = RECORD_NORMAL;

        //auto priority = ((activity == ACT_CSGO_RELOAD) && player->get_animation_layer(1).m_flWeight > 0.001f && player->get_animation_layer(1).m_flCycle < 1.f);
        shot_this_tick = false;
        valid = false;
        dormant = false;

        /*if (auto wpn = player->get_weapon(); wpn != nullptr)
            shot_time = wpn->m_flLastShotTime();
        else
            shot_time = 0;*/

        //if (priority)
        //    type = RECORD_PRIORITY;

        bones_count = player->m_bone_count();
        bones_count = Math::clamp(bones_count, 0, 128);

        if (backup) {
            memcpy(matrixes, player->m_CachedBoneData().Base(), bones_count * sizeof(matrix3x4_t));
            valid = false;
            dormant = false;
            animated = true;
            exploit = false;
        }
        //memcpy(leftmatrixes, feature::resolver->player_records[player->entindex() - 1].left_mx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightmatrixes, feature::resolver->player_records[player->entindex() - 1].right_mx, bones_count * sizeof(matrix3x4_t));

        //memcpy(leftlmatrixes, feature::resolver->player_records[player->entindex() - 1].left_lmx, bones_count * sizeof(matrix3x4_t));
        //memcpy(rightlmatrixes, feature::resolver->player_records[player->entindex() - 1].right_lmx, bones_count * sizeof(matrix3x4_t));

        //left_side = feature::resolver->player_records[player->entindex() - 1].left_side;
        //right_side = feature::resolver->player_records[player->entindex() - 1].right_side;

        //resolver_index = 0;

        origin = player->m_vecOrigin();
        abs_origin = player->get_abs_origin();
        velocity = player->m_vecVelocity();
        animation_time = feature::lagcomp->get_interpolated_time();
        object_mins = player->OBBMins();
        object_maxs = player->OBBMaxs();
        eye_angles = player->m_angEyeAngles();
        abs_angles = player->get_abs_angles().y;
        entity_flags = player->m_fFlags();
        simulation_time = player->m_flSimulationTime();
        simulation_time_old = player->m_flOldSimulationTime();
        lower_body_yaw = player->m_flLowerBodyYawTarget();
        time_of_last_injury = player->m_flTimeOfLastInjury();
        velocity_modifier = player->m_flVelocityModifier();
        //anim_velocity = player->m_vecVelocity();
        ientity_fl#ifdef VIRTUALIZER
    VIRTUALIZER_FISH_LITE_END;}

void c_lagcomp::build_local_bones(C_BasePlayer* local)
{
    const auto dolboeb = local->m_flPoseParameter();
    local->force_bone_rebuild();
    local->m_flPoseParameter() = ctx.poses[ANGLE_REAL];
    local->set_abs_angles(QAngle(0, ctx.angles[ANGLE_REAL], 0));
    memcpy(ctx.m_local()->animation_layers_ptr(), ctx.local_layers[ANGLE_REAL], 0x38 * ctx.m_local()->get_animation_layers_count());
    /*cheat::main::setuped_bones = */local->SetupBonesEx();
    //memcpy(ctx.matrix, ctx.m_local()->m_CachedBoneData().Base(), min(128, ctx.m_local()->GetBoneCount()) * sizeof(matrix3x4_t));
    local->m_flPoseParameter() = dolboeb;
}

#endif // VIRTUALIZERags = player->m_iEFlags();
        duck_amt = player->m_flDuckAmount();
        ground_accel_last_time = player->m_flGroundAccelLinearFracLastTime();

        if (!backup)
            head_pos = player->get_bone_pos(8);
        if (!backup)
            desync_delta = feature::anti_aim->get_max_desync_delta(player);

        thirdperson_recoil = player->m_flThirdpersonRecoil();
        stop_to_full_run_frac = player->get_animation_state() ? player->get_animation_state()->m_walk_run_transition : 0.f;

        if (auto weapon = player->get_weapon(); weapon != nullptr && weapon)
            shot_time = weapon->m_flLastShotTime();
        else
            shot_time = -1;

        lag = TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime());

        // clamp it so we don't interpolate too far : )
        lag = Math::clamp(lag, 0, 31);

        time_delta = player->m_flSimulationTime() - player->m_flOldSimulationTime();

        if (*(void**)pla{
    //            if (cmd->buttons & IN_JUMP)
    //            {
    //                int sequence = is_moving ? 16 : 15;

    //                if (is_crouched)
    //                    sequence = is_moving ? 18 : 17;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }
    //            else
    //            {
    //                static int sequence = 14;

    //                land->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(land, sequence);
    //                land->m_nSequence = sequence;
    //                land->m_flCycle = land->m_flWeight = 0.f;
    //            }

    //            m_flDurationInAir = 0;
    //        }
    //        else if (on_ground && !was_on_ground && !animstate->m_landing)
    //        {
    //            auto sequence = is_moving ? 22 : 20;

    //            if (is_crouched)
    //                sequence = is_moving ? 19 : 21;

    //            if (cmd->buttons & IN_JUMP)
    //                sequence = animstate->m_duration_in_air > 1 ? 24 : 23;

    //            jump_fall->m_flPlaybackRate = ctx.m_local()->GetLayerSequenceCycleRate(jump_fall, sequence);
    //            jump_fall->m_nSequence = sequence;
    //            jump_fall->m_flCycle = jump_fall->m_flWeight = 0.f;

    //            /*anim_state->m_landing = true;
    //            anim_state->m_on_ground = true;
    //            anim_state->m_landed_on_ground_this_frame = true;
    //            anim_state->m_duration_in_air = 0.f;*/
    //            //ctx.fake_state.m_landing = true;
    //        }

    //        if ((!was_on_ground && on_ground) && !(cmd->buttons & IN_JUMP))
    //        {yer && player->get_animation_state())
            memcpy(&animstate, player->get_animation_state(), 0x334);
int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);
    math::fast_vec_normalize(up);

    auto is_special_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;
    auto inaccuracy = weapon_info->flInaccuracyStand;

    if (g_ctx.local()->m_fFlags() & FL_DUCKING)
    {
        if (is_special_weapon)
            inaccuracy = weapon_info->flInaccuracyCrouchAlt;
        else
            inaccuracy = weapon_info->flInaccuracyCrouch;
    }
    else if (is_special_weapon)
        inaccuracy = weapon_info->flInaccuracyStandAlt;

    if (g_ctx.globals.inaccuracy - 0.000001f < inaccuracy)
        final_hitchance = 100;
    else
    {
        static auto setup_spread_values = true;
        static float spread_values[256][6];

        if (setup_spread_values)
        {
            setup_spread_values = false;

            for (auto i = 0; i < 256; ++i)
            {
                math::random_seed(i + 1);

                auto a = math::random_float(0.0f, 1.0f);
                auto b = math::random_float(0.0f, DirectX::XM_2PI);
                auto c = math::random_float(0.0f, 1.0f);
                auto d = math::random_float(0.0f, DirectX::XM_2PI);

                spread_values[i][0] = a;
                spread_values[i][1] = c;

                auto sin_b = 0.0f, cos_b = 0.0f;
                DirectX::XMScalarSinCos(&sin_b, &cos_b, b);

                auto sin_d = 0.0f, cos_d = 0.0f;
                DirectX::XMScalarSinCos(&sin_d, &cos_d, d);

                spread_values[i][2] = sin_b;
                spread_values[i][3] = cos_b;
                spread_values[i][4] = sin_d;
                spread_values[i][5] = cos_d;
            }
        }

        auto hits = 0;

        for (auto i = 0; i < 256; ++i)
        {
            auto inaccuracy = spread_values[i][0] * g_ctx.globals.inaccuracy;
            auto spread = spread_values[i][1] * g_ctx.globals.spread;

            auto spread_x = spread_values[i][3] * inaccuracy + spread_values[i][5] * spread;
            auto spread_y = spread_values[i][2] * inaccuracy + spread_values[i][4] * spread;

            auto direction = ZERO;

            direction.x = forward.x + right.x * spread_x + up.x * spread_y;
            direction.y = forward.y + right.y * spread_x + up.y * spread_y;
            direction.z = forward.z + right.z * spread_x + up.z * spread_y;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
                ++hits;
        }

        final_hitchance = (int)((float)hits / 2.56f);
    }

    if (g_ctx.globals.double_tap_aim)
        return final_hitchance;

    auto damage = 0;
    auto high_accuracy_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08;

    auto spread = g_ctx.globals.spread + g_ctx.globals.inaccuracy;

    for (auto i = 1; i <= 6; ++i)
    {
        for (auto j = 0; j < 8; ++j)
        {
            auto current_spread = spread * ((float)i / 6.0f);

            auto direction_cos = 0.0f;
            auto direction_sin = 0.0f;

            DirectX::XMScalarSinCos(&direction_cos, &direction_sin, (float)j / 8.0f * DirectX::XM_2PI);

            auto spread_x = direction_cos * current_spread;
            auto spread_y = direction_sin * current_spread;

            auto direction = ZERO;

            direction.x = forward.x + spread_x * right.x + spread_y * up.x;
            direction.y = forward.y + spread_x * right.y + spread_y * up.y;
            direction.z = forward.z + spread_x * right.z + spread_y * up.z;

            auto end = g_ctx.globals.eye_pos + direction * weapon_info->flRange;

            if (hitbox_intersection(final_target.record->player, final_target.record->matrixes_data.main, final_target.data.hitbox, g_ctx.globals.eye_pos, end))
            {
                auto fire_data = autowall::get().wall_penetration(g_ctx.globals.eye_pos, end, final_target.record->player);
                auto valid_hitbox = true;

                if (final_target.data.hitbox == HITBOX_HEAD && fire_data.hitbox != HITBOX_HEAD)
                    valid_hitbox = false;

                if (fire_data.valid && fire_data.damage >= 1 && valid_hitbox)
                    damage += high_accuracy_weapon ? fire_data.damage : 1;
            }
        }
    }

    if (high_accuracy_weapon)
        return (float)damage / 48.0f >= get_minimum_damage(final_target.data.visible, final_target.health) ? final_hitchance : 0;

    return (float)damage / 48.0f >= (float)g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount * 0.01f ? final_hitchance : 0;
}

        /*pose_paramaters.fill(0);
        left_poses.fill(0);
        right_poses.fill(0);*/
        fill(begin(pose_paramaters), end(pose_paramaters), 0.f);
        if (!backup) {
            fill(begin(left_poses), end(left_poses), 0.f);
            fill(begi    auto aim_angle = math::calculate_angle(g_ctx.globals.eye_pos, final_target.data.point.point).Clamp();

    if (!g_cfg.ragebot.silent_aim)
        m_engine()->SetViewAngles(aim_angle);

    if (!g_cfg.ragebot.autoshoot

    player_info_t player_info;
    m_engine()->GetPlayerInfo(final_target.record->i, &player_info);

    cmd->m_viewangles = aim_angle;
    cmd->m_buttons |= IN_ATTACK;
    cmd->m_tickcount = TIME_TO_TICKS(final_target.record->simulation_time + util::get_interpolation());

    last_target_index = final_target.record->i;
    last_shoot_position = g_ctx.globals.eye_pos;
    last_target[last_target_index] = Last_target
    {
        *final_target.record, final_target.data, final_target.distance
    };

    auto shot = &g_ctx.shots.emplace_back();

    shot->last_target = last_target_index;
    shot->side = final_target.record->side;
    shot->fire_tick = m_globals()->m_tickcount;
    shot->shot_info.target_name = player_info.szName;
    shot->shot_info.client_hitbox = get_hitbox_name(final_target.data.hitbox);
    shot->shot_info.client_damage = final_target.data.damage;
    shot->shot_info.hitchance = math::clamp(final_hitchance, 0, 100);
    shot->shot_info.backtrack_ticks = backtrack_ticks;
    shot->shot_info.aim_point = final_target.data.point.point;

    g_ctx.globals.aimbot_working = true;
    g_ctx.globals.revolver_working = false;
    g_ctx.globals.last_aimbot_shot = m_globals()->m_tickcount;
}

int aim::calculate_hitchance(const Vector& aim_angle)
{
    auto final_hitchance = 0;
    auto weapon_info = g_ctx.globals.weapon->get_csweapon_info();

    if (!weapon_info)
        return final_hitchance;

    auto forward = ZERO;
    auto right = ZERO;
    auto up = ZERO;

    math::angle_vectors(aim_angle, &forward, &right, &up);

    math::fast_vec_normalize(forward);
    math::fast_vec_normalize(right);&& !(cmd->m_buttons & IN_ATTACK))
        return;

    auto final_hitchance = 0;
    auto hitchance_amount = 0;

    if (g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].double_tap_hitchance_amount;
    else if (!g_ctx.globals.double_tap_aim && g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance)
        hitchance_amount = g_cfg.ragebot.weapon[g_ctx.globals.current_weapon].hitchance_amount;

    if (hitchance_amount)
    {
        if (g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 && !(g_ctx.local()->m_fFlags() & FL_ONGROUND) && !(engineprediction::get().backup_data.flags & FL_ONGROUND) && fabs(engineprediction::get().backup_data.velocity.z) < 5.0f && engineprediction::get().backup_data.velocity.Length2D() < 5.0f) //-V807
            final_hitchance = 101;
        else
            final_hitchance = calculate_hitchance(aim_angle);

        if (final_hitchance < hitchance_amount)
        {
            auto is_zoomable_weapon = g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SCAR20 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_G3SG1 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SSG08 || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AWP || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_AUG || g_ctx.globals.weapon->m_iItemDefinitionIndex() == WEAPON_SG553;

            if (g_cfg.ragebot.autoscope && is_zoomable_weapon && !g_ctx.globals.weapon->m_zoomLevel())
                cmd->m_buttons |= IN_ZOOM;

            return;
        }
    }n(right_poses), end(right_poses), 0.f);
        }

        if (player->get_animation_layers_count() > 0)
            memcpy(anim_layers, player->animation_layers_ptr(), 0x38 * player->get_animation_layers_count());

        //*(&player->get_bone_accessor()->m_WritableBones + 8) = m_writable_bones;
        //readable_bones_count = player->GetBoneAccessor().m_ReadableBones;
        breaking_lc = false;

        tickcount = ctx.current_tickcount;
        simulation_time_delay = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick - TIME_TO_TICKS(player->m_flSimulationTime());

        lc_exploit = simulation_time_delay >= 12;

        if (csgo.m_client_state())
            m_tick = csgo.m_client_state()->m_clockdrift_manager.m_nServerTick;

        latency = ctx.latency[FLOW_INCOMING];

        not_desyncing = false;
        data_filled = true;
    //}
}
les, entIndex);
    Vector deltaVec = Vector(0, 0, 0);
    Vector origin = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecOrigin;
    /*for (int o = 0; o < 5; o++)
    {
        Vector movementDirection = LagCompensation::m_PlayerTrack[entIndex].at(0).m_vecVelocity;
        movementDirection.z = 0;
        //deltaVec = -circles[o].center + origin;
        //QAngle deltaAngle;
        //Math::VectorAngles(deltaVec, deltaAngle);
        //if (deltaAngle.yaw > 180.f)
        //    deltaAngle.yaw -= 360.f;
        //movementDirection = Math::RotateVectorYaw(Vector(0, 0, 0), deltaAngle.yaw + 180, movementDirection);
        movementDirection.NormalizeInPlace();
        bool isGrounded = ent->GetFlags() & FL_ONGROUND;
        for (int i = 0; i < predictAmount; i++)
        {
            float omega = currentVelocity.Length2D() * circles[o].iRadius;
            float predictionAngle = circles[o].direction * RAD2DEG(omega * g_GlobalVars->interval_per_tick);
            //g_CVar->ConsoleDPrintf("Predicted angle: %f Center: %f %f Rad: %f Vel: %f Accel: %f VelZ: %f \n", predictionAngle, circles[o].center.x, circles[o].center.y, circles[o].radius, currentVelocity.Length(), acceleration, currentVelocity.z);
            currentVelocity = Math::RotateVectorYaw(Vector(0, 0, 0), predictionAngle, currentVelocity);
            movementDirection = currentVelocity;
            movementDirection.z = 0;
            movementDirection.NormalizeInPlace();
            currentVelocity.x += acceleration * movementDirection.x * g_GlobalVars->interval_per_tick;
            currentVelocity.y += acceleration * movementDirection.y * g_GlobalVars->interval_per_tick;
            Movement::PlayerMove(ent, currentPosition, currentVelocity, isGrounded, true, g_GlobalVars->interval_per_tick);
            LagCompensation::m_PlayerTrack_Future[entIndex].push_back(LagRecord(LagRecord(ent, nullptr), currentPosition, (i + 1) * g_GlobalVars->interval_per_tick));
        }*.
        break;
    }
}

void LagCompensation::CreateMove(SDK::CUserCmd* cmd)
{
    if (!INTERFACES::Engine->IsInGame())
        return;
    for (int i = 1; i < 65; ++i)
    {
        SDK::CBaseEntity* ent = (SDK::CBaseEntity*)INTERFACES::ClientEntityList->GetClientEntity(i);
        auto local_player = INTERFACES::ClientEntityList->GetClientEntity(INTERFACES::Engine->GetLocalPlayer());
        if (!local_player)
            continue;
        if (!ent
            || ent == local_player
            || ent->GetIsDormant()
            || !ent->GetHealth() > 0) {
            m_PlayerTrack[i].clear();
            continue;
        }
        SDK::player_info_t entityInformation;
        INTERFACES::Engine->GetPlayerInfo(i, &entityInformation);
        if (m_PlayerTrack[i].size() > 0 && m_PlayerTrack[i].at(0).m_flSimulationTime == ent->GetSimTime())
            continue;
        if (m_PlayerTrack[i].size() >= MAX_RECORDS - 1)
            m_PlayerTrack[i].pop_back();
        /*if (m_PlayerTrack[i].size() >= 1) {
            g_PlayerSettings[i].lastSimTimeDelta = ent->GetSimTime() - m_PlayerTrack[i].at(0).m_flSimulationTime;
            g_PlayerSettings[i].breakingLC = (ent->GetVecOrigin() - m_PlayerTrack[i].at(0).m_vecOrigin).Length2DSqr() > 4096;
        }

        /*m_PlayerTrack[i].push_front(LagRecord(ent, cmd));
        if (aim_type == 2)
            CreateFutureTicks(i);
        //if (g_PlayerSettings[i].breakingLC && m_PlayerTrack_Future[i].size() == 0)
            //g_PlayerSettings[i].breakingLC = false;
    }
}
void LagCompensation::StartLagCompensation(SDK::CBaseEntity* player)
{
    if (m_pCurrentPlayer)
        return;
    matrix3x4_t boneMatrix[MAXSTUDIOBONES];
    ((SDK::CBaseAnimating*)player)->GetDirectBoneMatrix(boneMatrix);
    m_pCurrentPlayer = player;
    m_RestoreData = LagRecord(player, NULL);
    SDK::studiohdr_t *hdr = INTERFACES::ModelInfo->GetStudioModel(player->GetModel());
    if (!hdr)
        return;
    int size = hdr->numbones;
    for (int i = 0; i < size; i++)
        memcpy(m_RestoreData.boneMatrix + i, boneMatrix + i, sizeof(matrix3x4_t));
}
void LagCompensation::BacktrackPlayer(SDK::CBaseEntity* player, LagRecord record, bool setAngles)
{
    //Prevent the physics engine from culling the player
    if (setAngles)
    {
        player->SetAbsAngles(record.m_vecAngles);
        player->SetAbsOrigin(record.m_vecOrigin);
    }
    //Screw aiming at air with autowall especially, just tell the game what bonematrix to use
    ((SDK::CBaseAnimating*)player)->SetBoneMatrix(record.boneMatrix);
}
void LagCompensation::EndLagCompensation(SDK::CBaseEntity* player)
{
    m_pCurrentPlayer = nullptr;
    BacktrackPlayer(player, m_RestoreData);
}
template<class T> const T&
clamp(const T& x, const T& upper, const T& lower) { return min(upper, max(x, lower)); }
void resolver::resolve_yaw()
{
    player_info_t player_info;
    auto animstate = player->get_animation_state();

    if (!m_engine()->GetPlayerInfo(player->EntIndex(), &player_info) || !animstate || player_info.fakeplayer || g_cfg.player_list.disable_resolver[player_record->i] || !g_ctx.local()->is_alive() || player->m_iTeamNum() == g_ctx.local()->m_iTeamNum() || abs(TIME_TO_TICKS(player->m_flSimulationTime() - player->m_flOldSimulationTime()) - 1) || player_record->shot)
    {
        player_record->side = RESOLVER_ORIGINAL;
        return;
    }

    if (g_ctx.globals.missed_shots[player->EntIndex()])
    {
        switch (last_side)
        {
        case RESOLVER_ORIGINAL:
            g_ctx.globals.missed_shots[player->EntIndex()] = 0;
            break;
        case RESOLVER_ZERO:
            player_record->side = RESOLVER_LOW_POSITIVE;

            was_first_bruteforce = false;
            was_second_bruteforce = false;
            return;
        case RESOLVER_POSITIVE:
            player_record->side = was_second_bruteforce ? RESOLVER_ZERO : RESOLVER_NEGATIVE;

            was_first_bruteforce = true;
            return;
        case RESOLVER_NEGATIVE:
            player_record->side = was_first_bruteforce ? RESOLVER_ZERO : RESOLVER_POSITIVE;

            was_second_bruteforce = true;
            return;
        case RESOLVER_LOW_POSITIVE:
            player_record->side = RESOLVER_LOW_NEGATIVE;
            return;
        case RESOLVER_LOW_NEGATIVE:
            player_record->side = RESOLVER_POSITIVE;
            return;
        }
    }

    auto valid_move = true;
    if (animstate->m_velocity > 0.1f)
    {
        valid_move = animstate->m_flTimeSinceStartedMoving < 0.22f;
    }

    if (valid_move && player_record->layers[3].m_flWeight == 0.f && player_record->layers[3].m_flCycle == 0.f && player_record->layers[6].m_flWeight == 0.f)
    {
        auto delta = math::angle_difference(player->m_angEyeAngles().y, zero_goal_feet_yaw);
        auto positive_resolver = (2 * (delta <= 0.0f) - 1) > 0;
        player_record->side = positive_resolver ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
    }
    else if (!valid_move &&    !(static_cast<int>(player_record->layers[12].m_flWeight * 1000.f)) && static_cast<int>(player_record->layers[6].m_flWeight * 1000.f) == static_cast<int>(previous_layers[6].m_flWeight * 1000.f))
    {
        auto delta_negative = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[0][6].m_flPlaybackRate);
        auto delta_zero = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[1][6].m_flPlaybackRate);
        auto delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate);

         if (delta_positive = abs(player_record->layers[6].m_flPlaybackRate - resolver_layers[2][6].m_flPlaybackRate))

        if (delta_zero < delta_positive || delta_negative <= delta_positive || (delta_positive * 1000.f))
        {
            if (delta_zero >= delta_negative && delta_positive > delta_negative && !(delta_negative * 1000.f))
            {
                player_record->side = RESOLVER_POSITIVE;
            }
        }
        else
        {
            player_record->side = RESOLVER_NEGATIVE;
        }

float v25, v26, v27, v28
      if ( ( v25 - v26 ) <= v27 ) {
         if ( -v27 <= ( v25 - v26 ) )
            v28 = v25;
         else
            v28 = v26 - v27;
      } else {
         v28 = v26 + v27;
         player_record->lock_side = 1;
      }

      std::cout "rezolver mod 1 ";
      m_globals()->m_curtime;
      m_globals()->m_curtime;
      //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);
    }
    else
    {
        autowall::get().wall_penetration = m_globals()->m_curtime; // grenade prediction
        auto lby_update_de
        entity->SetEyeAngles(info.lby); // set final 6 layer lta = abs((((update_delta + 180) % 360 + 360) % 360 - 180));
        if (m_globals()->m_curtime - lock_side > 2.0f)
        {
            auto fire_data_positive = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.positive), player);
            auto fire_data_negative = autowall::get().wall_penetration(g_ctx.globals.eye_pos, player->hitbox_position_matrix(HITBOX_HEAD, player_record->matrixes_data.negative), player);

            if (fire_data_positive.visible != fire_data_negative.visible)
            {
                player_record->side = fire_data_negative.visible ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                lock_side = m_globals()->m_curtime;
            }
            else
            {
                if (fire_data_positive.damage != fire_data_negative.damage)
                {
                    player_record->side = fire_data_negative.damage > fire_data_positive.damage ? RESOLVER_POSITIVE : RESOLVER_NEGATIVE;
                }
            }
            else if if if else (
                find_layer(1))
                - 67
            std::regex("final reziolver set4eed hlgjnv ");
            //XIAOMI HOOK MI MIX WARE BETA V4.LUA.JS.CC.COM
float for (std::vector<>::iterator i = .begin(); i != .end(); ++i)
{
   
}
fire_data_positive
was_first_bruteforce
    return;

    bool is_local_player = entity == local_player;
    bool is_teammate = local_player->GetTeam() == entity->GetTeam() && !is_local_player;

    if (is_local_player)
        return;

    if (is_teammate)
        return;

    if (entity->GetHealth() <= 0)
        return;

    if (local_player->GetHealth() <= 0)
        return;

    //--- Variable Declaration ---//;
    auto &info = player_info[entity->GetIndex()];

    //--- Variable Defenitions/Checks ---//
    float fl_lby = entity->GetLowerBodyYaw();

    info.lby = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw(), 0.f);
    info.inverse = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 180.f, 0.f);
    info.last_lby = Vector(entity->GetEyeAngles().x, info.last_moving_lby, 0.f);
    info.inverse_left = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() + 115.f, 0.f);
    info.inverse_right = Vector(entity->GetEyeAngles().x, entity->GetLowerBodyYaw() - 115.f, 0.f);

    info.back = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 180.f, 0.f);
    info.right = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y + 70.f, 0.f);
    info.left = Vector(entity->GetEyeAngles().x, UTILS::CalcAngle(entity->GetVecOrigin(), local_player->GetVecOrigin()).y - 70.f, 0.f);

    info.backtrack = Vector(entity->GetEyeAngles().x, lby_to_back[entity->GetIndex()], 0.f);

    shots_missed[entity->GetIndex()] = shots_fired[entity->GetIndex()] - shots_hit[entity->GetIndex()];
    info.is_moving = entity->GetVelocity().Length2D() > 0.1 && entity->GetFlags() & FL_ONGROUND && !info.could_be_slowmo;
    info.is_jumping = !entity->GetFlags() & FL_ONGROUND;
    info.could_be_slowmo = entity->GetVelocity().Length2D() > 6 && entity->GetVelocity().Length2D() < 36 && !info.is_crouching;
    info.is_crouching = entity->GetFlags() & FL_DUCKING;
    update_time[entity->GetIndex()] = info.next_lby_update_time;

    static float old_simtime[65];
    if (entity->GetSimTime() != old_simtime[entity->GetIndex()])
    {
        using_fake_angles[entity->GetIndex()] = entity->GetSimTime() - old_simtime[entity->GetIndex()] == INTERFACES::Globals->interval_per_tick; entity->GetSimTime() - old_simtime[entity->GetIndex()] >= TICKS_TO_TIME(2);
        old_simtime[entity->GetIndex()] = entity->GetSimTime();
    }

    //--- Actual Angle Resolving ---//
    if (!using_fake_angles[entity->GetIndex()])
    {
        if (backtrack_tick[entity->GetIndex()])
        {
            resolve_type[entity->GetIndex()] = 7;
            entity->SetEyeAngles(info.backtrack);
        }
        else if (info.stored_lby != entity->GetLowerBodyYaw()) // || entity->GetSimTime() > info.next_lby_update_time) lby prediction
        {
            entity->GetSimTime() > info.next_lby_update_time;
            entity->SetEyeAngles(info.lby);
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            info.stored_lby = entity->GetLowerBodyYaw();
            resolve_type[entity->GetIndex()] = 3;
        }
        else if (info.is_jumping)
        {
            nospread_resolve(entity, entity->GetIndex());
        }
        else if (info.is_moving) //while moving
        {
            entity->SetEyeAngles(info.lby);
            info.last_moving_lby = entity->GetLowerBodyYaw();
            info.stored_missed = shots_missed[entity->GetIndex()];
            resolve_type[entity->GetIndex()] = 1;
        }
        else
        {
            if (shots_missed[entity->GetIndex()] > info.stored_missed) //if we have missed 1 shot since we have stopped moving
            {
                resolve_type[entity->GetIndex()] = 4;
                switch (shots_missed[entity->GetIndex()] % 4)
                {
                case 0: entity->SetEyeAngles(info.inverse); break;
                case 1: entity->SetEyeAngles(info.left); break;
                case 2: entity->SetEyeAngles(info.back); break;
                case 3: entity->SetEyeAngles(info.right); break;
                }
            }
            else //first thing we shoot when they stop
            {
                entity->SetEyeAngles(info.last_lby);
                resolve_type[entity->GetIndex()] = 5;
            }
        }
    }


    SDK::CAnimationLayer layer = entity->GetAnimOverlay(0);
    if (entity->GetSimTime() != info.stored_simtime)
    {
        info.stored_simtime = entity->GetSimTime();
        info.prev_layer = info.backup_layer;
        SDK::CAnimationLayer dummy;
        info.backup_layer = find_layer(entity, 979, &dummy) ? dummy : layer;
    }

    SDK::CAnimationLayer prev = info.prev_layer;
    auto server_time = local_player->GetTickBase() * INTERFACES::Globals->interval_per_tick; //i have a global dedicated to curtime but am using this because lemon is gay

    if (info.is_moving && !info.could_be_slowmo)
    {
        entity->SetEyeAngles(info.lby);
        info.last_moving_lby = entity->GetLowerBodyYaw();
        info.stored_missed = shots_missed[entity->GetIndex()];
        info.last_move_time = server_time;
        info.reset_state = true;
        resolve_type[entity->GetIndex()] = 1;
    }
    else
    {
        if (info.stored_lby != entity->GetLowerBodyYaw())
        {
            entity->SetEyeAngles(info.lby);
            info.stored_lby = entity->GetLowerBodyYaw();
            info.next_lby_update_time = entity->GetSimTime() + 1.1;
            resolve_type[entity->GetIndex()] = 7;
        }
        else if (server_time - info.last_move_time < 0.1 && info.reset_state)
        {
            info.pre_anim_lby = entity->GetLowerBodyYaw();
            info.reset_state = false;
            info.breaking_lby = false;
            //std::cout << "reset and lby break is false!" << std::endl;
        }
        auto previous_is_valid = entity->
        }
    }
}

float resolver::resolve_pitch()
{
    return original_pitch;
}
bool aim::hitbox_intersection(player_t* e, matrix3x4_t* matrix, int hitbox, const Vector& start, const Vector& end)
{
    // note: simv0l - pasted from r7 software.
    auto model = e->GetModel();

    if (!model)
        return false;

    auto studio_model = m_modelinfo()->GetStudioModel(model);

    if (!studio_model)
        return false;

    auto studio_set = studio_model->pHitboxSet(e->m_nHitboxSet());

    if (!studio_set)
        return false;

    auto studio_hitbox = studio_set->pHitbox(hitbox);

    if (!studio_hitbox)
        return false;

    Vector min, max;

    const auto is_capsule = studio_hitbox->radius != -1.f;

    if (is_capsule)
    {
        math::vector_transform(studio_hitbox->bbmin, matrix[studio_hitbox->bone], min);
        math::vector_transform(studio_hitbox->bbmax, matrix[studio_hitbox->bone], max);
        const auto dist = math::segment_to_segment(start, end, min, max);

        if (dist < studio_hitbox->radius)
            return true;
    }
    else
    {
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmin, studio_hitbox->rotation), matrix[studio_hitbox->bone], min);
        math::vector_transform(math::vector_rotate(studio_hitbox->bbmax, studio_hitbox->rotation), matrix[studio_hitbox->bone], max);

        math::vector_i_transform(start, matrix[studio_hitbox->bone], min);
        math::vector_i_rotate(end, matrix[studio_hitbox->bone], max);

        if (math::intersect_line_with_bb(min, max, studio_hitbox->bbmin, studio_hitbox->bbmax))
            return true;
    }

    return false;
также девкор сурс
Пожалуйста, авторизуйтесь для просмотра ссылки.
Anko1337
Опай, когда ты уже угомонишься? Жалко конечно что ты слил сурсы 2х летней давности которые купил за 200р :weary:
 
Забаненный
Статус
Оффлайн
Регистрация
16 Фев 2018
Сообщения
67
Реакции[?]
57
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Опай, когда ты уже угомонишься? Жалко конечно что ты слил сурсы 2х летней давности которые купил за 200р :weary:
Ему сейчас не до такой возни.
Так что, вряд ли это он
 
desolver.dev
Участник
Статус
Оффлайн
Регистрация
21 Май 2017
Сообщения
465
Реакции[?]
397
Поинты[?]
1K
Сверху Снизу