@@ -46,105 +46,57 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
4646 // Remove original "No scp can touch" logic.
4747 newInstructions . RemoveRange ( 0 , 3 ) ;
4848
49- // Find ServerProcessPickup, insert before it.
50- int offset = - 3 ;
49+ int offset = 2 ;
5150 int index = newInstructions . FindLastIndex (
52- instruction => instruction . Calls ( Method ( typeof ( Scp330Bag ) , nameof ( Scp330Bag . ServerProcessPickup ) ) ) ) + offset ;
51+ instruction => instruction . Calls ( Method ( typeof ( Scp330Candies ) , nameof ( Scp330Candies . GetRandom ) ) ) ) + offset ;
5352
5453 newInstructions . InsertRange (
5554 index ,
5655 new [ ]
5756 {
58- // Player.Get(ply)
59- new CodeInstruction ( OpCodes . Ldarg_1 ) . MoveLabelsFrom ( newInstructions [ index ] ) ,
60- new ( OpCodes . Call , Method ( typeof ( Player ) , nameof ( Player . Get ) , new [ ] { typeof ( ReferenceHub ) } ) ) ,
57+ // ply
58+ new CodeInstruction ( OpCodes . Ldarg_1 ) ,
6159
62- // num2
60+ // usage
6361 new ( OpCodes . Ldloc_1 ) ,
6462
65- // InteractingScp330EventArgs ev = new(Player, int)
63+ // shouldPlaySound
64+ new ( OpCodes . Ldloc_2 ) ,
65+
66+ // shouldSever
67+ new ( OpCodes . Ldloc_3 ) ,
68+
69+ // candyKindID
70+ new ( OpCodes . Ldloc_S , 4 ) ,
71+
72+ // InteractingScp330EventArgs ev = new(ReferenceHub, int, bool, bool, CandyKindID)
6673 new ( OpCodes . Newobj , GetDeclaredConstructors ( typeof ( InteractingScp330EventArgs ) ) [ 0 ] ) ,
6774 new ( OpCodes . Dup ) ,
6875 new ( OpCodes . Dup ) ,
6976 new ( OpCodes . Stloc , ev . LocalIndex ) ,
7077
7178 // Scp330.OnInteractingScp330(ev)
7279 new ( OpCodes . Call , Method ( typeof ( Handlers . Scp330 ) , nameof ( Handlers . Scp330 . OnInteractingScp330 ) ) ) ,
80+ new ( OpCodes . Dup ) ,
81+ new ( OpCodes . Dup ) ,
82+ new ( OpCodes . Dup ) ,
7383
74- // if (!ev.IsAllowed)
75- // return;
76- new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . IsAllowed ) ) ) ,
77- new ( OpCodes . Brfalse , returnLabel ) ,
78-
79- // ldarg.1 to player
80- new ( OpCodes . Ldarg_1 ) ,
81-
82- // ev.Candy
83- new ( OpCodes . Ldloc , ev . LocalIndex ) ,
84- new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . Candy ) ) ) ,
85-
86- // bag
87- new ( OpCodes . Ldloca_S , 2 ) ,
88-
89- // ServerProcessPickup(ReferenceHub, CandyKindID, Scp330Bag)
90- new CodeInstruction ( OpCodes . Call , Method ( typeof ( InteractingScp330 ) , nameof ( ServerProcessPickup ) , new [ ] { typeof ( ReferenceHub ) , typeof ( CandyKindID ) , typeof ( Scp330Bag ) . MakeByRefType ( ) } ) ) ,
91- } ) ;
92-
93- int remove_offset = - 3 ;
94- int remove_index = newInstructions . FindLastIndex (
95- instruction => instruction . Calls ( Method ( typeof ( Scp330Bag ) , nameof ( Scp330Bag . ServerProcessPickup ) ) ) ) + remove_offset ;
96-
97- // Remove original add candy logic
98- newInstructions . RemoveRange ( remove_index , 4 ) ;
99-
100- /* next code will used to override sound rpc check by EXILED
101- * old:
102- * if (args.PlaySound)
103- * new:
104- * if (args.PlaySound | ev.PlaySound)
105- */
106- offset = 1 ;
107- index = newInstructions . FindLastIndex (
108- instruction => instruction . Calls ( PropertyGetter ( typeof ( LabApi . Events . Arguments . PlayerEvents . PlayerInteractingScp330EventArgs ) , nameof ( LabApi . Events . Arguments . PlayerEvents . PlayerInteractingScp330EventArgs . PlaySound ) ) ) ) + offset ;
109- newInstructions . InsertRange (
110- index ,
111- new [ ]
112- {
113- // load ev.ShouldPlaySound and or operation with nw property.
114- new CodeInstruction ( OpCodes . Ldloc_S , ev . LocalIndex ) ,
84+ // shouldPlaySound = ev.ShouldPlaySound
11585 new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . ShouldPlaySound ) ) ) ,
116- new ( OpCodes . Or ) ,
117- } ) ;
118- /* next code will used to override Sever check by EXILED
119- * old:
120- * if (args.AllowPunishment && uses >= 2)
121- * new:
122- * if (args.AllowPunishment && ev.ShouldSever)
123- */
86+ new ( OpCodes . Stloc , 2 ) ,
12487
125- // set `notSeverLabel`
126- offset = - 1 ;
127- index = newInstructions . FindLastIndex (
128- instruction => instruction . LoadsField ( Field ( typeof ( Scp330Interobject ) , nameof ( Scp330Interobject . _previousUses ) ) ) ) + offset ;
129-
130- Label notSeverLabel = newInstructions [ index ] . labels [ 0 ] ;
131-
132- offset = 2 ;
133- index = newInstructions . FindLastIndex (
134- instruction => instruction . Calls ( PropertyGetter ( typeof ( LabApi . Events . Arguments . PlayerEvents . PlayerInteractingScp330EventArgs ) , nameof ( LabApi . Events . Arguments . PlayerEvents . PlayerInteractingScp330EventArgs . AllowPunishment ) ) ) ) + offset ;
88+ // shouldSever = ev.ShouldSever
89+ new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . ShouldSever ) ) ) ,
90+ new ( OpCodes . Stloc , 3 ) ,
13591
136- // remove `uses >= 2` check, to override that by ev.ShouldSever
137- newInstructions . RemoveRange ( index , 3 ) ;
92+ // candyKindID = ev.Candy
93+ new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . Candy ) ) ) ,
94+ new ( OpCodes . Stloc_S , 4 ) ,
13895
139- newInstructions . InsertRange (
140- index ,
141- new [ ]
142- {
143- // if (!ev.ShouldSever)
144- // goto shouldNotSever;
145- new CodeInstruction ( OpCodes . Ldloc_S , ev . LocalIndex ) ,
146- new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . ShouldSever ) ) ) ,
147- new ( OpCodes . Brfalse_S , notSeverLabel ) ,
96+ // if (!ev.IsAllowed)
97+ // return;
98+ new ( OpCodes . Callvirt , PropertyGetter ( typeof ( InteractingScp330EventArgs ) , nameof ( InteractingScp330EventArgs . IsAllowed ) ) ) ,
99+ new ( OpCodes . Brfalse , returnLabel ) ,
148100 } ) ;
149101
150102 newInstructions [ newInstructions . Count - 1 ] . labels . Add ( returnLabel ) ;
@@ -154,28 +106,5 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
154106
155107 ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
156108 }
157-
158- private static bool ServerProcessPickup ( ReferenceHub player , CandyKindID candy , out Scp330Bag bag )
159- {
160- if ( ! Scp330Bag . TryGetBag ( player , out bag ) )
161- {
162- player . inventory . ServerAddItem ( ItemType . SCP330 , ItemAddReason . AdminCommand ) ;
163-
164- if ( ! Scp330Bag . TryGetBag ( player , out bag ) )
165- return false ;
166-
167- bag . Candies = new List < CandyKindID > { candy } ;
168- bag . ServerRefreshBag ( ) ;
169-
170- return true ;
171- }
172-
173- bool result = bag . TryAddSpecific ( candy ) ;
174-
175- if ( bag . AcquisitionAlreadyReceived )
176- bag . ServerRefreshBag ( ) ;
177-
178- return result ;
179- }
180109 }
181110}
0 commit comments