SHARE
TWEET

Untitled

a guest Jan 24th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float MaxDelta(C_BaseEntity* pEnt) {
  2.  
  3.     auto animstate = uintptr_t(pEnt->AnimState());
  4.  
  5.     float duckammount = *(float*)(animstate + 0xA4);
  6.     float speedfraction = max(0, min(*reinterpret_cast<float*>(animstate + 0xF8), 1));
  7.  
  8.     float speedfactor = max(0, min(1, *reinterpret_cast<float*> (animstate + 0xFC)));
  9.  
  10.     float unk1 = ((*reinterpret_cast<float*> (animstate + 0x11C) * -0.30000001f) - 0.19999999f)* speedfraction;
  11.     float unk2 = unk1 + 1.f;
  12.     float unk3;
  13.  
  14.     if (duckammount > 0) {
  15.         unk2 += ((duckammount * speedfactor) * (0.5f - unk2));
  16.     }
  17.  
  18.     unk3 = *(float*)(animstate + 0x334) * unk2;
  19.  
  20.     return unk3;
  21. }
  22. void Resolver::AnimationFix(C_BaseEntity* pEnt)
  23. {
  24.     //who needs structs or classes not me lol
  25.     static float oldSimtime[65];
  26.     static float storedSimtime[65];
  27.     static float ShotTime[65];
  28.     static float SideTime[65][3];
  29.     static int LastDesyncSide[65];
  30.     static bool Delaying[65];
  31.     static AnimationLayer StoredLayers[64][15];
  32.     static C_AnimState * StoredAnimState[65];
  33.     static float StoredPosParams[65][24];
  34.     static Vector oldEyeAngles[65];
  35.     static float oldGoalfeetYaw[65];
  36.     float* PosParams = (float*)((uintptr_t)pEnt + 0x2774);
  37.     bool update = false;
  38.     bool shot = false;
  39.  
  40.     static bool jittering[65];
  41.  
  42.     auto* AnimState = pEnt->AnimState();
  43.     if (!AnimState || !pEnt->AnimOverlays() || !PosParams)
  44.         return;
  45.  
  46.     auto RemapVal = [](float val, float A, float B, float C, float D) -> float
  47.     {
  48.         if (A == B)
  49.             return val >= B ? D : C;
  50.         return C + (D - C) * (val - A) / (B - A);
  51.     };
  52.  
  53.     if (storedSimtime[pEnt->EntIndex()] != pEnt->GetSimulationTime())
  54.     {
  55.         jittering[pEnt->EntIndex()] = false;
  56.         pEnt->ClientAnimations(true);
  57.         pEnt->UpdateClientAnimation();
  58.  
  59.         memcpy(StoredPosParams[pEnt->EntIndex()], PosParams, sizeof(float) * 24);
  60.         memcpy(StoredLayers[pEnt->EntIndex()], pEnt->AnimOverlays(), (sizeof(AnimationLayer) * pEnt->NumOverlays()));
  61.  
  62.         oldGoalfeetYaw[pEnt->EntIndex()] = AnimState->m_flGoalFeetYaw;
  63.  
  64.         if (pEnt->GetActiveWeapon() && !pEnt->IsKnifeorNade())
  65.         {
  66.             if (ShotTime[pEnt->EntIndex()] != pEnt->GetActiveWeapon()->GetLastShotTime())
  67.             {
  68.                 shot = true;
  69.                 ShotTime[pEnt->EntIndex()] = pEnt->GetActiveWeapon()->GetLastShotTime();
  70.             }
  71.             else
  72.                 shot = false;
  73.         }
  74.         else
  75.         {
  76.             shot = false;
  77.             ShotTime[pEnt->EntIndex()] = 0.f;
  78.         }
  79.  
  80.         float angToLocal = g_Math.NormalizeYaw(g_Math.CalcAngle(Globals::pLocalEntity->GetOrigin(), pEnt->GetOrigin()).y);
  81.  
  82.         float Back = g_Math.NormalizeYaw(angToLocal);
  83.         float DesyncFix = 0;
  84.         float Resim = g_Math.NormalizeYaw((0.24f / (pEnt->GetSimulationTime() - oldSimtime[pEnt->EntIndex()]))*(oldEyeAngles[pEnt->EntIndex()].y - pEnt->GetEyeAngles().y));
  85.  
  86.         if (Resim > MaxDelta(pEnt))
  87.             Resim = MaxDelta(pEnt);
  88.         if (Resim < -MaxDelta(pEnt))
  89.             Resim = -MaxDelta(pEnt);
  90.  
  91.         if (pEnt->GetVelocity().Length2D() > 0.5f && !shot)
  92.         {
  93.             float Delta = g_Math.NormalizeYaw(g_Math.NormalizeYaw(g_Math.CalcAngle(Vector(0, 0, 0), pEnt->GetVelocity()).y) - g_Math.NormalizeYaw(g_Math.NormalizeYaw(AnimState->m_flGoalFeetYaw + RemapVal(PosParams[11], 0, 1, -60, 60)) + Resim));
  94.  
  95.             int CurrentSide = 0;
  96.  
  97.             if (Delta < 0)
  98.             {
  99.                 CurrentSide = 1;
  100.                 SideTime[pEnt->EntIndex()][1] = g_pGlobalVars->curtime;
  101.             }
  102.             else if (Delta > 0)
  103.             {
  104.                 CurrentSide = 2;
  105.                 SideTime[pEnt->EntIndex()][2] = g_pGlobalVars->curtime;
  106.             }
  107.  
  108.             if (LastDesyncSide[pEnt->EntIndex()] == 1)
  109.             {
  110.                 Resim += (MaxDelta(pEnt) - Resim);
  111.                 DesyncFix += (MaxDelta(pEnt) - Resim);
  112.             }
  113.             if (LastDesyncSide[pEnt->EntIndex()] == 2)
  114.             {
  115.                 Resim += (-MaxDelta(pEnt) - Resim);
  116.                 DesyncFix += (-MaxDelta(pEnt) - Resim);
  117.             }
  118.  
  119.             if (LastDesyncSide[pEnt->EntIndex()] != CurrentSide)
  120.             {
  121.                 Delaying[pEnt->EntIndex()] = true;
  122.  
  123.                 if (.5f < (g_pGlobalVars->curtime - SideTime[pEnt->EntIndex()][LastDesyncSide[pEnt->EntIndex()]]))
  124.                 {
  125.                     LastDesyncSide[pEnt->EntIndex()] = CurrentSide;
  126.                     Delaying[pEnt->EntIndex()] = false;
  127.                 }
  128.             }
  129.  
  130.             if (!Delaying[pEnt->EntIndex()])
  131.                 LastDesyncSide[pEnt->EntIndex()] = CurrentSide;
  132.         }
  133.         else if (!shot)
  134.         {
  135.             float Brute = UseFreestandAngle[pEnt->EntIndex()] ? g_Math.NormalizeYaw(Back + FreestandAngle[pEnt->EntIndex()]) : pEnt->GetLowerBodyYaw();
  136.  
  137.             float Delta = g_Math.NormalizeYaw(g_Math.NormalizeYaw(Brute - g_Math.NormalizeYaw(g_Math.NormalizeYaw(AnimState->m_flGoalFeetYaw + RemapVal(PosParams[11], 0, 1, -60, 60))) + Resim));
  138.  
  139.             if (Delta > MaxDelta(pEnt))
  140.                 Delta = MaxDelta(pEnt);
  141.             if (Delta < -MaxDelta(pEnt))
  142.                 Delta = -MaxDelta(pEnt);
  143.  
  144.             Resim += Delta;
  145.             DesyncFix += Delta;
  146.  
  147.             if (Resim > MaxDelta(pEnt))
  148.                 Resim = MaxDelta(pEnt);
  149.             if (Resim < -MaxDelta(pEnt))
  150.                 Resim = -MaxDelta(pEnt);
  151.         }
  152.  
  153.         float Equalized = g_Math.NormalizeYaw(g_Math.NormalizeYaw(AnimState->m_flGoalFeetYaw + RemapVal(PosParams[11], 0, 1, -60, 60)) + Resim);
  154.  
  155.         float JitterDelta = fabs(g_Math.NormalizeYaw(oldEyeAngles[pEnt->EntIndex()].y - pEnt->GetEyeAngles().y));
  156.  
  157.         if (JitterDelta >= 70.f && !shot)
  158.             jittering[pEnt->EntIndex()] = true;
  159.  
  160.         if (pEnt != Globals::pLocalEntity && pEnt->GetTeam() != Globals::pLocalEntity->GetTeam() && (pEnt->GetFlags() & FL_ONGROUND) && g_Menu.Config.Resolver)
  161.         {
  162.             if (jittering[pEnt->EntIndex()])
  163.                 AnimState->m_flGoalFeetYaw = g_Math.NormalizeYaw(pEnt->GetEyeAngles().y + DesyncFix);
  164.             else
  165.                 AnimState->m_flGoalFeetYaw = Equalized;
  166.  
  167.             pEnt->SetLowerBodyYaw(AnimState->m_flGoalFeetYaw);
  168.         }
  169.  
  170.         StoredAnimState[pEnt->EntIndex()] = AnimState;
  171.  
  172.         oldEyeAngles[pEnt->EntIndex()] = pEnt->GetEyeAngles();
  173.  
  174.         oldSimtime[pEnt->EntIndex()] = storedSimtime[pEnt->EntIndex()];
  175.  
  176.         storedSimtime[pEnt->EntIndex()] = pEnt->GetSimulationTime();
  177.  
  178.         update = true;
  179.     }
  180.  
  181.     pEnt->ClientAnimations(false);
  182.  
  183.     /*if (pEnt != Globals::pLocalEntity && pEnt->GetTeam() != Globals::pLocalEntity->GetTeam() && (pEnt->GetFlags() & FL_ONGROUND) && g_Menu.Config.Resolver)
  184.         pEnt->SetLowerBodyYaw(AnimState->m_flGoalFeetYaw);*/
  185.  
  186.     AnimState = StoredAnimState[pEnt->EntIndex()];
  187.  
  188.     memcpy((void*)PosParams, &StoredPosParams[pEnt->EntIndex()], (sizeof(float) * 24));
  189.     memcpy(pEnt->AnimOverlays(), StoredLayers[pEnt->EntIndex()], (sizeof(AnimationLayer) * pEnt->NumOverlays()));
  190.  
  191.     if (pEnt != Globals::pLocalEntity && pEnt->GetTeam() != Globals::pLocalEntity->GetTeam() && (pEnt->GetFlags() & FL_ONGROUND) && g_Menu.Config.Resolver && jittering[pEnt->EntIndex()])
  192.         pEnt->SetAbsAngles(Vector(0, pEnt->GetEyeAngles().y, 0));
  193.     else
  194.         pEnt->SetAbsAngles(Vector(0, oldGoalfeetYaw[pEnt->EntIndex()], 0));
  195.  
  196.     /*if (pEnt == Globals::pLocalEntity && pEnt->GetVelocity().Length2D() < 45.f && !(Globals::IsSlowwalking || Globals::IsFakewalking))
  197.     {
  198.         AnimState->m_flUnknownFraction = 0.f;
  199.         AnimState->m_flLeanAmount = 0.f;
  200.         Globals::pLocalEntity->SetSequence(0);
  201.         if (g_Menu.Config.ShowAccurateLby)
  202.             pEnt->SetLowerBodyYaw(pEnt->GetEyeAngles().y);
  203.         pEnt->ClientAnimations(false);
  204.     }*/
  205.  
  206.     *reinterpret_cast<int*>(uintptr_t(pEnt) + 0xA30) = g_pGlobalVars->framecount;
  207.     *reinterpret_cast<int*>(uintptr_t(pEnt) + 0xA28) = 0;
  208. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top