-
Notifications
You must be signed in to change notification settings - Fork 3
/
CBulletListener.h
123 lines (103 loc) · 2.92 KB
/
CBulletListener.h
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
118
119
120
121
122
123
#pragma once
#include "Interfaces.h"
#include "Entities.h"
#include "Menu.h"
#include "Hooks.h"
#include "Utilities.h"
#include "RenderManager.h"
class trace_info
{
public:
trace_info(Vector starts, Vector positions, float times, int userids)
{
this->start = starts;
this->position = positions;
this->time = times;
this->userid = userids;
}
Vector position;
Vector start;
float time;
int userid;
};
extern std::vector<trace_info> trace_logs;
#define g_pGameEventManager Interfaces::EventManager
class CBulletListener
{
class BulletListener : IGameEventListener2
{
public:
void start()
{
if (!g_pGameEventManager->AddListener(this, "bullet_impact", false))
{
throw std::exception("Failed to register the event");
}
}
void stop()
{
g_pGameEventManager->RemoveListener(this);
}
void FireGameEvent(IGameEvent* event) override
{
CBulletListener::singleton()->OnFireEvent(event);
}
int GetEventDebugID(void) override
{
return EVENT_DEBUG_ID_INIT /*0x2A*/;
}
};
public:
static CBulletListener* singleton()
{
static CBulletListener* instance = new CBulletListener();
return instance;
}
void init()
{
_listener.start();
}
void OnFireEvent(IGameEvent* event)
{
if (!strcmp(event->GetName(), "bullet_impact") && g_menu::window.VisualsTab.BulletTracers.GetState())
{
auto* index = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetPlayerForUserID(event->GetInt("userid")));
Vector position(event->GetFloat("x"), event->GetFloat("y"), event->GetFloat("z"));
if (index)
trace_logs.push_back(trace_info(index->GetEyePosition(), position, Interfaces::Globals->curtime, event->GetInt("userid")));
}
}
void OnStudioRender()
{
if (g_menu::window.VisualsTab.BulletTracers.GetState()) {
for (unsigned int i = 0; i < trace_logs.size(); i++) {
auto *shooter = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetPlayerForUserID(trace_logs[i].userid));
if (!shooter) return;
Color color;
if (shooter->GetTeamNum() == 3)
color = Color(g_menu::window.ColorsTab.BULLETCT_R.GetValue(), g_menu::window.ColorsTab.BULLETCT_G.GetValue(), g_menu::window.ColorsTab.BULLETCT_B.GetValue(), 255);
else
color = Color(g_menu::window.ColorsTab.BULLET_T_R.GetValue(), g_menu::window.ColorsTab.BULLET_T_G.GetValue(), g_menu::window.ColorsTab.BULLET_T_B.GetValue(), 255);
Hooks::DrawBeamd(trace_logs[i].start, trace_logs[i].position, color);
trace_logs.erase(trace_logs.begin() + i);
}
}
}
private:
BulletListener _listener;
class cbullet_tracer_info
{
public:
cbullet_tracer_info(Vector src, Vector dst, float time, Color color)
{
this->src = src;
this->dst = dst;
this->time = time;
this->color = color;
}
Vector src, dst;
float time;
Color color;
};
std::vector<cbullet_tracer_info> logs;
};