From 392653a44e9380a9cd6904bd16f983386173ac1b Mon Sep 17 00:00:00 2001 From: maro Date: Tue, 8 Apr 2025 11:41:00 -0400 Subject: [PATCH 1/7] changing connectors --- .../Map/SpawningRoomConnectorEventArgs.cs | 37 ++++++++++ EXILED/Exiled.Events/Handlers/Map.cs | 11 +++ .../Events/Map/SpawningRoomConnector.cs | 70 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs create mode 100644 EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs diff --git a/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs new file mode 100644 index 0000000000..b4a7e0ec38 --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Map +{ + using Exiled.Events.EventArgs.Interfaces; + using MapGeneration.RoomConnectors; + + /// + /// Contains all information before spawning the connector between rooms. + /// + public class SpawningRoomConnectorEventArgs : IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// The connector type the game is trying to spawn. + public SpawningRoomConnectorEventArgs(SpawnableRoomConnectorType connectorType) + { + ConnectorType = connectorType; + } + + /// + /// Gets or sets which Connector the game should spawn. + /// + public SpawnableRoomConnectorType ConnectorType { get; set; } + + /// + /// Gets or sets a value indicating whether the item can be spawned. + /// + public bool IsAllowed { get; set; } = true; + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Map.cs b/EXILED/Exiled.Events/Handlers/Map.cs index 00d73e9ba0..4db303b36d 100644 --- a/EXILED/Exiled.Events/Handlers/Map.cs +++ b/EXILED/Exiled.Events/Handlers/Map.cs @@ -105,6 +105,11 @@ public static class Map /// public static Event PickupDestroyed { get; set; } = new(); + /// + /// Invoked before a room connector spawns. + /// + public static Event SpawningRoomConnector { get; set; } = new(); + /// /// Invoked before a team vehicle is spawned. /// @@ -221,6 +226,12 @@ public static class Map /// The instance. public static void OnPickupDestroyed(PickupDestroyedEventArgs ev) => PickupDestroyed.InvokeSafely(ev); + /// + /// Invoked before a room connector spawns. + /// + /// The instance. + public static void OnSpawningRoomConnector(SpawningRoomConnectorEventArgs ev) => SpawningRoomConnector.InvokeSafely(ev); + /// /// Invoked before a team vehicle is spawned. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs new file mode 100644 index 0000000000..7bda1a7f85 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Map +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using Exiled.API.Features.Pools; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Map; + using HarmonyLib; + using MapGeneration.RoomConnectors; + using Respawning; + + using static HarmonyLib.AccessTools; + + /// + /// Patches . + /// Adds the event. + /// + [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.SpawningRoomConnector))] + [HarmonyPatch(typeof(RoomConnectorDistributorSettings), nameof(RoomConnectorDistributorSettings.TryGetTemplate))] + internal static class SpawningRoomConnector + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + LocalBuilder ev = generator.DeclareLocal(typeof(SpawningRoomConnectorEventArgs)); + + Label retLabel = generator.DefineLabel(); + + newInstructions.InsertRange(0, new[] + { + // type + new CodeInstruction(OpCodes.Ldarg_0), + + // SpawningRoomConnectorEventArgs ev = new SpawningRoomConnectorEventArgs(type) + new CodeInstruction(OpCodes.Newobj, AccessTools.Constructor(typeof(SpawningRoomConnectorEventArgs), new[] { typeof(SpawnableRoomConnectorType) })), + new CodeInstruction(OpCodes.Dup), + new CodeInstruction(OpCodes.Stloc, ev.LocalIndex), + + // Handlers.Map.OnSpawningRoomConnector(ev); + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Handlers.Map), nameof(Handlers.Map.OnSpawningRoomConnector))), + + // if (!ev.IsAllowed) + // return; + new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), + new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(SpawningRoomConnectorEventArgs), nameof(SpawningRoomConnectorEventArgs.IsAllowed))), + new CodeInstruction(OpCodes.Brfalse_S, retLabel), + + // type = ev.ConnectorType + new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), + new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(SpawningRoomConnectorEventArgs), nameof(SpawningRoomConnectorEventArgs.ConnectorType))), + new CodeInstruction(OpCodes.Starg_S, 0), + }); + + newInstructions[newInstructions.Count - 1].WithLabels(retLabel); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From aec1ef4be6c2551fb2be847eef0b82027f73941d Mon Sep 17 00:00:00 2001 From: maro Date: Tue, 8 Apr 2025 11:51:22 -0400 Subject: [PATCH 2/7] fix for line error --- .../Patches/Events/Map/SpawningRoomConnector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs index 7bda1a7f85..9147bc4265 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) ExMod Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -20,8 +20,8 @@ namespace Exiled.Events.Patches.Events.Map using static HarmonyLib.AccessTools; /// - /// Patches . - /// Adds the event. + /// Patches . + /// Adds the event. /// [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.SpawningRoomConnector))] [HarmonyPatch(typeof(RoomConnectorDistributorSettings), nameof(RoomConnectorDistributorSettings.TryGetTemplate))] From 6abfc73c0cd05cfa6442c9a746dd6e65ecaeb6fc Mon Sep 17 00:00:00 2001 From: maro <68162163+mawosl@users.noreply.github.com> Date: Tue, 8 Apr 2025 12:34:44 -0400 Subject: [PATCH 3/7] Update SpawningRoomConnectorEventArgs.cs --- .../EventArgs/Map/SpawningRoomConnectorEventArgs.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs index b4a7e0ec38..0ca3729072 100644 --- a/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs @@ -30,8 +30,8 @@ public SpawningRoomConnectorEventArgs(SpawnableRoomConnectorType connectorType) public SpawnableRoomConnectorType ConnectorType { get; set; } /// - /// Gets or sets a value indicating whether the item can be spawned. + /// Gets or sets a value indicating whether the connector can be spawned. /// public bool IsAllowed { get; set; } = true; } -} \ No newline at end of file +} From 3770873d6a5c2cb3ac473fd101414ecab4e4b4a2 Mon Sep 17 00:00:00 2001 From: Yamato Date: Sun, 20 Apr 2025 16:31:59 +0200 Subject: [PATCH 4/7] Adding Room Propperty & Help please Can Someone help me to remove the Error on Ret ???? --- .../Map/SpawningRoomConnectorEventArgs.cs | 25 +++++- .../Events/Map/SpawningRoomConnector.cs | 77 ++++++++++++++----- 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs index 0ca3729072..179c244e83 100644 --- a/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Map/SpawningRoomConnectorEventArgs.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) ExMod Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -7,8 +7,10 @@ namespace Exiled.Events.EventArgs.Map { + using Exiled.API.Features; using Exiled.Events.EventArgs.Interfaces; using MapGeneration.RoomConnectors; + using MapGeneration.RoomConnectors.Spawners; /// /// Contains all information before spawning the connector between rooms. @@ -18,12 +20,31 @@ public class SpawningRoomConnectorEventArgs : IDeniableEvent /// /// Initializes a new instance of the class. /// + /// The RoomConnectorSpawnpointBase. /// The connector type the game is trying to spawn. - public SpawningRoomConnectorEventArgs(SpawnableRoomConnectorType connectorType) + public SpawningRoomConnectorEventArgs(RoomConnectorSpawnpointBase roomConnectorSpawnpointBase, SpawnableRoomConnectorType connectorType) { + RoomConnectorSpawnpoint = roomConnectorSpawnpointBase; ConnectorType = connectorType; + RoomForward = Room.Get(RoomConnectorSpawnpoint._parentRoom); + RoomBackward = Room.Get(RoomConnectorSpawnpoint.transform.position + (RoomConnectorSpawnpoint.transform.forward * -1)); } + /// + /// Gets the RoomConnectorSpawnpointBase. + /// + public RoomConnectorSpawnpointBase RoomConnectorSpawnpoint { get; } + + /// + /// Gets the Room forward of the Connector. + /// + public Room RoomForward { get; } + + /// + /// Gets the Room Backward of the Connector. + /// + public Room RoomBackward { get; } + /// /// Gets or sets which Connector the game should spawn. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs index 9147bc4265..9ea26a23b3 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) ExMod Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -7,60 +7,95 @@ 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; using HarmonyLib; - using MapGeneration.RoomConnectors; - using Respawning; + using MapGeneration; + using MapGeneration.RoomConnectors.Spawners; using static HarmonyLib.AccessTools; /// - /// Patches . + /// Patches . /// Adds the event. /// [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.SpawningRoomConnector))] - [HarmonyPatch(typeof(RoomConnectorDistributorSettings), nameof(RoomConnectorDistributorSettings.TryGetTemplate))] + [HarmonyPatch(typeof(RoomConnectorSpawnpointBase), nameof(RoomConnectorSpawnpointBase.Spawn))] internal static class SpawningRoomConnector { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { List newInstructions = ListPool.Pool.Get(instructions); - LocalBuilder ev = generator.DeclareLocal(typeof(SpawningRoomConnectorEventArgs)); Label retLabel = generator.DefineLabel(); - newInstructions.InsertRange(0, new[] + newInstructions.InsertRange(0, new CodeInstruction[] { + // this + new(OpCodes.Ldarg_0), + // type - new CodeInstruction(OpCodes.Ldarg_0), + new(OpCodes.Ldarg_1), - // SpawningRoomConnectorEventArgs ev = new SpawningRoomConnectorEventArgs(type) - new CodeInstruction(OpCodes.Newobj, AccessTools.Constructor(typeof(SpawningRoomConnectorEventArgs), new[] { typeof(SpawnableRoomConnectorType) })), - new CodeInstruction(OpCodes.Dup), - new CodeInstruction(OpCodes.Stloc, ev.LocalIndex), + // SpawningRoomConnectorEventArgs ev = new SpawningRoomConnectorEventArgs(RoomConnectorSpawnpointBase, SpawnableRoomConnectorType) + new(OpCodes.Newobj, Constructor(typeof(SpawningRoomConnectorEventArgs))), + new(OpCodes.Dup), + new(OpCodes.Dup), // Handlers.Map.OnSpawningRoomConnector(ev); - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Handlers.Map), nameof(Handlers.Map.OnSpawningRoomConnector))), + new(OpCodes.Call, Method(typeof(Handlers.Map), nameof(Handlers.Map.OnSpawningRoomConnector))), + + // type = ev.ConnectorType + new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningRoomConnectorEventArgs), nameof(SpawningRoomConnectorEventArgs.ConnectorType))), + new(OpCodes.Starg_S, 1), // if (!ev.IsAllowed) // return; - new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), - new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(SpawningRoomConnectorEventArgs), nameof(SpawningRoomConnectorEventArgs.IsAllowed))), - new CodeInstruction(OpCodes.Brfalse_S, retLabel), - - // type = ev.ConnectorType - new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), - new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(SpawningRoomConnectorEventArgs), nameof(SpawningRoomConnectorEventArgs.ConnectorType))), - new CodeInstruction(OpCodes.Starg_S, 0), + new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningRoomConnectorEventArgs), nameof(SpawningRoomConnectorEventArgs.IsAllowed))), + new(OpCodes.Brfalse_S, retLabel), }); newInstructions[newInstructions.Count - 1].WithLabels(retLabel); + for (int z = 0; z < newInstructions.Count; z++) + { + Log.Info($"[{z}]{newInstructions[z].opcode} {newInstructions[z].operand} ({newInstructions[z].labels.Count})"); + yield return newInstructions[z]; + } + + ListPool.Pool.Return(newInstructions); + } + } + + /// + /// Patches . + /// Adds the event. + /// + [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.SpawningRoomConnector))] + [HarmonyPatch(typeof(SeedSynchronizer), nameof(SeedSynchronizer.GenerateLevel))] + internal static class SpawningRoomConnectorFix + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + int offset = 0; + int index = newInstructions.FindIndex(i => i.Calls(Method(typeof(RoomConnectorSpawnpointBase), nameof(RoomConnectorSpawnpointBase.SetupAllRoomConnectors)))) + offset; + + newInstructions.RemoveAt(index); + + offset = -1; + index = newInstructions.FindIndex(i => i.opcode == OpCodes.Newobj && (ConstructorInfo)i.operand == GetDeclaredConstructors(typeof(PluginAPI.Events.MapGeneratedEvent))[0]) + offset; + newInstructions.Insert(index, new CodeInstruction(OpCodes.Call, Method(typeof(RoomConnectorSpawnpointBase), nameof(RoomConnectorSpawnpointBase.SetupAllRoomConnectors))).MoveLabelsFrom(newInstructions[index])); + for (int z = 0; z < newInstructions.Count; z++) yield return newInstructions[z]; From 389b5469803242dcdd4764ef3692d8e262f59705 Mon Sep 17 00:00:00 2001 From: maro Date: Sun, 20 Apr 2025 14:37:19 -0400 Subject: [PATCH 5/7] chimpanzee --- .../Events/Map/SpawningRoomConnector.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs index 9ea26a23b3..88aafae087 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs @@ -7,6 +7,8 @@ namespace Exiled.Events.Patches.Events.Map { + using MapGeneration.RoomConnectors; + #pragma warning disable SA1402 // File may only contain a single type using System.Collections.Generic; @@ -35,6 +37,7 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); + LocalBuilder evLocal = generator.DeclareLocal(typeof(SpawningRoomConnectorEventArgs)); Label retLabel = generator.DefineLabel(); newInstructions.InsertRange(0, new CodeInstruction[] @@ -46,30 +49,33 @@ private static IEnumerable Transpiler(IEnumerable i.opcode == OpCodes.Ret); + newInstructions[earlyRetIndex].WithLabels(retLabel); for (int z = 0; z < newInstructions.Count; z++) - { - Log.Info($"[{z}]{newInstructions[z].opcode} {newInstructions[z].operand} ({newInstructions[z].labels.Count})"); yield return newInstructions[z]; - } ListPool.Pool.Return(newInstructions); } From 8917c241b4b68fa80f4083093e07ce3481d9a538 Mon Sep 17 00:00:00 2001 From: maro Date: Sun, 20 Apr 2025 14:40:13 -0400 Subject: [PATCH 6/7] chimpanzee 2 --- .../Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs index 88aafae087..5f0385f6f1 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs @@ -51,8 +51,7 @@ private static IEnumerable Transpiler(IEnumerable Date: Sun, 20 Apr 2025 14:55:15 -0400 Subject: [PATCH 7/7] why hate Ldloc_S :( --- .../Patches/Events/Map/SpawningRoomConnector.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs index 5f0385f6f1..7b11934f9d 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningRoomConnector.cs @@ -36,8 +36,6 @@ internal static class SpawningRoomConnector private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { List newInstructions = ListPool.Pool.Get(instructions); - - LocalBuilder evLocal = generator.DeclareLocal(typeof(SpawningRoomConnectorEventArgs)); Label retLabel = generator.DefineLabel(); newInstructions.InsertRange(0, new CodeInstruction[] @@ -52,20 +50,18 @@ private static IEnumerable Transpiler(IEnumerable