forked from pain1929/csgo-game-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.hpp
181 lines (150 loc) · 4.6 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
#include "csgo.hpp"
#include <Windows.h>
// pain1929 2023-05-01 五一快乐
enum BONE {
HEAD,
ROOT
};
namespace CSGO_INFO {
struct POS {
float x, y, z;
};
CSGO_INFO::POS WindowSize(HWND hwnd);
BOOL CALLBACK enumFunc(HWND hwnd, LPARAM data);
HWND GetWindowHandle(DWORD PID);
struct ViewMatrix {
float floats[16];
};
void* CLIENT = GetModuleHandle("client.dll");
void* ENGINE = GetModuleHandle("engine.dll");
POS RES = WindowSize(GetWindowHandle(GetCurrentProcessId()));
}
class Player {
public:
void* address;
Player(int index);
Player(void* address);
~Player();
CSGO_INFO::POS GetHead();
CSGO_INFO::POS GetRoot();
int GetHealth();
int GetTeam();
bool IsEnemy();
bool IsAlive();
bool IsSleeping();
bool IsLocalPlayer();
bool IsNULL();
CSGO_INFO::ViewMatrix GetViewMatrix();
CSGO_INFO::POS WorldToScreen(BONE bone);
static int MAX();
static Player GetLocalPlayer();
private:
};
Player::Player(int index) {
this->address = *(void**)((int)CSGO_INFO::CLIENT + hazedumper::signatures::dwEntityList + (index * 0x10));
}
Player::Player(void* address) {
this->address = address;
}
Player::~Player(){}
bool Player::IsNULL() {
return this->address == 0 ||
this->GetHealth()>100 ||
this->GetHealth() <0 ||
(this->GetTeam()!=2 && this->GetTeam()!=3);
}
CSGO_INFO::POS Player::GetHead() {
CSGO_INFO::POS pos;
void* bone = *(void**)((int)this->address + hazedumper::netvars::m_dwBoneMatrix);
pos.x = *(float*)((int)bone + 0x180 + 12);
pos.y = *(float*)((int)bone + 0x180 + 28);
pos.z = *(float*)((int)bone + 0x180 + 44);
return pos;
}
CSGO_INFO::POS Player::GetRoot() {
CSGO_INFO::POS pos = { 0 };
pos.x = *(float*)((int)this->address + 0x138);
pos.y = *(float*)((int)this->address + 0x138 + 4);
pos.z = *(float*)((int)this->address + 0x138 + 8);
return pos;
}
int Player::GetHealth() {
return *(int*)((int)this->address + hazedumper::netvars::m_iHealth);
}
Player Player::GetLocalPlayer() {
void* addr = *(void**)((int)CSGO_INFO::CLIENT + hazedumper::signatures::dwLocalPlayer);
return Player(addr);
}
bool Player::IsLocalPlayer() {
return this->address == Player::GetLocalPlayer().address;
}
int Player::GetTeam() {
return *(int*)((int)this->address + hazedumper::netvars::m_iTeamNum);
}
bool Player::IsEnemy() {
return this->GetTeam() != Player::GetLocalPlayer().GetTeam();
}
bool Player::IsAlive() {
return this->GetHealth() <= 100 && this->GetHealth() > 0;
}
bool Player::IsSleeping() {
return *(bool*)((int)this->address + hazedumper::signatures::m_bDormant);
}
CSGO_INFO::ViewMatrix Player::GetViewMatrix() {
return *(CSGO_INFO::ViewMatrix*)((int)CSGO_INFO::CLIENT + hazedumper::signatures::dwViewMatrix);
}
int Player::MAX() {
void* clientstate = *(void**)((int)CSGO_INFO::ENGINE + hazedumper::signatures::dwClientState);
return *(int*)((int)clientstate + hazedumper::signatures::dwClientState_MaxPlayer);
}
CSGO_INFO::POS Player::WorldToScreen(BONE P) {
CSGO_INFO::POS player_pos;
if (P == BONE::HEAD) {
player_pos = this->GetHead();
}
else if (P == BONE::ROOT) {
player_pos = this->GetRoot();
}
else {
return { 0 , 0 ,0 };
}
CSGO_INFO::ViewMatrix viewMatrix = Player::GetViewMatrix();
CSGO_INFO::POS out;
float _x = viewMatrix.floats[0] * player_pos.x + viewMatrix.floats[1] * player_pos.y + viewMatrix.floats[2] * player_pos.z + viewMatrix.floats[3];
float _y = viewMatrix.floats[4] * player_pos.x + viewMatrix.floats[5] * player_pos.y + viewMatrix.floats[6] * player_pos.z + viewMatrix.floats[7];
out.z = viewMatrix.floats[12] * player_pos.x + viewMatrix.floats[13] * player_pos.y + viewMatrix.floats[14] * player_pos.z + viewMatrix.floats[15];
if (out.z <= 0) {
return {0 , 0 , 0};
}
_x *= 1.f / out.z;
_y *= 1.f / out.z;
out.x = CSGO_INFO::RES.x * .5f;
out.y = CSGO_INFO::RES.y * .5f;
out.x += 0.5f * _x * CSGO_INFO::RES.x + 0.5f;
out.y -= 0.5f * _y * CSGO_INFO::RES.y + 0.5f;
return out;
}
//根据窗口句柄获取窗口尺寸
CSGO_INFO::POS CSGO_INFO::WindowSize(HWND hwnd) {
RECT rect;
GetWindowRect(hwnd, &rect);
return { (float)(rect.right - rect.left) , (float)(rect.bottom - rect.top) , 0 };
}
//回调函数
BOOL CALLBACK CSGO_INFO::enumFunc(HWND hwnd, LPARAM data) {
DWORD TARGET_PID = *(DWORD*)(data);
DWORD PID = 0;
GetWindowThreadProcessId(hwnd, &PID);
if (TARGET_PID == PID) {
*(HWND*)(data) = hwnd;
return false;
}
else {
return true;
}
}
//获取窗口句柄
HWND CSGO_INFO::GetWindowHandle(DWORD PID) {
EnumWindows(enumFunc, (LPARAM)&PID);
return *(HWND*)&PID;
}