Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Credits: https://pastebin.com/XshJcJgL
- https://pastebin.com/u/ThePJ120
- */
- namespace Func
- {
- int G_Client(int clientIndex) {return Offsets::G_Client_s + ( clientIndex * Offsets::G_ClientSize ); }
- int G_Entity(int clientIndex) {return Offsets::G_Entity + ( clientIndex * Offsets::G_EntitySize ); }
- #pragma region Calls
- opd_s Com_sprintf_t = { Offsets::com_sprintf, TOC };
- int(*Com_sprintf)(char *dest, int size, const char *fmt, ...) = (int(*)(char* , int, char const *, ...))&Com_sprintf_t;
- opd_s SV = { Offsets::SV_GameSendServerCommand, TOC };
- void(*svgssc)(int client, int type, char* cmd) = (void(*)(int, int, char*))&SV;
- opd_s gs = { Offsets::Dvar_GetString, TOC };
- const char*(*Dvar_GetString)(const char* Dvar) = (const char*(*)(const char*))&gs;
- #pragma endregion
- #pragma region Client functions
- #pragma region Sv_GameSendServerCommand
- void SV_GSSC(int client, char* command)
- {
- svgssc(client, 0, command);
- }
- void iPrintlnBold(int client, char* text)
- {
- char buf[100];
- Com_sprintf(buf, 100, "c \"%s%s", text, "\"");
- SV_GSSC(client, buf);
- }
- void iPrintln(int client, char* text)
- {
- char buf[100];
- Com_sprintf(buf, 100, "f \"%s%s", text, "\"");
- SV_GSSC(client, buf);
- }
- #pragma endregion
- bool IsDead(int client)
- {
- return *(bool*)(G_Client(client) + 0x3313);
- }
- bool CheckTeam(int Client, int OtherClient)
- {
- int Attacker = *(int*)(G_Client(Client) + 0x33D7);
- int Victim = *(int*)(G_Client(OtherClient) + 0x33D7);
- if (Attacker == Victim)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- bool CheckIfLiving(int client)
- {
- if (*(char*)(G_Entity(client) + 0x19F) != 0)
- {
- return true;
- }
- else return false;
- }
- bool ClientIsInGame(int clientIndex)
- {
- if (*(int*)G_Client(clientIndex) != 0)
- return true;
- else return false;
- }
- struct Vec3
- {
- float x, y, z;
- };
- Vec3 Difference;
- Vec3 GetVec(Vec3 Attacker, Vec3 Target)
- {
- Difference.x = (Target.x - Attacker.x);
- Difference.y = (Target.y - Attacker.y);
- Difference.z = (Target.z - Attacker.z);
- return Difference;
- }
- float dx, dy, dz;
- float Get3dDistance(Vec3 c1, Vec3 c2)
- {
- float dx = c2.x - c1.x;
- float dy = c2.y - c1.y;
- float dz = c2.z - c1.z;
- return sqrt((float)((dx * dx) + (dy * dy) + (dz * dz)));
- }
- Vec3 vec;
- Vec3 GetPlayerOrigin(int Client)
- {
- vec = *(Vec3*)(G_Client(Client) + 0x1C);
- return vec;
- }
- Vec3 VecV;
- Vec3 GetPlayerOriginVictim(int Client)
- {
- VecV = *(Vec3*)(G_Client(Client) + 0x1C);
- VecV.z -= 24;
- return VecV;
- }
- int Nearest;
- int GetNearestPlayer(int Client)
- {
- float MaxDistance = 99999999;
- for (int i = 0; i < 12; i++)
- {
- Vec3 Attacker = GetPlayerOrigin(Client);
- Vec3 Vic = GetPlayerOrigin(i);
- float ActualDistance = Get3dDistance(Attacker, Vic);
- if ((i != Client) && CheckIfLiving(i) && ClientIsInGame(i))
- {
- if (cstrcmp(Func::Dvar_GetString("ui_gametype"), "dm") == 0)
- {
- if (ActualDistance < MaxDistance)
- {
- Nearest = i;
- MaxDistance = ActualDistance;
- }
- }
- else
- {
- if (!CheckTeam(Client, i))
- {
- if (ActualDistance < MaxDistance)
- {
- Nearest = i;
- MaxDistance = ActualDistance;
- }
- }
- }
- }
- }
- return Nearest;
- }
- float angles[3];
- float* vectoangles(Vec3 Angles)
- {
- float forward;
- float yaw, pitch;
- float PI = 3.1415926535897931;
- if (Angles.x == 0 && Angles.y == 0)
- {
- yaw = 0;
- if (Angles.z > 0) pitch = 90.00;
- else pitch = 270.00;
- }
- else
- {
- if (Angles.x != -1) yaw = (float)(atan2((double)Angles.y, (double)Angles.x) * 180.00 / PI);
- else if (Angles.y > 0) yaw = 90.00;
- else yaw = 270;
- if (yaw < 0) yaw += 360.00;
- forward = (float)sqrt((double)(Angles.x * Angles.x + Angles.y * Angles.y));
- pitch = (float)(atan2((double)Angles.z, (double)forward) * 180.00 / PI);
- if (pitch < 0) pitch += 360.00;
- }
- angles[0] = -pitch;
- angles[1] = yaw;
- angles[2] = 0;
- return angles;
- }
- opd_s Setangles_t = { 0x001767E0, TOC };
- void(*SetClientViewAnlges)(int Ent, float* Angles) = (void(*)(int, float*))&Setangles_t;
- void SetViewAngles(int Client)
- {
- int Victim = GetNearestPlayer(Client);
- float* Angles = vectoangles(GetVec(GetPlayerOrigin(Client), GetPlayerOriginVictim(Victim)));
- SetClientViewAnlges(G_Entity(Client), Angles);
- }
- #pragma endregion
- #pragma region Game Functions
- bool InGame()
- {
- if (*(char*)Offsets::cl_InGame != 1)
- return false;
- return true;
- }
- #pragma endregion
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement