From a36d3293c96f0b1c585828496337a24ac3c1a02d Mon Sep 17 00:00:00 2001 From: BotoX Date: Sat, 2 Nov 2019 01:35:20 +0100 Subject: [PATCH] LagCompensation: fix dhooks crash --- .../gamedata/LagCompensation.games.txt | 15 +++++++++++ LagCompensation/scripting/LagCompensation.sp | 27 ++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/LagCompensation/gamedata/LagCompensation.games.txt b/LagCompensation/gamedata/LagCompensation.games.txt index 46f7aaa..117ae39 100644 --- a/LagCompensation/gamedata/LagCompensation.games.txt +++ b/LagCompensation/gamedata/LagCompensation.games.txt @@ -79,6 +79,21 @@ } } } + + "CLogicMeasureMovement__SetTarget_post" + { + "signature" "CLogicMeasureMovement::SetTarget" + "callconv" "thiscall" + "return" "void" + "this" "ignore" + "arguments" + { + "pName" + { + "type" "charptr" + } + } + } } } } diff --git a/LagCompensation/scripting/LagCompensation.sp b/LagCompensation/scripting/LagCompensation.sp index 18ca339..c6b0676 100644 --- a/LagCompensation/scripting/LagCompensation.sp +++ b/LagCompensation/scripting/LagCompensation.sp @@ -59,6 +59,7 @@ Handle g_hSetLocalAngles; Handle g_hUTIL_Remove; Handle g_hRestartRound; Handle g_hSetTarget; +Handle g_hSetTargetPost; char g_aBlockTriggerTouch[MAX_EDICTS] = {0, ...}; char g_aaBlockTouch[MAXPLAYERS + 1][MAX_EDICTS]; @@ -136,12 +137,26 @@ public void OnPluginStart() SetFailState("Failed to setup detour for CLogicMeasureMovement__SetTarget"); } - if(!DHookEnableDetour(g_hSetTarget, true, Detour_OnSetTargetPost)) + if(!DHookEnableDetour(g_hSetTarget, false, Detour_OnSetTargetPre)) { delete hGameData; SetFailState("Failed to detour CLogicMeasureMovement__SetTarget."); } + // CLogicMeasureMovement::SetTarget (fix post hook crashing due to this pointer being overwritten) + g_hSetTargetPost = DHookCreateFromConf(hGameData, "CLogicMeasureMovement__SetTarget_post"); + if(!g_hSetTargetPost) + { + delete hGameData; + SetFailState("Failed to setup detour for CLogicMeasureMovement__SetTarget_post"); + } + + if(!DHookEnableDetour(g_hSetTargetPost, true, Detour_OnSetTargetPost)) + { + delete hGameData; + SetFailState("Failed to detour CLogicMeasureMovement__SetTarget_post."); + } + delete hGameData; RegAdminCmd("sm_unlag", Command_AddLagCompensation, ADMFLAG_RCON, "sm_unlag "); @@ -323,9 +338,15 @@ public MRESReturn Detour_OnRestartRound() } // https://developer.valvesoftware.com/wiki/Logic_measure_movement -public MRESReturn Detour_OnSetTargetPost(int pThis, Handle hParams) +int g_OnSetTarget_pThis; +public MRESReturn Detour_OnSetTargetPre(int pThis, Handle hParams) { - int entity = GetEntPropEnt(pThis, Prop_Data, "m_hTarget"); + g_OnSetTarget_pThis = pThis; + return MRES_Ignored; +} +public MRESReturn Detour_OnSetTargetPost(Handle hParams) +{ + int entity = GetEntPropEnt(g_OnSetTarget_pThis, Prop_Data, "m_hTarget"); if(!IsValidEntity(entity)) return MRES_Ignored;