-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPlayer.hpp
184 lines (147 loc) · 4.27 KB
/
Player.hpp
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#pragma once
#include "lua.hpp"
#include "Netvars.hpp"
#include <optional>
constexpr auto entity = hash::fnv1a("DT_BaseEntity");
class Player
{
public:
inline const char* get_classname()
{
void* networkable = this + 8;
using get_client_class_t = const char**(__thiscall*)(void*);
return *(method<get_client_class_t>(2, networkable)(networkable) + 2);
}
inline bool is_dormant()
{
void* networkable = this + 8;
using is_dormant_t = bool(__thiscall*)(void*);
return method<is_dormant_t>(8, networkable)(networkable);
}
inline size_t get_index()
{
void* networkable = this + 8;
using get_entity_index_t = size_t(__thiscall*)(void*);
return method<get_entity_index_t>(9, networkable)(networkable);
}
inline bool is_npc()
{
return !!std::memcmp(this->get_classname(), "npc", 3);
}
inline bool is_player()
{
return !!std::strstr(this->get_classname(), "player");
}
inline const Angle& get_angles()
{
using namespace hash::literals;
auto offset = globals::netvars["DT_GMOD_Player"_fnv1a]["m_angEyeAngles[0]"_fnv1a];
return *reinterpret_cast<Angle*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline const int32_t get_health()
{
using namespace hash::literals;
auto offset = globals::netvars[entity]["m_iHealth"_fnv1a];
return *reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline const int32_t get_max_health()
{
using namespace hash::literals;
auto offset = globals::netvars[entity]["m_iMaxHealth"_fnv1a];
return *reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline const Vector& get_pos()
{
using namespace hash::literals;
auto offset = globals::netvars[entity]["m_vecOrigin"_fnv1a];
return *reinterpret_cast<Vector*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline const uint32_t get_team()
{
using namespace hash::literals;
auto offset = globals::netvars[entity]["m_iTeamNum"_fnv1a];
return *reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline std::optional<uint32_t> get_team_color()
{
auto glua = globals::lua->create_interface(lua::type::client);
if (!glua)
return {};
glua->PushSpecial(lua::special::glob);
glua->GetField(-1, "team");
glua->GetField(-1, "GetColor");
glua->PushNumber(this->get_team());
glua->Call(1, 1);
glua->PushString("r");
glua->GetTable(-2);
auto r = glua->GetNumber(-1);
glua->Pop();
glua->PushString("g");
glua->GetTable(-2);
auto g = glua->GetNumber(-1);
glua->Pop();
glua->PushString("b");
glua->GetTable(-2);
auto b = glua->GetNumber(-1);
glua->Pop(4);
return 0xFF000000 + (static_cast<uint32_t>(r)) + (static_cast<uint32_t>(g) << 8) + (static_cast<uint32_t>(b) << 16);
}
inline std::optional<bool> is_admin()
{
auto glua = globals::lua->create_interface(lua::type::client);
if (!glua)
return {};
glua->PushSpecial(lua::special::glob);
glua->GetField(-1, "Entity");
glua->PushNumber(this->get_index());
glua->Call(1, 1);
glua->GetField(-1, "IsAdmin");
glua->Push(-2);
glua->Call(1, 1);
bool admin = glua->GetBool();
glua->Pop(3);
return admin;
}
inline const Vector& get_oob_min()
{
using namespace hash::literals;
auto offset = globals::netvars[entity]["m_vecMins"_fnv1a];
return *reinterpret_cast<Vector*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline const Vector& get_oob_max()
{
using namespace hash::literals;
auto offset = globals::netvars[entity]["m_vecMaxs"_fnv1a];
return *reinterpret_cast<Vector*>(reinterpret_cast<uintptr_t>(this) + offset);
}
inline std::string get_team_name()
{
auto glua = globals::lua->create_interface(lua::type::client);
if (!glua)
return {};
glua->PushSpecial(lua::special::glob);
glua->GetField(-1, "team");
glua->GetField(-1, "GetName");
glua->PushNumber(this->get_team());
glua->Call(1, 1);
std::string team = glua->GetString();
glua->Pop(3);
return team;
}
inline std::string get_name()
{
auto glua = globals::lua->create_interface(lua::type::client);
if (!glua)
return {};
glua->PushSpecial(lua::special::glob);
glua->GetField(-1, "Entity");
glua->PushNumber(this->get_index());
glua->Call(1, 1);
glua->GetField(-1, "Name");
glua->Push(-2);
glua->Call(1, 1);
std::string name = glua->GetString();
glua->Pop(3);
return name;
}
};