Skip to content

Commit

Permalink
Barnacle prediction fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ampreeT committed Dec 30, 2024
1 parent 9c42f76 commit b2100ef
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripting/include/srccoop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define ENTPATCH_FUNC_TRACKAUTOCHANGE
#define ENTPATCH_FUNC_TRACKTRAIN
#define ENTPATCH_NPC_RUNTASK
#define ENTPATCH_BARNACLE_PREDICTION

#define PLAYERPATCH_SUIT_SOUNDS
#define PLAYERPATCH_PICKUP_FORCEPLAYERTODROPTHISOBJECT
Expand Down Expand Up @@ -97,6 +98,7 @@
#define ENTPATCH_FUNC_TRACKAUTOCHANGE
#define ENTPATCH_FUNC_TRACKTRAIN
#define ENTPATCH_NPC_RUNTASK
#define ENTPATCH_BARNACLE_PREDICTION
#define ENTPATCH_BM_XENTURRET
#define ENTPATCH_BM_ICHTHYOSAUR
#define ENTPATCH_BM_GARGANTUA
Expand Down
53 changes: 53 additions & 0 deletions scripting/include/srccoop/entitypatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1570,3 +1570,56 @@ public MRESReturn Hook_ScriptedSequenceStartScript(int _this)
}
return MRES_Ignored;
}

//------------------------------------------------------
// npc_barnacle
// Fixes prediction and view jitter while being grabbed by a barnacle.
//------------------------------------------------------
public void Hook_Barnacle_OnGrab(const char[] szOutput, const int iCaller, const int iActivator, const float flDelay)
{
CNPC_Barnacle pBarnacle = CNPC_Barnacle(iCaller);

// The enemy of the barnacle is not set until after `CNPC_Barnacle::AttachTongueToTarget` is finished executing.
// https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/sp/src/game/server/hl2/npc_barnacle.cpp#L1359
CreateTimer(0.0, Timer_Barnacle_OnGrab, pBarnacle, TIMER_FLAG_NO_MAPCHANGE);
}

//------------------------------------------------------
// npc_barnacle
// Fixes prediction and view jitter while being grabbed by a barnacle.
//------------------------------------------------------
public void Timer_Barnacle_OnGrab(Handle hTimer, const CNPC_Barnacle pBarnacle)
{
if (pBarnacle.IsValid() && pBarnacle.IsAlive())
{
CBaseEntity pEnemy = pBarnacle.GetEnemy();
if (pEnemy != NULL_CBASEENTITY && pEnemy.IsPlayer())
{
CBasePlayer pPlayer = view_as<CBasePlayer>(pEnemy);

// Prevents client-side prediction errors for movement while being pulled up.
pPlayer.m_fFlags |= FL_ATCONTROLS;
// Removes the initial view jitter when being pulled up.
pPlayer.SetMoveType(MOVETYPE_FLY);
// Remove the view jitter while being pulled up.
pPlayer.SetLaggedMovement(0.0);
}
}
}

//------------------------------------------------------
// npc_barnacle
// Fixes prediction and view jitter while being grabbed by a barnacle.
//------------------------------------------------------
public void Hook_Barnacle_OnRelease(const char[] szOutput, const int iCaller, const int iActivator, const float flDelay)
{
CNPC_Barnacle pBarnacle = CNPC_Barnacle(iCaller);
CBaseEntity pEnemy = pBarnacle.GetEnemy();
if (pEnemy != NULL_CBASEENTITY && pEnemy.IsPlayer())
{
CBasePlayer pPlayer = view_as<CBasePlayer>(pEnemy);
pPlayer.m_fFlags &= ~FL_ATCONTROLS;
pPlayer.SetMoveType(MOVETYPE_WALK);
pPlayer.SetLaggedMovement(1.0);
}
}
5 changes: 5 additions & 0 deletions scripting/srccoop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ public void OnPluginStart()
}
}
}

#if defined ENTPATCH_BARNACLE_PREDICTION
HookEntityOutput("npc_barnacle", "OnGrab", Hook_Barnacle_OnGrab);
HookEntityOutput("npc_barnacle", "OnRelease", Hook_Barnacle_OnRelease);
#endif
}

#pragma dynamic ENTITYSTRING_LENGTH
Expand Down

0 comments on commit b2100ef

Please sign in to comment.