This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
nekohook/modules/source2013/util/conditions.cpp
2020-08-04 13:13:01 -04:00

48 lines
1.2 KiB
C++

/*
*
* We use the cpp file for conditions that need to be cached for a reason
*
*
*/
#if defined(NEKO_TF2)
#include "../../../framework/game.hpp" // Stuff to init with
#include "../../../util/chrono.hpp" // For time keeping
#include "../hacks/ifaces.hpp"
#include "conditions.hpp"
namespace modules::source {
namespace conditions {
// Time when the local player started zooming
static CatTimer zoom_timer;
static void WorldTick() {
auto local_ent =
iface::entity_list->GetClientEntity(iface::engine->GetLocalPlayer());
if (!HasCondition((CatEntity*)local_ent, TfCond::kZoomed))
zoom_timer.Reset();
}
void Init() { events::world.Listen(WorldTick, cat::Order::kBefore); }
} // namespace conditions
bool CanHeadshot() {
// Get local ent
auto local_ent =
iface::entity_list->GetClientEntity(iface::engine->GetLocalPlayer());
if (!local_ent || local_ent->IsDormant()) return false;
// Check if currently zoomed
if (!HasCondition((CatEntity*)local_ent, TfCond::kZoomed)) return false;
// Check if zoomed long enough
return conditions::zoom_timer.CheckTime(std::chrono::milliseconds(200));
}
} // namespace modules::source
#endif