Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SrLitch crash fix #111

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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 @@ -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
Loading