2019-09-25 11:37:40 +02:00
|
|
|
#include <sourcemod>
|
|
|
|
#include <sdktools>
|
2019-12-18 12:02:38 +01:00
|
|
|
#include <PhysHooks>
|
2019-09-25 11:37:40 +02:00
|
|
|
#include <dhooks>
|
|
|
|
|
|
|
|
#pragma semicolon 1
|
|
|
|
#pragma newdecls required
|
|
|
|
|
2020-02-23 20:28:06 +01:00
|
|
|
#define MAX_MISSED_TICKS 16
|
|
|
|
|
2019-09-25 11:37:40 +02:00
|
|
|
public Plugin myinfo =
|
|
|
|
{
|
|
|
|
name = "AntiLagSwitch",
|
|
|
|
author = "BotoX",
|
|
|
|
description = "",
|
2020-02-23 20:28:06 +01:00
|
|
|
version = "1.0",
|
2019-09-25 11:37:40 +02:00
|
|
|
url = ""
|
|
|
|
};
|
|
|
|
|
|
|
|
Handle g_hProcessUsercmds;
|
|
|
|
Handle g_hRunNullCommand;
|
|
|
|
|
2019-09-27 21:50:07 +02:00
|
|
|
int g_LastProcessed[MAXPLAYERS + 1];
|
|
|
|
|
2019-09-25 11:37:40 +02:00
|
|
|
public void OnPluginStart()
|
|
|
|
{
|
|
|
|
Handle hGameConf = LoadGameConfigFile("AntiLagSwitch.games");
|
|
|
|
if(!hGameConf)
|
|
|
|
SetFailState("Failed to load AntiLagSwitch gamedata.");
|
|
|
|
|
|
|
|
// void CBasePlayer::RunNullCommand( void )
|
|
|
|
StartPrepSDKCall(SDKCall_Player);
|
|
|
|
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "RunNullCommand"))
|
|
|
|
SetFailState("PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, \"RunNullCommand\" failed!");
|
|
|
|
|
|
|
|
g_hRunNullCommand = EndPrepSDKCall();
|
|
|
|
|
|
|
|
int Offset = GameConfGetOffset(hGameConf, "ProcessUsercmds");
|
|
|
|
if(Offset == -1)
|
|
|
|
SetFailState("Failed to find ProcessUsercmds offset");
|
|
|
|
|
|
|
|
/* void CBasePlayer::ProcessUsercmds( CUserCmd *cmds, int numcmds, int totalcmds,
|
|
|
|
int dropped_packets, bool paused ) */
|
|
|
|
g_hProcessUsercmds = DHookCreate(Offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, Hook_ProcessUsercmds);
|
|
|
|
if(g_hProcessUsercmds == INVALID_HANDLE)
|
|
|
|
SetFailState("Failed to DHookCreate ProcessUsercmds");
|
|
|
|
|
|
|
|
DHookAddParam(g_hProcessUsercmds, HookParamType_ObjectPtr); // 1 - CUserCmd *cmds
|
|
|
|
DHookAddParam(g_hProcessUsercmds, HookParamType_Int); // 2 - int numcmds
|
|
|
|
DHookAddParam(g_hProcessUsercmds, HookParamType_Int); // 3 - int totalcmds
|
|
|
|
DHookAddParam(g_hProcessUsercmds, HookParamType_Int); // 4 - int dropped_packets
|
|
|
|
DHookAddParam(g_hProcessUsercmds, HookParamType_Bool); // 5 - bool paused
|
|
|
|
|
|
|
|
delete hGameConf;
|
|
|
|
|
|
|
|
// Late load.
|
|
|
|
for(int client = 1; client <= MaxClients; client++)
|
|
|
|
{
|
|
|
|
if(IsClientInGame(client))
|
|
|
|
OnClientPutInServer(client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnClientPutInServer(int client)
|
|
|
|
{
|
|
|
|
DHookEntity(g_hProcessUsercmds, true, client);
|
2019-09-27 21:50:07 +02:00
|
|
|
g_LastProcessed[client] = GetGameTickCount();
|
2019-09-25 11:37:40 +02:00
|
|
|
}
|
|
|
|
|
2019-09-27 21:50:07 +02:00
|
|
|
public void OnClientDisconnect(int client)
|
2019-09-25 11:37:40 +02:00
|
|
|
{
|
2019-09-27 21:50:07 +02:00
|
|
|
g_LastProcessed[client] = 0;
|
|
|
|
}
|
2019-09-25 11:37:40 +02:00
|
|
|
|
2019-10-02 18:54:19 +02:00
|
|
|
public void OnPrePlayerThinkFunctions()
|
2019-09-27 21:50:07 +02:00
|
|
|
{
|
2020-02-23 20:28:06 +01:00
|
|
|
int minimum = GetGameTickCount() - MAX_MISSED_TICKS;
|
2019-09-27 21:50:07 +02:00
|
|
|
for(int client = 1; client <= MaxClients; client++)
|
|
|
|
{
|
|
|
|
if(IsClientInGame(client) && (IsFakeClient(client) || g_LastProcessed[client] < minimum))
|
|
|
|
{
|
|
|
|
RunNullCommand(client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MRESReturn Hook_ProcessUsercmds(int client, Handle hParams)
|
|
|
|
{
|
|
|
|
g_LastProcessed[client] = GetGameTickCount();
|
2019-09-25 11:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int RunNullCommand(int client)
|
|
|
|
{
|
|
|
|
return SDKCall(g_hRunNullCommand, client);
|
|
|
|
}
|