auto clear soundcache, fully dormant tracers

This commit is contained in:
TotallyNotElite 2019-06-11 00:41:32 +02:00
parent dc8e3eff47
commit a8f2dc5df6
8 changed files with 86 additions and 38 deletions

View File

@ -110,7 +110,7 @@ public:
{ {
return RAW_ENT(this)->GetAbsOrigin(); return RAW_ENT(this)->GetAbsOrigin();
}; };
Vector m_vecDormantOrigin(); std::optional<Vector> m_vecDormantOrigin();
int m_iTeam() int m_iTeam()
{ {
return NET_INT(RAW_ENT(this), netvar.iTeamNum); return NET_INT(RAW_ENT(this), netvar.iTeamNum);

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "timer.hpp" #include "timer.hpp"
#include "map" #include <map>
#include "public/mathlib/vector.h" #include "public/mathlib/vector.h"
#include <optional>
struct CSndInfo_t struct CSndInfo_t
{ {
Vector m_pOrigin; Vector m_pOrigin;
@ -13,3 +14,8 @@ struct SoundStruct
Timer last_update; Timer last_update;
}; };
extern std::map<int, SoundStruct> sound_cache; extern std::map<int, SoundStruct> sound_cache;
namespace soundcache
{
std::optional<Vector> GetSoundLocation(int entid);
}

View File

@ -128,13 +128,14 @@ bool CachedEntity::IsVisible()
return false; return false;
} }
Vector CachedEntity::m_vecDormantOrigin() std::optional<Vector> CachedEntity::m_vecDormantOrigin()
{ {
if (!RAW_ENT(this)->IsDormant()) if (!RAW_ENT(this)->IsDormant())
return m_vecOrigin(); return m_vecOrigin();
else if (!sound_cache[m_IDX].last_update.check(10000) && !sound_cache[m_IDX].sound.m_pOrigin.IsZero()) auto vec = soundcache::GetSoundLocation(this->m_IDX);
return sound_cache[m_IDX].sound.m_pOrigin; if (vec)
return Vector(0.0f); return *vec;
return std::nullopt;
} }
namespace entity_cache namespace entity_cache

View File

@ -88,7 +88,6 @@ bool IsTarget(CachedEntity *ent)
return false; return false;
} }
// Function called by game for movement
void CreateMove() void CreateMove()
{ {
// Check user settings if auto-sticky is enabled // Check user settings if auto-sticky is enabled
@ -112,7 +111,7 @@ void CreateMove()
// Cycle through the ents and search for valid ents // Cycle through the ents and search for valid ents
for (int i = 0; i <= HIGHEST_ENTITY; i++) 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); CachedEntity *ent = ENTITY(i);
// Check for dormancy and if valid // Check for dormancy and if valid
if (CE_INVALID(ent)) if (CE_INVALID(ent))

View File

@ -45,7 +45,7 @@ public:
auto ent = ENTITY(i); 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 (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; nearby = true;
break; break;

View File

@ -89,9 +89,9 @@ void DrawEntity(int x, int y, CachedEntity *ent)
return; return;
if (clazz <= 0 || clazz > 9) if (clazz <= 0 || clazz > 9)
return; return;
if (ent->m_vecDormantOrigin() == Vector(0.0f)) if (!ent->m_vecDormantOrigin())
return; 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) 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_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; 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); 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()) switch (ent->m_iClassID())
{ {
@ -157,18 +157,18 @@ void DrawEntity(int x, int y, CachedEntity *ent)
} }
else if (ent->m_Type() == ENTITY_GENERIC) else if (ent->m_Type() == ENTITY_GENERIC)
{ {
if (ent->m_vecDormantOrigin() == Vector(0.0f)) if (!ent->m_vecDormantOrigin())
return; return;
if (show_healthpacks && (ent->m_ItemType() == ITEM_HEALTH_LARGE || ent->m_ItemType() == ITEM_HEALTH_MEDIUM || ent->m_ItemType() == ITEM_HEALTH_SMALL)) 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 sz = *icon_size * 0.15f * 0.5f;
float sz2 = *icon_size * 0.85; float sz2 = *icon_size * 0.85;
tx_items[0].draw(x + wtr.first + sz, y + wtr.second + sz, sz2, sz2, colors::white); 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)) 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 sz = *icon_size * 0.15f * 0.5f;
float sz2 = *icon_size * 0.85; float sz2 = *icon_size * 0.85;
tx_items[1].draw(x + wtr.first + sz, y + wtr.second + sz, sz2, sz2, colors::white); tx_items[1].draw(x + wtr.first + sz, y + wtr.second + sz, sz2, sz2, colors::white);

