-
Автор темы
- #1
Resolver.cpp:
#include "animation_system.h"
#include "..\ragebot\aim.h"
#include "../visuals/player_esp.h"
/* Semi Fixed Resolver by Purlex */
void CResolver::initialize(player_t* e, adjust_data* record, const float& goal_feet_yaw, const float& pitch)
{
player=e;
player_record = record;
original_pitch = math::normalize_pitch(pitch);
original_goal_feet_yaw = math::normalize_yaw(goal_feet_yaw);
}
void CResolver::initialize_yaw(player_t* e, adjust_data* record)
{
player=e;
player_record = record;
player_record->left = b_yaw(player, player->m_angEyeAngles().y, 1);
player_record->right = b_yaw(player, player->m_angEyeAngles().y, 2);
player_record->middle = b_yaw(player, player->m_angEyeAngles().y, 3);
}
void CResolver::reset()
{
player = nullptr;
player_record = nullptr;
side=false;
fake=false;
was_first_brute force = false;
was_second_bruteforce = false;
original_goal_feet_yaw = 0.0f;
original_pitch=0.0f;
}
bool CResolver::IsAdjustingBalance()
{
for (int i = 0; i < 15; i++)
{
const int activity = player->sequence_activity(player_record->layers[i].m_nSequence);
if (activity == 979)
{
return true;
}
}
return false;
}
bool CResolver::is_breaking_lby(AnimationLayer cur_layer, AnimationLayer prev_layer)
{
if (IsAdjustingBalance())
{
if ((prev_layer.m_flCycle != cur_layer.m_flCycle) || cur_layer.m_flWeight == 1.f)
{
return true;
}
else if (cur_layer.m_flWeight == 0.f && (prev_layer.m_flCycle > 0.92f && cur_layer.m_flCycle > 0.92f))
{
return true;
}
}
return false;
}
static auto GetSmoothedVelocity = [](float min_delta, Vector a, Vector b) {
Vector delta = a - b;
float delta_length = delta.Length();
if (delta_length <= min_delta)
{
if (-min_delta <= delta_length)
return a;
else
{
float iradius = 1.0f / (delta_length + FLT_EPSILON);
return b - ((delta * iradius) * min_delta);
}
}
else
{
float iradius = 1.0f / (delta_length + FLT_EPSILON);
return b + ((delta * iradius) * min_delta);
}
};
inline float anglemod(float a)
{
a = (360.f / 65536) * ((int)(a * (65536.f / 360.0f)) & 65535);
return a;
}
float ApproachAngle(float target, float value, float speed)
{
target = anglemod(target);
value = anglemod(value);
float delta = target - value;
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;
}
float CResolver::b_yaw(player_t* entity, float original_yaw, int idk)
{
float best_rotation = original_yaw;
if (idk == 1)
{
for (int i = 1; i <= 8; i++)
{
float rotation = original_yaw - (45.f * i);
if (entity->CanUseHitboxes() && entity->GetHitboxPos(0).DistTo(entity->GetHitboxPos(4)) < 37.f)
{
best_rotation = rotation;
break;
}
else if (entity->CanUseHitboxes() && entity->GetHitboxPos(0).DistTo(entity->GetHitboxPos(4)) > 37.f)
{
best_rotation = rotation;
break;
}
}
}
if (idk == 2)
{
for (int i = 1; i <= 8; i++)
{
float rotation = original_yaw + (45.f * i);
if (entity->CanUseHitboxes() && entity->GetHitboxPos(0).DistTo(entity->GetHitboxPos(4)) < 37.f)
{
best_rotation = rotation;
break;
}
else if (entity->CanUseHitboxes() && entity->GetHitboxPos(0).DistTo(entity->GetHitboxPos(4)) > 37.f)
{
best_rotation = rotation;
break;
}
}
}
if (idk == 3)
{
if (entity->CanUseHitboxes() && entity->GetHitboxPos(0).DistTo(entity->GetHitboxPos(4)) < 37.f)
{
best_rotation = original_yaw;
}
else if (entity->CanUseHitboxes() && entity->GetHitboxPos(0).DistTo(entity->GetHitboxPos(4)) > 37.f)
{
best_rotation = original_yaw + 180.f;
}
}
return best_rotation;
}
bool is_slow_walking(player_t* player)
{
return player->m_vecVelocity().Length2D() <= (player->m_flMaxspeed() / 3);
}
int GetChokedPackets(player_t*player)
{
if (player->m_flSimulationTime() > player->m_flOldSimulationTime())
return TIME_TO_TICKS(fabsf(player->m_flSimulationTime() - player->m_flOldSimulationTime()));
return 1;
}
void layer_test(player_t* player, adjust_data* record)
{
if (player->GetAnimOverlay(3))
{
auto layers = player->GetAnimOverlays();
auto activity = player->sequence_activity(layers[3].m_nSequence);
//Using keyframes of act 979 causes issues while jumping
if (activity == 979)
{
record->adjusting_balance = true;
}
//Check if player is breaking LBY by moving
if (layers[3].m_flWeight < 0.1f && activity != 0)
{
record->breaking_lby = true;
}
}
}
void get_side_standing(player_t* player, float goal_feet_yaw, adjust_data* record)
{
Vector velocity = player->m_vecVelocity();
vector direction;
Vector pivot = player->m_vecOrigin();
math::angle_vectors(QAngle(0, goal_feet_yaw, 0), direction);
float speed = velocity.Length2D();
vector velocity_direction = velocity.Normalized();
Vector side1, side2;
VectorAngles(velocity_direction, side1);
side2 = side1 + QAngle(0, 90, 0);
vector newvec1, newvec2;
AngleVectors(side1, &newvec1);
AngleVectors(side2, &newvec2);
newvec1 *= 45.f;
newvec2 *= 45.f;
Vector eye_pos = player->GetEyePos();
Ray_tray;
ray.Init(eye_pos, (eye_pos + (newvec1 + newvec2)).Length2D());
trace_ttr;
CTraceFilter traceFilter;
traceFilter.pSkip = player;
g_EngineTrace->TraceRay(ray, MASK_SHOT_BRUSHONLY, &traceFilter, &tr);
Vector hitpoint = tr endpos;
Ray_t ray1;
ray1.Init(eye_pos, (eye_pos - (newvec1 + newvec2)).Length2D());
g_EngineTrace->TraceRay(ray1, MASK_SHOT_BRUSHONLY, &traceFilter, &tr);
if ((hitpoint - tr.endpos).Length() > 65.f)
{
// i take sides here incase some retard decides to use wallbug or something similar to that to fuck up the resolver. this avoids him fucking up the direction resolve so he gets his real head back.
if ((velocity_direction.Dot(newvec1) > newvec2.Dot(velocity_direction)) && !record->bruteforce)
{
record->last_resolve_side = false;
record->has_balance_adjusted = false;
record->direction = newvec1;
}
else if ((velocity_direction.Dot(newvec1) < newvec2.Dot(velocity_direction)) && !record->bruteforce)
{
record->last_resolve_side = true;
record->has_balance_adjusted = false;
record->direction = newvec2;
}
else
{
record->has_balance_adjusted = true;
record->direction = Vector(1, 0, 0);
}
}
else
{
record->has_balance_adjusted = true;
record->direction = Vector(1, 0, 0);
}
}
void get_back(player_t* player, float goal_feet_yaw, adjust_data* record)
{
Vector velocity = player->m_vecVelocity();
vector direction;
Vector pivot = player->m_vecOrigin();
math::angle_vectors(QAngle(0, goal_feet_yaw, 0), direction);
float speed = velocity.Length2D();
vector velocity_direction = velocity.Normalized();
Vector side1, side2;
VectorAngles(velocity_direction, side1);
side2 = side1 + QAngle(0, 180, 0);
vector newvec1, newvec2;
AngleVectors(side1, &newvec1);
AngleVectors(side2, &newvec2);
newvec1 *= 45.f;
newvec2 *= 45.f;
Vector eye_pos = player->GetEyePos();
Ray_tray;
ray.Init(eye_pos, (eye_pos + (newvec1 + newvec2)).Length2D());
trace_ttr;
CTraceFilter traceFilter;
traceFilter.pSkip = player;
g_EngineTrace->TraceRay(ray, MASK_SHOT_BRUSHONLY, &traceFilter, &tr);
Vector hitpoint = tr endpos;
Ray_t ray1;
ray1.Init(eye_pos, (eye_pos - (newvec1 + newvec2)).Length2D());
g_EngineTrace->TraceRay(ray1, MASK_SHOT_BRUSHONLY, &traceFilter, &tr);
if ((hitpoint - tr.endpos).Length() > 65.f)
{
if ((velocity_direction.Dot(newvec1) > newvec2.Dot(velocity_direction)) && !record->bruteforce)
{
record->last_resolve_side = false;
record->has_balance_adjusted = false;
record->direction = newvec1;
}
else if ((velocity_direction.Dot(newvec1) < newvec2.Dot(velocity_direction)) && !record->bruteforce)
{
record->last_resolve_side = true;
record->has_balance_adjusted = false;
record->direction = newvec2;
}
else
{
record->has_balance_adjusted = true;
record->direction = Vector(1, 0, 0);
}
}
else
{
record->has_balance_adjusted = true;
record->direction = Vector(1, 0, 0);
}
}
float GetFeetYaw(player_t* player)
{
if (!player)
return 0.f;
const float pose_param = player->m_flPoseParameter()[11];
const float goal_feet_yaw = player->m_flLowerBodyYawTarget();
return goal_feet_yaw;
}
float CResolver::ResolveYaw(player_t*player)
{
if (!player)
return 0.f;
float yaw = player->m_angEyeAngles().y;
adjust_data* record = &player_record[player->EntIndex()];
if (!record)
return yaw;
float goal_feet_yaw = GetFeetYaw(player);
if (record->adjusting_balance)
{
// Inverse lby breaker.
if (record->breaking_lby && !record->bruteforce && !record->has_balance_adjusted)
{
get_side_standing(player, goal_feet_yaw, record);
}
if (record->last_resolve_side && record->has_balance_adjusted)
{
yaw = (goal_feet_yaw - 90.f) + 180.f;
}
else if (!record->last_resolve_side && record->has_balance_adjusted)
{
yaw = (goal_feet_yaw + 90.f) + 180.f;
}
else if (record->bruteforce && record->last_resolve_side && !record->has_balance_adjusted)
{
yaw = b_yaw(player, yaw, 1);
}
else if (record->bruteforce && !record->last_resolve_side && !record->has_balance_adjusted)
{
yaw = b_yaw(player, yaw, 2);
}
//Last resort.
if (record->has_balance_adjusted && record->last_resolve_side)
{
yaw = (goal_feet_yaw - 90.f) + 180.f;
}
else if (record->has_balance_adjusted && !record->last_resolve_side)
{
yaw = (goal_feet_yaw + 90.f) + 180.f;
}
record->should_fake = true;
}
return yaw;
}
void CResolver::Resolve(player_t* player)
{
if (!player)
return;
adjust_data* record = &player_record[player->EntIndex()];
if (!record)
return;
record->should_fake = false;
layer_test(player, record);
if (player->GetAnimOverlay(3))
{
// player is using standup anim, check if it's breaking balance.
if (is_breaking_lby(player->GetAnimOverlay(3), record->layers[3]))
{
record->adjusting_balance = true;
}
else
{
record->adjusting_balance = false;
}
}
// pre-resolve
if (!record->adjusting_balance)
{
record->last_resolve_side = false;
record->should_fake = false;
}
else
{
// not standing
if (!player->IsStanding())
{
// broke balance, apply yaw resolve
if (record->breaking_lby)
{
if (record->has_balance_adjusted)
{
if (record->last_resolve_side)
{
player->m_angEyeAngles().y = (record->yaw - 90.f) + 180.f;
}
else
{
player->m_angEyeAngles().y = (record->yaw + 90.f) + 180.f;
}
}
else if (record->bruteforce)
{
if (record->last_resolve_side)
{
player->m_angEyeAngles().y = b_yaw(player, player->m_angEyeAngles().y, 1);
}
else
{
player->m_angEyeAngles().y = b_yaw(player, player->m_angEyeAngles().y, 2);
}
}
}
record->should_fake = true;
}
else
{
// not moving
if (!is_slow_walking(player))
{
if (!record->has_balance_adjusted && !record->bruteforce)
{
if (record->last_resolve_side)
{
player->m_angEyeAngles().y = b_yaw(player, player->m_angEyeAngles().y, 1);
}
else
{
player->m_angEyeAngles().y = b_yaw(player, player->m_angEyeAngles().y, 2);
}
}
else if (record->has_balance_adjusted)
{
if (record->last_resolve_side)
{
player->m_angEyeAngles().y = (record->yaw - 90.f) + 180.f;
}
else
{
player->m_angEyeAngles().y = (record->yaw + 90.f) + 180.f;
}
}
record->should_fake = true;
}
else
{
// balancing
if (record->breaking_lby)
{
record->should_fake = true;
// adjust balance
if (record->brute force)
{
if (!record->has_balance_adjusted)
{
if (record->last_resolve_side)
{
player->m_angEyeAngles().y = b_yaw(player, player->m_angEyeAngles().y, 1);
}
else
{
player->m_angEyeAngles().y = b_yaw(player, player->m_angEyeAngles().y, 2);
}
}
}
else
{
if (record->has_balance_adjusted)
{
if (record->last_resolve_side)
{
player->m_angEyeAngles().y = (record->yaw - 90.f) + 180.f;
}
else
{
player->m_angEyeAngles().y = (record->yaw + 90.f) + 180.f;
}
}
}
}
}
}
}
}
and tbh I already know its bad I didn't even test got to lazy its 4:23 AM
Maybe I'll actually take my time and help y'all legendware pasters with making a resolver :?