#include "Resolver.h"
#include "..\Aimbot\Aimbot.h"
#include "..\Aimbot\Autowall.h"
#include "..\Aimbot\LagComp.h"
#include "..\..\Utils\Utils.h"
#include "..\..\SDK\IVEngineClient.h"
#include "..\..\SDK\Hitboxes.h"
#include "..\..\SDK\PlayerInfo.h"
#include "..\..\Utils\Math.h"
#include "..\..\Menu\Menu.h"
#include "..\..\Menu\config.h"
#include "..\..\SDK\CEntity.h"
#include "..\..\SDK\ICvar.h"
Resolver g_Resolver;
float MaxDelta(C_BaseEntity* pEnt)
{
auto animstate = uintptr_t(pEnt->AnimState());
float duckammount = *(float*)(animstate + 0xA4);
float speedfraction = max(0, min(*reinterpret_cast<float*>(animstate + 0xF8), 1));
float speedfactor = max(0, min(1, *reinterpret_cast<float*> (animstate + 0xFC)));
float unk1 = ((*reinterpret_cast<float*> (animstate + 0x11C) * -0.30000001f) - 0.19999999f)* speedfraction;
float unk2 = unk1 + 1.f;
float unk3;
if (duckammount > 0) {
unk2 += ((duckammount * speedfactor) * (0.5f - unk2));
}
unk3 = *(float*)(animstate + 0x334) * unk2;
return unk3;
}
inline float RandomFloat(float min, float max)
{
static auto fn = (decltype(&RandomFloat))(GetProcAddress(GetModuleHandle("vstdlib.dll"), "RandomFloat"));
return fn(min, max);
}
float AngleNormalize(float angles)
{
angles = fmodf(angles, 360.0f);
if (angles > 180)
{
angles -= 360;
}
if (angles < -180)
{
angles += 360;
}
return angles;
}
inline float ClampYaw(float yaw)
{
while (yaw > 180.f)
yaw -= 360.f;
while (yaw < -180.f)
yaw += 360.f;
return yaw;
}
float __fastcall AngleDiff(float a1, float a2)
{
float val = fmodf(a1 - a2, 360.0);
while (val < -180.0f) val += 360.0f;
while (val > 180.0f) val -= 360.0f;
return val;
}
//void Resolver::AnimationFix(C_BaseEntity* entity)
//{
// //auto animstate = pEnt->AnimState();
// //switch (Globals::MissedShots[pEnt->EntIndex()] % 12) //19 //26 //14 //8
// //{
// // case 1: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 180.f; break;
// // case 2: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw + 89.f; break;
// // case 3: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 89.f; break;
// // case 4: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw + 70.f; break;
// // case 5: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 70.f; break;
// // case 6: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw + 60.f; break;
// // case 7: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 60.f; break;
// // case 8: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw + 58.f; break;
// // case 9: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 58.f; break;
// // case 10: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw + 45.f; break;
// // case 11: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 45.f; break;
// // case 12: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw + 30.f; break;
// // case 13: animstate->m_flGoalFeetYaw = animstate->m_flGoalFeetYaw - 30.f; break;*/
// //case 0: pEnt->GetEyeAngles().y + 180.f; break;
// //case 1: pEnt->GetEyeAngles().y - 180.f; break;
// //case 2: pEnt->GetEyeAngles().y + 89.f; break;
// //case 3: pEnt->GetEyeAngles().y - 89.f; break;
// //case 4: pEnt->GetEyeAngles().y + 60.f; break;
// //case 5: pEnt->GetEyeAngles().y - 60.f; break;
// //case 6: pEnt->GetEyeAngles().y + 58.f; break;
// //case 7: pEnt->GetEyeAngles().y - 58.f; break;
// //case 8: pEnt->GetEyeAngles().y + 45.f; break;
// //case 9: pEnt->GetEyeAngles().y - 45.f; break;
// //case 10: pEnt->GetEyeAngles().y + 30.f; break;
// //case 11: pEnt->GetEyeAngles().y - 30.f; break;
// //}
// float Resolved = entity->GetEyeAngles().y;
// auto v3 = Globals::LocalPlayer;
// auto animstate = entity->AnimState();
// if (v3 != entity)
// {
// if (animstate)
// {
// //switch (Globals::MissedShots[entity->EntIndex()] % 2) //10
// //{
// ///*case 1: animstate->m_flEyeYaw = animstate->m_flEyeYaw + MaxDelta(entity); break;
// //case 2: animstate->m_flEyeYaw = animstate->m_flEyeYaw - MaxDelta(entity); break;*/
// // /*case 0:
// // animstate->m_flGoalFeetYaw += 180.0f;
// // break;
// // case 1:
// // animstate->m_flGoalFeetYaw -= 180.0f;
// // break;
// // case 2:
// // animstate->m_flGoalFeetYaw += 89.0f;
// // break;
// // case 3:
// // animstate->m_flGoalFeetYaw -= 89.0f;
// // break;
// // case 4:
// // animstate->m_flGoalFeetYaw += 60.0f;
// // break;
// // case 5:
// // animstate->m_flGoalFeetYaw -= 60.0f;
// // break;
// // case 6:
// // animstate->m_flGoalFeetYaw += 58.0f;
// // break;
// // case 7:
// // animstate->m_flGoalFeetYaw -= 58.0f;
// // break;
// // case 8:
// // animstate->m_flGoalFeetYaw += 45.0f;
// // break;
// // case 9:
// // animstate->m_flGoalFeetYaw -= 45.0f;
// // break;
// // case 10:
// // animstate->m_flGoalFeetYaw -= 30.0f;
// // break;
// // case 11:
// // animstate->m_flGoalFeetYaw += 30.0f;
// // break;*/
// //}
// switch (Globals::MissedShots[entity->EntIndex()] % 6)
// {
// case 0: animstate->m_flGoalFeetYaw + 60.f; break;
// case 1: animstate->m_flGoalFeetYaw - 60.f; break;
// case 2: animstate->m_flGoalFeetYaw + 45.f; break;
// case 3: animstate->m_flGoalFeetYaw - 45.f; break;
// case 4: animstate->m_flGoalFeetYaw + 30.f; break;
// case 5: animstate->m_flGoalFeetYaw - 30.f; break;
// }
// /*animstate->m_flGoalFeetYaw = fabs( Resolved);*/
// }
// }
//}
void Resolver::AnimationFix(C_BaseEntity* entity)
{
auto lby = entity->GetLowerBodyYaw();
auto animstate = entity->AnimState();
if (Globals::LocalPlayer != entity)
{
if (animstate)
{
float ResolvedYaw = animstate->m_flEyeYaw;
float PrecisionDelta = std::remainderf(animstate->m_flEyeYaw, 360.f) - animstate->m_flGoalFeetYaw;
if (PrecisionDelta < 0)
animstate->m_flGoalFeetYaw = animstate->m_flEyeYaw - 60;
else if (PrecisionDelta > 0)
animstate->m_flGoalFeetYaw = animstate->m_flEyeYaw + 60;
switch (Globals::MissedShots[entity->EntIndex()] % 2)
{
case 0:
animstate->m_flGoalFeetYaw = PrecisionDelta < 0 ? animstate->m_flEyeYaw + 60 : animstate->m_flGoalFeetYaw = animstate->m_flEyeYaw - 60;
break;
case 1:
animstate->m_flGoalFeetYaw = animstate->m_flEyeYaw;
break;
default:
break;
}
}
}
}
//void Resolver::AnimationFix(C_BaseEntity* entity)
//{
// auto v3 = Globals::LocalPlayer;
// auto lby = entity->GetLowerBodyYaw();
// auto animstate = entity->AnimState();
// if (v3 != entity)
// {
// if (animstate)
// {
// float ResolvedYaw = entity->GetEyeAngles().y;
// switch (Globals::MissedShots[entity->EntIndex()] % 2)
// {
// case 0:
// animstate->m_flEyeYaw + MaxDelta(entity);
// break;
// case 1:
// animstate->m_flEyeYaw - MaxDelta(entity);
// break;
// /*case 0:
// animstate->m_flGoalFeetYaw += 0.f;
// break;
// case 1:
// animstate->m_flGoalFeetYaw += 60.f;
// break;
// case 2:
// animstate->m_flGoalFeetYaw -= 60.f;
// break;
// case 3:
// animstate->m_flGoalFeetYaw += 58.f;
// break;
// case 4:
// animstate->m_flGoalFeetYaw -= 58.f;
// break;
// case 5:
// animstate->m_flGoalFeetYaw += 23.f;
// break;
// case 6:
// animstate->m_flGoalFeetYaw -= 23.f;
// break;
// default:
// break;*/
// }
// }
// }
//}
float flAngleMod(float flAngle)
{
return((360.0f / 65536.0f) * ((int32_t)(flAngle * (65536.0f / 360.0f)) & 65535));
}
float ApproachAngle(float target, float value, float speed)
{
target = flAngleMod(target);
value = flAngleMod(value);
float delta = target - value;
// Speed is assumed to be positive
if (speed < 0)
speed = -speed;
if (delta < -180)
delta += 360;
else if (delta > 180)
delta -= 360;
if (delta > speed)
value += speed;
else if (delta < -speed)
value -= speed;
else
value = target;
return value;
}
void update_animations(C_BaseEntity* entity)
{
auto state = entity->AnimState(); if (!state) return;
auto index = entity->EntIndex();
static float sim_time[65];
if (sim_time[index] != entity->GetSimulationTime())
{
const float curtime = g_pGlobalVars->curtime;
const float frametime = g_pGlobalVars->frametime;
static auto host_timescale = g_pCvar->FindVar(("host_timescale"));
g_pGlobalVars->frametime = g_pGlobalVars->intervalPerTick * host_timescale->GetFloat();
g_pGlobalVars->curtime = entity->GetSimulationTime() + g_pGlobalVars->intervalPerTick;
Vector backup_velocity = entity->GetVelocity();
int backup_flags = entity->GetFlags();
Vector abs = entity->GetAbsAngles();
AnimationLayer backup_layers[15];
std::memcpy(backup_layers, entity->GetAnimOverlays4(), (sizeof(AnimationLayer) * 15));
state->m_bOnGround ? backup_flags |= (1 << 0) : backup_flags &= ~(1 << 0);
backup_flags &= ~0x1000;
abs = entity->GetVelocity();
abs = entity->GetVelocity();
if (state->m_iLastClientSideAnimationUpdateFramecount == g_pGlobalVars->framecount)
state->m_iLastClientSideAnimationUpdateFramecount = g_pGlobalVars->framecount - 1;
entity->UpdateClientAnimation();
float lby_delta = entity->GetLowerBodyYaw() - entity->GetEyeAngles().y;
lby_delta = std::remainderf(lby_delta, 360.f);
lby_delta = std::clamp(lby_delta, -60.f, 60.f);
float feet_yaw = std::remainderf(entity->GetEyeAngles().y + lby_delta, 360.f);
if (feet_yaw < 0.f) {
feet_yaw += 360.f;
}
static float pitch, yaw = 0.f;
entity->AnimState()->m_flGoalFeetYaw = entity->AnimState()->m_flCurrentFeetYaw = feet_yaw;
std::memcpy(entity->GetAnimOverlays4(), backup_layers, (sizeof(AnimationLayer) * 15));
g_pGlobalVars->curtime = curtime;
g_pGlobalVars->frametime = frametime;
sim_time[index] = entity->GetSimulationTime();
}
entity->InvalidateBoneCache();
entity->SetupBones(nullptr, -1, 0x7FF00, g_pGlobalVars->curtime);
}
void update_state(C_AnimState * state, Vector angles) {
using Fn = void(__vectorcall*)(void *, void *, float, float, float, void *);
static auto fn = reinterpret_cast<Fn>(Utils::FindSignature("client_panorama.dll", "55 8B EC 83 E4 F8 83 EC 18 56 57 8B F9 F3 0F 11 54 24"));
fn(state, nullptr, 0.0f, angles[1], angles[0], nullptr);
}
void HandleBackUpResolve(C_BaseEntity* entity) {
if (!c_config::get().aimbot_resolver)
return;
if (entity->GetTeam() == Globals::LocalPlayer->GetTeam())
return;
const auto player_animation_state = entity->AnimState();
if (!player_animation_state)
return;
float m_flLastClientSideAnimationUpdateTimeDelta = fabs(player_animation_state->m_iLastClientSideAnimationUpdateFramecount - player_animation_state->m_flLastClientSideAnimationUpdateTime);
auto v48 = 0.f;
if (player_animation_state->m_flFeetSpeedForwardsOrSideWays >= 0.0f)
{
v48 = fminf(player_animation_state->m_flFeetSpeedForwardsOrSideWays, 1.0f);
}
else
{
v48 = 0.0f;
}
float v49 = ((player_animation_state->m_flStopToFullRunningFraction * -0.30000001) - 0.19999999) * v48;
float flYawModifier = v49 + 1.0;
if (player_animation_state->m_fDuckAmount > 0.0)
{
float v53 = 0.0f;
if (player_animation_state->m_flFeetSpeedUnknownForwardOrSideways >= 0.0)
{
v53 = fminf(player_animation_state->m_flFeetSpeedUnknownForwardOrSideways, 1.0);
}
else
{
v53 = 0.0f;
}
}
float flMaxYawModifier = player_animation_state->pad10[516] * flYawModifier;
float flMinYawModifier = player_animation_state->pad10[512] * flYawModifier;
float newFeetYaw = 0.f;
auto eyeYaw = player_animation_state->m_flEyeYaw;
auto lbyYaw = player_animation_state->m_flGoalFeetYaw;
float eye_feet_delta = fabs(eyeYaw - lbyYaw);
if (eye_feet_delta <= flMaxYawModifier)
{
if (flMinYawModifier > eye_feet_delta)
{
newFeetYaw = fabs(flMinYawModifier) + eyeYaw;
}
}
else
{
newFeetYaw = eyeYaw - fabs(flMaxYawModifier);
}
float v136 = fmod(newFeetYaw, 360.0);
if (v136 > 180.0)
{
v136 = v136 - 360.0;
}
if (v136 < 180.0)
{
v136 = v136 + 360.0;
}
player_animation_state->m_flGoalFeetYaw = v136;
//Комментировать отсюда
//static int stored_yaw = 0;
//if (pEnt->GetEyeAnglesPointer()->y != stored_yaw) {
// if ((pEnt->GetEyeAnglesPointer()->y - stored_yaw > 120)) { // Arbitrary high angle value.
// if (pEnt->GetEyeAnglesPointer()->y - stored_yaw > 120) {
// pEnt->GetEyeAnglesPointer()->y = pEnt->GetEyeAnglesPointer()->y - (pEnt->GetEyeAnglesPointer()->y - stored_yaw);
// }
// stored_yaw = pEnt->GetEyeAnglesPointer()->y;
// }
//}
//if (pEnt->GetVelocity().Length2D() > 0.1f)
//{
// player_animation_state->m_flGoalFeetYaw = ApproachAngle(pEnt->GetLowerBodyYaw(), player_animation_state->m_flGoalFeetYaw, (player_animation_state->m_flStopToFullRunningFraction * 20.0f) + 30.0f *player_animation_state->m_flLastClientSideAnimationUpdateTime);
//}
//else
//{
// player_animation_state->m_flGoalFeetYaw = ApproachAngle(pEnt->GetLowerBodyYaw(), player_animation_state->m_flGoalFeetYaw, (m_flLastClientSideAnimationUpdateTimeDelta * 100.0f));
//}
//if (Globals::MissedShots[pEnt->EntIndex()] > 2) {
// switch (Globals::MissedShots[pEnt->EntIndex()] % 4) {
// case 0: pEnt->GetEyeAnglesPointer()->y = pEnt->GetEyeAnglesPointer()->y += 45; break;
// case 1: pEnt->GetEyeAnglesPointer()->y = pEnt->GetEyeAnglesPointer()->y -= 45; break;
// case 2: pEnt->GetEyeAnglesPointer()->y = pEnt->GetEyeAnglesPointer()->y -= 30; break;
// case 3: pEnt->GetEyeAnglesPointer()->y = pEnt->GetEyeAnglesPointer()->y += 30; break;
// }
//}
}
void HandleHits(C_BaseEntity* pEnt)
{
auto NetChannel = g_pEngine->GetNetChannelInfo();
if (!NetChannel)
return;
static float predTime[65];
static bool init[65];
if (Globals::Shot[pEnt->EntIndex()])
{
if (init[pEnt->EntIndex()])
{
g_Resolver.pitchHit[pEnt->EntIndex()] = pEnt->GetEyeAngles().x;
predTime[pEnt->EntIndex()] = g_pGlobalVars->curtime + NetChannel->GetAvgLatency(FLOW_INCOMING) + NetChannel->GetAvgLatency(FLOW_OUTGOING) + TICKS_TO_TIME(1) + TICKS_TO_TIME(g_pEngine->GetNetChannel()->m_nChokedPackets);
init[pEnt->EntIndex()] = false;
}
if (g_pGlobalVars->curtime > predTime[pEnt->EntIndex()] && !Globals::Hit[pEnt->EntIndex()])
{
Globals::MissedShots[pEnt->EntIndex()] += 1;
Globals::Shot[pEnt->EntIndex()] = false;
}
else if (g_pGlobalVars->curtime <= predTime[pEnt->EntIndex()] && Globals::Hit[pEnt->EntIndex()])
Globals::Shot[pEnt->EntIndex()] = false;
}
else
init[pEnt->EntIndex()] = true;
Globals::Hit[pEnt->EntIndex()] = false;
}
void Resolver::OnCreateMove() // cancer v2
{
if (!c_config::get().aimbot_resolver)
return;
if (!Globals::LocalPlayer->IsAlive())
return;
if (!Globals::LocalPlayer->GetActiveWeapon() || Globals::LocalPlayer->IsKnifeorNade())
return;
for (int i = 1; i < g_pEngine->GetMaxClients(); ++i)
{
C_BaseEntity* entity;
C_BaseEntity* pPlayerEntity = g_pEntityList->GetClientEntity(i);
if (!pPlayerEntity
|| !pPlayerEntity->IsAlive()
|| pPlayerEntity->IsDormant()
|| pPlayerEntity == Globals::LocalPlayer
|| pPlayerEntity->GetTeam() == Globals::LocalPlayer->GetTeam())
{
UseFreestandAngle[i] = false;
continue;
}
if (abs(pPlayerEntity->GetVelocity().Length2D()) > 29.f)
UseFreestandAngle[pPlayerEntity->EntIndex()] = false;
if (abs(pPlayerEntity->GetVelocity().Length2D()) <= 29.f && !UseFreestandAngle[pPlayerEntity->EntIndex()])
{
bool Autowalled = false, HitSide1 = false, HitSide2 = false;
float angToLocal = g_Math.CalcAngle(Globals::LocalPlayer->GetOrigin(), pPlayerEntity->GetOrigin()).y;
Vector ViewPoint = Globals::LocalPlayer->GetOrigin() + Vector(0, 0, 90);
Vector2D Side1 = { (45 * sin(g_Math.GRD_TO_BOG(angToLocal))),(45 * cos(g_Math.GRD_TO_BOG(angToLocal))) };
Vector2D Side2 = { (45 * sin(g_Math.GRD_TO_BOG(angToLocal + 180))) ,(45 * cos(g_Math.GRD_TO_BOG(angToLocal + 180))) };
Vector2D Side3 = { (50 * sin(g_Math.GRD_TO_BOG(angToLocal))),(50 * cos(g_Math.GRD_TO_BOG(angToLocal))) };
Vector2D Side4 = { (50 * sin(g_Math.GRD_TO_BOG(angToLocal + 180))) ,(50 * cos(g_Math.GRD_TO_BOG(angToLocal + 180))) };
Vector Origin = pPlayerEntity->GetOrigin();
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 };
if (g_Autowall.CanHitFloatingPoint(OriginAutowall, ViewPoint))
{
if (side == 0)
{
HitSide1 = true;
FreestandAngle[pPlayerEntity->EntIndex()] = 90;
}
else if (side == 1)
{
HitSide2 = true;
FreestandAngle[pPlayerEntity->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 (g_Autowall.CanHitFloatingPoint(OriginAutowall222, OriginAutowall2))
{
if (side222 == 0)
{
HitSide1 = true;
FreestandAngle[pPlayerEntity->EntIndex()] = 90;
}
else if (side222 == 1)
{
HitSide2 = true;
FreestandAngle[pPlayerEntity->EntIndex()] = -90;
}
Autowalled = true;
}
}
}
}
if (Autowalled)
{
if (HitSide1 && HitSide2)
UseFreestandAngle[pPlayerEntity->EntIndex()] = false;
else
UseFreestandAngle[pPlayerEntity->EntIndex()] = true;
}
}
}
}
void Resolver::FrameStage(ClientFrameStage_t stage)
{
if (!Globals::LocalPlayer || !g_pEngine->IsInGame())
return;
static bool wasDormant[65];
for (int i = 1; i < g_pEngine->GetMaxClients(); ++i)
{
C_BaseEntity* pPlayerEntity = g_pEntityList->GetClientEntity(i);
if (!pPlayerEntity
|| !pPlayerEntity->IsAlive())
continue;
if (pPlayerEntity->IsDormant())
{
wasDormant[i] = true;
continue;
}
if (stage == FRAME_RENDER_START)
{
HandleHits(pPlayerEntity);
AnimationFix(pPlayerEntity);
}
if (stage == FRAME_NET_UPDATE_POSTDATAUPDATE_START) {
HandleBackUpResolve(pPlayerEntity);
}
if (stage == FRAME_NET_UPDATE_END && pPlayerEntity != Globals::LocalPlayer)
{
auto VarMap = reinterpret_cast<uintptr_t>(pPlayerEntity) + 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;
}
}