LagCompensation: fix dhooks crash

This commit is contained in:
BotoX 2019-11-02 01:35:20 +01:00
parent f0d3ba3296
commit a36d3293c9
2 changed files with 39 additions and 3 deletions

View File

@ -79,6 +79,21 @@
} }
} }
} }
"CLogicMeasureMovement__SetTarget_post"
{
"signature" "CLogicMeasureMovement::SetTarget"
"callconv" "thiscall"
"return" "void"
"this" "ignore"
"arguments"
{
"pName"
{
"type" "charptr"
}
}
}
} }
} }
} }

View File

@ -59,6 +59,7 @@ Handle g_hSetLocalAngles;
Handle g_hUTIL_Remove; Handle g_hUTIL_Remove;
Handle g_hRestartRound; Handle g_hRestartRound;
Handle g_hSetTarget; Handle g_hSetTarget;
Handle g_hSetTargetPost;
char g_aBlockTriggerTouch[MAX_EDICTS] = {0, ...}; char g_aBlockTriggerTouch[MAX_EDICTS] = {0, ...};
char g_aaBlockTouch[MAXPLAYERS + 1][MAX_EDICTS]; char g_aaBlockTouch[MAXPLAYERS + 1][MAX_EDICTS];
@ -136,12 +137,26 @@ public void OnPluginStart()
SetFailState("Failed to setup detour for CLogicMeasureMovement__SetTarget"); SetFailState("Failed to setup detour for CLogicMeasureMovement__SetTarget");
} }
if(!DHookEnableDetour(g_hSetTarget, true, Detour_OnSetTargetPost)) if(!DHookEnableDetour(g_hSetTarget, false, Detour_OnSetTargetPre))
{ {
delete hGameData; delete hGameData;
SetFailState("Failed to detour CLogicMeasureMovement__SetTarget."); 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; delete hGameData;
RegAdminCmd("sm_unlag", Command_AddLagCompensation, ADMFLAG_RCON, "sm_unlag <entidx>"); RegAdminCmd("sm_unlag", Command_AddLagCompensation, ADMFLAG_RCON, "sm_unlag <entidx>");
@ -323,9 +338,15 @@ public MRESReturn Detour_OnRestartRound()
} }
// https://developer.valvesoftware.com/wiki/Logic_measure_movement // 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)) if(!IsValidEntity(entity))
return MRES_Ignored; return MRES_Ignored;