daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Animation.hpp"
  2. #include "../helpers/Math.hpp"
  3. #include "AimRage.hpp"
  4.  
  5. void Animation::UpdatePlayerAnimations(int32_t idx)
  6. {
  7.     return;     //recent update broke animatuon fix.
  8.  
  9.     C_BasePlayer *player = C_BasePlayer::GetPlayerByIndex(idx);
  10.     if (checks::is_bad_ptr(player) || !player->IsAlive())
  11.         return;
  12.  
  13.     static float timestamp = 0;
  14.  
  15.     auto &info = arr_infos[idx];
  16.  
  17.     bool
  18.         allocate = (checks::is_bad_ptr(info.m_playerAnimState)),
  19.         change = (!allocate) && (&player->GetRefEHandle() != info.m_ulEntHandle),
  20.         reset = (!allocate && !change) && (player->m_flSpawnTime() != info.m_flSpawnTime);
  21.  
  22.     // player changed, free old animation state.
  23.     if (change)
  24.     {
  25.         if (!checks::is_bad_ptr(info.m_playerAnimState) && abs(g_GlobalVars->curtime - timestamp) > 0.1)    //basic nullptr check and expirmantal crash fix
  26.         {
  27.             arr_infos_record[idx].clear();
  28.             g_pMemAlloc->Free(info.m_playerAnimState);  //calling this too fast crashes?
  29.             timestamp = g_GlobalVars->curtime;
  30.         }
  31.         else
  32.         {
  33.             return;
  34.         }
  35.     }
  36.  
  37.     // need to reset? (on respawn)
  38.     if (reset)
  39.     {
  40.         if (!checks::is_bad_ptr(info.m_playerAnimState))
  41.         {
  42.             // reset animation state.
  43.             C_BasePlayer::ResetAnimationState(info.m_playerAnimState);
  44.  
  45.             // note new spawn time.
  46.             info.m_flSpawnTime = player->m_flSpawnTime();
  47.         }
  48.     }
  49.  
  50.     // need to allocate or create new due to player change.
  51.     if (allocate || change)
  52.     {
  53.         C_CSGOPlayerAnimState *state = (C_CSGOPlayerAnimState*)g_pMemAlloc->Alloc(sizeof(C_CSGOPlayerAnimState));
  54.  
  55.         if (checks::is_bad_ptr(state))
  56.             return;
  57.  
  58.         player->CreateAnimationState(state);
  59.  
  60.         // used to detect if we need to recreate / reset.
  61.         info.m_ulEntHandle = const_cast<CBaseHandle*>(&player->GetRefEHandle());
  62.         info.m_flSpawnTime = player->m_flSpawnTime();
  63.  
  64.         // note anim state for future use.
  65.         info.m_playerAnimState = state;
  66.     }
  67.  
  68.     if (checks::is_bad_ptr(info.m_playerAnimState))
  69.         return;
  70.  
  71.     std::array<float_t, 24> backup_poses = player->m_flPoseParameter();
  72.  
  73.     AnimationLayer backup_layers[15];
  74.     std::memcpy(backup_layers, player->GetAnimOverlays(), (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  75.  
  76.     // fixing legs and few other things missing here
  77.     C_BasePlayer::UpdateAnimationState(info.m_playerAnimState, (player == g_LocalPlayer) ? (Global::visualAngles) : (player->m_angEyeAngles()));
  78.  
  79.     info.m_flPoseParameters = player->m_flPoseParameter();
  80.     std::memcpy(info.m_AnimationLayer, player->GetAnimOverlays(), (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  81.  
  82.     player->m_flPoseParameter() = backup_poses;
  83.     std::memcpy(player->GetAnimOverlays(), backup_layers, (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  84.  
  85.     arr_infos_record[idx].push_front({ g_GlobalVars->curtime, arr_infos[idx] });
  86. }
  87.  
  88. void Animation::UpdateAnimationAngles(AnimationInfo &anim, QAngle angles)
  89. {
  90.     return;
  91.     C_BasePlayer::UpdateAnimationState(anim.m_playerAnimState, angles);
  92. }
  93.  
  94. AnimationInfo &Animation::GetPlayerAnimationInfo(int32_t idx)
  95. {
  96.     return arr_infos[idx];
  97. }
  98.  
  99. AnimationInfo &Animation::GetPlayerAnimationInfo(int32_t idx, float time)
  100. {
  101.     for (auto i = arr_infos_record[idx].begin(); i != arr_infos_record[idx].end(); i++)
  102.     {
  103.         if (time == i->first)
  104.             return i->second;
  105.     }
  106.     return AnimationInfo();
  107. }
  108.  
  109. std::deque<std::pair<float, AnimationInfo>> Animation::GetPlayerAnimationRecord(int32_t idx)
  110. {
  111.     return arr_infos_record[idx];
  112. }
  113.  
  114. void Animation::RestoreAnim(C_BasePlayer *player, float time)
  115. {
  116.     return;
  117.     auto anim = GetPlayerAnimationInfo(player->EntIndex(), time);
  118.     if (anim.m_flSpawnTime > 0.1f)
  119.         ApplyAnim(player, anim);
  120. }
  121.  
  122. void Animation::RestoreAnim(C_BasePlayer *player)
  123. {
  124.     return;
  125.     if (arr_infos_record[player->EntIndex()].empty())
  126.         return;
  127.  
  128.     ApplyAnim(player, arr_infos_record[player->EntIndex()].front().second);
  129. }
  130.  
  131. void Animation::ApplyAnim(C_BasePlayer *player, AnimationInfo anim)
  132. {
  133.     return;
  134.     player->m_flPoseParameter() = anim.m_flPoseParameters;
  135.     std::memcpy(player->GetAnimOverlays(), anim.m_AnimationLayer, (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  136. }
  137.  
  138. void Animation::HandleAnimFix(C_BasePlayer *player, bool restore, bool modify_angles, bool modify_origin)
  139. {
  140.     return;
  141.     if (checks::is_bad_ptr(player))
  142.         return;
  143.  
  144.     int i = player->EntIndex();
  145.     if (restore)
  146.     {
  147.         if (modify_origin) player->SetAbsOrigin(origin_backup.at(i));
  148.         if (modify_angles) player->SetAbsAngles(angles_backup.at(i));
  149.         player->m_flPoseParameter() = animation_backup.at(i).m_flPoseParameters;
  150.         std::memcpy(player->GetAnimOverlays(), animation_backup.at(i).m_AnimationLayer, (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  151.     }
  152.     else
  153.     {
  154.         origin_backup.at(i) = player->GetAbsOrigin();
  155.         angles_backup.at(i) = player->GetAbsAngles();
  156.  
  157.         animation_backup.at(i).m_flPoseParameters = player->m_flPoseParameter();
  158.         std::memcpy(animation_backup.at(i).m_AnimationLayer, player->GetAnimOverlays(), (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  159.  
  160.         Vector origin = player->m_vecOrigin();
  161.         QAngle angles = (player == g_LocalPlayer) ? (Global::visualAngles) : (player->m_angEyeAngles()); angles.pitch = 0; angles.roll = 0;
  162.  
  163.         auto &anim_data = GetPlayerAnimationInfo(i);
  164.  
  165.         if (checks::is_bad_ptr(anim_data.m_playerAnimState))
  166.             return;
  167.  
  168.         if (modify_origin) player->SetAbsOrigin(origin);
  169.         if (modify_angles) player->SetAbsAngles(angles);
  170.         player->m_flPoseParameter() = anim_data.m_flPoseParameters;
  171.         std::memcpy(player->GetAnimOverlays(), anim_data.m_AnimationLayer, (sizeof(AnimationLayer) * player->GetNumAnimOverlays()));
  172.     }
  173. }
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