get good get legendware
-
Автор темы
- #1
here is a normal safepoint without using the engine tracer to lose 100 fps lol
C++:
float SegmentToSegment(const Vector s1, const Vector s2, const Vector k1, const Vector k2)
{
static auto constexpr epsilon = 0.00000001;
auto u = s2 - s1;
auto v = k2 - k1;
const auto w = s1 - k1;
const auto a = u.Dot(u);
const auto b = u.Dot(v);
const auto c = v.Dot(v);
const auto d = u.Dot(w);
const auto e = v.Dot(w);
const auto D = a * c - b * b;
float sn, sd = D;
float tn, td = D;
if (D < epsilon) {
sn = 0.0;
sd = 1.0;
tn = e;
td = c;
}
else {
sn = b * e - c * d;
tn = a * e - b * d;
if (sn < 0.0) {
sn = 0.0;
tn = e;
td = c;
}
else if (sn > sd) {
sn = sd;
tn = e + b;
td = c;
}
}
if (tn < 0.0) {
tn = 0.0;
if (-d < 0.0)
sn = 0.0;
else if (-d > a)
sn = sd;
else {
sn = -d;
sd = a;
}
}
else if (tn > td) {
tn = td;
if (-d + b < 0.0)
sn = 0;
else if (-d + b > a)
sn = sd;
else {
sn = -d + b;
sd = a;
}
}
const float sc = abs(sn) < epsilon ? 0.0 : sn / sd;
const float tc = abs(tn) < epsilon ? 0.0 : tn / td;
m128 n;
auto dp = w + u * sc - v * tc;
n.f[0] = dp.Dot(dp);
const auto calc = sqrt_ps(n.v);
return reinterpret_cast<const m128*>(&calc)->f[0];
}
bool Intersect(Vector start, Vector end, Vector a, Vector b, float radius)
{
const auto dist = SegmentToSegment(a, b, start, end);
return (dist < radius);
}
void aim::CalculateHitboxData(C_Hitbox* rtn, player_t* ent, int ihitbox, matrix3x4_t* matrix)
{
if (ihitbox < 0 || ihitbox > 19) return;
if (!ent) return;
const auto model = ent->GetModel();
if (!model)
return;
auto pStudioHdr = m_modelinfo()->GetStudioModel(model);
if (!pStudioHdr)
return;
auto studio_set = pStudioHdr->pHitboxSet(ent->m_nHitboxSet());
if (!studio_set)
return;
auto hitbox = studio_set->pHitbox(ihitbox);
if (!hitbox)
return;
const auto is_capsule = hitbox->radius != -1.f;
Vector min, max;
if (is_capsule) {
math::vector_transform(hitbox->bbmin, matrix[hitbox->bone], min);
math::vector_transform(hitbox->bbmax, matrix[hitbox->bone], max);
}
else
{
math::vector_transform(math::vector_rotate(hitbox->bbmin, hitbox->rotation), matrix[hitbox->bone], min);
math::vector_transform(math::vector_rotate(hitbox->bbmax, hitbox->rotation), matrix[hitbox->bone], max);
}
rtn->hitboxID = ihitbox;
rtn->isOBB = !is_capsule;
rtn->radius = hitbox->radius;
rtn->mins = min;
rtn->maxs = max;
rtn->bone = hitbox->bone;
}
bool aim::CanSafepoint(adjust_data* record, Vector Eyepos, Vector aimpoint, int hitbox)
{
Vector angle = math::calculate_angle(Eyepos, aimpoint);
Vector forward;
math::AngleVectors({ angle.x, angle.y, angle.z }, &forward);
auto end = Eyepos + forward * 8092.f;
if (g_cfg.ragebot.use_semisafe)
{
bool low = record->low_delta_s && (record->curMode == STANDING || record->curMode == SLOW_WALKING);
auto left = low ? record->matrixes_data.low_second : record->matrixes_data.second;
auto right = low ? record->matrixes_data.low_first : record->matrixes_data.first;
}
else
{
auto left = record->matrixes_data.second;
auto right = record->matrixes_data.first;
}
auto center = record->matrixes_data.zero;
C_Hitbox box1; CalculateHitboxData(&box1, record->player, hitbox, left);
C_Hitbox box2; CalculateHitboxData(&box2, record->player, hitbox, right);
C_Hitbox box3; CalculateHitboxData(&box3, record->player, hitbox, center);
auto overlaps = box1.isOBB || box2.isOBB || box3.isOBB;
if (overlaps) {
math::vector_i_transform(Eyepos, left[box1.bone], box1.mins);
math::vector_i_rotate(end, left[box1.bone], box1.maxs);
math::vector_i_transform(Eyepos, right[box2.bone], box2.mins);
math::vector_i_rotate(end, right[box2.bone], box2.maxs);
math::vector_i_transform(Eyepos, center[box3.bone], box3.mins);
math::vector_i_rotate(end, center[box3.bone], box3.maxs);
}
auto hits = 0;
if (overlaps ? math::intersect_line_with_bb(Eyepos, end, box1.mins, box1.maxs) : Intersect(Eyepos, end, box1.mins, box1.maxs, box1.radius))
hits += 1;
if (overlaps ? math::intersect_line_with_bb(Eyepos, end, box2.mins, box2.maxs) : Intersect(Eyepos, end, box2.mins, box2.maxs, box2.radius))
hits += 1;
if (overlaps ? math::intersect_line_with_bb(Eyepos, end, box3.mins, box3.maxs) : Intersect(Eyepos, end, box3.mins, box3.maxs, box3.radius))
hits += 1;
return (hits >= 3);
}