-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsgo_sdk.cpp
136 lines (102 loc) · 2.79 KB
/
csgo_sdk.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "csgo_sdk.h"
#include <cmath>
namespace sdk {
modules_t::modules_t(forceinline::memory_manager* memory) {
client_dll = memory->get_module_base("client.dll");
engine_dll = memory->get_module_base("engine.dll");
}
vec3_t::vec3_t() {
x = y = z = 0;
}
vec3_t::vec3_t(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
vec3_t vec3_t::operator+(const vec3_t& other) {
return { x + other.x, y + other.y, z + other.z };
}
vec3_t vec3_t::operator+=(const vec3_t& other) {
x += other.x;
y += other.y;
z += other.z;
return *this;
}
vec3_t vec3_t::operator-(const vec3_t& other) {
return { x - other.x, y - other.y, z - other.z };
}
vec3_t vec3_t::operator-=(const vec3_t& other) {
x -= other.x;
y -= other.y;
z -= other.z;
return *this;
}
vec3_t vec3_t::operator*(float factor) {
return { x * factor, y * factor, z * factor };
}
vec3_t vec3_t::operator*(const vec3_t& other) {
return { x * other.x, y * other.y, z * other.z };
}
vec3_t vec3_t::operator*=(float factor) {
x *= factor;
y *= factor;
z *= factor;
return *this;
}
vec3_t vec3_t::operator*=(const vec3_t& other) {
x *= other.x;
y *= other.y;
z *= other.z;
return *this;
}
vec3_t vec3_t::operator/(float factor) {
return { x / factor, y / factor, z / factor };
}
vec3_t vec3_t::operator/(const vec3_t& other) {
return { x / other.x, y / other.y, z / other.z };
}
vec3_t vec3_t::operator/=(float factor) {
x /= factor;
y /= factor;
z /= factor;
return *this;
}
vec3_t vec3_t::operator/=(const vec3_t& other) {
x /= other.x;
y /= other.y;
z /= other.z;
return *this;
}
bool vec3_t::is_zero() {
return x == 0 && y == 0 && z == 0;
}
float vec3_t::dot(const vec3_t& other) {
return x * other.x + y * other.y + z * other.z;
}
float vec3_t::dist(const vec3_t& other) {
return (*this - other).length();
}
float vec3_t::length() {
return sqrt(length_sqr());
}
float vec3_t::length_sqr() {
return x * x + y * y + z * z;
}
bool world_to_screen(const vec3_t& screen_size, const vec3_t& pos, vec3_t& out, sdk::view_matrix_t matrix) {
out.x = matrix[0][0] * pos.x + matrix[0][1] * pos.y + matrix[0][2] * pos.z + matrix[0][3];
out.y = matrix[1][0] * pos.x + matrix[1][1] * pos.y + matrix[1][2] * pos.z + matrix[1][3];
float w = matrix[3][0] * pos.x + matrix[3][1] * pos.y + matrix[3][2] * pos.z + matrix[3][3];
if (w < 0.01f)
return false;
float inv_w = 1.f / w;
out.x *= inv_w;
out.y *= inv_w;
float x = screen_size.x * .5f;
float y = screen_size.y * .5f;
x += 0.5f * out.x * screen_size.x + 0.5f;
y -= 0.5f * out.y * screen_size.y + 0.5f;
out.x = x;
out.y = y;
return true;
}
}