View difference between Paste ID: 1xJDZiq0 and XshJcJgL
SHOW: | | - or go back to the newest paste.
1
/*
2
Credits: https://pastebin.com/XshJcJgL
3
         https://pastebin.com/u/ThePJ120
4
*/
5
6
namespace Func
7
{
8
	int G_Client(int clientIndex)   {return Offsets::G_Client_s + ( clientIndex * Offsets::G_ClientSize ); }
9
	int G_Entity(int clientIndex)   {return Offsets::G_Entity + ( clientIndex * Offsets::G_EntitySize ); }
10
11
	#pragma region Calls
12
	opd_s Com_sprintf_t = { Offsets::com_sprintf, TOC };
13
	int(*Com_sprintf)(char *dest, int size, const char *fmt, ...) = (int(*)(char* , int, char const *, ...))&Com_sprintf_t;
14
15
	opd_s SV = { Offsets::SV_GameSendServerCommand, TOC };
16
	void(*svgssc)(int client, int type, char* cmd) = (void(*)(int, int, char*))&SV;
17
18
19
	opd_s gs = { Offsets::Dvar_GetString, TOC };
20
	const char*(*Dvar_GetString)(const char* Dvar) = (const char*(*)(const char*))&gs;
21
	#pragma endregion
22
	#pragma region Client functions
23
	#pragma region Sv_GameSendServerCommand
24
	void SV_GSSC(int client, char* command)
25
	{
26
		svgssc(client, 0, command);
27
	}
28
29
	void iPrintlnBold(int client, char* text)
30
	{
31
		char buf[100];
32
		Com_sprintf(buf, 100, "c \"%s%s", text, "\"");
33
		SV_GSSC(client, buf);
34
	}
35
36
	void iPrintln(int client, char* text)
37
	{
38
		char buf[100];
39
		Com_sprintf(buf, 100, "f \"%s%s", text, "\"");
40
		SV_GSSC(client, buf);
41
	}
42
43
	#pragma endregion
44
	bool IsDead(int client)
45
	{
46
		return *(bool*)(G_Client(client) + 0x3313);
47
	}
48
49
	bool CheckTeam(int Client, int OtherClient)
50
	{
51
		int Attacker = *(int*)(G_Client(Client) + 0x33D7);
52
		int Victim = *(int*)(G_Client(OtherClient) + 0x33D7);
53
		if (Attacker == Victim)
54
		{
55
			return true;
56
		}
57
		else
58
		{
59
			return false;
60
		}
61
	}
62
63
	bool CheckIfLiving(int client)
64
	{
65
		if (*(char*)(G_Entity(client) + 0x19F) != 0)
66
		{
67
			return true;
68
		}
69
		else return false;
70
	}
71
72
	bool ClientIsInGame(int clientIndex)
73
	{
74
		if (*(int*)G_Client(clientIndex) != 0)
75
			return true;
76
		else return false;
77
	}
78
79
	struct Vec3
80
	{
81
		float x, y, z;
82
	};
83
84
	Vec3 Difference;
85
	Vec3 GetVec(Vec3 Attacker, Vec3 Target)
86
	{
87
		Difference.x = (Target.x - Attacker.x);
88
		Difference.y = (Target.y - Attacker.y);
89
		Difference.z = (Target.z - Attacker.z);
90
		return Difference;
91
	}
92
93
	float dx, dy, dz;
94
	float Get3dDistance(Vec3 c1, Vec3 c2)
95
	{
96
		float dx = c2.x - c1.x;
97
		float dy = c2.y - c1.y;
98
		float dz = c2.z - c1.z;
99
100
		return sqrt((float)((dx * dx) + (dy * dy) + (dz * dz)));
101
	}
102
103
	Vec3 vec;
104
	Vec3 GetPlayerOrigin(int Client)
105
	{
106
		vec = *(Vec3*)(G_Client(Client) + 0x1C);
107
		return vec;
108
	}
109
110
	Vec3 VecV;
111
	Vec3 GetPlayerOriginVictim(int Client)
112
	{
113
		VecV = *(Vec3*)(G_Client(Client) + 0x1C);
114
		VecV.z -= 24;
115
		return VecV;
116
	}
117
118
	int Nearest;
119
	int GetNearestPlayer(int Client)
120
	{
121
		float MaxDistance = 99999999;
122
		for (int i = 0; i < 12; i++)
123
		{
124
			Vec3 Attacker = GetPlayerOrigin(Client);
125
			Vec3 Vic = GetPlayerOrigin(i);
126
			float ActualDistance = Get3dDistance(Attacker, Vic);
127
			if ((i != Client) && CheckIfLiving(i) && ClientIsInGame(i))
128
			{
129
				if (cstrcmp(Func::Dvar_GetString("ui_gametype"), "dm") == 0)
130
				{
131
					if (ActualDistance < MaxDistance)
132
					{
133
						Nearest = i;
134
						MaxDistance = ActualDistance;
135
					}
136
				}
137
				else
138
				{
139
					if (!CheckTeam(Client, i))
140
					{
141
						if (ActualDistance < MaxDistance)
142
						{
143
							Nearest = i;
144
							MaxDistance = ActualDistance;
145
						}
146
					}
147
				}
148
			}
149
		}
150
		return Nearest;
151
	}
152
153
	float angles[3];
154
	float* vectoangles(Vec3 Angles)
155
	{
156
		float forward;
157
		float yaw, pitch;
158
		float PI = 3.1415926535897931;
159
		if (Angles.x == 0 && Angles.y == 0)
160
		{
161
			yaw = 0;
162
			if (Angles.z > 0) pitch = 90.00;
163
			else pitch = 270.00;
164
		}
165
		else
166
		{
167
			if (Angles.x != -1) yaw = (float)(atan2((double)Angles.y, (double)Angles.x) * 180.00 / PI);
168
			else if (Angles.y > 0) yaw = 90.00;
169
			else yaw = 270;
170
			if (yaw < 0) yaw += 360.00;
171
172
			forward = (float)sqrt((double)(Angles.x * Angles.x + Angles.y * Angles.y));
173
			pitch = (float)(atan2((double)Angles.z, (double)forward) * 180.00 / PI);
174
			if (pitch < 0) pitch += 360.00;
175
		}
176
		angles[0] = -pitch;
177
		angles[1] = yaw;
178
		angles[2] = 0;
179
180
		return angles;
181
	}
182
183
	opd_s Setangles_t = { 0x001767E0, TOC };
184
	void(*SetClientViewAnlges)(int Ent, float* Angles) = (void(*)(int, float*))&Setangles_t;
185
186
	void SetViewAngles(int Client)
187
	{
188
		int Victim = GetNearestPlayer(Client);
189
		float* Angles = vectoangles(GetVec(GetPlayerOrigin(Client), GetPlayerOriginVictim(Victim)));
190
		SetClientViewAnlges(G_Entity(Client), Angles);
191
	}
192
193
	#pragma endregion
194
	#pragma region Game Functions
195
	bool InGame()
196
	{
197
		if (*(char*)Offsets::cl_InGame != 1)
198
			return false;
199
		return true;
200
	}
201
	#pragma endregion
202
};