L L4D2node

UTIL_GetClosestPlayer

0x0042e030 · 268 bytes · __cdecl

_Z21UTIL_GetClosestPlayerRK6VectoriPf

Decompiled

undefined (3 params)

/* UTIL_GetClosestPlayer(Vector const&, int, float*) */

CBaseEntity * UTIL_GetClosestPlayer(Vector *param_1,int param_2,float *param_3)

{
  char cVar1;
  CBaseEntity *this;
  int iVar2;
  float *pfVar3;
  CBaseEntity *pCVar4;
  int iVar5;
  float fVar6;
  float local_20;
  
  if (*(int *)(gpGlobals + 0x14) < 1) {
    pCVar4 = (CBaseEntity *)0x0;
    local_20 = 1e+12;
  }
  else {
    iVar5 = 1;
    pCVar4 = (CBaseEntity *)0x0;
    local_20 = 1e+12;
    do {
      this = (CBaseEntity *)UTIL_PlayerByIndex(iVar5);
      if ((((this != (CBaseEntity *)0x0) && (*(int *)(this + 0x30) != 0)) &&
          (*(int *)(this + 0x30) - *(int *)(gpGlobals + 0x58) >> 4 != 0)) &&
         ((cVar1 = (**(code **)(*(int *)this + 300))(this), cVar1 != '\0' &&
          (iVar2 = CBaseEntity::GetTeamNumber(this), iVar2 == param_2)))) {
        pfVar3 = (float *)(**(code **)(*(int *)this + 0x288))(this);
        fVar6 = (pfVar3[1] - *(float *)(param_1 + 4)) * (pfVar3[1] - *(float *)(param_1 + 4)) +
                (pfVar3[2] - *(float *)(param_1 + 8)) * (pfVar3[2] - *(float *)(param_1 + 8)) +
                (*pfVar3 - *(float *)param_1) * (*pfVar3 - *(float *)param_1);
        if (fVar6 < local_20) {
          pCVar4 = this;
          local_20 = fVar6;
        }
      }
      iVar5 = iVar5 + 1;
    } while (iVar5 <= *(int *)(gpGlobals + 0x14));
  }
  if (param_3 != (float *)0x0) {
    *param_3 = SQRT(local_20);
  }
  return pCVar4;
}

SourceMod gamedata

paste into addons/sourcemod/gamedata/<your_plugin>.txt
used as the SourceMod key — change to fit your plugin's convention
SourceMod library name (server / engine / matchmaking)

Just a Signatures{} block, ready to drop into a gamedata file. Wire it up in your plugin however you like - SDKCall, DHooks, raw memory ops, or anything else.



        

        

          

Type inference is best-effort from the C signature - sanity-check the DHooks types before shipping.

Return-type handling cheatsheet (DHookReturn)