Skip to content

Commit

Permalink
Merge remote-tracking branch 'ExMod/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus-QC committed Sep 24, 2024
2 parents 6fc6890 + 879bd8e commit 5b93a20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ public class InteractingLockerEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="lockerChamber">
/// <param name="locker">
/// <inheritdoc cref="InteractingLocker" />
/// </param>
/// <param name="colliderId">
/// <inheritdoc cref="InteractingChamber" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public InteractingLockerEventArgs(Player player, MapGeneration.Distributors.LockerChamber lockerChamber, bool isAllowed)
public InteractingLockerEventArgs(Player player, MapGeneration.Distributors.Locker locker, byte colliderId, bool isAllowed)
{
Player = player;
InteractingChamber = API.Features.Lockers.Chamber.Get(lockerChamber);
InteractingLocker = API.Features.Lockers.Locker.Get(locker);
InteractingChamber = API.Features.Lockers.Chamber.Get(locker.Chambers[colliderId]);
IsAllowed = isAllowed;
}

Expand All @@ -52,7 +56,7 @@ public InteractingLockerEventArgs(Player player, MapGeneration.Distributors.Lock
/// <summary>
/// Gets the locker which is containing <see cref="InteractingChamber"/>.
/// </summary>
public Locker InteractingLocker => InteractingChamber.Locker;
public Locker InteractingLocker { get; }

/// <summary>
/// Gets the interacting chamber.
Expand Down
13 changes: 6 additions & 7 deletions EXILED/Exiled.Events/Patches/Events/Player/InteractingLocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,28 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

const int offset = -9;
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Newobj) + offset;
int index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldloc_0);

newInstructions.InsertRange(
index,
new[]
{
// Player.Get(ply);
new CodeInstruction(OpCodes.Ldarg_1),
new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// this.Chambers[colliderId]
// this
new(OpCodes.Ldarg_0),
new(OpCodes.Ldfld, Field(typeof(Locker), nameof(Locker.Chambers))),

// colliderId
new(OpCodes.Ldarg_2),
new(OpCodes.Ldelem_Ref),

// !flag
new(OpCodes.Ldloc_0),
new(OpCodes.Ldc_I4_0),
new(OpCodes.Ceq),

// InteractingLockerEventArgs ev = new(Player, Locker, LockerChamber, byte, bool)
// InteractingLockerEventArgs ev = new(Player, Locker, byte, bool)
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(InteractingLockerEventArgs))[0]),
new(OpCodes.Dup),

Expand Down

0 comments on commit 5b93a20

Please sign in to comment.