Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IRacle1 committed Aug 12, 2024
1 parent a3595e1 commit 3716a71
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions EXILED/Exiled.Events/Patches/Events/Map/SpawningItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
LocalBuilder ev = generator.DeclareLocal(typeof(SpawningItemEventArgs));

Label skip = generator.DefineLabel();
Label skipdoorSpawn = generator.DefineLabel();
Label doorSpawn = generator.DefineLabel();
Label returnLabel = generator.DefineLabel();

Expand Down Expand Up @@ -68,7 +67,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Ldc_I4_0).MoveLabelsFrom(newInstructions[lastIndex]),
new(OpCodes.Stloc_S, initiallySpawn.LocalIndex),

// door = doorNametagExtension.TargetDoor
// door = nametagExtension.TargetDoor
new(OpCodes.Ldloc_2),
new(OpCodes.Ldfld, Field(typeof(DoorVariantExtension), nameof(DoorVariantExtension.TargetDoor))),
new(OpCodes.Stloc_S, door.LocalIndex),
Expand Down Expand Up @@ -100,30 +99,30 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// goto doorSpawn
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningItemEventArgs), nameof(SpawningItemEventArgs.ShouldInitiallySpawn))),
new(OpCodes.Brtrue_S, skipdoorSpawn),
new(OpCodes.Ldc_I4_0),
new(OpCodes.Ceq),

new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningItemEventArgs), nameof(SpawningItemEventArgs.TriggerDoor))),
new(OpCodes.Brtrue_S, doorSpawn),
new(OpCodes.Ldnull),
new(OpCodes.Cgt_Un),

new CodeInstruction(OpCodes.Nop).WithLabels(skipdoorSpawn),
new(OpCodes.And),
new(OpCodes.Brtrue_S, doorSpawn),
});

lastIndex = newInstructions.FindLastIndex(instruction => instruction.IsLdarg(0));

newInstructions[lastIndex].labels.Add(doorSpawn);

// Replace
// "base.RegisterUnspawnedObject(doorNametagExtension.TargetDoor, itemPickupBase.gameObject);"
// with "base.RegisterUnspawnedObject(ev.Door.Base, itemPickupBase.gameObject);"
offset = -1;
index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ldfld) + offset;

newInstructions.RemoveRange(index, 2);

newInstructions.InsertRange(index, new[]
{
// ev.Door.Base
// door = ev.Door.Base
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningItemEventArgs), nameof(SpawningItemEventArgs.TriggerDoor))),
new(OpCodes.Callvirt, PropertyGetter(typeof(Door), nameof(Door.Base))),
Expand Down

0 comments on commit 3716a71

Please sign in to comment.