Skip to content
Merged
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
27 changes: 21 additions & 6 deletions EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ namespace Exiled.Events.Patches.Events.Map
#pragma warning disable SA1402 // File may only contain a single type

using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

using Exiled.API.Features;
using Exiled.API.Features.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Map;
Expand Down Expand Up @@ -87,15 +85,32 @@ internal static class SpawningRoomConnectorFix
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);
Label skip = generator.DefineLabel();

// steal the code to put it later in the code:
// RoomConnectorSpawnpointBase.SetupAllRoomConnectors();
// ServerEvents.OnMapGenerated(new MapGeneratedEventArgs(SeedSynchronizer.Seed));
const int lengthOfCodeToMove = 4;
int index = newInstructions.FindIndex(i => i.Calls(Method(typeof(RoomConnectorSpawnpointBase), nameof(RoomConnectorSpawnpointBase.SetupAllRoomConnectors))));
List<Label> labels = newInstructions[index].ExtractLabels();
List<CodeInstruction> codeInstructionsCopy = newInstructions.GetRange(index, 4);
newInstructions.RemoveRange(index, 4);
List<CodeInstruction> codeInstructionsCopy = newInstructions.GetRange(index, lengthOfCodeToMove);
newInstructions.RemoveRange(index, lengthOfCodeToMove);
newInstructions[index].labels.AddRange(labels);

index = newInstructions.FindIndex(x => x.OperandIs(Field(typeof(SeedSynchronizer), nameof(SeedSynchronizer.MapGenerated))));
newInstructions.InsertRange(index, codeInstructionsCopy);
index = newInstructions.FindIndex(x => x.OperandIs(Field(typeof(SeedSynchronizer), nameof(SeedSynchronizer.OnGenerationStage))));
newInstructions[index].labels.Add(skip);
const int lengthOfCodeAdded = 3;
newInstructions.InsertRange(index, new List<CodeInstruction>()
{
// if (mapGenerationPhase == MapGenerationPhase.ParentRoomRegistration)
// // The moved code
new(OpCodes.Ldloc_2),
new(OpCodes.Ldc_I4_1),
new(OpCodes.Bne_Un_S, skip),
});

newInstructions.InsertRange(index + lengthOfCodeAdded, codeInstructionsCopy);

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

Expand Down
Loading