diff --git a/include/core/profiler.hpp b/include/core/profiler.hpp index fd12c271..849b428c 100644 --- a/include/core/profiler.hpp +++ b/include/core/profiler.hpp @@ -43,7 +43,7 @@ public: #if ENABLE_PROFILER #define PROF_SECTION(id) \ static ProfilerSection __PROFILER__##id(#id); \ - ProfilerNode __PROFILER_NODE__##id(__PROFILER__##id); + volatile ProfilerNode __PROFILER_NODE__##id(__PROFILER__##id); #else #define PROF_SECTION(id) #endif diff --git a/src/entityhitboxcache.cpp b/src/entityhitboxcache.cpp index c382d496..af5153e3 100644 --- a/src/entityhitboxcache.cpp +++ b/src/entityhitboxcache.cpp @@ -44,9 +44,6 @@ void EntityHitboxCache::InvalidateCache() void EntityHitboxCache::Update() { InvalidateCache(); - if (CE_BAD(parent_ref)) - if (GetHitbox(0)) - return; } void EntityHitboxCache::Init() @@ -103,7 +100,7 @@ bool EntityHitboxCache::VisibilityCheck(int id) return m_VisCheck[id]; } -static settings::Int setupbones_time{ "source.setupbones-time", "0" }; +static settings::Int setupbones_time{ "source.setupbones-time", "1" }; static std::mutex setupbones_mutex; @@ -155,34 +152,32 @@ void EntityHitboxCache::Reset() CachedHitbox *EntityHitboxCache::GetHitbox(int id) { + if (m_CacheValidationFlags[id]) + return &m_CacheInternal[id]; mstudiobbox_t *box; if (!m_bInit) Init(); if (id < 0 || id >= m_nNumHitboxes) - return 0; + return nullptr; if (!m_bSuccess) - return 0; + return nullptr; if (CE_BAD(parent_ref)) - return 0; - typedef int (*InvalidateBoneCache_t)(IClientEntity *); - static uintptr_t addr = gSignatures.GetClientSignature("55 8B 0D ? ? ? ? 89 E5 8B 45 ? 8D 51"); - static InvalidateBoneCache_t InvalidateBoneCache = InvalidateBoneCache_t(addr); - InvalidateBoneCache(RAW_ENT(parent_ref)); - auto model = (model_t *) RAW_ENT(parent_ref)->GetModel(); + return nullptr; + auto model = (const model_t *) RAW_ENT(parent_ref)->GetModel(); if (!model) - return 0; + return nullptr; auto shdr = g_IModelInfo->GetStudiomodel(model); if (!shdr) - return 0; + return nullptr; auto set = shdr->pHitboxSet(CE_INT(parent_ref, netvar.iHitboxSet)); if (!dynamic_cast(set)) - return 0; + return nullptr; box = set->pHitbox(id); if (!box) - return 0; + return nullptr; if (box->bone < 0 || box->bone >= MAXSTUDIOBONES) - return 0; + return nullptr; VectorTransform(box->bbmin, GetBones()[box->bone], m_CacheInternal[id].min); VectorTransform(box->bbmax, GetBones()[box->bone], m_CacheInternal[id].max); m_CacheInternal[id].bbox = box; diff --git a/src/hacks/Backtrack.cpp b/src/hacks/Backtrack.cpp index caf23994..b33fb9d2 100644 --- a/src/hacks/Backtrack.cpp +++ b/src/hacks/Backtrack.cpp @@ -75,7 +75,7 @@ void Init() { for (int i = 0; i < 32; i++) for (int j = 0; j < 66; j++) - EmptyBacktrackData(headPositions[i][j]); + headPositions[i][j] = {}; } int BestTick = -1; @@ -107,23 +107,21 @@ static void Run() CUserCmd *cmd = current_user_cmd; float bestFov = 99999; - float prev_distance = 9999; - - auto bestEntBestTick = getBestEntBestTick(); - BestTick = bestEntBestTick.second; - iBestTarget = bestEntBestTick.first; - + float prev_distance = 9999; + std::pair bestEntBestTick = getBestEntBestTick(); + BestTick = bestEntBestTick.second; + iBestTarget = bestEntBestTick.first; + // Fill backtrack data (stored in headPositions) for (int i = 1; i < g_IEngine->GetMaxClients(); i++) { CachedEntity *pEntity = ENTITY(i); - if (CE_BAD(pEntity) || !pEntity->m_bAlivePlayer()) { for (BacktrackData &btd : headPositions[i]) - EmptyBacktrackData(btd); + btd.simtime = FLT_MAX; continue; } - if (pEntity->m_iTeam() == LOCAL_E->m_iTeam()) + if (!pEntity->m_bEnemy()) continue; if (pEntity->m_Type() != ENTITY_PLAYER) continue; @@ -131,26 +129,24 @@ static void Run() continue; if (HasCondition(pEntity)) continue; + auto &hbd = headPositions[i][cmd->command_number % getTicks()]; float _viewangles = CE_VECTOR(pEntity, netvar.m_angEyeAngles).y; - float viewangles = (_viewangles > 180) ? _viewangles - 360 : _viewangles; - float simtime = CE_FLOAT(pEntity, netvar.m_flSimulationTime); - Vector ent_orig = pEntity->InternalEntity()->GetAbsOrigin(); - std::array hbdArray; - for (size_t i = 0; i < hbdArray.max_size(); i++) + hbd.viewangles = (_viewangles > 180) ? _viewangles - 360 : _viewangles; + hbd.simtime = CE_FLOAT(pEntity, netvar.m_flSimulationTime); + hbd.entorigin = pEntity->InternalEntity()->GetAbsOrigin(); + hbd.tickcount = cmd->tick_count; + + for (size_t i = 0; i < 18; i++) { - hbdArray.at(i).center = pEntity->hitboxes.GetHitbox(i)->center; - hbdArray.at(i).min = pEntity->hitboxes.GetHitbox(i)->min; - hbdArray.at(i).max = pEntity->hitboxes.GetHitbox(i)->max; + hbd.hitboxes[i].center = pEntity->hitboxes.GetHitbox(i)->center; + hbd.hitboxes[i].min = pEntity->hitboxes.GetHitbox(i)->min; + hbd.hitboxes[i].max = pEntity->hitboxes.GetHitbox(i)->max; } - hitboxData collidable{}; - { - collidable.min = RAW_ENT(pEntity)->GetCollideable()->OBBMins() + ent_orig; - collidable.max = RAW_ENT(pEntity)->GetCollideable()->OBBMaxs() + ent_orig; - collidable.center = (collidable.min + collidable.max) / 2; - } - auto hdr = g_IModelInfo->GetStudiomodel(RAW_ENT(pEntity)->GetModel()); - headPositions[i][cmd->command_number % getTicks()] = BacktrackData{ cmd->tick_count, hbdArray, collidable, viewangles, simtime, ent_orig, cmd->command_number % getTicks() }; + hbd.collidable.min = RAW_ENT(pEntity)->GetCollideable()->OBBMins() + hbd.entorigin; + hbd.collidable.max = RAW_ENT(pEntity)->GetCollideable()->OBBMaxs() + hbd.entorigin; + hbd.collidable.center = (hbd.collidable.min + hbd.collidable.max) / 2; } + if (iBestTarget != -1 && CanShoot()) { CachedEntity *tar = ENTITY(iBestTarget); diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 1357226c..e59bceca 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -117,8 +117,6 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, CUs } ret = original::CreateMove(this_, input_sample_time, cmd); - PROF_SECTION(CreateMove); - if (!cmd) { g_Settings.is_create_move = false; @@ -146,7 +144,7 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, CUs return true; } - // PROF_BEGIN(); + PROF_SECTION(CreateMove); if (current_user_cmd && current_user_cmd->command_number) last_cmd_number = current_user_cmd->command_number; diff --git a/src/hooks/HookTools.cpp b/src/hooks/HookTools.cpp index 7fea402b..e1085442 100644 --- a/src/hooks/HookTools.cpp +++ b/src/hooks/HookTools.cpp @@ -6,24 +6,23 @@ namespace EC struct EventCallbackData { - explicit EventCallbackData(const EventFunction &function, std::string name, enum ec_priority priority) : function{ function }, priority{ int(priority) }, event_name{ name }, section{ name } + explicit EventCallbackData(const EventFunction &function, std::string name, enum ec_priority priority) : function{ function }, priority{ int(priority) }, section{ name }, event_name{ name } { + section.m_name = name; } EventFunction function; int priority; - mutable ProfilerSection section; + ProfilerSection section; std::string event_name; - bool operator<(const EventCallbackData &other) const - { - return priority < other.priority; - } }; -// Ordered set to always keep priorities correct -static std::multiset events[ec_types::EcTypesSize]; + +static std::vector events[ec_types::EcTypesSize]; void Register(enum ec_types type, const EventFunction &function, const std::string &name, enum ec_priority priority) { - events[type].insert(EventCallbackData(function, name, priority)); + events[type].emplace_back(function, name, priority); + // Order vector to always keep priorities correct + std::sort(events[type].begin(), events[type].end(), [](EventCallbackData &a, EventCallbackData &b) { return a.priority < b.priority; }); } void Unregister(enum ec_types type, const std::string &name) @@ -39,11 +38,11 @@ void Unregister(enum ec_types type, const std::string &name) void run(ec_types type) { - const auto &set = events[type]; - for (auto &i : set) + auto &vector = events[type]; + for (auto &i : vector) { #if ENABLE_PROFILER - ProfilerNode node(i.section); + volatile ProfilerNode node(i.section); #endif i.function(); }