1
+ // -----------------------------------------------------------------------
2
+ // <copyright file="PlacedAmnesticCloud.cs" company="Exiled Team">
3
+ // Copyright (c) Exiled Team. All rights reserved.
4
+ // Licensed under the CC BY-SA 3.0 license.
5
+ // </copyright>
6
+ // -----------------------------------------------------------------------
7
+
8
+ namespace Exiled . Events . Patches . Events . Scp939
9
+ {
10
+ using System . Collections . Generic ;
11
+ using System . Reflection . Emit ;
12
+
13
+ using Exiled . API . Features . Pools ;
14
+ using Exiled . Events . Attributes ;
15
+ using Exiled . Events . EventArgs . Scp939 ;
16
+ using Exiled . Events . Handlers ;
17
+ using HarmonyLib ;
18
+ using PlayerRoles . PlayableScps . Scp939 ;
19
+
20
+ using static HarmonyLib . AccessTools ;
21
+
22
+ /// <summary>
23
+ /// Patches <see cref="Scp939AmnesticCloudAbility.OnStateEnabled" />
24
+ /// to add the <see cref="Scp939.PlacedAmnesticCloud" /> event.
25
+ /// </summary>
26
+ [ EventPatch ( typeof ( Scp939 ) , nameof ( Scp939 . PlacedAmnesticCloud ) ) ]
27
+ [ HarmonyPatch ( typeof ( Scp939AmnesticCloudAbility ) , nameof ( Scp939AmnesticCloudAbility . OnStateEnabled ) ) ]
28
+ internal static class PlacedAmnesticCloud
29
+ {
30
+ private static IEnumerable < CodeInstruction > Transpiler ( IEnumerable < CodeInstruction > instructions , ILGenerator generator )
31
+ {
32
+ List < CodeInstruction > newInstructions = ListPool < CodeInstruction > . Pool . Get ( instructions ) ;
33
+
34
+ LocalBuilder cloud = generator . DeclareLocal ( typeof ( Scp939AmnesticCloudInstance ) ) ;
35
+
36
+ const int offset = - 2 ;
37
+ int index = newInstructions . FindIndex ( x => x . opcode == OpCodes . Callvirt && x . OperandIs ( Method ( typeof ( Scp939AmnesticCloudInstance ) , nameof ( Scp939AmnesticCloudInstance . ServerSetup ) ) ) ) + offset ;
38
+
39
+ newInstructions . InsertRange (
40
+ index ,
41
+ new [ ]
42
+ {
43
+ // Scp939AmnesticCloudInstance cloud = Object.Instantiate<Scp939AmnesticCloudInstance>(this._instancePrefab)
44
+ new CodeInstruction ( OpCodes . Dup ) ,
45
+ new CodeInstruction ( OpCodes . Stloc_S , cloud ) ,
46
+ } ) ;
47
+
48
+ index = newInstructions . FindLastIndex ( x => x . opcode == OpCodes . Ret ) ;
49
+
50
+ // Scp939.OnPlacedAmnesticCloud(new PlacedAmnesticCloudEventArgs(this.Owner, cloud));
51
+ newInstructions . InsertRange (
52
+ index ,
53
+ new [ ]
54
+ {
55
+ // this.Owner
56
+ new CodeInstruction ( OpCodes . Ldarg_0 ) ,
57
+ new ( OpCodes . Callvirt , PropertyGetter ( typeof ( Scp939AmnesticCloudAbility ) , nameof ( Scp939AmnesticCloudAbility . Owner ) ) ) ,
58
+
59
+ // cloud
60
+ new CodeInstruction ( OpCodes . Ldloc_S , cloud ) ,
61
+
62
+ // Scp939.OnPlacedAmnesticCloud(new PlacedAmnesticCloudEventArgs(this.Owner, cloud));
63
+ new ( OpCodes . Newobj , GetDeclaredConstructors ( typeof ( PlacedAmnesticCloudEventArgs ) ) [ 0 ] ) ,
64
+ new ( OpCodes . Call , Method ( typeof ( Scp939 ) , nameof ( Scp939 . OnPlacedAmnesticCloud ) ) ) ,
65
+ } ) ;
66
+
67
+ for ( int z = 0 ; z < newInstructions . Count ; z ++ )
68
+ yield return newInstructions [ z ] ;
69
+
70
+ ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
71
+ }
72
+ }
73
+ }
0 commit comments