#pragma semicolon 1
#include <amxmodx>
#include <fakemeta>
public plugin_init()
{
register_plugin("Fake Ping For Players", "1.0", "fl0wer");
register_forward(FM_UpdateClientData, "@UpdateClientData_Post", true);
}
@UpdateClientData_Post(id)
{
static bool:sending;
static bits, added;
static ping, loss;
static i;
get_user_ping(i, ping, loss);
sending = false;
bits = added = 0;
for (i = 1; i <= MaxClients; i++)
{
if (!is_user_connected(i))
continue;
if (!sending)
{
message_begin(MSG_ONE_UNRELIABLE, SVC_PINGS, _, id);
sending = true;
}
AddBits(bits, added, 1, 1);
AddBits(bits, added, i - 1, 5);
AddBits(bits, added, max(ping - 10, 1), 12);
AddBits(bits, added, 0, 7);
WriteBytes(bits, added, false);
}
if (sending)
{
AddBits(bits, added, 0, 1);
WriteBytes(bits, added, true);
message_end();
}
}
AddBits(&bits, &added, value, bitCount)
{
if (bitCount > (32 - added) || bitCount < 1)
return;
if (value >= (1<<bitCount))
value = (1<<bitCount) - 1;
bits = bits + (value<<added);
added += bitCount;
}
WriteBytes(&bits, &added, remaining)
{
while (added >= 8)
{
write_byte(bits & ((1<<8) - 1));
bits = (bits>>8);
added -= 8;
}
if (remaining && added > 0)
{
write_byte(bits);
bits = added = 0;
}
}