@@ -10,18 +10,12 @@ namespace Exiled.Events.Patches.Events.Scp330
10
10
using System . Collections . Generic ;
11
11
using System . Reflection . Emit ;
12
12
13
- using API . Features . Pools ;
14
-
15
- using CustomPlayerEffects ;
13
+ using Exiled . API . Features . Pools ;
16
14
using Exiled . Events . Attributes ;
17
15
using Exiled . Events . EventArgs . Scp330 ;
18
16
using Exiled . Events . Handlers ;
19
-
20
17
using HarmonyLib ;
21
-
22
18
using Interactables . Interobjects ;
23
-
24
- using InventorySystem ;
25
19
using InventorySystem . Items . Usables . Scp330 ;
26
20
27
21
using static HarmonyLib . AccessTools ;
@@ -79,69 +73,25 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
79
73
new ( OpCodes . Brfalse , returnLabel ) ,
80
74
} ) ;
81
75
82
- // Logic to find the only ServerProcessPickup and replace with our own.
83
- int removeServerProcessOffset = - 2 ;
84
- int removeServerProcessIndex = newInstructions . FindLastIndex (
85
- instruction => instruction . Calls ( Method ( typeof ( Scp330Bag ) , nameof ( Scp330Bag . ServerProcessPickup ) ) ) ) + removeServerProcessOffset ;
86
-
87
- newInstructions . RemoveRange ( removeServerProcessIndex , 3 ) ;
88
-
89
- // Replace NW server process logic.
90
- newInstructions . InsertRange (
91
- removeServerProcessIndex ,
92
- new [ ]
93
- {
94
- // ldarg.1 is already in the stack
95
-
96
- // ev.Candy
97
- new CodeInstruction ( OpCodes . Ldloc , ev ) ,
98
- new CodeInstruction ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . Candy ) ) ) ,
99
-
100
- // bag
101
- new CodeInstruction ( OpCodes . Ldloca_S , 3 ) ,
102
-
103
- // ServerProcessPickup(ReferenceHub, CandyKindID, ref Scp330Bag)
104
- new CodeInstruction ( OpCodes . Call , Method ( typeof ( InteractingScp330 ) , nameof ( ServerProcessPickup ) , new [ ] { typeof ( ReferenceHub ) , typeof ( CandyKindID ) , typeof ( Scp330Bag ) . MakeByRefType ( ) } ) ) ,
105
- } ) ;
106
-
107
76
// This is to find the location of RpcMakeSound to remove the original code and add a new sever logic structure (Start point)
108
77
int addShouldSeverOffset = 1 ;
109
78
int addShouldSeverIndex = newInstructions . FindLastIndex (
110
79
instruction => instruction . Calls ( Method ( typeof ( Scp330Interobject ) , nameof ( Scp330Interobject . RpcMakeSound ) ) ) ) + addShouldSeverOffset ;
111
80
112
- // This is to find the location of the next return (End point)
113
- int includeSameLine = 1 ;
114
- int nextReturn = newInstructions . FindIndex ( addShouldSeverIndex , instruction => instruction . opcode == OpCodes . Ret ) + includeSameLine ;
115
- Label originalLabel = newInstructions [ addShouldSeverIndex ] . ExtractLabels ( ) [ 0 ] ;
116
-
117
- // Remove original code from after RpcMakeSound to next return and then fully replace it.
118
- newInstructions . RemoveRange ( addShouldSeverIndex , nextReturn - addShouldSeverIndex ) ;
119
-
120
- addShouldSeverIndex = newInstructions . FindLastIndex (
121
- instruction => instruction . Calls ( Method ( typeof ( Scp330Interobject ) , nameof ( Scp330Interobject . RpcMakeSound ) ) ) ) + addShouldSeverOffset ;
81
+ int serverEffectLocationStart = - 1 ;
82
+ int enableEffect = newInstructions . FindLastIndex (
83
+ instruction => instruction . LoadsField ( Field ( typeof ( PlayerEffectsController ) , nameof ( ReferenceHub . playerEffectsController ) ) ) ) + serverEffectLocationStart ;
122
84
123
85
newInstructions . InsertRange (
124
86
addShouldSeverIndex ,
125
- new CodeInstruction [ ]
87
+ new [ ]
126
88
{
127
89
// if (!ev.ShouldSever)
128
90
// goto shouldNotSever;
129
- new CodeInstruction ( OpCodes . Ldloc , ev . LocalIndex ) . WithLabels ( originalLabel ) ,
91
+ new CodeInstruction ( OpCodes . Ldloc , ev . LocalIndex ) ,
130
92
new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . ShouldSever ) ) ) ,
131
93
new ( OpCodes . Brfalse , shouldNotSever ) ,
132
-
133
- // ev.Player.EnableEffect("SevereHands", 1, 0f, false)
134
- new ( OpCodes . Ldloc , ev . LocalIndex ) ,
135
- new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . Player ) ) ) ,
136
- new ( OpCodes . Ldstr , nameof ( SeveredHands ) ) ,
137
- new ( OpCodes . Ldc_I4_1 ) ,
138
- new ( OpCodes . Ldc_R4 , 0f ) ,
139
- new ( OpCodes . Ldc_I4_0 ) ,
140
- new ( OpCodes . Callvirt , Method ( typeof ( Player ) , nameof ( Player . EnableEffect ) , new [ ] { typeof ( string ) , typeof ( byte ) , typeof ( float ) , typeof ( bool ) } ) ) ,
141
- new ( OpCodes . Pop ) ,
142
-
143
- // return;
144
- new ( OpCodes . Ret ) ,
94
+ new ( OpCodes . Br , enableEffect ) ,
145
95
} ) ;
146
96
147
97
// This will let us jump to the taken candies code and lock until ldarg_0, meaning we allow base game logic handle candy adding.
@@ -157,28 +107,5 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
157
107
158
108
ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
159
109
}
160
-
161
- private static bool ServerProcessPickup ( ReferenceHub player , CandyKindID candy , out Scp330Bag bag )
162
- {
163
- if ( ! Scp330Bag . TryGetBag ( player , out bag ) )
164
- {
165
- player . inventory . ServerAddItem ( ItemType . SCP330 ) ;
166
-
167
- if ( ! Scp330Bag . TryGetBag ( player , out bag ) )
168
- return false ;
169
-
170
- bag . Candies = new List < CandyKindID > { candy } ;
171
- bag . ServerRefreshBag ( ) ;
172
-
173
- return true ;
174
- }
175
-
176
- bool result = bag . TryAddSpecific ( candy ) ;
177
-
178
- if ( bag . AcquisitionAlreadyReceived )
179
- bag . ServerRefreshBag ( ) ;
180
-
181
- return result ;
182
- }
183
110
}
184
111
}
0 commit comments