@@ -15,8 +15,9 @@ namespace Exiled.Events.Patches.Events.Player
1515 using Exiled . API . Features . Pools ;
1616 using Exiled . Events . Attributes ;
1717 using Exiled . Events . EventArgs . Player ;
18-
1918 using HarmonyLib ;
19+ using LabApi . Events . Arguments . PlayerEvents ;
20+ using LabApi . Events . Handlers ;
2021
2122 using static HarmonyLib . AccessTools ;
2223
@@ -55,8 +56,14 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
5556 // isTriggerable
5657 new CodeInstruction ( OpCodes . Ldloca_S , 3 ) ,
5758
59+ // referenceHub
60+ new CodeInstruction ( OpCodes . Ldloca_S , 4 ) ,
61+
62+ // referenceHub2
63+ new CodeInstruction ( OpCodes . Ldloca_S , 5 ) ,
64+
5865 // TriggeringTesla.TriggeringTeslaEvent(BaseTeslaGate baseTeslaGate, ref bool inIdleRange, ref bool isTriggerable)
59- new CodeInstruction ( OpCodes . Call , Method ( typeof ( TriggeringTesla ) , nameof ( TriggeringTeslaEvent ) , new [ ] { typeof ( BaseTeslaGate ) , typeof ( bool ) . MakeByRefType ( ) , typeof ( bool ) . MakeByRefType ( ) } ) ) ,
66+ new CodeInstruction ( OpCodes . Call , Method ( typeof ( TriggeringTesla ) , nameof ( TriggeringTeslaEvent ) , new [ ] { typeof ( BaseTeslaGate ) , typeof ( bool ) . MakeByRefType ( ) , typeof ( bool ) . MakeByRefType ( ) , typeof ( ReferenceHub ) . MakeByRefType ( ) , typeof ( ReferenceHub ) . MakeByRefType ( ) , } ) ) ,
6067 } ) ;
6168
6269 for ( int z = 0 ; z < newInstructions . Count ; z ++ )
@@ -65,7 +72,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
6572 ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
6673 }
6774
68- private static void TriggeringTeslaEvent ( BaseTeslaGate baseTeslaGate , ref bool inIdleRange , ref bool isTriggerable )
75+ private static void TriggeringTeslaEvent ( BaseTeslaGate baseTeslaGate , ref bool inIdleRange , ref bool isTriggerable , ref ReferenceHub referenceHub , ref ReferenceHub referenceHub2 )
6976 {
7077 TeslaGate teslaGate = TeslaGate . Get ( baseTeslaGate ) ;
7178
@@ -88,11 +95,35 @@ private static void TriggeringTeslaEvent(BaseTeslaGate baseTeslaGate, ref bool i
8895 if ( ! ev . IsAllowed )
8996 continue ;
9097
91- if ( ev . IsTriggerable && ! isTriggerable )
98+ if ( ev . IsTriggerable && ! isTriggerable && ! teslaGate . IsShocking )
99+ {
92100 isTriggerable = ev . IsTriggerable ;
101+ PlayerTriggeringTeslaEventArgs playerTriggeringTeslaEventArgs = new ( player . ReferenceHub , teslaGate . Base ) ;
102+ PlayerEvents . OnTriggeringTesla ( playerTriggeringTeslaEventArgs ) ;
103+ if ( ! playerTriggeringTeslaEventArgs . IsAllowed )
104+ {
105+ isTriggerable = false ;
106+ }
107+ else
108+ {
109+ referenceHub2 = player . ReferenceHub ;
110+ }
111+ }
93112
94113 if ( ev . IsInIdleRange && ! inIdleRange )
114+ {
95115 inIdleRange = ev . IsInIdleRange ;
116+ PlayerIdlingTeslaEventArgs playerIdlingTeslaEventArgs = new ( player . ReferenceHub , teslaGate . Base ) ;
117+ PlayerEvents . OnIdlingTesla ( playerIdlingTeslaEventArgs ) ;
118+ if ( ! playerIdlingTeslaEventArgs . IsAllowed )
119+ {
120+ inIdleRange = false ;
121+ }
122+ else
123+ {
124+ referenceHub = player . ReferenceHub ;
125+ }
126+ }
96127 }
97128 }
98129 }
0 commit comments