auto clear soundcache, fully dormant tracers
This commit is contained in:
parent
dc8e3eff47
commit
a8f2dc5df6
@ -110,7 +110,7 @@ public:
|
||||
{
|
||||
return RAW_ENT(this)->GetAbsOrigin();
|
||||
};
|
||||
Vector m_vecDormantOrigin();
|
||||
std::optional<Vector> m_vecDormantOrigin();
|
||||
int m_iTeam()
|
||||
{
|
||||
return NET_INT(RAW_ENT(this), netvar.iTeamNum);
|
||||
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include "timer.hpp"
|
||||
#include "map"
|
||||
#include <map>
|
||||
#include "public/mathlib/vector.h"
|
||||
#include <optional>
|
||||
struct CSndInfo_t
|
||||
{
|
||||
Vector m_pOrigin;
|
||||
@ -13,3 +14,8 @@ struct SoundStruct
|
||||
Timer last_update;
|
||||
};
|
||||
extern std::map<int, SoundStruct> sound_cache;
|
||||
|
||||
namespace soundcache
|
||||
{
|
||||
std::optional<Vector> GetSoundLocation(int entid);
|
||||
}
|
||||
|
@ -128,13 +128,14 @@ bool CachedEntity::IsVisible()
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector CachedEntity::m_vecDormantOrigin()
|
||||
std::optional<Vector> CachedEntity::m_vecDormantOrigin()
|
||||
{
|
||||
if (!RAW_ENT(this)->IsDormant())
|
||||
return m_vecOrigin();
|
||||
else if (!sound_cache[m_IDX].last_update.check(10000) && !sound_cache[m_IDX].sound.m_pOrigin.IsZero())
|
||||
return sound_cache[m_IDX].sound.m_pOrigin;
|
||||
return Vector(0.0f);
|
||||
auto vec = soundcache::GetSoundLocation(this->m_IDX);
|
||||
if (vec)
|
||||
return *vec;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
namespace entity_cache
|
||||
|
@ -88,7 +88,6 @@ bool IsTarget(CachedEntity *ent)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Function called by game for movement
|
||||
void CreateMove()
|
||||
{
|
||||
// Check user settings if auto-sticky is enabled
|
||||
@ -112,7 +111,7 @@ void CreateMove()
|
||||
// Cycle through the ents and search for valid ents
|
||||
for (int i = 0; i <= HIGHEST_ENTITY; i++)
|
||||
{
|
||||
// Assign the for loops tick number to an ent
|
||||
// Assign the for loops index to an ent
|
||||
CachedEntity *ent = ENTITY(i);
|
||||
// Check for dormancy and if valid
|
||||
if (CE_INVALID(ent))
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
auto ent = ENTITY(i);
|
||||
if (CE_VALID(ent) && (ent->m_Type() == ENTITY_PLAYER || ent->m_iClassID() == CL_CLASS(CObjectSentrygun)) && ent->m_bEnemy() && ent->m_bAlivePlayer())
|
||||
{
|
||||
if (ent->m_vecDormantOrigin() != Vector(0.0f) && ent->m_vecDormantOrigin().DistTo(LOCAL_E->m_vecOrigin()) < *safety)
|
||||
if (ent->m_vecDormantOrigin() && ent->m_vecDormantOrigin()->DistTo(LOCAL_E->m_vecOrigin()) < *safety)
|
||||
{
|
||||
nearby = true;
|
||||
break;
|
||||
|
@ -89,9 +89,9 @@ void DrawEntity(int x, int y, CachedEntity *ent)
|
||||
return;
|
||||
if (clazz <= 0 || clazz > 9)
|
||||
return;
|
||||
if (ent->m_vecDormantOrigin() == Vector(0.0f))
|
||||
if (!ent->m_vecDormantOrigin())
|
||||
return;
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin().x, ent->m_vecDormantOrigin().y);
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin()->x, ent->m_vecDormantOrigin()->y);
|
||||
|
||||
if (use_icons)
|
||||
{
|
||||
@ -118,9 +118,9 @@ void DrawEntity(int x, int y, CachedEntity *ent)
|
||||
{
|
||||
if (ent->m_iClassID() == CL_CLASS(CObjectDispenser) || ent->m_iClassID() == CL_CLASS(CObjectSentrygun) || ent->m_iClassID() == CL_CLASS(CObjectTeleporter))
|
||||
{
|
||||
if (ent->m_vecDormantOrigin() == Vector(0.0f))
|
||||
if (!ent->m_vecDormantOrigin())
|
||||
return;
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin().x, ent->m_vecDormantOrigin().y);
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin()->x, ent->m_vecDormantOrigin()->y);
|
||||
tx_teams[CE_INT(ent, netvar.iTeamNum) - 2].draw(x + wtr.first, y + wtr.second, *icon_size * 1.5f, *icon_size * 1.5f, colors::white);
|
||||
switch (ent->m_iClassID())
|
||||
{
|
||||
@ -157,18 +157,18 @@ void DrawEntity(int x, int y, CachedEntity *ent)
|
||||
}
|
||||
else if (ent->m_Type() == ENTITY_GENERIC)
|
||||
{
|
||||
if (ent->m_vecDormantOrigin() == Vector(0.0f))
|
||||
if (!ent->m_vecDormantOrigin())
|
||||
return;
|
||||
if (show_healthpacks && (ent->m_ItemType() == ITEM_HEALTH_LARGE || ent->m_ItemType() == ITEM_HEALTH_MEDIUM || ent->m_ItemType() == ITEM_HEALTH_SMALL))
|
||||
{
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin().x, ent->m_vecDormantOrigin().y);
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin()->x, ent->m_vecDormantOrigin()->y);
|
||||
float sz = *icon_size * 0.15f * 0.5f;
|
||||
float sz2 = *icon_size * 0.85;
|
||||
tx_items[0].draw(x + wtr.first + sz, y + wtr.second + sz, sz2, sz2, colors::white);
|
||||
}
|
||||
else if (show_ammopacks && (ent->m_ItemType() == ITEM_AMMO_LARGE || ent->m_ItemType() == ITEM_AMMO_MEDIUM || ent->m_ItemType() == ITEM_AMMO_SMALL))
|
||||
{
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin().x, ent->m_vecDormantOrigin().y);
|
||||
const auto &wtr = WorldToRadar(ent->m_vecDormantOrigin()->x, ent->m_vecDormantOrigin()->y);
|
||||
float sz = *icon_size * 0.15f * 0.5f;
|
||||
float sz2 = *icon_size * 0.85;
|
||||
tx_items[1].draw(x + wtr.first + sz, y + wtr.second + sz, sz2, sz2, colors::white);
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "common.hpp"
|
||||
#include "PlayerTools.hpp"
|
||||
#include "playerresource.h"
|
||||
#include "soundcache.hpp"
|
||||
|
||||
namespace hacks::shared::tracers
|
||||
{
|
||||
@ -58,12 +60,12 @@ inline std::optional<rgba_t> getColor(CachedEntity *ent)
|
||||
{
|
||||
if (ent->m_Type() == ENTITY_BUILDING)
|
||||
{
|
||||
if (!ent->m_bEnemy())
|
||||
if (!ent->m_bEnemy() || !ent->m_vecDormantOrigin())
|
||||
return std::nullopt;
|
||||
float dist = ent->m_vecDormantOrigin().DistTo(LOCAL_E->m_vecOrigin());
|
||||
float dist = ent->m_vecDormantOrigin()->DistTo(LOCAL_E->m_vecOrigin());
|
||||
if (*max_dist && dist > *max_dist)
|
||||
return std::nullopt;
|
||||
if (GetFov(g_pLocalPlayer->v_OrigViewangles, g_pLocalPlayer->v_Eye, ent->m_vecDormantOrigin()) < *min_fov)
|
||||
if (GetFov(g_pLocalPlayer->v_OrigViewangles, g_pLocalPlayer->v_Eye, *ent->m_vecDormantOrigin()) < *min_fov)
|
||||
return std::nullopt;
|
||||
float hf = float(std::min(dist, *green_dist)) / float(*green_dist);
|
||||
rgba_t color(0.0f, 2.0f * hf, 2.0f * (1.0f - hf));
|
||||
@ -77,9 +79,9 @@ inline std::optional<rgba_t> getColor(CachedEntity *ent)
|
||||
auto state = playerlist::AccessData(ent->player_info.friendsID);
|
||||
if (state.state == playerlist::k_EState::DEFAULT)
|
||||
{
|
||||
if (!ent->m_bEnemy())
|
||||
if (!ent->m_bEnemy() || !ent->m_vecDormantOrigin())
|
||||
return std::nullopt;
|
||||
float dist = ent->m_vecDormantOrigin().DistTo(LOCAL_E->m_vecOrigin());
|
||||
float dist = ent->m_vecDormantOrigin()->DistTo(LOCAL_E->m_vecOrigin());
|
||||
if (*max_dist && dist > *max_dist)
|
||||
return std::nullopt;
|
||||
return colors::Health(std::min(dist, *green_dist), *green_dist);
|
||||
@ -110,22 +112,38 @@ void draw()
|
||||
{
|
||||
// Get and check player
|
||||
auto ent = ENTITY(i);
|
||||
if (CE_INVALID(ent) || !ent->m_bAlivePlayer())
|
||||
continue;
|
||||
Vector origin = ent->m_vecDormantOrigin();
|
||||
if (origin == Vector(0.0f, 0.0f, 0.0f))
|
||||
continue;
|
||||
if (*buildings)
|
||||
if (ent->m_Type() != ENTITY_PLAYER && ent->m_Type() != ENTITY_BUILDING)
|
||||
Vector origin;
|
||||
std::optional<rgba_t> color = std::nullopt;
|
||||
|
||||
if (CE_INVALID(ent))
|
||||
{
|
||||
if (i > 32)
|
||||
continue;
|
||||
if (ent == LOCAL_E)
|
||||
continue;
|
||||
auto color = getColor(ent);
|
||||
if (!color)
|
||||
continue;
|
||||
if (RAW_ENT(ent)->IsDormant())
|
||||
color = colors::FromRGBA8(160, 160, 160, 255);
|
||||
color->a = *opaque;
|
||||
if (g_pPlayerResource->GetTeam(i) == g_pLocalPlayer->team || !g_pPlayerResource->isAlive(i))
|
||||
continue;
|
||||
auto vec = soundcache::GetSoundLocation(i);
|
||||
if (!vec)
|
||||
continue;
|
||||
origin = *vec;
|
||||
color = colors::FromRGBA8(160, 160, 160, *opaque);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ent->m_bAlivePlayer() || !ent->m_vecDormantOrigin())
|
||||
continue;
|
||||
origin = *ent->m_vecDormantOrigin();
|
||||
if (*buildings)
|
||||
if (ent->m_Type() != ENTITY_PLAYER && ent->m_Type() != ENTITY_BUILDING)
|
||||
continue;
|
||||
if (ent == LOCAL_E)
|
||||
continue;
|
||||
color = getColor(ent);
|
||||
if (!color)
|
||||
continue;
|
||||
if (RAW_ENT(ent)->IsDormant())
|
||||
color = colors::FromRGBA8(160, 160, 160, *opaque);
|
||||
color->a = *opaque;
|
||||
}
|
||||
|
||||
Vector out;
|
||||
if (!draw::WorldToScreen(origin, out))
|
||||
|
@ -4,8 +4,9 @@ std::map<int, SoundStruct> sound_cache;
|
||||
|
||||
namespace soundcache
|
||||
{
|
||||
constexpr unsigned int EXPIRETIME = 10000;
|
||||
|
||||
void CreateMove()
|
||||
static void CreateMove()
|
||||
{
|
||||
if (CE_BAD(LOCAL_E))
|
||||
return;
|
||||
@ -16,6 +17,23 @@ void CreateMove()
|
||||
sound_cache[i.m_nSoundSource].sound.m_pOrigin = *i.m_pOrigin;
|
||||
sound_cache[i.m_nSoundSource].last_update.update();
|
||||
}
|
||||
|
||||
for (auto it = sound_cache.cbegin(); it != sound_cache.cend();)
|
||||
{
|
||||
if (it->second.last_update.check(EXPIRETIME))
|
||||
|
||||
it = sound_cache.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Vector> GetSoundLocation(int entid)
|
||||
{
|
||||
auto it = sound_cache.find(entid);
|
||||
if (it == sound_cache.end())
|
||||
return std::nullopt;
|
||||
return it->second.sound.m_pOrigin;
|
||||
}
|
||||
|
||||
class SoundCacheEventListener : public IGameEventListener2
|
||||
@ -24,7 +42,13 @@ class SoundCacheEventListener : public IGameEventListener2
|
||||
{
|
||||
if (!isHackActive())
|
||||
return;
|
||||
sound_cache[event->GetInt("userid")].sound.m_pOrigin = Vector(0.0f);
|
||||
// Find userid in map
|
||||
auto it = sound_cache.find(event->GetInt("userid"));
|
||||
// No action if it doesn't exist
|
||||
if (it == sound_cache.end())
|
||||
return;
|
||||
// Erase it from the map
|
||||
sound_cache.erase(it);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user