diff --git a/src/entitycache.cpp b/src/entitycache.cpp index 97399f9c..2e6a58a7 100644 --- a/src/entitycache.cpp +++ b/src/entitycache.cpp @@ -12,7 +12,9 @@ #include "profiler.h" CachedEntity::CachedEntity() { +#if PROXY_ENTITY != true m_pEntity = nullptr; +#endif m_Bones = 0; m_Bones = new matrix3x4_t[MAXSTUDIOBONES]; m_pHitboxCache = new EntityHitboxCache(this); @@ -26,7 +28,7 @@ CachedEntity::~CachedEntity() { } IClientEntity* CachedEntity::InternalEntity() { - return m_pEntity; + return g_IEntityList->GetClientEntity(m_IDX); } void EntityCache::Invalidate() { @@ -38,13 +40,16 @@ void CachedEntity::Update(int idx) { SEGV_BEGIN m_IDX = idx; + if (!RAW_ENT(this)) return; +#if PROXY_ENTITY != true m_pEntity = g_IEntityList->GetClientEntity(idx); if (!m_pEntity) { return; } - m_iClassID = m_pEntity->GetClientClass()->m_ClassID; +#endif + m_iClassID = RAW_ENT(this)->GetClientClass()->m_ClassID; - Vector origin = m_pEntity->GetAbsOrigin(); + Vector origin = RAW_ENT(this)->GetAbsOrigin(); //if (TF2 && EstimateAbsVelocity) EstimateAbsVelocity(m_pEntity, m_vecVelocity); /*if ((gvars->realtime - m_fLastUpdate) >= 0.05f) { //if (gvars->tickcount - m_nLastTick > 1) { @@ -74,7 +79,6 @@ void CachedEntity::Update(int idx) { if (m_pHitboxCache) { SAFE_CALL(m_pHitboxCache->Update()); } - if (m_iClassID == g_pClassID->C_Player) { m_Type = EntityType::ENTITY_PLAYER; } else if (m_iClassID == g_pClassID->CTFGrenadePipebombProjectile || @@ -105,7 +109,6 @@ void CachedEntity::Update(int idx) { m_flDistance = (g_pLocalPlayer->v_Origin.DistTo(m_vecOrigin)); } m_bAlivePlayer = false; - // TODO temporary! /*m_bCritProjectile = false; m_bIsVisible = false; @@ -127,7 +130,7 @@ void CachedEntity::Update(int idx) { } if (m_Type == EntityType::ENTITY_PLAYER) { - m_bAlivePlayer = !(NET_BYTE(m_pEntity, netvar.iLifeState)); + m_bAlivePlayer = !(NET_BYTE(RAW_ENT(this), netvar.iLifeState)); if (m_pPlayerInfo) { delete m_pPlayerInfo; m_pPlayerInfo = 0; @@ -145,7 +148,7 @@ void CachedEntity::Update(int idx) { m_iHealth = CE_INT(this, netvar.iBuildingHealth); m_iMaxHealth = CE_INT(this, netvar.iBuildingMaxHealth); } - SEGV_END_INFO("Updating entity") + SEGV_END_INFO("Updating entity"); } static CatVar fast_vischeck(CV_SWITCH, "fast_vischeck", "0", "Fast VisCheck", "VisCheck only certain player hitboxes"); @@ -194,7 +197,7 @@ bool CachedEntity::IsVisible() { matrix3x4_t* CachedEntity::GetBones() { if (!m_bBonesSetup) { - m_bBonesSetup = m_pEntity->SetupBones(m_Bones, MAXSTUDIOBONES, 0x100, 0); // gvars->curtime + m_bBonesSetup = RAW_ENT(this)->SetupBones(m_Bones, MAXSTUDIOBONES, 0x100, 0); // gvars->curtime } return m_Bones; } @@ -210,9 +213,7 @@ EntityCache::~EntityCache() { void EntityCache::Update() { m_nMax = g_IEntityList->GetHighestEntityIndex(); for (int i = 0; i < m_nMax && i < MAX_ENTITIES; i++) { - //logging::Info("Updating %i", i); m_pArray[i].Update(i); - //logging::Info("Back!"); } } diff --git a/src/entitycache.h b/src/entitycache.h index 178122d0..5000b611 100644 --- a/src/entitycache.h +++ b/src/entitycache.h @@ -24,44 +24,28 @@ struct mstudiobbox_t; #define MAX_STRINGS 16 #define MAX_ENTITIES 2048 +#define PROXY_ENTITY true + +#if PROXY_ENTITY == true +#define RAW_ENT(ce) ((ce) ? (ce)->InternalEntity() : nullptr) +#else +#define RAW_ENT(ce) ce->m_pEntity +#endif + #define CE_VAR(entity, offset, type) \ - NET_VAR(entity->m_pEntity, offset, type) + NET_VAR(RAW_ENT(entity), offset, type) #define CE_INT(entity, offset) CE_VAR(entity, offset, int) #define CE_FLOAT(entity, offset) CE_VAR(entity, offset, float) #define CE_BYTE(entity, offset) CE_VAR(entity, offset, unsigned char) #define CE_VECTOR(entity, offset) CE_VAR(entity, offset, Vector) -#define CE_GOOD_NO_DORMANT_CHECK(entity) (!g_Settings.bInvalid && dynamic_cast(entity) && dynamic_cast(entity->m_pEntity)) -#define CE_GOOD(entity) (!g_Settings.bInvalid && dynamic_cast(entity) && dynamic_cast(entity->m_pEntity) && (g_IEntityList->GetClientEntity(entity->m_IDX) == entity->m_pEntity) && entity->m_pEntity->GetIClientEntity() && !entity->m_pEntity->GetIClientEntity()->IsDormant()) +#define CE_GOOD(entity) (!g_Settings.bInvalid && dynamic_cast(entity) && RAW_ENT(entity) && !RAW_ENT(entity)->IsDormant()) #define CE_BAD(entity) (!CE_GOOD(entity)) #define IDX_GOOD(idx) (idx >= 0 && idx < HIGHEST_ENTITY && idx < MAX_ENTITIES) #define IDX_BAD(idx) !IDX_GOOD(idx) -#define PROXY_ENTITY false - -#if PROXY_ENTITY == true -#define RAW_ENT(ce) ce->InternalEntity() -#else -#define RAW_ENT(ce) ce->m_pEntity -#endif - - -// This will be used later. maybe. -#define ENTITY_ITERATE_INT(iterator, entity, max) \ - for (int iterator = 0; iterator < max; iterator++) { \ - CachedEntity* entity = gEntityCache.GetEntity(iterator); \ - if (CE_BAD(entity)) continue; - -#define ENTITY_ITERATE_EVERYTHING(iterator, entity) \ - ENTITY_ITERATE_INT(iterator, entity, gEntityCache.m_nMax) - -#define ENTITY_ITERATE_PLAYERS(iterator, entity) \ - ENTITY_ITERATE_INT(iterator, entity, MIN(gEntityCache.m_nMax, 64)) - -#define END_ENTITY_ITERATING } - #define HIGHEST_ENTITY gEntityCache.m_nMax #define ENTITY(idx) gEntityCache.GetEntity(idx) @@ -146,11 +130,13 @@ public: EntityHitboxCache* m_pHitboxCache; int m_IDX; IClientEntity* InternalEntity(); - IClientEntity* m_pEntity; Vector m_vecVOrigin; Vector m_vecVelocity; Vector m_vecAcceleration; float m_fLastUpdate; +#if PROXY_ENTITY != true || 1 // FIXME?? + IClientEntity* m_pEntity; +#endif }; class EntityCache { diff --git a/src/hacks/ESP.cpp b/src/hacks/ESP.cpp index 3220dd72..2fa45eed 100644 --- a/src/hacks/ESP.cpp +++ b/src/hacks/ESP.cpp @@ -214,7 +214,7 @@ void ProcessEntity(CachedEntity* ent) { if (ent->m_iClassID == g_pClassID->CTFTankBoss && tank) { AddEntityString(ent, "Tank"); } else if (ent->m_iClassID == g_pClassID->CTFDroppedWeapon && item_esp && item_dropped_weapons) { - AddEntityString(ent, format("WEAPON ", ent->m_pEntity->GetClientClass()->GetName())); + AddEntityString(ent, format("WEAPON ", RAW_ENT(ent)->GetClientClass()->GetName())); } else if (ent->m_iClassID == g_pClassID->CCurrencyPack && item_money) { if (CE_BYTE(ent, netvar.bDistributed)) { if (item_money_red) { @@ -312,7 +312,7 @@ void ProcessEntity(CachedEntity* ent) { CachedEntity* weapon = ENTITY(CE_INT(ent, netvar.hActiveWeapon) & 0xFFF); if (CE_GOOD(weapon)) { if (show_weapon) { - AddEntityString(ent, std::string(vfunc(weapon->m_pEntity, 398, 0)(weapon->m_pEntity))); + AddEntityString(ent, std::string(vfunc(RAW_ENT(weapon), 398, 0)(RAW_ENT(weapon)))); } } } diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index 988f3cca..9754c64c 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -256,9 +256,9 @@ void DoWalking() { IClientEntity* owner_weapon = g_IEntityList->GetClientEntity(owner_weapon_eid); if (owner_weapon && CE_GOOD(g_pLocalPlayer->weapon())) { // IsBaseCombatWeapon() - if (vfunc(g_pLocalPlayer->weapon()->m_pEntity, 190, 0)(g_pLocalPlayer->weapon()->m_pEntity) && + if (vfunc(RAW_ENT(g_pLocalPlayer->weapon()), 190, 0)(RAW_ENT(g_pLocalPlayer->weapon())) && vfunc(owner_weapon, 190, 0)(owner_weapon)) { - int my_slot = vfunc(g_pLocalPlayer->weapon()->m_pEntity, 395, 0)(g_pLocalPlayer->weapon()->m_pEntity); + int my_slot = vfunc(RAW_ENT(g_pLocalPlayer->weapon()), 395, 0)(RAW_ENT(g_pLocalPlayer->weapon())); int owner_slot = vfunc(owner_weapon, 395, 0)(owner_weapon); if (g_pLocalPlayer->clazz == tf_medic && always_medigun) { if (my_slot != 1) { diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index 59ee5d05..52630f25 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -77,7 +77,7 @@ void Draw() { if (!debug_info) return; if (CE_GOOD(g_pLocalPlayer->weapon())) { - AddSideString(format("Slot: ", vfunc(g_pLocalPlayer->weapon()->m_pEntity, 395, 0)(g_pLocalPlayer->weapon()->m_pEntity))); + AddSideString(format("Slot: ", vfunc(RAW_ENT(g_pLocalPlayer->weapon()), 395, 0)(RAW_ENT(g_pLocalPlayer->weapon())))); /*AddSideString(colors::white, "Weapon: %s [%i]", RAW_ENT(g_pLocalPlayer->weapon())->GetClientClass()->GetName(), g_pLocalPlayer->weapon()->m_iClassID); //AddSideString(colors::white, "flNextPrimaryAttack: %f", CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flNextPrimaryAttack)); //AddSideString(colors::white, "nTickBase: %f", (float)(CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) * gvars->interval_per_tick); diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 35c4e8f0..9c3c45f5 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -143,7 +143,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { } } - if (CE_GOOD(g_pLocalPlayer->entity)) { g_pLocalPlayer->v_OrigViewangles = cmd->viewangles; // PROF_BEGIN(); @@ -226,7 +225,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { g_Settings.last_angles = cmd->viewangles; } - // PROF_END("CreateMove"); g_pLocalPlayer->bAttackLastTick = (cmd->buttons & IN_ATTACK); return ret;