From d7201835d1823ce5e2cc81af3a1718c322a2f34d Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Thu, 1 Nov 2018 15:45:56 +0100 Subject: [PATCH] FIX INCORRECT HITBOXES --- include/helpers.hpp | 2 ++ src/helpers.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ src/hooks/CreateMove.cpp | 5 ++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index ee20e429..f6f7ab29 100755 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -67,6 +67,8 @@ powerup_type GetPowerupOnPlayer(CachedEntity *player); // It's better if it won't create a new object each time it gets called. // So it returns a success state, and the values are stored in out reference. bool GetHitbox(CachedEntity *entity, int hb, Vector &out); +std::optional GetUncachedHitbox(IClientEntity *ent, + int id); weaponmode GetWeaponMode(); void FixMovement(CUserCmd &cmd, Vector &viewangles); diff --git a/src/helpers.cpp b/src/helpers.cpp index b1f08d0e..cbf69193 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -571,6 +571,53 @@ bool GetHitbox(CachedEntity *entity, int hb, Vector &out) return true; } +void VectorTransform2(const Vector in1, matrix3x4_t in2, Vector *out) { + Vector a = { in2[0][0], in2[0][1], in2[0][2] }; + Vector b = { in2[1][0], in2[1][1], in2[1][2] }; + Vector c = { in2[2][0], in2[2][1], in2[2][2] }; + out->x = DotProduct(in1, a) + in2[0][3]; + out->y = DotProduct(in1, b) + in2[1][3]; + out->z = DotProduct(in1, c) + in2[2][3]; +} + +std::optional GetUncachedHitbox(IClientEntity *ent, + int id) +{ + if (ent && !g_Settings.bInvalid && !ent->IsDormant() && + !(NET_BYTE(ent, netvar.iLifeState))) + { + const model_t *model = ent->GetModel(); + if (!model) + return std::nullopt; + studiohdr_t *studiomodel = g_IModelInfo->GetStudiomodel(model); + if (!studiomodel) + return std::nullopt; + matrix3x4_t bonematrix[128]; + if (!ent->SetupBones(bonematrix, 128, 0x7FFF, 0)) + return std::nullopt; + mstudiohitboxset_t *set = + studiomodel->pHitboxSet(NET_INT(ent, netvar.iHitboxSet)); + mstudiobbox_t *box = set->pHitbox(id); + if (!box) + return std::nullopt; + hitbox_cache::CachedHitbox hitbox; + VectorTransform2(box->bbmin, bonematrix[box->bone], &hitbox.min); + VectorTransform2(box->bbmax, bonematrix[box->bone], &hitbox.max); + hitbox.center = (hitbox.min + hitbox.max) / 2; + hitbox.bbox = box; + return std::make_optional(hitbox); + } + return std::nullopt; +} + +std::optional GetUncachedHitbox(CachedEntity *ent, + int id) +{ + if (CE_BAD(ent)) + return std::nullopt; + return GetUncachedHitbox(ent->InternalEntity(), id); +} + void VectorAngles(Vector &forward, Vector &angles) { float tmp, yaw, pitch; diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 9f60ff39..8b1f62b2 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -246,7 +246,10 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, entity_cache::Invalidate(); } // Disabled because this causes EXTREME aimbot inaccuracy - // if (!cmd->command_number) return ret; + // Actually dont disable it. It causes even more inaccuracy + if (!cmd->command_number) + return ret; + // PROF_BEGIN(); { PROF_SECTION(EntityCache);