void c_resolver_recode::AnimationFix(C_CSPlayer* pEnt)
{
static float oldSimtime[65];
static float storedSimtime[65];
static float ShotTime[65];
static float SideTime[65][3];
static int LastDesyncSide[65];
static bool Delaying[65];
static AnimationLayer StoredLayers[64][15];
static C_AnimState* StoredAnimState[65];
static float StoredPosParams[65][24];
static Vector oldEyeAngles[65];
static float oldGoalfeetYaw[65];
float* PosParams = (float*)((uintptr_t)pEnt + 0x2774);
bool update = false;
bool shot = false;
static bool jittering[65];
auto* AnimState = pEnt->get_anim_state2();
if (!AnimState || !pEnt->get_animation_laye() || !PosParams)
return;
auto RemapVal = [](float val, float A, float B, float C, float D) -> float
{
if (A == B)
return val >= B ? D : C;
return C + (D - C) * (val - A) / (B - A);
};
if (storedSimtime[pEnt->EntIndex()] != pEnt->get_simtime())
{
jittering[pEnt->EntIndex()] = false;
pEnt->get_clientside_animation() = true;
pEnt->update_clientside_anim();
memcpy(StoredPosParams[pEnt->EntIndex()], PosParams, sizeof(float) * 24);
memcpy(StoredLayers[pEnt->EntIndex()], pEnt->get_animation_laye(), (sizeof(AnimationLayer) * pEnt->NumOverlays()));
oldGoalfeetYaw[pEnt->EntIndex()] = AnimState->m_flGoalFeetYaw;
auto weapon = get_weapon(g_pLocalPlayer->get_active_weapon());
if (pEnt->get_active_weapon() && !pEnt->IsKnifeorNade())
{
if (ShotTime[pEnt->EntIndex()] != weapon->get_last_shot_time())
{
shot = true;
ShotTime[pEnt->EntIndex()] = weapon->get_last_shot_time();
}
else
shot = false;
}
else
{
shot = false;
ShotTime[pEnt->EntIndex()] = 0.f;
}
float angToLocal = NormalizeYaw2(CalcAngle(g_pLocalPlayer->get_origin(), pEnt->get_origin()).y);
float Back = NormalizeYaw2(angToLocal);
float DesyncFix = 0;
float Resim = NormalizeYaw2((0.24f / (pEnt->get_simtime() - oldSimtime[pEnt->EntIndex()])) * (oldEyeAngles[pEnt->EntIndex()].y - pEnt->get_eye_angles().y));
if (Resim > 58.f)
Resim = 58.f;
if (Resim < -58.f)
Resim = -58.f;
if (pEnt->get_velocity().Length2D() > 0.5f && !shot)
{
float Delta = NormalizeYaw2(NormalizeYaw2(CalcAngle(Vector(0, 0, 0), pEnt->get_velocity()).y) - NormalizeYaw2(NormalizeYaw2(AnimState->m_flGoalFeetYaw + RemapVal(PosParams[11], 0, 1, -60, 60)) + Resim));
int CurrentSide = 0;
if (Delta < 0)
{
CurrentSide = 1;
SideTime[pEnt->EntIndex()][1] = g_pGlobals->curtime;
}
else if (Delta > 0)
{
CurrentSide = 2;
SideTime[pEnt->EntIndex()][2] = g_pGlobals->curtime;
}
if (LastDesyncSide[pEnt->EntIndex()] == 1)
{
Resim += (58.f - Resim);
DesyncFix += (58.f - Resim);
}
if (LastDesyncSide[pEnt->EntIndex()] == 2)
{
Resim += (-58.f - Resim);
DesyncFix += (-58.f - Resim);
}
if (LastDesyncSide[pEnt->EntIndex()] != CurrentSide)
{
Delaying[pEnt->EntIndex()] = true;
if (.5f < (g_pGlobals->curtime - SideTime[pEnt->EntIndex()][LastDesyncSide[pEnt->EntIndex()]]))
{
LastDesyncSide[pEnt->EntIndex()] = CurrentSide;
Delaying[pEnt->EntIndex()] = false;
}
}
if (!Delaying[pEnt->EntIndex()])
LastDesyncSide[pEnt->EntIndex()] = CurrentSide;
}
else if (!shot)
{
float Brute = UseFreestandAngle[pEnt->EntIndex()] ? NormalizeYaw2(Back + FreestandAngle[pEnt->EntIndex()]) : pEnt->get_lby();
float Delta = NormalizeYaw2(NormalizeYaw2(Brute - NormalizeYaw2(NormalizeYaw2(AnimState->m_flGoalFeetYaw + RemapVal(PosParams[11], 0, 1, -60, 60))) + Resim));
if (Delta > 58.f)
Delta = 58.f;
if (Delta < -58.f)
Delta = -58.f;
Resim += Delta;
DesyncFix += Delta;
if (Resim > 58.f)
Resim = 58.f;
if (Resim < -58.f)
Resim = -58.f;
}
float Equalized = NormalizeYaw2(NormalizeYaw2(AnimState->m_flGoalFeetYaw + RemapVal(PosParams[11], 0, 1, -60, 60)) + Resim);
float JitterDelta = fabs(NormalizeYaw2(oldEyeAngles[pEnt->EntIndex()].y - pEnt->get_eye_angles().y));
if (JitterDelta >= 70.f && !shot)
jittering[pEnt->EntIndex()] = true;
if (pEnt != g_pLocalPlayer && pEnt->get_team() != g_pLocalPlayer->get_team() && (pEnt->get_flags() & FL_ONGROUND) && vars::aa.resolver_stick.get<bool>())
{
if (jittering[pEnt->EntIndex()])
AnimState->m_flGoalFeetYaw = NormalizeYaw2(pEnt->get_eye_angles().y + DesyncFix);
else
AnimState->m_flGoalFeetYaw = Equalized;
pEnt->get_lby() = AnimState->m_flGoalFeetYaw;
}
StoredAnimState[pEnt->EntIndex()] = AnimState;
oldEyeAngles[pEnt->EntIndex()] = pEnt->get_eye_angles1();
oldSimtime[pEnt->EntIndex()] = storedSimtime[pEnt->EntIndex()];
storedSimtime[pEnt->EntIndex()] = pEnt->get_simtime();
update = true;
}
pEnt->get_clientside_animation() = false;
if (pEnt != g_pLocalPlayer && pEnt->get_team() != g_pLocalPlayer->get_team() && (pEnt->get_flags() & FL_ONGROUND) && vars::aa.resolver_stick.get<bool>())
pEnt->get_lby() = AnimState->m_flGoalFeetYaw;
AnimState = StoredAnimState[pEnt->EntIndex()];
memcpy((void*)PosParams, &StoredPosParams[pEnt->EntIndex()], (sizeof(float) * 24));
memcpy(pEnt->get_animation_laye(), StoredLayers[pEnt->EntIndex()], (sizeof(AnimationLayer) * pEnt->NumOverlays()));
if (pEnt != g_pLocalPlayer && pEnt->get_team() != g_pLocalPlayer->get_team() && (pEnt->get_flags() & FL_ONGROUND) && vars::aa.resolver_stick.get<bool>() && jittering[pEnt->EntIndex()])
pEnt->set_abs_angles(Vector(0, pEnt->get_eye_angles().y, 0));
else
pEnt->set_abs_angles(Vector(0, oldGoalfeetYaw[pEnt->EntIndex()], 0));
*reinterpret_cast<int*>(uintptr_t(pEnt) + 0xA30) = g_pGlobals->framecount;
*reinterpret_cast<int*>(uintptr_t(pEnt) + 0xA28) = 0;
}
CNetChannel* net_channel;
void HandleHits(C_CSPlayer* pEnt)
{
auto NetChannel = g_pEngine->GetNetChannelInfo();
if (!NetChannel)
return;
static float predTime[65];
static bool init[65];
if (g_Shot[pEnt->EntIndex()])
{
if (init[pEnt->EntIndex()])
{
c_resolver_recode::get().pitchHit[pEnt->EntIndex()] = pEnt->get_eye_angles().x;
predTime[pEnt->EntIndex()] = g_pGlobals->curtime + NetChannel->GetAvgLatency(FLOW_INCOMING) + NetChannel->GetAvgLatency(FLOW_OUTGOING) + ticks_to_time(1) + ticks_to_time(net_channel->m_nChokedPackets);
init[pEnt->EntIndex()] = false;
}
if (g_pGlobals->curtime > predTime[pEnt->EntIndex()] && !g_Hit[pEnt->EntIndex()])
{
g_MissedShots[pEnt->EntIndex()] += 1;
g_Shot[pEnt->EntIndex()] = false;
}
else if (g_pGlobals->curtime <= predTime[pEnt->EntIndex()] && g_Hit[pEnt->EntIndex()])
g_Shot[pEnt->EntIndex()] = false;
}
else
init[pEnt->EntIndex()] = true;
g_Hit[pEnt->EntIndex()] = false;
}
void c_resolver_recode::OnCreateMove()
{
if (!vars::aa.resolver_stick.get<bool>())
return;
if (!g_pLocalPlayer->get_alive())
return;
if (!g_pLocalPlayer->get_active_weapon() || g_pLocalPlayer->IsKnifeorNade())
return;
for (auto i = 1; i < g_pGlobals->maxClients; i++)
{
auto player = get_entity(i);
if (!player || player == g_pLocalPlayer)
{
continue;
}
if (!player->get_alive())
{
continue;
}
if (player->IsDormant())
{
continue;
}
{
UseFreestandAngle[i] = false;
continue;
}
if (abs(player->get_velocity().Length2D()) > 29.f)
UseFreestandAngle[player->EntIndex()] = false;
if (abs(player->get_velocity().Length2D()) <= 29.f && !UseFreestandAngle[player->EntIndex()])
{
bool Autowalled = false, HitSide1 = false, HitSide2 = false;
float angToLocal = CalcAngle(g_pLocalPlayer->get_origin(), player->get_origin()).y;
Vector ViewPoint = g_pLocalPlayer->get_origin() + Vector(0, 0, 90);
Vector2D Side1 = { (45 * sin(GRD_TO_BOG(angToLocal))),(45 * cos(GRD_TO_BOG(angToLocal))) };
Vector2D Side2 = { (45 * sin(GRD_TO_BOG(angToLocal + 180))) ,(45 * cos(GRD_TO_BOG(angToLocal + 180))) };
Vector2D Side3 = { (50 * sin(GRD_TO_BOG(angToLocal))),(50 * cos(GRD_TO_BOG(angToLocal))) };
Vector2D Side4 = { (50 * sin(GRD_TO_BOG(angToLocal + 180))) ,(50 * cos(GRD_TO_BOG(angToLocal + 180))) };
Vector Origin = player->get_origin();
Vector2D OriginLeftRight[] = { Vector2D(Side1.x, Side1.y), Vector2D(Side2.x, Side2.y) };
Vector2D OriginLeftRightLocal[] = { Vector2D(Side3.x, Side3.y), Vector2D(Side4.x, Side4.y) };
for (int side = 0; side < 2; side++)
{
Vector OriginAutowall = { Origin.x + OriginLeftRight[side].x, Origin.y - OriginLeftRight[side].y , Origin.z + 90 };
Vector OriginAutowall2 = { ViewPoint.x + OriginLeftRightLocal[side].x, ViewPoint.y - OriginLeftRightLocal[side].y , ViewPoint.z };
float point_damage;
if (penetration::get().can_hit(player,OriginAutowall, point_damage, ViewPoint))
{
if (side == 0)
{
HitSide1 = true;
FreestandAngle[player->EntIndex()] = 90;
}
else if (side == 1)
{
HitSide2 = true;
FreestandAngle[player->EntIndex()] = -90;
}
Autowalled = true;
}
else
{
for (int side222 = 0; side222 < 2; side222++)
{
Vector OriginAutowall222 = { Origin.x + OriginLeftRight[side222].x, Origin.y - OriginLeftRight[side222].y , Origin.z + 90 };
if (penetration::get().can_hit(player, OriginAutowall222, point_damage, OriginAutowall2))
{
if (side222 == 0)
{
HitSide1 = true;
FreestandAngle[player->EntIndex()] = 90;
}
else if (side222 == 1)
{
HitSide2 = true;
FreestandAngle[player->EntIndex()] = -90;
}
Autowalled = true;
}
}
}
}
if (Autowalled)
{
if (HitSide1 && HitSide2)
UseFreestandAngle[player->EntIndex()] = false;
else
UseFreestandAngle[player->EntIndex()] = true;
}
}
}
}
void c_resolver_recode::FrameStage(ClientFrameStage_t stage)
{
if (!g_pLocalPlayer || !g_pEngine->IsInGame())
return;
static bool wasDormant[65];
for (auto i = 1; i < g_pGlobals->maxClients; i++)
{
auto player = get_entity(i);
if (!player
|| !player->get_alive())
continue;
if (player->IsDormant())
{
wasDormant[i] = true;
continue;
}
if (stage == FRAME_RENDER_START)
{
HandleHits(player);
AnimationFix(player);
}
if (stage == FRAME_NET_UPDATE_END && player != g_pLocalPlayer)
{
auto VarMap = reinterpret_cast<uintptr_t>(player) + 36;
auto VarMapSize = *reinterpret_cast<int*>(VarMap + 20);
for (auto index = 0; index < VarMapSize; index++)
*reinterpret_cast<uintptr_t*>(*reinterpret_cast<uintptr_t*>(VarMap) + index * 12) = 0;
}
wasDormant[i] = false;
}
}