View File

@ -1,5 +1,7 @@
#include "common.hpp" #include "common.hpp"
#include "PlayerTools.hpp" #include "PlayerTools.hpp"
#include "playerresource.h"
#include "soundcache.hpp"
namespace hacks::shared::tracers 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_Type() == ENTITY_BUILDING)
{ {
if (!ent->m_bEnemy()) if (!ent->m_bEnemy() || !ent->m_vecDormantOrigin())
return std::nullopt; 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) if (*max_dist && dist > *max_dist)
return std::nullopt; 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; return std::nullopt;
float hf = float(std::min(dist, *green_dist)) / float(*green_dist); float hf = float(std::min(dist, *green_dist)) / float(*green_dist);
rgba_t color(0.0f, 2.0f * hf, 2.0f * (1.0f - hf)); 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); auto state = playerlist::AccessData(ent->player_info.friendsID);
if (state.state == playerlist::k_EState::DEFAULT) if (state.state == playerlist::k_EState::DEFAULT)
{ {
if (!ent->m_bEnemy()) if (!ent->m_bEnemy() || !ent->m_vecDormantOrigin())
return std::nullopt; 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) if (*max_dist && dist > *max_dist)
return std::nullopt; return std::nullopt;
return colors::Health(std::min(dist, *green_dist), *green_dist); return colors::Health(std::min(dist, *green_dist), *green_dist);
@ -110,22 +112,38 @@ void draw()
{ {
// Get and check player // Get and check player
auto ent = ENTITY(i); auto ent = ENTITY(i);
if (CE_INVALID(ent) || !ent->m_bAlivePlayer()) Vector origin;
continue; std::optional<rgba_t> color = std::nullopt;
Vector origin = ent->m_vecDormantOrigin();
if (origin == Vector(0.0f, 0.0f, 0.0f)) if (CE_INVALID(ent))
continue; {
if (*buildings) if (i > 32)
if (ent->m_Type() != ENTITY_PLAYER && ent->m_Type() != ENTITY_BUILDING)
continue; continue;
if (ent == LOCAL_E) if (g_pPlayerResource->GetTeam(i) == g_pLocalPlayer->team || !g_pPlayerResource->isAlive(i))
continue; continue;
auto color = getColor(ent); auto vec = soundcache::GetSoundLocation(i);
if (!color) if (!vec)
continue; continue;
if (RAW_ENT(ent)->IsDormant()) origin = *vec;
color = colors::FromRGBA8(160, 160, 160, 255); color = colors::FromRGBA8(160, 160, 160, *opaque);
color->a = *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; Vector out;
if (!draw::WorldToScreen(origin, out)) if (!draw::WorldToScreen(origin, out))

View File

@ -4,8 +4,9 @@ std::map<int, SoundStruct> sound_cache;
namespace soundcache namespace soundcache
{ {
constexpr unsigned int EXPIRETIME = 10000;
void CreateMove() static void CreateMove()
{ {
if (CE_BAD(LOCAL_E)) if (CE_BAD(LOCAL_E))
return; return;
@ -16,6 +17,23 @@ void CreateMove()
sound_cache[i.m_nSoundSource].sound.m_pOrigin = *i.m_pOrigin; sound_cache[i.m_nSoundSource].sound.m_pOrigin = *i.m_pOrigin;
sound_cache[i.m_nSoundSource].last_update.update(); 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 class SoundCacheEventListener : public IGameEventListener2
@ -24,7 +42,13 @@ class SoundCacheEventListener : public IGameEventListener2
{ {
if (!isHackActive()) if (!isHackActive())
return; 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);
} }
}; };