Skip to content

Commit 5e3427e

Browse files
authored
Merge branch 'dev' into IScp330Event
2 parents 9153b43 + 3ffe156 commit 5e3427e

File tree

1 file changed

+7
-80
lines changed

1 file changed

+7
-80
lines changed

EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs

Lines changed: 7 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@ namespace Exiled.Events.Patches.Events.Scp330
1010
using System.Collections.Generic;
1111
using System.Reflection.Emit;
1212

13-
using API.Features.Pools;
14-
15-
using CustomPlayerEffects;
13+
using Exiled.API.Features.Pools;
1614
using Exiled.Events.Attributes;
1715
using Exiled.Events.EventArgs.Scp330;
1816
using Exiled.Events.Handlers;
19-
2017
using HarmonyLib;
21-
2218
using Interactables.Interobjects;
23-
24-
using InventorySystem;
2519
using InventorySystem.Items.Usables.Scp330;
2620

2721
using static HarmonyLib.AccessTools;
@@ -79,69 +73,25 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
7973
new(OpCodes.Brfalse, returnLabel),
8074
});
8175

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-
10776
// This is to find the location of RpcMakeSound to remove the original code and add a new sever logic structure (Start point)
10877
int addShouldSeverOffset = 1;
10978
int addShouldSeverIndex = newInstructions.FindLastIndex(
11079
instruction => instruction.Calls(Method(typeof(Scp330Interobject), nameof(Scp330Interobject.RpcMakeSound)))) + addShouldSeverOffset;
11180

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;
12284

12385
newInstructions.InsertRange(
12486
addShouldSeverIndex,
125-
new CodeInstruction[]
87+
new[]
12688
{
12789
// if (!ev.ShouldSever)
12890
// goto shouldNotSever;
129-
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex).WithLabels(originalLabel),
91+
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex),
13092
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldSever))),
13193
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),
14595
});
14696

14797
// 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
157107

158108
ListPool<CodeInstruction>.Pool.Return(newInstructions);
159109
}
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-
}
183110
}
184111
}

0 commit comments

Comments
 (0)