-
Автор темы
- #1
было куча тем и прочей залупы но чтоб полностью разобраться я хочу сделать его тут на примере лв
укажите на ошибки, хочу понять в чем проблема, что изменить, что добавить?
C++:
void lagcompensation::update_player_animations(player_t* e)
{
auto animstate = e->get_animation_state();
if (!animstate)
return;
player_info_t player_info;
if (!m_engine()->GetPlayerInfo(e->EntIndex(), &player_info))
return;
auto records = &player_records[e->EntIndex()]; //-V826
if (records->empty())
return;
adjust_data* previous_record = nullptr;
if (records->size() >= 2)
previous_record = &records->at(1);
auto record = &records->front();
AnimationLayer animlayers[13];
memcpy(animlayers, e->get_animlayers(), e->animlayer_count() * sizeof(AnimationLayer));
std::memcpy(record->layers, animlayers, e->animlayer_count() * sizeof(AnimationLayer));
//std::memcpy(player_resolver[e->EntIndex()].previous_layers, animlayers, e->animlayer_count() * sizeof(AnimationLayer));
//UpdateResolverLayer(e, 1, matrix3x4_t * m_pMatrix);
auto backup_lower_body_yaw_target = e->m_flLowerBodyYawTarget();
auto backup_duck_amount = e->m_flDuckAmount();
auto backup_flags = e->m_fFlags();
auto backup_eflags = e->m_iEFlags();
auto backup_absorigin = e->GetAbsOrigin();
auto backup_absangles = e->GetAbsAngles();
auto backup_curtime = m_globals()->m_curtime; //-V807
auto backup_frametime = m_globals()->m_frametime;
auto backup_realtime = m_globals()->m_realtime;
auto backup_framecount = m_globals()->m_framecount;
auto backup_tickcount = m_globals()->m_tickcount;
auto backup_interpolation_amount = m_globals()->m_interpolation_amount;
m_globals()->m_curtime = e->m_flSimulationTime();
m_globals()->m_frametime = m_globals()->m_intervalpertick;
e->GetAbsOrigin();
e->GetAbsAngles();
if (previous_record)
{
const auto weapon = e->m_hActiveWeapon()->get_csweapon_info();
if (record->flags & FL_ONGROUND
&& m_globals()->m_intervalpertick >= 1) {
const auto average_speed = record->velocity.Length2D();
if (average_speed > 0.1f) {
const auto alive_loop_weight = record->layers[11].m_flWeight;
if (alive_loop_weight > 0.f
&& alive_loop_weight < 1.f) {
const auto unk = (1.f - alive_loop_weight) * 0.35f;
if (unk > 0.f
&& unk < 1.f) {
const auto max_speed = weapon ? weapon->flMaxPlayerSpeed : 250.f;
const auto modifier = ((unk + 0.55f) * max_speed) / average_speed;
record->velocity.x *= modifier;
record->velocity.y *= modifier;
}
}
record->velocity.z = 0.f;
}
}
auto i = 1;
if (!(record->layers[6].m_flCycle == 0.0f || previous_record->layers[6].m_flCycle == 0.0f) && record->velocity.Length2D() <= 1.1f)
{
record->velocity.x = (i & 1 ? -1.1f : 1.1f);
record->velocity.y = 0.f;
record->velocity.z = 0.f;
}
auto speed = record->velocity.Length2D();
if (record->velocity.Length2D() > (speed * 0.52f) && previous_record->velocity.Length2D() > (speed * 0.52f)
|| record->velocity.Length2D() <= (speed * 0.52f) && previous_record->velocity.Length2D() <= (speed * 0.52f))
{
auto manually_calculated = animstate->m_flStopToFullRunningFraction;
manually_calculated += (record->velocity.Length2D() > (speed * 0.52f) ? (2.f * animstate->m_flUpdateTimeDelta) : -(2.f * animstate->m_flUpdateTimeDelta));
manually_calculated = math::clamp(manually_calculated, 0, 1);
if (abs(manually_calculated - animstate->m_flStopToFullRunningFraction) >= 0.1f)// {
e->get_animation_state()->m_flStopToFullRunningFraction = manually_calculated;
}
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.Zero();
e->get_animation_state()->m_flFeetCycle /*= record.feet_cycle*/ = animlayers[6].m_flCycle;
}
e->m_iEFlags() &= ~0x1800;
if (e->m_fFlags() & FL_ONGROUND && e->m_vecVelocity().Length() > 0.0f && animlayers[6].m_flWeight <= 0.0f)
e->m_vecVelocity().Zero();
e->m_vecAbsVelocity() = e->m_vecVelocity();
e->m_bClientSideAnimation() = true;
if (is_dormant[e->EntIndex()])
{
is_dormant[e->EntIndex()] = false;
if (e->m_fFlags() & FL_ONGROUND)
{
animstate->m_bOnGround = true;
animstate->m_bInHitGroundAnimation = false;
}
animstate->time_since_in_air() = 0.0f;
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y);
}
auto updated_animations = false;
c_baseplayeranimationstate state;
memcpy(&state, animstate, sizeof(c_baseplayeranimationstate));
if (previous_record)
{
memcpy(e->get_animlayers(), previous_record->layers, e->animlayer_count() * sizeof(AnimationLayer));
auto ticks_chocked = 1;
auto simulation_ticks = TIME_TO_TICKS(e->m_flSimulationTime() - previous_record->simulation_time);
if (simulation_ticks > 0 && simulation_ticks < 31)
ticks_chocked = simulation_ticks;
if (ticks_chocked > 1)
{
auto land_time = 0.0f;
auto land_in_cycle = false;
auto is_landed = false;
auto on_ground = false;
if (animlayers[4].m_flCycle < 0.5f && (!(e->m_fFlags() & FL_ONGROUND) || !(previous_record->flags & FL_ONGROUND)))
{
land_time = e->m_flSimulationTime() - animlayers[4].m_flPlaybackRate * animlayers[4].m_flCycle;
land_in_cycle = land_time >= previous_record->simulation_time;
}
auto duck_amount_per_tick = (e->m_flDuckAmount() - previous_record->duck_amount) / ticks_chocked;
for (auto i = 0; i < ticks_chocked; ++i)
{
auto simulated_time = previous_record->simulation_time + TICKS_TO_TIME(i);
if (duck_amount_per_tick) //-V550
e->m_flDuckAmount() = previous_record->duck_amount + duck_amount_per_tick * (float)i;
on_ground = e->m_fFlags() & FL_ONGROUND;
if (land_in_cycle && !is_landed)
{
if (land_time <= simulated_time)
{
is_landed = true;
on_ground = true;
}
else
on_ground = previous_record->flags & FL_ONGROUND;
}
if (on_ground)
e->m_fFlags() |= FL_ONGROUND;
else
e->m_fFlags() &= ~FL_ONGROUND;
auto simulated_ticks = TIME_TO_TICKS(simulated_time);
m_globals()->m_realtime = simulated_time;
m_globals()->m_curtime = simulated_time;
m_globals()->m_framecount = simulated_ticks;
m_globals()->m_tickcount = simulated_ticks;
m_globals()->m_interpolation_amount = 0.0f;
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
m_globals()->m_realtime = backup_realtime;
m_globals()->m_curtime = backup_curtime;
m_globals()->m_framecount = backup_framecount;
m_globals()->m_tickcount = backup_tickcount;
m_globals()->m_interpolation_amount = backup_interpolation_amount;
updated_animations = true;
}
}
}
if (!updated_animations)
{
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
}
memcpy(animstate, &state, sizeof(c_baseplayeranimationstate));
auto setup_matrix = [&](player_t* e, AnimationLayer* layers, const int& matrix) -> void
{
e->invalidate_physics_recursive(8);
AnimationLayer backup_layers[13];
memcpy(backup_layers, e->get_animlayers(), e->animlayer_count() * sizeof(AnimationLayer));
memcpy(e->get_animlayers(), layers, e->animlayer_count() * sizeof(AnimationLayer));
switch (matrix)
{
case MAIN:
e->setup_bones_fixed(record->matrixes_data.main, BONE_USED_BY_ANYTHING);
break;
case NONE:
e->setup_bones_fixed(record->matrixes_data.zero, BONE_USED_BY_HITBOX);
break;
case FIRST:
e->setup_bones_fixed(record->matrixes_data.first, BONE_USED_BY_HITBOX);
break;
case SECOND:
e->setup_bones_fixed(record->matrixes_data.second, BONE_USED_BY_HITBOX);
break;
}
memcpy(e->get_animlayers(), backup_layers, e->animlayer_count() * sizeof(AnimationLayer));
};
#if RELEASE
if (!player_info.fakeplayer && g_ctx.local()->is_alive() && e->m_iTeamNum() != g_ctx.local()->m_iTeamNum() && !g_cfg.legitbot.enabled) //-V807
#else
if (g_ctx.local()->is_alive() && e->m_iTeamNum() != g_ctx.local()->m_iTeamNum() && !g_cfg.legitbot.enabled)
#endif
{
auto v48 = 0.f;
float v49 = ((animstate->m_flStopToFullRunningFraction * -0.30000001) - 0.19999999) * v48;
float flYawModifier = v49 + 1.0;
float back = math::calculate_angle(g_ctx.local()->m_vecOrigin(), e->m_vecOrigin()).y;
float flMaxBodyYaw = *(float*)(uintptr_t(animstate) + 0x338) * flYawModifier;
float flMinBodyYaw = *(float*)(uintptr_t(animstate) + 0x334) * flYawModifier;
/*float flMinBodyYaw = flYawModifier * -e->get_max_desync_delta();
float flMaxBodyYaw = flYawModifier * e->get_max_desync_delta();*/
animstate->m_flGoalFeetYaw = previous_goal_feet_yaw[e->EntIndex()]; //-V807
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
previous_goal_feet_yaw[e->EntIndex()] = animstate->m_flGoalFeetYaw;
memcpy(animstate, &state, sizeof(c_baseplayeranimationstate));
std::memcpy(player_resolver[e->EntIndex()].previous_layers, animlayers, e->animlayer_count() * sizeof(AnimationLayer));
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y); //-V807
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
setup_matrix(e, player_resolver[e->EntIndex()].resolver_layers[0], NONE);
memcpy(animstate, &state, sizeof(c_baseplayeranimationstate));
std::memcpy(player_resolver[e->EntIndex()].resolver_layers[0], animlayers, e->animlayer_count() * sizeof(AnimationLayer));
//e->copy_animlayers(player_resolver[e->EntIndex()].layers[0]);
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y + flMaxBodyYaw);
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
setup_matrix(e, player_resolver[e->EntIndex()].resolver_layers[1], FIRST);
memcpy(animstate, &state, sizeof(c_baseplayeranimationstate));
std::memcpy(player_resolver[e->EntIndex()].resolver_layers[1], animlayers, e->animlayer_count() * sizeof(AnimationLayer));
//e->copy_animlayers(player_resolver[e->EntIndex()].layers[1]);
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y - flMinBodyYaw);
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
setup_matrix(e, player_resolver[e->EntIndex()].resolver_layers[2], SECOND);
memcpy(animstate, &state, sizeof(c_baseplayeranimationstate));
std::memcpy(player_resolver[e->EntIndex()].resolver_layers[2], animlayers, e->animlayer_count() * sizeof(AnimationLayer));
// e->copy_animlayers(player_resolver[e->EntIndex()].layers[2]);
player_resolver[e->EntIndex()].initialize(e, record, previous_goal_feet_yaw[e->EntIndex()], e->m_angEyeAngles().x);
player_resolver[e->EntIndex()].resolve_yaw();
if (g_cfg.player_list.low_delta[e->EntIndex()])
{
switch (record->side)
{
case RESOLVER_FIRST:
record->side = RESOLVER_LOW_FIRST;
break;
case RESOLVER_SECOND:
record->side = RESOLVER_LOW_SECOND;
break;
case RESOLVER_LOW_FIRST:
record->side = RESOLVER_FIRST;
break;
case RESOLVER_LOW_SECOND:
record->side = RESOLVER_SECOND;
break;
}
}
switch (record->side)
{
case RESOLVER_ORIGINAL:
animstate->m_flGoalFeetYaw = previous_goal_feet_yaw[e->EntIndex()];
break;
case RESOLVER_ZERO:
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y);
break;
case RESOLVER_FIRST:
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y + flMaxBodyYaw);
break;
case RESOLVER_SECOND:
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y - flMinBodyYaw);
break;
case RESOLVER_LOW_FIRST:
animstate->m_flGoalFeetYaw = math::normalize_yaw(back);
break;
case RESOLVER_LOW_SECOND:
animstate->m_flGoalFeetYaw = math::normalize_yaw(e->m_angEyeAngles().y);
break;
}
e->m_angEyeAngles().x = player_resolver[e->EntIndex()].resolve_pitch();
}
g_ctx.globals.updating_animation = true;
e->update_clientside_animation();
g_ctx.globals.updating_animation = false;
setup_matrix(e, animlayers, MAIN);
memcpy(e->m_CachedBoneData().Base(), record->matrixes_data.main, e->m_CachedBoneData().Count() * sizeof(matrix3x4_t));
m_globals()->m_curtime = backup_curtime;
m_globals()->m_frametime = backup_frametime;
e->m_flLowerBodyYawTarget() = backup_lower_body_yaw_target;
e->m_flDuckAmount() = backup_duck_amount;
e->m_fFlags() = backup_flags;
e->m_iEFlags() = backup_eflags;
e->set_abs_origin(backup_absorigin);
e->set_abs_angles(backup_absangles);
memcpy(e->get_animlayers(), animlayers, e->animlayer_count() * sizeof(AnimationLayer));
record->store_data(e, false);
if (e->m_flSimulationTime() < e->m_flOldSimulationTime())
record->invalid = true;
}