@@ -53,26 +53,31 @@ public async Task TakeDamageListenersAreFired()
5353
5454 var postCallback = FunctionReference . Create ( ( IntPtr entityPtr , IntPtr damageInfoPtr ) => { postCallCount ++ ; } ) ;
5555
56- NativeAPI . AddListener ( "OnEntityTakeDamagePre" , preCallback ) ;
57- NativeAPI . AddListener ( "OnEntityTakeDamagePost" , postCallback ) ;
56+ try
57+ {
58+ NativeAPI . AddListener ( "OnEntityTakeDamagePre" , preCallback ) ;
59+ NativeAPI . AddListener ( "OnEntityTakeDamagePost" , postCallback ) ;
5860
59- // Spawn a bot and deal damage to it
60- NativeAPI . IssueServerCommand ( "bot_kick" ) ;
61- NativeAPI . IssueServerCommand ( "bot_add" ) ;
62- await WaitOneFrame ( ) ;
61+ // Spawn a bot and deal damage to it
62+ NativeAPI . IssueServerCommand ( "bot_kick" ) ;
63+ NativeAPI . IssueServerCommand ( "bot_add" ) ;
64+ await WaitOneFrame ( ) ;
6365
64- var player = Utilities . GetPlayers ( ) . FirstOrDefault ( p => p . IsBot ) ;
65- var playerHealth = player . PlayerPawn . Value . Health ;
66- DealDamageFunc ( player , player , 10 ) ;
66+ var player = Utilities . GetPlayers ( ) . FirstOrDefault ( p => p . IsBot ) ;
67+ var playerHealth = player . PlayerPawn . Value . Health ;
68+ DealDamageFunc ( player , player , 10 ) ;
6769
68- await WaitOneFrame ( ) ;
69- Assert . Equal ( player . PlayerPawn . Value . Health , playerHealth - 10 ) ;
70+ await WaitOneFrame ( ) ;
71+ Assert . Equal ( playerHealth - 10 , player . PlayerPawn . Value . Health ) ;
7072
71- Assert . Equal ( 1 , preCallCount ) ;
72- Assert . Equal ( 1 , postCallCount ) ;
73-
74- NativeAPI . RemoveListener ( "OnEntityTakeDamagePre" , preCallback ) ;
75- NativeAPI . RemoveListener ( "OnEntityTakeDamagePost" , postCallback ) ;
73+ Assert . Equal ( 1 , preCallCount ) ;
74+ Assert . Equal ( 1 , postCallCount ) ;
75+ }
76+ finally
77+ {
78+ NativeAPI . RemoveListener ( "OnEntityTakeDamagePre" , preCallback ) ;
79+ NativeAPI . RemoveListener ( "OnEntityTakeDamagePost" , postCallback ) ;
80+ }
7681 }
7782
7883 [ Fact ]
@@ -95,28 +100,33 @@ public async Task TakeDamageListenerCanBeCancelled()
95100
96101 Listeners . OnEntityTakeDamagePost postCallback = ( entity , damageInfo , damageResult ) => { postCallCount ++ ; } ;
97102
98- NativeAPI . AddListener ( "OnEntityTakeDamagePre" , preCallback ) ;
99- NativeAPI . AddListener ( "OnEntityTakeDamagePre" , secondCallback ) ;
100- NativeAPI . AddListener ( "OnEntityTakeDamagePost" , postCallback ) ;
101-
102- // Spawn a bot and deal damage to it
103- NativeAPI . IssueServerCommand ( "bot_kick" ) ;
104- NativeAPI . IssueServerCommand ( "bot_add" ) ;
105- await WaitOneFrame ( ) ;
106-
107- var player = Utilities . GetPlayers ( ) . FirstOrDefault ( p => p . IsBot ) ;
108- var playerHealth = player . PlayerPawn . Value . Health ;
109- DealDamageFunc ( player , player , 10 ) ;
110-
111- await WaitOneFrame ( ) ;
112- Assert . Equal ( player . PlayerPawn . Value . Health , playerHealth ) ;
113-
114- Assert . Equal ( 1 , preCallCount ) ;
115- Assert . Equal ( 0 , postCallCount ) ;
116-
117- NativeAPI . RemoveListener ( "OnEntityTakeDamagePre" , preCallback ) ;
118- NativeAPI . RemoveListener ( "OnEntityTakeDamagePre" , secondCallback ) ;
119- NativeAPI . RemoveListener ( "OnEntityTakeDamagePost" , postCallback ) ;
103+ try
104+ {
105+ NativeAPI . AddListener ( "OnEntityTakeDamagePre" , preCallback ) ;
106+ NativeAPI . AddListener ( "OnEntityTakeDamagePre" , secondCallback ) ;
107+ NativeAPI . AddListener ( "OnEntityTakeDamagePost" , postCallback ) ;
108+
109+ // Spawn a bot and deal damage to it
110+ NativeAPI . IssueServerCommand ( "bot_kick" ) ;
111+ NativeAPI . IssueServerCommand ( "bot_add" ) ;
112+ await WaitOneFrame ( ) ;
113+
114+ var player = Utilities . GetPlayers ( ) . FirstOrDefault ( p => p . IsBot ) ;
115+ var playerHealth = player . PlayerPawn . Value . Health ;
116+ DealDamageFunc ( player , player , 10 ) ;
117+
118+ await WaitOneFrame ( ) ;
119+ Assert . Equal ( player . PlayerPawn . Value . Health , playerHealth ) ;
120+
121+ Assert . Equal ( 1 , preCallCount ) ;
122+ Assert . Equal ( 0 , postCallCount ) ;
123+ }
124+ finally
125+ {
126+ NativeAPI . RemoveListener ( "OnEntityTakeDamagePre" , preCallback ) ;
127+ NativeAPI . RemoveListener ( "OnEntityTakeDamagePre" , secondCallback ) ;
128+ NativeAPI . RemoveListener ( "OnEntityTakeDamagePost" , postCallback ) ;
129+ }
120130 }
121131
122132 private static void DealDamageFunc ( CCSPlayerController attacker , CCSPlayerController victim , int damage ,
0 commit comments