void AntiAim::UpdateLBYBreaker(CUserCmd *usercmd)
{
bool
allocate = (m_serverAnimState == nullptr),
change = (!allocate) && (&g_LocalPlayer->GetRefEHandle() != m_ulEntHandle),
reset = (!allocate && !change) && (g_LocalPlayer->m_flSpawnTime() != m_flSpawnTime);
// player changed, free old animation state.
if (change)
g_pMemAlloc->Free(m_serverAnimState);
// need to reset? (on respawn)
if (reset)
{
// reset animation state.
C_BasePlayer::ResetAnimationState(m_serverAnimState);
// note new spawn time.
m_flSpawnTime = g_LocalPlayer->m_flSpawnTime();
}
// need to allocate or create new due to player change.
if (allocate || change)
{
// only works with games heap alloc.
C_CSGOPlayerAnimState *state = (C_CSGOPlayerAnimState*)g_pMemAlloc->Alloc(sizeof(C_CSGOPlayerAnimState));
if (state != nullptr)
g_LocalPlayer->CreateAnimationState(nullptr);
// used to detect if we need to recreate / reset.
m_ulEntHandle = const_cast<CBaseHandle*>(&g_LocalPlayer->GetRefEHandle());
m_flSpawnTime = g_LocalPlayer->m_flSpawnTime();
// note anim state for future use.
m_serverAnimState = state;
}
float_t curtime = TICKS_TO_TIME(AimRage::Get().GetTickbase() + 11.f);
if (!g_ClientState->chokedcommands && m_serverAnimState)
{
C_BasePlayer::UpdateAnimationState(m_serverAnimState, usercmd->viewangles);
// calculate delta.
float_t delta = std::abs(Math::ClampYaw(usercmd->viewangles.yaw - g_LocalPlayer->m_flLowerBodyYawTarget()));
// walking, delay next update by 1.1s.
if (m_serverAnimState->m_flVelocity() > 0.1f && (g_LocalPlayer->m_fFlags() & FL_ONGROUND))
m_flNextBodyUpdate = curtime + g_LocalPlayer->m_flSimulationTime() + 1.1f;
else if (curtime >= m_flNextBodyUpdate)
{
if (delta > (M_PI / 180 - m_flNextBodyUpdate) * 0.35f)
; // server will update lby.
m_flNextBodyUpdate = curtime + g_LocalPlayer->m_flSimulationTime() + 0.22f;
}
}
// if was jumping and then onground and bsendpacket true, we're gonna update.
m_bBreakLowerBody = (g_LocalPlayer->m_fFlags() & FL_ONGROUND) && ((m_flNextBodyUpdate - curtime) <= g_GlobalVars->interval_per_tick);
}