UTIL_GetClosestPlayer
0x0042df20 · 269 bytes · __cdecl
_Z21UTIL_GetClosestPlayerRK6VectorPf
Decompiled
undefined (2 params)
/* UTIL_GetClosestPlayer(Vector const&, float*) */
int * UTIL_GetClosestPlayer(Vector *param_1,float *param_2)
{
char cVar1;
int *piVar2;
float *pfVar3;
int iVar4;
int *piVar5;
float fVar6;
float local_20;
if (*(int *)(gpGlobals + 0x14) < 1) {
piVar2 = (int *)0x0;
local_20 = 1e+12;
}
else {
iVar4 = 1;
local_20 = 1e+12;
piVar5 = (int *)0x0;
do {
while ((((piVar2 = (int *)UTIL_PlayerByIndex(iVar4), piVar2 == (int *)0x0 ||
(piVar2[0xc] == 0)) || (piVar2[0xc] - *(int *)(gpGlobals + 0x58) >> 4 == 0)) ||
(cVar1 = (**(code **)(*piVar2 + 300))(piVar2), cVar1 == '\0'))) {
LAB_0042df56:
iVar4 = iVar4 + 1;
piVar2 = piVar5;
if (*(int *)(gpGlobals + 0x14) < iVar4) goto LAB_0042e000;
}
pfVar3 = (float *)(**(code **)(*piVar2 + 0x288))(piVar2);
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 (local_20 <= fVar6) goto LAB_0042df56;
iVar4 = iVar4 + 1;
piVar5 = piVar2;
local_20 = fVar6;
} while (iVar4 <= *(int *)(gpGlobals + 0x14));
}
LAB_0042e000:
if (param_2 != (float *)0x0) {
*param_2 = SQRT(local_20);
}
return piVar2;
}
SourceMod gamedata
paste intoaddons/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.
Signatures + Functions block. The plugin uses
DHookCreateFromConf - DHooks reads return type, this-type,
calling convention, and argument types straight from the gamedata. Less
boilerplate in the plugin, types travel with the gamedata.
Gamedata KeyValues
DHooks plugin example
Type inference is best-effort from the C signature - sanity-check the DHooks types before shipping.