Skip to content

Commit

Permalink
Update left4dhooks to latest version.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirPlease committed Dec 19, 2023
1 parent e3de4f5 commit 4a47a32
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 21 deletions.
27 changes: 26 additions & 1 deletion addons/sourcemod/gamedata/left4dhooks.l4d2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@
}
}

"L4DD::CTerrorPlayer::OnIncapacitatedAsSurvivor"
{
"signature" "CTerrorPlayer::OnIncapacitatedAsSurvivor"
"callconv" "thiscall"
"return" "int"
"this" "entity"
"arguments"
{
"a1"
{
"type" "objectptr"
}
}
}

"L4DD::CTerrorPlayer::OnKnockedDown"
{
"signature" "CTerrorPlayer::OnKnockedDown"
Expand Down Expand Up @@ -1448,7 +1463,7 @@
{
"type" "cbaseentity"
}
"a3"
"a2"
{
"type" "int"
}
Expand Down Expand Up @@ -3628,6 +3643,16 @@
/* Search "#L4D_idle_spectator" xref to VTable, target is function above. */
}

/* CTerrorPlayer::OnIncapacitatedAsSurvivor(CTerrorPlayer *this, const CTakeDamageInfo *) */
"CTerrorPlayer::OnIncapacitatedAsSurvivor"
{
"library" "server"
"linux" "@_ZN13CTerrorPlayer25OnIncapacitatedAsSurvivorERK15CTakeDamageInfo"
"windows" "\x2A\x2A\x2A\x2A\x2A\x2A\x83\x2A\x2A\x83\x2A\x2A\x55\x8B\x2A\x2A\x89\x2A\x2A\x2A\x8B\x2A\x81\x2A\x2A\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x33\x2A\x89\x2A\x2A\x56\x57\x8B\x2A\x2A\x6A\x2A\x8B"
/* ? ? ? ? ? ? 83 ? ? 83 ? ? 55 8B ? ? 89 ? ? ? 8B ? 81 ? ? ? ? ? A1 ? ? ? ? 33 ? 89 ? ? 56 57 8B ? ? 6A ? 8B */
/* Search "PlayerIncapacitated" */
}

/**
* Witch::SetHarasser(Witch *this, CBaseEntity *)
**/
Expand Down
Binary file modified addons/sourcemod/plugins/left4dhooks.smx
Binary file not shown.
52 changes: 48 additions & 4 deletions addons/sourcemod/scripting/include/left4dhooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@



// Natives: 260 (including 3 for L4D1 only)
// Natives: 272 (including 3 for L4D1 only)
// L4D1 = 31 [left4downtown] + 47 [l4d_direct] + 16 [l4d2addresses] + 70 [silvers - mine!] + 4 [anim] = 169
// L4D2 = 61 [left4downtown] + 59 [l4d_direct] + 31 [l4d2addresses] + 114 [silvers - mine!] + 4 [anim] = 269

// Forwards: 204 (including 5 for L4D1 only)
// L4D1 = 139
// L4D2 = 199
// Forwards: 207 (including 5 for L4D1 only)
// L4D1 = 142
// L4D2 = 202

// Stocks: 169 (L4D1 = 114, L4D2 = 167)
// left4dhooks_silver 46 stocks (L4D1 = 39, L4D2 = 53)
Expand Down Expand Up @@ -2677,6 +2677,50 @@ forward void L4D_OnPlayerCough_Post(int client, int attacker);
**/
forward void L4D_OnPlayerCough_PostHandled(int client, int attacker);

/**
* @brief Called when CTerrorPlayer::OnIncapacitatedAsSurvivor() is invoked
* @remarks Called when a player is about to be incapacitated
*
* @param client Client index of the player affected
* @param inflictor The inflictor entity index
* @param attacker The attacker entity index
* @param damage Amount of damage being caused
* @param damagetype Type of damage being caused
*
* @return return Plugin_Handled to block, Plugin_Changed to modify values, Plugin_Continue otherwise
**/
forward Action L4D_OnIncapacitated(int client, int &inflictor, int &attacker, float &damage, int &damagetype);

