This repository was archived by the owner on Jan 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathSticky.cpp
More file actions
105 lines (83 loc) · 2.86 KB
/
Sticky.cpp
File metadata and controls
105 lines (83 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Sticky.h"
#include "Util.h"
#include "SDK.h"
#include "Triggerbot.h"
CAutoSticky gSticky;
bool IsBombVisible(CBaseEntity* first, CBaseEntity* second) {
trace_t trace; Ray_t ray; CTraceFilter filter;
Vector first_origin = first->GetAbsOrigin(),
second_origin = second->GetAbsOrigin();
second_origin[2] += 10.0f;
filter.pSkip = first;
ray.Init(first_origin, second_origin);
gInts.EngineTrace->TraceRay(ray, MASK_SHOT, &filter, &trace);
return (trace.m_pEnt == second);
}
bool HasCond(CBaseEntity* entity, int condition) {
if (entity->GetCond() & condition) {
return true;
}
return false;
}
void CAutoSticky::Run(CBaseEntity* g_pLocalPlayer, CUserCmd* g_pUserCmd)
{
if (!gTrigger.stickydetonate.value)
return;
auto IsLocalGrenade = [&](CBaseEntity* entity)
{
if (entity->GetClientClass()->iClassID != 216) return false;
if (entity->GetPipeType() != 1) return false;
auto get_thrower = entity->GetThrower();
if (!get_thrower) return false;
auto entity_handle = (CBaseEntity*)gInts.EntList2->GetClientEntityFromHandle(get_thrower);
if (!entity_handle) return false;
if (entity_handle != g_pLocalPlayer) return false;
return true;
};
for (int i = 0; i < gInts.EntList2->GetHighestEntityIndex(); i++)
{
CBaseEntity* first_entity = reinterpret_cast<CBaseEntity*>(gInts.EntList2->GetClientEntity(i));
if (!first_entity) {
continue;
}
Vector sticky_position = first_entity->get_world_space_center();
if (IsLocalGrenade(first_entity)) {
for (int player = 0; player < gInts.Engine->GetMaxClients(); player++) {
if (i == g_pLocalPlayer->GetIndex()) { continue; }
CBaseEntity* second_entity = reinterpret_cast<CBaseEntity*>(gInts.EntList2->GetClientEntity(player));
if (!second_entity || second_entity->IsDormant() || second_entity->IsDead()) {
continue;
}
if (second_entity->GetTeamNum() == g_pLocalPlayer->GetTeamNum()) {
continue;
}
if (HasCond(second_entity, 32) || HasCond(second_entity, 16384) ||
HasCond(second_entity, 16) || HasCond(second_entity, 8192)) {
continue;
}
auto get_distance = [&](Vector to, Vector from) -> float {
Vector delta = to - from;
float distance = ::sqrt(delta.length());
if (distance < 1.0f) {
distance = 1.0f;
}
return distance;
};
auto is_bomb_visible = [&](CBaseEntity* first, CBaseEntity* second) {
trace_t tr; Ray_t ray; CTraceFilter filter;
auto first_origin = first->GetAbsOrigin(),
second_origin = second->GetAbsOrigin();
filter.pSkip = first;
ray.Init(first_origin, second_origin);
gInts.EngineTrace->TraceRay(ray, MASK_SHOT, &filter, &tr);
return (tr.m_pEnt == second);
};
if (get_distance(sticky_position, second_entity->GetAbsOrigin()) < 12.0f) {
if (is_bomb_visible(first_entity, second_entity)) {
g_pUserCmd->buttons |= IN_ATTACK2;
}
}
}
}
}
}