Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public InteractingLockerEventArgs(Player player, MapGeneration.Distributors.Lock
InteractingLocker = Locker.Get(locker);
InteractingChamber = Chamber.Get(locker.Chambers[colliderId]);
IsAllowed = isAllowed;
CanInteract = true;
}

/// <summary>
Expand All @@ -50,10 +51,15 @@ public InteractingLockerEventArgs(Player player, MapGeneration.Distributors.Lock
public Chamber InteractingChamber { get; }

/// <summary>
/// Gets or sets a value indicating whether the player can interact with the locker.
/// Gets or sets a value indicating whether the player can access the locker.
/// </summary>
public bool IsAllowed { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the player can interact with the locker.
/// </summary>
public bool CanInteract { get; set; }

/// <summary>
/// Gets the player who's interacting with the locker.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Exiled.Events.Patches.Events.Player
/// Patches <see cref="DoorVariant.ServerInteract(ReferenceHub, byte)" />.
/// Adds the <see cref="Handlers.Player.InteractingDoor" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Player.InteractingDoor))]
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.InteractingDoor))]
[HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.ServerInteract), typeof(ReferenceHub), typeof(byte))]
internal static class InteractingDoor
{
Expand Down
15 changes: 14 additions & 1 deletion EXILED/Exiled.Events/Patches/Events/Player/InteractingLocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int offset = -9;
LocalBuilder evLocal = generator.DeclareLocal(typeof(InteractingLockerEventArgs));

Label retLabel = generator.DefineLabel();

const int offset = -9;
int index = newInstructions.FindIndex(i => i.opcode == OpCodes.Newobj && (ConstructorInfo)i.operand == GetDeclaredConstructors(typeof(LabApi.Events.Arguments.PlayerEvents.PlayerInteractingLockerEventArgs))[0]) + offset;

newInstructions.InsertRange(
Expand All @@ -58,17 +62,26 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// InteractingLockerEventArgs ev = new(Player, Locker, byte, bool)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(InteractingLockerEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Stloc, evLocal),

// Handlers.Player.OnInteractingLocker(ev)
new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnInteractingLocker))),

// if (!ev.CanInteract) return
new(OpCodes.Ldloc, evLocal),
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingLockerEventArgs), nameof(InteractingLockerEventArgs.CanInteract))),
new(OpCodes.Brfalse_S, retLabel),

// flag = !ev.IsAllowed
new(OpCodes.Ldloc, evLocal),
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingLockerEventArgs), nameof(InteractingLockerEventArgs.IsAllowed))),
new(OpCodes.Ldc_I4_0),
new(OpCodes.Ceq),
new(OpCodes.Stloc_1),
});

newInstructions[newInstructions.Count - 1].labels.Add(retLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

Expand Down