Skip to content

Commit

Permalink
Common Shove: Fix shove immunity when climbing (#729)
Browse files Browse the repository at this point in the history
Fix:
- Fixed a mistake causing Common Infected to be immune to shoves when climbing.

Change:
- Updated gamedata to correct the way getting nextbot body.
  • Loading branch information
jensewe authored Jan 10, 2024
1 parent a088d92 commit 6865b5b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
24 changes: 18 additions & 6 deletions addons/sourcemod/gamedata/l4d_fix_common_shove.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
{
"Offsets"
{
"Infected::m_body"
"CBaseEntity::MyNextBotPointer"
{
"linux" "3472"
"windows" "3452"
"linux" "72"
"windows" "71"
}

"INextBot::GetBodyInterface"
{
"linux" "44"
"windows" "43"
}
}

Expand All @@ -27,10 +33,16 @@
{
"Offsets"
{
"Infected::m_body"
"CBaseEntity::MyNextBotPointer"
{
"linux" "82"
"windows" "81"
}

"INextBot::GetBodyInterface"
{
"linux" "7328"
"windows" "7332"
"linux" "49"
"windows" "48"
}
}

Expand Down
Binary file modified addons/sourcemod/plugins/fixes/l4d_fix_common_shove.smx
Binary file not shown.
79 changes: 52 additions & 27 deletions addons/sourcemod/scripting/l4d_fix_common_shove.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <left4dhooks_anim>
#include <actions>

#define PLUGIN_VERSION "1.2"
#define PLUGIN_VERSION "1.3"

public Plugin myinfo =
{
Expand All @@ -20,7 +20,8 @@ public Plugin myinfo =

#define GAMEDATA_FILE "l4d_fix_common_shove"

int g_iOffs_Infected__m_body;
Handle g_hCall_MyNextBotPointer;
Handle g_hCall_GetBodyInterface;
Handle g_hCall_SetDesiredPosture;

enum ActivityType
Expand All @@ -41,15 +42,24 @@ enum PostureType
LIE
};

methodmap IBody
INextBot MyNextBotPointer(int entity)
{
public void SetDesiredPosture(PostureType posture) {
SDKCall(g_hCall_SetDesiredPosture, this, posture);
return SDKCall(g_hCall_MyNextBotPointer, entity);
}

methodmap INextBot
{
public ZombieBotBody GetBodyInterface() {
return SDKCall(g_hCall_GetBodyInterface, this);
}
}

methodmap ZombieBotBody < IBody
methodmap ZombieBotBody
{
public void SetDesiredPosture(PostureType posture) {
SDKCall(g_hCall_SetDesiredPosture, this, posture);
}

property int m_activity {
public get() { return LoadFromAddress(view_as<Address>(this) + view_as<Address>(80), NumberType_Int32); }
public set(int act) { StoreToAddress(view_as<Address>(this) + view_as<Address>(80), act, NumberType_Int32); }
Expand Down Expand Up @@ -156,9 +166,17 @@ public void OnPluginStart()
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
g_hCall_SetDesiredPosture = EndPrepSDKCall();

g_iOffs_Infected__m_body = gd.GetOffset("Infected::m_body");
if (g_iOffs_Infected__m_body == -1)
SetFailState("Missing offset \"Infected::m_body\"");
StartPrepSDKCall(SDKCall_Entity);
if (!PrepSDKCall_SetFromConf(gd, SDKConf_Virtual, "CBaseEntity::MyNextBotPointer"))
SetFailState("Missing signature \"CBaseEntity::MyNextBotPointer\"");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
g_hCall_MyNextBotPointer = EndPrepSDKCall();

StartPrepSDKCall(SDKCall_Raw);
if (!PrepSDKCall_SetFromConf(gd, SDKConf_Virtual, "INextBot::GetBodyInterface"))
SetFailState("Missing signature \"INextBot::GetBodyInterface\"");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
g_hCall_GetBodyInterface = EndPrepSDKCall();

delete gd;

Expand Down Expand Up @@ -201,7 +219,7 @@ public void OnActionCreated(BehaviorAction action, int actor, const char[] name)

Action InfectedShoved_OnStart(BehaviorAction action, int actor, any priorAction, ActionResult result)
{
if (GetEntPropEnt(actor, Prop_Data, "m_hGroundEntity") == -1) // falling check
if (MyNextBotPointer(actor).GetBodyInterface().m_activity == L4D2_ACT_TERROR_FALL) // falling check
{
if (g_iShoveFlag & SHOVE_FALLING)
{
Expand All @@ -227,7 +245,7 @@ Action InfectedShoved_OnStart(BehaviorAction action, int actor, any priorAction,

if (g_iShoveFlag & SHOVE_CROUCHING)
{
Infected__GetBodyInterface(actor).SetDesiredPosture(STAND); // force standing to activate shoves
MyNextBotPointer(actor).GetBodyInterface().SetDesiredPosture(STAND); // force standing to activate shoves
}

if (g_iShoveFlag & SHOVE_LANDING
Expand Down Expand Up @@ -259,7 +277,7 @@ Action InfectedShoved_OnShoved(BehaviorAction action, int actor, int entity, Act
{
if (g_iShoveFlag & SHOVE_CROUCHING)
{
Infected__GetBodyInterface(actor).SetDesiredPosture(STAND); // force standing to activate shoves
MyNextBotPointer(actor).GetBodyInterface().SetDesiredPosture(STAND); // force standing to activate shoves
}
}

Expand All @@ -281,26 +299,33 @@ Action InfectedShoved_OnLandOnGroundPost(BehaviorAction action, int actor, int e

bool ForceActivityInterruptible(int infected)
{
ZombieBotBody body = Infected__GetBodyInterface(infected);
ZombieBotBody body = MyNextBotPointer(infected).GetBodyInterface();

switch (body.m_activity) // perhaps unnecessary
if (L4D_IsEngineLeft4Dead1()) // perhaps unnecessary
{
case L4D2_ACT_TERROR_JUMP_LANDING,
L4D2_ACT_TERROR_JUMP_LANDING_HARD,
L4D2_ACT_TERROR_JUMP_LANDING_NEUTRAL,
L4D2_ACT_TERROR_JUMP_LANDING_HARD_NEUTRAL:
switch (body.m_activity)
{
body.m_activityType &= ~ACTIVITY_UNINTERRUPTIBLE;
return true;
case L4D1_ACT_TERROR_JUMP_LANDING,
L4D1_ACT_TERROR_JUMP_LANDING_HARD,
L4D1_ACT_TERROR_JUMP_LANDING_NEUTRAL,
L4D1_ACT_TERROR_JUMP_LANDING_HARD_NEUTRAL: { }
default: { return false; }
}
}
else
{
switch (body.m_activity)
{
case L4D2_ACT_TERROR_JUMP_LANDING,
L4D2_ACT_TERROR_JUMP_LANDING_HARD,
L4D2_ACT_TERROR_JUMP_LANDING_NEUTRAL,
L4D2_ACT_TERROR_JUMP_LANDING_HARD_NEUTRAL: { }
default: { return false; }
}
}

return false;
}

ZombieBotBody Infected__GetBodyInterface(int infected)
{
return view_as<ZombieBotBody>(GetEntData(infected, g_iOffs_Infected__m_body, 4));
body.m_activityType &= ~ACTIVITY_UNINTERRUPTIBLE;
return true;
}

stock bool IsInfected(int entity)
Expand Down Expand Up @@ -333,4 +358,4 @@ ConVar CreateConVarHook(const char[] name,
cv.AddChangeHook(callback);

return cv;
}
}

0 comments on commit 6865b5b

Please sign in to comment.