Skip to content

Commit

Permalink
Merge pull request #440 from zer0k-z/getobstarget-validcheck
Browse files Browse the repository at this point in the history
Add valid client check to GetObserverTarget
  • Loading branch information
zealain authored Jan 10, 2023
2 parents e5b1744 + 0696e24 commit ddcd7ef
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions addons/sourcemod/scripting/include/gokz.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum ObsMode
#define PI 3.14159265359
#define SPEED_NORMAL 250.0
#define SPEED_NO_WEAPON 260.0
#define IGNORE_JUMP_TIME 0.2
#define IGNORE_JUMP_TIME 0.2
stock float PLAYER_MINS[3] = {-16.0, -16.0, 0.0};
stock float PLAYER_MAXS[3] = {16.0, 16.0, 72.0};
stock float PLAYER_MAXS_DUCKED[3] = {16.0, 16.0, 54.0};
Expand All @@ -60,17 +60,17 @@ stock float PLAYER_MAXS_DUCKED[3] = {16.0, 16.0, 54.0};
stock char[] GOKZ_FormatTime(float time, bool precise = true)
{
char formattedTime[12];

int roundedTime = RoundFloat(time * 100); // Time rounded to number of centiseconds

int centiseconds = roundedTime % 100;
roundedTime = (roundedTime - centiseconds) / 100;
int seconds = roundedTime % 60;
roundedTime = (roundedTime - seconds) / 60;
int minutes = roundedTime % 60;
roundedTime = (roundedTime - minutes) / 60;
int hours = roundedTime;

if (hours == 0)
{
if (precise)
Expand Down Expand Up @@ -244,6 +244,10 @@ stock ObsMode GetObserverMode(int client)
*/
stock int GetObserverTarget(int client)
{
if (!IsValidClient(client))
{
return -1;
}
ObsMode mode = GetObserverMode(client);
if (mode == ObsMode_InEye || mode == ObsMode_Chase)
{
Expand Down Expand Up @@ -280,7 +284,7 @@ stock void EmitSoundToClientSpectators(int client, const char[] sound)
stock float CalcDeltaAngle(float angleA, float angleB)
{
float difference = angleB - angleA;

if (difference > 180.0)
{
difference = difference - 360.0;
Expand All @@ -289,7 +293,7 @@ stock float CalcDeltaAngle(float angleA, float angleB)
{
difference = difference + 360.0;
}

return difference;
}

Expand All @@ -307,20 +311,20 @@ stock void Color_StripFromChatText(const char[] input, char[] output, int size)
{
int x = 0;
for (int i = 0; input[i] != '\0'; i++) {

if (x + 1 == size)
{
break;
}

int character = input[i];

if (character > 0x08)
{
output[x++] = character;
}
}

output[x] = '\0';
}

Expand Down Expand Up @@ -368,7 +372,7 @@ stock int NextIndex(int index, int max)
}

/**
* Reorders an array with current index at the front, and previous
* Reorders an array with current index at the front, and previous
* values after, including looping back to the end after reaching
* the start of the array.
*
Expand Down Expand Up @@ -407,14 +411,14 @@ stock int Steam2ToSteamAccountID(const char[] steamID2)
{
return -1;
}

int IDNumberPart1 = StringToInt(pieces[1]);
int IDNumberPart2 = StringToInt(pieces[2]);
if (pieces[1][0] != '0' && IDNumberPart1 == 0 || IDNumberPart1 != 0 && IDNumberPart1 != 1 || IDNumberPart2 <= 0)
{
return -1;
}

return IDNumberPart1 + (IDNumberPart2 << 1);
}

Expand All @@ -432,7 +436,7 @@ stock void TeleportPlayer(int client, const float origin[3], const float angles[
// Clear the player's parent before teleporting to fix being
// teleported into seemingly random places if the player has a parent.
AcceptEntityInput(client, "ClearParent");

Movement_SetOrigin(client, origin);
if (setAngles)
{
Expand All @@ -441,28 +445,28 @@ stock void TeleportPlayer(int client, const float origin[3], const float angles[
Movement_SetEyeAngles(client, angles);
}
// Duck the player if there is something blocking them from above
Handle trace = TR_TraceHullFilterEx(origin,
origin,
Handle trace = TR_TraceHullFilterEx(origin,
origin,
view_as<float>( { -16.0, -16.0, 0.0 } ), // Standing players are 32 x 32 x 72
view_as<float>( { 16.0, 16.0, 72.0 } ),
MASK_PLAYERSOLID,
TraceEntityFilterPlayers,
view_as<float>( { 16.0, 16.0, 72.0 } ),
MASK_PLAYERSOLID,
TraceEntityFilterPlayers,
client);
bool ducked = TR_DidHit(trace);

if (holdStill)
{
// Prevent noclip exploit
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);

// Intelligently hold player still to prevent booster and trigger exploits
StartHoldStill(client, ducked);
}
else if (ducked)
{
ForcePlayerDuck(client);
}

delete trace;
}

Expand All @@ -472,7 +476,7 @@ static void StartHoldStill(int client, bool ducked)
data.WriteCell(GetClientUserId(client));
data.WriteCell(0); // tick counter
data.WriteCell(GOKZ_TP_FREEZE_TICKS); // number of ticks to hold still
data.WriteCell(ducked);
data.WriteCell(ducked);
ContinueHoldStill(data);
}

Expand All @@ -484,12 +488,12 @@ public void ContinueHoldStill(DataPack data)
int tickCount = data.ReadCell();
bool ducked = data.ReadCell();
delete data;

if (!IsValidClient(client))
{
return;
}

if (ticks < tickCount)
{
Movement_SetVelocity(client, view_as<float>( { 0.0, 0.0, 0.0 } ));
Expand All @@ -503,16 +507,16 @@ public void ContinueHoldStill(DataPack data)
{
Movement_SetMovetype(client, MOVETYPE_LADDER);
}

// Prevent noclip exploit
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);

// Force duck on player and make sure that the player can't trigger triggers above them.
// they can still trigger triggers even when we force ducking.
if (ducked)
{
ForcePlayerDuck(client);

if (ticks < tickCount - 1)
{
// Don't trigger triggers
Expand All @@ -524,7 +528,7 @@ public void ContinueHoldStill(DataPack data)
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);
}
}

++ticks;
data = new DataPack();
data.WriteCell(GetClientUserId(client));
Expand Down Expand Up @@ -556,11 +560,11 @@ stock void ForcePlayerDuck(int client)
stock bool IsPlayerStuck(int client)
{
float vecMin[3], vecMax[3], vecOrigin[3];

GetClientMins(client, vecMin);
GetClientMaxs(client, vecMax);
GetClientAbsOrigin(client, vecOrigin);

TR_TraceHullFilter(vecOrigin, vecOrigin, vecMin, vecMax, MASK_PLAYERSOLID, TraceEntityFilterPlayers);
return TR_DidHit(); // head in wall ?
}
Expand All @@ -578,12 +582,12 @@ stock bool GetEntityAbsOrigin(int entity, float result[3])
{
return false;
}

if (!HasEntProp(entity, Prop_Data, "m_vecAbsOrigin"))
{
return false;
}

GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", result);
return true;
}
Expand Down Expand Up @@ -631,7 +635,7 @@ stock int GOKZFindEntityByName(const char[] name, const char[] className = "", b
{
continue;
}

char entName[65];
GetEntityName(entity, entName, sizeof(entName));
if (StrEqual(entName, name))
Expand Down Expand Up @@ -719,10 +723,10 @@ stock void RotateVectorAxis(float vec[3], float axis[3], float theta, float resu
{
float cosTheta = Cosine(theta);
float sinTheta = Sine(theta);

float axisVecCross[3];
GetVectorCrossProduct(axis, vec, axisVecCross);

for (int i = 0; i < 3; i++)
{
result[i] = (vec[i] * cosTheta) + (axisVecCross[i] * sinTheta) + (axis[i] * GetVectorDotProduct(axis, vec)) * (1.0 - cosTheta);
Expand Down Expand Up @@ -750,7 +754,7 @@ stock void RotateVectorPitchYaw(float vec[3], float pitch, float yaw, float resu
}

/**
* Attempts to return a valid spawn location.
* Attempts to return a valid spawn location.
*
* @param origin Spawn origin if found.
* @param angles Spawn angles if found.
Expand All @@ -774,7 +778,7 @@ stock bool GetValidSpawn(float origin[3], float angles[3])
{
spawnEntity = FindEntityByClassname(spawnEntity, "info_player_terrorist");
}

if (spawnEntity != -1)
{
GetEntPropVector(spawnEntity, Prop_Data, "m_vecOrigin", spawnOrigin);
Expand All @@ -799,7 +803,7 @@ stock bool GetValidSpawn(float origin[3], float angles[3])
}

/**
* Check whether a position is a valid spawn location.
* Check whether a position is a valid spawn location.
* A spawn location is considered valid if it is in bounds and not stuck inside the ground.
*
* @param origin Origin vector.
Expand Down Expand Up @@ -842,9 +846,9 @@ stock void GetEntityPositions(int entity, float origin[3], float center[3], floa
origin[i] += tempOrigin[i];
}
}

GetEntPropVector(ent, Prop_Data, "m_angRotation", angles);

GetEntPropVector(ent, Prop_Send, "m_vecMaxs", maxs);
GetEntPropVector(ent, Prop_Send, "m_vecMins", mins);
for (int i = 0; i < 3; i++)
Expand Down Expand Up @@ -895,7 +899,7 @@ static bool FindValidPositionAroundCenter(float center[3], float distFromCenter[
{
float testOrigin[3];
int x, y;

for (int i = 0; i < 3; i++)
{
// The search starts from the center then outwards to opposite directions.
Expand Down Expand Up @@ -934,7 +938,7 @@ static bool CanSeeBox(float origin[3], float center[3], float distFromCenter[3])
float traceOrigin[3], traceDest[3], mins[3], maxs[3];

CopyVector(origin, traceOrigin);


SubtractVectors(center, distFromCenter, mins);
AddVectors(center, distFromCenter, maxs);
Expand Down Expand Up @@ -978,7 +982,7 @@ stock int GOKZGetEntityFromAddress(Address pEntity)
{
return EntRefToEntIndex(LoadFromAddress(pEntity + view_as<Address>(offs_RefEHandle), NumberType_Int32) | (1 << 31));
}

// if we don't have it already, attempt to lookup offset based on SDK information
// CWorld is derived from CBaseEntity so it should have both offsets
int offs_angRotation = FindDataMapInfo(0, "m_angRotation"), offs_vecViewOffset = FindDataMapInfo(0, "m_vecViewOffset");
Expand All @@ -996,7 +1000,7 @@ stock int GOKZGetEntityFromAddress(Address pEntity)
GetGameFolderName(game, sizeof(game));
SetFailState("Could not confirm offset of CBaseEntity::m_RefEHandle (incorrect assumption for game '%s'?)", game);
}

// offset seems right, cache it for the next call
offs_RefEHandle = offs_angRotation + 0x0C;
return GOKZGetEntityFromAddress(pEntity);
Expand Down

0 comments on commit ddcd7ef

Please sign in to comment.