This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
/
hitmarkers.cpp
117 lines (87 loc) · 3.43 KB
/
hitmarkers.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
#include "hitmarkers.h"
bool Settings::ESP::Hitmarker::enabled = false;
bool Settings::ESP::Hitmarker::enemies = false;
bool Settings::ESP::Hitmarker::allies = false;
ColorVar Settings::ESP::Hitmarker::color = ImColor(240, 10, 10, 255);
int Settings::ESP::Hitmarker::duration = 2000;
int Settings::ESP::Hitmarker::size = 16;
int Settings::ESP::Hitmarker::innerGap = 5;
bool Settings::ESP::Hitmarker::Damage::enabled = false;
// int - damage dealt, long - timestamp
std::vector<std::pair<int, long>> damages;
long lastHitmarkerTimestamp = 0;
void Hitmarkers::Paint()
{
if (!Settings::ESP::enabled || !Settings::ESP::Hitmarker::enabled)
return;
if (!engine->IsInGame())
return;
C_BasePlayer* localplayer = (C_BasePlayer*) entityList->GetClientEntity(engine->GetLocalPlayer());
if (!localplayer)
return;
if (!localplayer->GetAlive())
return;
int duration = Settings::ESP::Hitmarker::duration;
long now = Util::GetEpochTime();
long diff = lastHitmarkerTimestamp + duration - now;
if (diff <= 0)
return;
int width, height;
engine->GetScreenSize(width, height);
Color color = Color::FromImColor(Settings::ESP::Hitmarker::color.Color());
color.a = std::min(color.a, (int)(diff * color.a / duration * 2));
int sides[4][2] = { {-1, -1}, {1, 1}, {-1, 1}, {1, -1} };
for (auto& it : sides)
Draw::Line(width / 2 + (Settings::ESP::Hitmarker::innerGap * it[0]), height / 2 + (Settings::ESP::Hitmarker::innerGap * it[1]), width / 2 + (Settings::ESP::Hitmarker::size * it[0]), height / 2 + (Settings::ESP::Hitmarker::size * it[1]), color);
if (!Settings::ESP::Hitmarker::Damage::enabled)
return;
float textHeight = Draw::GetTextSize("[cool]", esp_font).y;
for (unsigned int i = 0; i < damages.size(); i++)
{
long timestamp = damages[i].second;
long hitDiff = timestamp + duration - now;
if (hitDiff <= 0)
{
damages.erase(damages.begin() + i);
continue;
}
Vector2D pos = Vector2D(
width / 2 + Settings::ESP::Hitmarker::size + 4,
height / 2 - Settings::ESP::Hitmarker::size - textHeight * i + 4
);
int damage = damages[i].first;
std::string damageStr = '-' + std::to_string(damage);
color.a = Color::FromImColor(Settings::ESP::Hitmarker::color.Color()).a;
color.a = std::min(color.a, (int)(hitDiff * color.a / duration * 2));
Draw::Text(pos, damageStr.c_str(), esp_font, color);
}
}
void Hitmarkers::FireGameEvent(IGameEvent* event)
{
if (!Settings::ESP::Hitmarker::enabled)
return;
if (!engine->IsInGame())
return;
if (strcmp(event->GetName(), "player_hurt") != 0)
return;
int hurt_player_id = event->GetInt("userid");
int attacker_id = event->GetInt("attacker");
if (engine->GetPlayerForUserID(hurt_player_id) == engine->GetLocalPlayer())
return;
// TODO: show hitmarks while spectating?
if (engine->GetPlayerForUserID(attacker_id) != engine->GetLocalPlayer())
return;
C_BasePlayer* localplayer = (C_BasePlayer*) entityList->GetClientEntity(engine->GetLocalPlayer());
if (!localplayer)
return;
C_BasePlayer* hurt_player = (C_BasePlayer*) entityList->GetClientEntity(engine->GetPlayerForUserID(hurt_player_id));
if (!hurt_player)
return;
if (hurt_player->GetTeam() == localplayer->GetTeam() && !Settings::ESP::Hitmarker::allies)
return;
if (hurt_player->GetTeam() != localplayer->GetTeam() && !Settings::ESP::Hitmarker::enemies)
return;
long now = Util::GetEpochTime();
lastHitmarkerTimestamp = now;
damages.insert(damages.begin(), std::pair<int, long>(event->GetInt("dmg_health"), now));
}