diff --git a/FixLagCompensation/gamedata/FixLagCompensation.games.txt b/FixLagCompensation/gamedata/FixLagCompensation.games.txt new file mode 100644 index 00000000..573eb3ba --- /dev/null +++ b/FixLagCompensation/gamedata/FixLagCompensation.games.txt @@ -0,0 +1,45 @@ +"Games" +{ + "cstrike" + { + "Offsets" + { + "IsMoving" + { + "windows" "74" + "linux" "75" + } + } + + "Signatures" + { + "CLagCompensationManager::BacktrackPlayer" + { + "library" "server" + "linux" "@_ZN23CLagCompensationManager15BacktrackPlayerEP11CBasePlayerf" + } + } + + "Functions" + { + "CLagCompensationManager__BacktrackPlayer" + { + "signature" "CLagCompensationManager::BacktrackPlayer" + "callconv" "thiscall" + "return" "void" + "this" "ignore" + "arguments" + { + "pPlayer" + { + "type" "cbaseentity" + } + "flTargetTime" + { + "type" "float" + } + } + } + } + } +} diff --git a/FixLagCompensation/scripting/FixLagCompensation.sp b/FixLagCompensation/scripting/FixLagCompensation.sp new file mode 100644 index 00000000..3d9d1f68 --- /dev/null +++ b/FixLagCompensation/scripting/FixLagCompensation.sp @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +#pragma semicolon 1 +#pragma newdecls required + +public Plugin myinfo = +{ + name = "FixLagCompensation", + author = "BotoX", + description = "", + version = "1.0", + url = "" +}; + +Handle g_hBacktrackPlayer; +Handle g_hIsMoving; + +public void OnPluginStart() +{ + Handle hGameData = LoadGameConfigFile("FixLagCompensation.games"); + if(!hGameData) + SetFailState("Failed to load FixLagCompensation gamedata."); + + // void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, float flTargetTime ) + g_hBacktrackPlayer = DHookCreateFromConf(hGameData, "CLagCompensationManager__BacktrackPlayer"); + if(!g_hBacktrackPlayer) + { + delete hGameData; + SetFailState("Failed to setup detour for CLagCompensationManager__BacktrackPlayer"); + } + + if(!DHookEnableDetour(g_hBacktrackPlayer, false, Detour_OnBacktrackPlayer)) + { + delete hGameData; + SetFailState("Failed to detour CLagCompensationManager__BacktrackPlayer."); + } + + // CBaseEntity::IsMoving + StartPrepSDKCall(SDKCall_Entity); + if(!PrepSDKCall_SetFromConf(hGameData, SDKConf_Virtual, "IsMoving")) + { + delete hGameData; + SetFailState("PrepSDKCall_SetFromConf(hGameData, SDKConf_Virtual, \"IsMoving\") failed!"); + } + PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); + g_hIsMoving = EndPrepSDKCall(); + + delete hGameData; +} + +public MRESReturn Detour_OnBacktrackPlayer(Handle hParams) +{ + if(DHookIsNullParam(hParams, 1)) + return MRES_Ignored; + + int client = DHookGetParam(hParams, 1); + if(client < 1 || client > MaxClients) + return MRES_Ignored; + + int GroundEntity = GetEntPropEnt(client, Prop_Data, "m_hGroundEntity"); + if(GroundEntity <= 0) + return MRES_Ignored; + + bool bIsMoving = SDKCall(g_hIsMoving, GroundEntity); + + if(bIsMoving) + return MRES_Supercede; + + return MRES_Ignored; +}