1+ #pragma semicolon 1
2+ #pragma newdecls required
3+
4+ #include <sourcemod>
5+ #include <dhooks>
6+ #include <left4dhooks>
7+
8+ #define PLUGIN_VERSION " 1.0"
9+
10+ public Plugin myinfo =
11+ {
12+ name = " [L4D & 2] Fix Shove Duration" ,
13+ author = " Forgetest" ,
14+ description = " Fix SI getting shoved by \" nothing\" ." ,
15+ version = PLUGIN_VERSION ,
16+ url = " https://github.com/Target5150/MoYu_Server_Stupid_Plugins"
17+ };
18+
19+ #define GAMEDATA_FILE " l4d_fix_shove_duration"
20+ #define KEY_FUNCTION " CTerrorPlayer::OnShovedByLunge"
21+
22+ ConVar z_gun_swing_duration ;
23+
24+ public void OnPluginStart ()
25+ {
26+ GameData conf = new GameData (GAMEDATA_FILE );
27+ if ( ! conf )
28+ SetFailState (" Missing gamedata \" " ...GAMEDATA_FILE ..." \" " );
29+
30+ DynamicDetour hDetour = DynamicDetour .FromConf (conf , KEY_FUNCTION );
31+ if ( ! hDetour )
32+ SetFailState (" Missing detour setup \" " ...KEY_FUNCTION ..." \" " );
33+ if ( ! hDetour .Enable (Hook_Pre , DTR_OnShovedByLunge ) || ! hDetour .Enable (Hook_Post , DTR_OnShovedByLunge_Post ) )
34+ SetFailState (" Failed to detour \" " ...KEY_FUNCTION ..." \" " );
35+
36+ delete hDetour ;
37+ delete conf ;
38+
39+ z_gun_swing_duration = FindConVar (" z_gun_swing_duration" );
40+ }
41+
42+ /*
43+ bool CTerrorPlayer::IsShoving()
44+ {
45+ if ( !m_shovingTimer.HasStarted() )
46+ return false;
47+
48+ return m_shovingTimer.IsLessThen( 1.0 );
49+ }
50+ */
51+
52+ MRESReturn DTR_OnShovedByLunge (DHookReturn hReturn , DHookParam hParams )
53+ {
54+ int client = hParams .Get (1 );
55+ ITimer_OffsetTimestamp (GetShovingTimer (client ), z_gun_swing_duration .FloatValue - 1.0 );
56+
57+ return MRES_Ignored ;
58+ }
59+
60+ MRESReturn DTR_OnShovedByLunge_Post (DHookReturn hReturn , DHookParam hParams )
61+ {
62+ int client = hParams .Get (1 );
63+ ITimer_OffsetTimestamp (GetShovingTimer (client ), 1.0 - z_gun_swing_duration .FloatValue );
64+
65+ return MRES_Ignored ;
66+ }
67+
68+ public Action L4D2_OnJockeyRide (int victim , int attacker )
69+ {
70+ ITimer_OffsetTimestamp (GetShovingTimer (victim ), z_gun_swing_duration .FloatValue - 1.0 );
71+
72+ return Plugin_Continue ;
73+ }
74+
75+ public void L4D2_OnJockeyRide_Post (int victim , int attacker )
76+ {
77+ ITimer_OffsetTimestamp (GetShovingTimer (victim ), 1.0 - z_gun_swing_duration .FloatValue );
78+ }
79+
80+ void ITimer_OffsetTimestamp (IntervalTimer timer , float offset )
81+ {
82+ if ( ITimer_HasStarted (timer ) )
83+ {
84+ float timestamp = __ITimer_GetTimestamp (timer );
85+ ITimer_SetTimestamp (timer , timestamp + offset );
86+ }
87+ }
88+
89+ // wait for left4dhooks update to fix this one
90+ /*
91+ any Direct_ITimer_GetTimestamp(Handle plugin, int numParams) // Native "ITimer_GetTimestamp"
92+ {
93+ CountdownTimer timer = GetNativeCell(1); // CountdownTimer
94+ return Stock_CTimer_GetTimestamp(timer); // ctimer
95+ }
96+ */
97+ float __ITimer_GetTimestamp (IntervalTimer timer )
98+ {
99+ return LoadFromAddress (view_as <Address >(timer ) + view_as <Address >(4 ), NumberType_Int32 );
100+ }
101+
102+ IntervalTimer GetShovingTimer (int client )
103+ {
104+ static int s_iOffs_ShovingTimer = - 1 ;
105+ if ( s_iOffs_ShovingTimer == - 1 )
106+ s_iOffs_ShovingTimer = FindSendPropInfo (" CTerrorPlayer" , " m_customAbility" ) + 164 ;
107+
108+ return view_as <IntervalTimer >(GetEntityAddress (client ) + view_as <Address >(s_iOffs_ShovingTimer ));
109+ }
0 commit comments