-
Автор темы
- #1
C++:
#include "local_animations.h"
#include "..\misc\misc.h"
#include "utils\ctx.hpp"
void local_animations::store_cm_animation_data(CUserCmd* cmd)
{
local_data.cm_stored_viewangles = cmd->m_viewangles;
local_data.cm_stored_commandnumber = cmd->m_command_number;
}
void local_animations::update_fake_animations(CUserCmd* cmd, bool* send_packet)
{
// coming soon
}
void local_animations::update_local_animations(CUserCmd* cmd, bool* send_packet)
{
static bool lock_viewangles = false;
static Vector target_angle = local_data.cm_stored_viewangles;
static Vector non_shot_target_angle = local_data.cm_stored_viewangles;
float m_real_spawntime;
g_ctx.local()->get_animlayers()[3].m_flWeight = 0.0f;
g_ctx.local()->get_animlayers()[3].m_flCycle = 0.0f;
if (g_ctx.globals.m_ragebot_shot_nr == local_data.cm_stored_commandnumber)
{
lock_viewangles = true;
target_angle = local_data.cm_stored_viewangles;
}
if (!lock_viewangles)
target_angle = local_data.cm_stored_viewangles;
auto animstate = g_ctx.local()->get_animation_state();
if (!animstate || !g_ctx.local()->is_alive() || g_ctx.local()->IsDormant())
{
m_real_spawntime = 0;
return;
}
g_ctx.local()->m_flThirdpersonRecoil() = g_ctx.local()->m_aimPunchAngle().x;
AnimationLayer old_anim_layers[13];
std::memcpy(old_anim_layers, g_ctx.local()->get_animlayers(), g_ctx.local()->animlayer_count() * sizeof(AnimationLayer));
if (g_ctx.local()->m_flSpawnTime() != m_real_spawntime || animstate->m_pBaseEntity != g_ctx.local())
{
g_ctx.globals.updating_animation = true;
g_ctx.local()->update_clientside_animation();
g_ctx.globals.updating_animation = false;
std::memcpy(g_ctx.local()->get_animlayers(), old_anim_layers, g_ctx.local()->animlayer_count() * sizeof(AnimationLayer));
m_real_spawntime = g_ctx.local()->m_flSpawnTime();
}
const auto old_render_angles = g_ctx.local()->get_render_angles();
const auto old_pose_params = g_ctx.local()->m_flPoseParameter();
animstate->m_flUpdateTimeDelta = fmaxf(m_globals()->m_curtime - animstate->m_flLastClientSideAnimationUpdateTime, 0.f);
g_ctx.local()->get_render_angles() = ((misc::get().hide_shots_key) && !g_ctx.globals.fakeducking && lock_viewangles) ? non_shot_target_angle : target_angle;
if (animstate->m_pActiveWeapon != animstate->m_pLastActiveWeapon)
{
for (int i = 0; i < 13; i++)
{
AnimationLayer pLayer = g_ctx.local()->get_animlayers()[i];
pLayer.m_pStudioHdr = NULL;
pLayer.m_nDispatchSequence = -1;
pLayer.m_nDispatchSequence_2 = -1;
}
}
float flNewDuckAmount;
if (animstate)
{
flNewDuckAmount = math::clamp(g_ctx.local()->m_flDuckAmount() + animstate->m_fLandingDuckAdditiveSomething, 0.0f, 1.0f);
flNewDuckAmount = math::approach(flNewDuckAmount, animstate->m_fDuckAmount, animstate->m_flUpdateTimeDelta * 6.0f);
flNewDuckAmount = math::clamp(flNewDuckAmount, 0.0f, 1.0f);
}
animstate->m_fDuckAmount = flNewDuckAmount;
g_ctx.local()->m_nSequence() = 0;
animstate->m_flFeetYawRate = 0;
g_ctx.globals.updating_animation = true;
g_ctx.local()->update_clientside_animation();
g_ctx.globals.updating_animation = false;
g_ctx.local()->force_bone_rebuild();
g_ctx.local()->setup_local_bones(MAXSTUDIOBONES);
g_ctx.local()->get_animation_state()->m_flFeetCycle = old_anim_layers[6].m_flCycle;
g_ctx.local()->get_animation_state()->m_flFeetYawRate = old_anim_layers[6].m_flWeight;
g_ctx.local()->get_animation_state()->m_flStrafeChangeCycle = old_anim_layers[7].m_flCycle;
g_ctx.local()->get_animation_state()->m_iStrafeSequence = old_anim_layers[7].m_nSequence;
g_ctx.local()->get_animation_state()->m_flStrafeChangeWeight = old_anim_layers[7].m_flWeight;
g_ctx.local()->get_animation_state()->m_flAccelerationWeight = old_anim_layers[12].m_flWeight;
for (int i = 0; i < 13; ++i)
{
AnimationLayer layer = g_ctx.local()->get_animlayers()[i];
if (!layer.m_nSequence && layer.m_pOwner && layer.m_flWeight != 0.0f)
{
((player_t*)layer.m_pOwner)->invalidate_physics_recursive(BOUNDS_CHANGED);
layer.m_flWeight = 0.0f;
}
}
if (*send_packet == false)
{
std::memcpy(g_ctx.local()->get_animlayers(), old_anim_layers, g_ctx.local()->animlayer_count() * sizeof(AnimationLayer));
return;
}
if (!lock_viewangles)
non_shot_target_angle = local_data.cm_stored_viewangles;
memcpy(m_real_poses, g_ctx.local()->m_flPoseParameter().data(), 24 * sizeof(float));
m_real_angles = g_ctx.local()->get_animation_state()->m_flGoalFeetYaw;
memcpy(m_real_layers, g_ctx.local()->get_animlayers(), g_ctx.local()->animlayer_count() * sizeof(AnimationLayer));
g_ctx.local()->m_flPoseParameter() = old_pose_params;
memcpy(g_ctx.local()->get_animlayers(), old_anim_layers, g_ctx.local()->animlayer_count() * sizeof(AnimationLayer));
g_ctx.local()->get_render_angles() = old_render_angles;
lock_viewangles = false;
}
void local_animations::build_local_bones(player_t* local)
{
float pose_parameter[24];
std::memcpy(pose_parameter, g_ctx.local()->m_flPoseParameter().data(), 24 * sizeof(float));
local->force_bone_rebuild();
std::memcpy(g_ctx.local()->m_flPoseParameter().data(), m_real_poses, 24 * sizeof(float));
local->set_abs_angles(Vector(0, m_real_angles, 0));
std::memcpy(g_ctx.local()->get_animlayers(), m_real_layers, g_ctx.local()->animlayer_count() * sizeof(AnimationLayer));
local->setup_local_bones(MAXSTUDIOBONES);
std::memcpy(g_ctx.local()->m_flPoseParameter().data(), pose_parameter, 24 * sizeof(float));
}