/**
* @brief Called when CTerrorPlayer::OnIncapacitatedAsSurvivor() is invoked
* @remarks Called when a player is about to be incapacitated
* @remarks This forward will not trigger if the relative pre-hook forward has been blocked with Plugin_Handled
*
* @param client Client index of the player affected
* @param inflictor The inflictor entity index
* @param attacker The attacker entity index
* @param damage Amount of damage being caused
* @param damagetype Type of damage being caused
*
* @noreturn
**/
forward void L4D_OnIncapacitated_Post(int client, int inflictor, int attacker, float damage, int damagetype);

/**
* @brief Called when CTerrorPlayer::OnIncapacitatedAsSurvivor() is invoked
* @remarks Called when a player is about to be incapacitated
* @remarks This forward will ONLY trigger if the relative pre-hook forward has been blocked with Plugin_Handled
*
* @param client Client index of the player affected
* @param inflictor The inflictor entity index
* @param attacker The attacker entity index
* @param damage Amount of damage being caused
* @param damagetype Type of damage being caused
*
* @noreturn
**/
forward void L4D_OnIncapacitated_PostHandled(int client, int inflictor, int attacker, float damage, int damagetype);

/**
* @brief Called when CTerrorPlayer::DropWeapons() is invoked
* @remarks Called when a player dies, listing their currently held weapons and objects that are being dropped
Expand Down
68 changes: 66 additions & 2 deletions addons/sourcemod/scripting/l4dd/l4dd_forwards.sp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ GlobalForward g_hFWD_CTerrorPlayer_OnFalling_Post;
GlobalForward g_hFWD_CTerrorPlayer_Cough;
GlobalForward g_hFWD_CTerrorPlayer_Cough_Post;
GlobalForward g_hFWD_CTerrorPlayer_Cough_PostHandled;
GlobalForward g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor;
GlobalForward g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post;
GlobalForward g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor_PostHandled;
GlobalForward g_hFWD_Witch_SetHarasser;
GlobalForward g_hFWD_Tank_EnterStasis_Post;
GlobalForward g_hFWD_Tank_LeaveStasis_Post;
Expand Down Expand Up @@ -399,6 +402,9 @@ void SetupDetours(GameData hGameData = null)
CreateDetour(hGameData, DTR_CTerrorPlayer_Cough, DTR_CTerrorPlayer_Cough_Post, "L4DD::CTerrorPlayer::Cough", "L4D_OnPlayerCough");
CreateDetour(hGameData, DTR_CTerrorPlayer_Cough, DTR_CTerrorPlayer_Cough_Post, "L4DD::CTerrorPlayer::Cough", "L4D_OnPlayerCough_Post", true);
CreateDetour(hGameData, DTR_CTerrorPlayer_Cough, DTR_CTerrorPlayer_Cough_Post, "L4DD::CTerrorPlayer::Cough", "L4D_OnPlayerCough_PostHandled", true);
CreateDetour(hGameData, DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor, DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post, "L4DD::CTerrorPlayer::OnIncapacitatedAsSurvivor", "L4D_OnIncapacitated");
CreateDetour(hGameData, DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor, DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post, "L4DD::CTerrorPlayer::OnIncapacitatedAsSurvivor", "L4D_OnIncapacitated_Post", true);
CreateDetour(hGameData, DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor, DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post, "L4DD::CTerrorPlayer::OnIncapacitatedAsSurvivor", "L4D_OnIncapacitated_PostHandled", true);
CreateDetour(hGameData, DTR_Witch_SetHarasser, INVALID_FUNCTION, "L4DD::Witch::SetHarasser", "L4D_OnWitchSetHarasser");
CreateDetour(hGameData, DTR_Tank_EnterStasis_Pre, DTR_Tank_EnterStasis_Post, "L4DD::Tank::EnterStasis", "L4D_OnEnterStasis");
CreateDetour(hGameData, DTR_Tank_LeaveStasis_Pre, DTR_Tank_LeaveStasis_Post, "L4DD::Tank::LeaveStasis", "L4D_OnLeaveStasis");
Expand Down Expand Up @@ -2984,7 +2990,7 @@ MRESReturn DTR_CTerrorWeapon_OnHit_Post(int weapon, DHookReturn hReturn, DHookPa
bool g_bBlock_CTerrorPlayer_OnShovedByPounceLanding;
MRESReturn DTR_CTerrorPlayer_OnShovedByPounceLanding(int pThis, DHookParam hParams) // Forward "L4D2_OnPounceOrLeapStumble"
{
//PrintToServer("##### DTR_CTerrorPlayer_OnShovedByPounceLanding");
// PrintToServer("##### DTR_CTerrorPlayer_OnShovedByPounceLanding");
int a1 = hParams.Get(1);

Action aResult = Plugin_Continue;
Expand Down Expand Up @@ -3421,6 +3427,64 @@ MRESReturn DTR_CTerrorPlayer_Cough_Post(int pThis, DHookReturn hReturn, DHookPar
return MRES_Ignored;
}

bool g_bBlock_CTerrorPlayer_OnIncapacitatedAsSurvivor;
MRESReturn DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor(int pThis, DHookReturn hReturn, DHookParam hParams) // Forward "L4D_OnIncapacitated"
{
//PrintToServer("##### DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor");
int inflictor = hParams.GetObjectVar(1, 48, ObjectValueType_EhandlePtr);
int attacker = hParams.GetObjectVar(1, 52, ObjectValueType_EhandlePtr);
float damage = hParams.GetObjectVar(1, 60, ObjectValueType_Float);
int damagetype = hParams.GetObjectVar(1, 72, ObjectValueType_Int);

Action aResult = Plugin_Continue;
Call_StartForward(g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor);
Call_PushCell(pThis);
Call_PushCellRef(inflictor);
Call_PushCellRef(attacker);
Call_PushFloatRef(damage);
Call_PushCellRef(damagetype);
Call_Finish(aResult);

if( aResult == Plugin_Handled )
{
g_bBlock_CTerrorPlayer_OnIncapacitatedAsSurvivor = true;

hReturn.Value = -1;
return MRES_Supercede;
}

if( aResult == Plugin_Changed )
{
hParams.SetObjectVar(1, 48, ObjectValueType_EhandlePtr, inflictor);
hParams.SetObjectVar(1, 52, ObjectValueType_EhandlePtr, attacker);
hParams.SetObjectVar(1, 60, ObjectValueType_Float, damage);
hParams.SetObjectVar(1, 72, ObjectValueType_Int, damagetype);
return MRES_ChangedHandled;
}

g_bBlock_CTerrorPlayer_OnIncapacitatedAsSurvivor = false;

return MRES_Ignored;
}

MRESReturn DTR_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post(int pThis, DHookReturn hReturn, DHookParam hParams) // Forward "L4D_OnIncapacitated_Post" abd "L4D_OnIncapacitated_PostHandled"
{
int inflictor = hParams.GetObjectVar(1, 48, ObjectValueType_EhandlePtr);
int attacker = hParams.GetObjectVar(1, 52, ObjectValueType_EhandlePtr);
float damage = hParams.GetObjectVar(1, 60, ObjectValueType_Float);
int damagetype = hParams.GetObjectVar(1, 72, ObjectValueType_Int);

Call_StartForward(g_bBlock_CTerrorPlayer_OnIncapacitatedAsSurvivor ? g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor_PostHandled : g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post);
Call_PushCell(pThis);
Call_PushCell(inflictor);
Call_PushCell(attacker);
Call_PushFloat(damage);
Call_PushCell(damagetype);
Call_Finish();

return MRES_Ignored;
}

MRESReturn DTR_CTerrorPlayer_DropWeapons(int pThis, DHookReturn hReturn) // Forward "L4D_OnDeathDroppedWeapons"
{
//PrintToServer("##### DTR_CTerrorPlayer_DropWeapons");
Expand All @@ -3435,7 +3499,7 @@ MRESReturn DTR_CTerrorPlayer_DropWeapons(int pThis, DHookReturn hReturn) // Forw
for( int i = 0; i < 5; i++ )
{
weapons[i] = GetPlayerWeaponSlot(pThis, i);
if( weapons[i] == weapon ) weapon = 0;
// if( weapons[i] == weapon ) weapon = -1;
}

weapons[5] = weapon; // Held weapon
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/l4dd/l4dd_natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,12 @@ int Native_CTerrorGameRules_GetSurvivorSetMap(Handle plugin, int numParams) // N
ValidateNatives(g_hSDK_KeyValues_GetString, "KeyValues::GetString");
ValidateNatives(g_hSDK_CTerrorGameRules_GetMissionInfo, "CTerrorGameRules::GetMissionInfo");

char sTemp[8];
//PrintToServer("#### CALL g_hSDK_CTerrorGameRules_GetMissionInfo");
int infoPointer = SDKCall(g_hSDK_CTerrorGameRules_GetMissionInfo);
ValidateAddress(infoPointer, "CTerrorGameRules::GetMissionInfo");

//PrintToServer("#### CALL g_hSDK_KeyValues_GetString");
char sTemp[8];
SDKCall(g_hSDK_KeyValues_GetString, infoPointer, sTemp, sizeof(sTemp), "survivor_set", "2"); // Default set = 2

return StringToInt(sTemp);
Expand Down Expand Up @@ -1820,7 +1820,7 @@ void OnAcidDamage(int victim, int attacker, int inflictor, float damage, int dam
{
if( ((damagetype == (DMG_ENERGYBEAM|DMG_RADIATION) && attacker > 0 && attacker <= MaxClients && IsClientInGame(attacker) && GetClientTeam(attacker) != 3)) || (damagetype == (DMG_ENERGYBEAM|DMG_RADIATION|DMG_PREVENT_PHYSICS_FORCE) && attacker > MaxClients) )
{
EmitSoundToAll(g_sAcidSounds[GetRandomInt(0, sizeof(g_sAcidSounds) - 1)], inflictor, SNDCHAN_AUTO, 85, _, 0.55, GetRandomInt(95, 105));
EmitSoundToAll(g_sAcidSounds[GetRandomInt(0, sizeof(g_sAcidSounds) - 1)], inflictor, SNDCHAN_AUTO, 85, _, 0.7, GetRandomInt(95, 105));

// Red flash when taking damage
Handle msg = StartMessageOne("Fade", victim);
Expand Down
3 changes: 3 additions & 0 deletions addons/sourcemod/scripting/l4dd/l4dd_setup.sp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ void SetupForwardsNatives()
g_hFWD_CTerrorPlayer_Cough = new GlobalForward("L4D_OnPlayerCough", ET_Event, Param_Cell, Param_Cell);
g_hFWD_CTerrorPlayer_Cough_Post = new GlobalForward("L4D_OnPlayerCough_Post", ET_Event, Param_Cell, Param_Cell);
g_hFWD_CTerrorPlayer_Cough_PostHandled = new GlobalForward("L4D_OnPlayerCough_PostHandled", ET_Event, Param_Cell, Param_Cell);
g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor = new GlobalForward("L4D_OnIncapacitated", ET_Event, Param_Cell, Param_CellByRef, Param_CellByRef, Param_FloatByRef, Param_CellByRef);
g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor_Post = new GlobalForward("L4D_OnIncapacitated_Post", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Float, Param_Cell);
g_hFWD_CTerrorPlayer_OnIncapacitatedAsSurvivor_PostHandled = new GlobalForward("L4D_OnIncapacitated_PostHandled", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Float, Param_Cell);
g_hFWD_Witch_SetHarasser = new GlobalForward("L4D_OnWitchSetHarasser", ET_Event, Param_Cell, Param_Cell);
g_hFWD_Tank_EnterStasis_Post = new GlobalForward("L4D_OnEnterStasis", ET_Event, Param_Cell);
g_hFWD_Tank_LeaveStasis_Post = new GlobalForward("L4D_OnLeaveStasis", ET_Event, Param_Cell);
Expand Down
22 changes: 13 additions & 9 deletions addons/sourcemod/scripting/l4dd/left4dhooks_changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
1.140 (03-Dec-2023)
- Added forwards "L4D_OnIncapacitated", "L4D_OnIncapacitated_Post" and "L4D_OnIncapacitated_PostHandled" to trigger when a Survivor is incapacitated. Requested by "HarryPotter".
- Fixed forwards "L4D2_OnPounceOrLeapStumble*" in L4D1 from throwing errors. Thanks to "HarryPotter" for reporting.
- Increased the Spitter Acid bug fix volume. Thanks to "Marttt" and "KadabraZz" for reporting.

- Updated: Plugin and test plugin.
- Updated: "/scripting/gamedata/left4dhooks.l4d1.txt" GaneData file.
- Updated: "/scripting/gamedata/left4dhooks.l4d2.txt" GaneData file.
- Updated: "/scripting/include/left4dhooks.inc" Include file.
- Updated: "/scripting/l4dd/l4dd_forwards.sp" project file.
- Updated: "/scripting/l4dd/l4dd_natives.sp" project file.
- Updated: "/scripting/l4dd/l4dd_setup.sp" project file.

1.139 (25-Oct-2023)
- Added new attribute "L4D2IWA_WeaponType" for use with the "L4D2_GetIntWeaponAttribute" native. Thanks to "Forgetest" for providing.
- Added new enum "WeaponType" for use with the "L4D2IWA_WeaponType" attribute. Thanks to "Forgetest" for providing.
Expand All @@ -14,15 +27,6 @@
- Fixed native "L4D2_IsRealismMode" from returning values other than 0 and 1. Thanks to "Eyal282" for reporting.
- Fixed forward "L4D2_OnFindScavengeItem*" to stop passing invalid entities. Thanks to "kochiurun119" for reporting.

- Updated: Plugin and test plugin.
- Updated: "/scripting/gamedata/left4dhooks.l4d1.txt" GaneData file.
- Updated: "/scripting/gamedata/left4dhooks.l4d2.txt" GaneData file.
- Updated: "/scripting/include/left4dhooks.inc" Include file.
- Updated: "/scripting/l4dd/l4dd_forwards.sp" project file.
- Updated: "/scripting/l4dd/l4dd_gamedata.sp" project file.
- Updated: "/scripting/l4dd/l4dd_natives.sp" project file.
- Updated: "/scripting/l4dd/l4dd_setup.sp" project file.

1.138 (25-Sep-2023)
- Fixed the "L4D2_CGasCan_EventKilled*" forwards not triggering when a gascan had not been picked up. Thanks to "Mystik Spiral" for reporting.

Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/left4dhooks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@



#define PLUGIN_VERSION "1.139"
#define PLUGIN_VERLONG 1139
#define PLUGIN_VERSION "1.140"
#define PLUGIN_VERLONG 1140

#define DEBUG 0
// #define DEBUG 1 // Prints addresses + detour info (only use for debugging, slows server down).
Expand Down
44 changes: 43 additions & 1 deletion addons/sourcemod/scripting/left4dhooks_test.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@



#define PLUGIN_VERSION "1.139"
#define PLUGIN_VERSION "1.140"

/*=======================================================================================
Plugin Info:
Expand Down Expand Up @@ -5606,6 +5606,48 @@ public void L4D_OnPlayerCough_PostHandled(int client, int attacker)
}
}

public Action L4D_OnIncapacitated(int client, int &inflictor, int &attacker, float &damage, int &damagetype)
{
static int called;
if( called < MAX_CALLS )
{
if( called == 0 ) g_iForwards++;
called++;

ForwardCalled("\"L4D_OnIncapacitated\" %d (%N). Inflictor: (Inf=%d) (Att=%d). Dmg: %f. DmgType: %d", client, client, inflictor, attacker, damage, damagetype);
}

// WORKS - Block player being incapacitated
// return Plugin_Handled;

return Plugin_Continue;
}

public void L4D_OnIncapacitated_Post(int client, int inflictor, int attacker, float damage, int damagetype)
{
static int called;
if( called < MAX_CALLS )
{
if( called == 0 ) g_iForwards++;
called++;

ForwardCalled("\"L4D_OnIncapacitated_Post\" %d (%N). Inflictor: (Inf=%d) (Att=%d). Dmg: %f. DmgType: %d", client, client, inflictor, attacker, damage, damagetype);
}
}

public void L4D_OnIncapacitated_PostHandled(int client, int inflictor, int attacker, float damage, int damagetype)
{
static int called;
if( called < MAX_CALLS )
{
if( called == 0 ) g_iForwards++;
called++;

ForwardCalled("\"L4D_OnIncapacitated_PostHandled\" %d (%N). Inflictor: (Inf=%d) (Att=%d). Dmg: %f. DmgType: %d", client, client, inflictor, attacker, damage, damagetype);
}
}


public void L4D_OnDeathDroppedWeapons(int client, int weapons[6])
{
static int called;
Expand Down

0 comments on commit 4a47a32

Please sign in to comment.