Skip to content

Commit

Permalink
Fixes issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Undid-Iridium committed Aug 9, 2024
1 parent c6ab57b commit fe44106
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Exiled.Events.Patches.Events.Scp330
/// Patches the <see cref="Scp330Interobject.ServerInteract(ReferenceHub, byte)" /> method to add the
/// <see cref="Scp330.InteractingScp330" /> event.
/// </summary>
[EventPatch(typeof(Scp330), nameof(Scp330.InteractingScp330))]
// [EventPatch(typeof(Scp330), nameof(Scp330.InteractingScp330))]
[HarmonyPatch(typeof(Scp330Interobject), nameof(Scp330Interobject.ServerInteract))]
public static class InteractingScp330
{
Expand All @@ -36,6 +36,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

Label shouldNotSever = generator.DefineLabel();
Label returnLabel = generator.DefineLabel();
Label enableEffectLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(InteractingScp330EventArgs));

Expand Down Expand Up @@ -74,14 +75,14 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
});

// This is to find the location of RpcMakeSound to remove the original code and add a new sever logic structure (Start point)
int addShouldSeverOffset = 1;
int addShouldSeverOffset = -1;
int addShouldSeverIndex = newInstructions.FindLastIndex(
instruction => instruction.Calls(Method(typeof(Scp330Interobject), nameof(Scp330Interobject.RpcMakeSound)))) + addShouldSeverOffset;

int serverEffectLocationStart = -1;
int enableEffect = newInstructions.FindLastIndex(
instruction => instruction.LoadsField(Field(typeof(ReferenceHub), nameof(ReferenceHub.playerEffectsController)))) + serverEffectLocationStart;

newInstructions[enableEffect].WithLabels(enableEffectLabel);
newInstructions.InsertRange(
addShouldSeverIndex,
new[]
Expand All @@ -91,7 +92,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldSever))),
new(OpCodes.Brfalse, shouldNotSever),
new(OpCodes.Br, enableEffect),
new(OpCodes.Br, enableEffectLabel),
});

// This will let us jump to the taken candies code and lock until ldarg_0, meaning we allow base game logic handle candy adding.
Expand Down

0 comments on commit fe44106

Please sign in to comment.