From c8067992a6678ed71f463b440a3cf926a2001cd2 Mon Sep 17 00:00:00 2001 From: VALERA771 <72030575+VALERA771@users.noreply.github.com> Date: Wed, 10 May 2023 05:09:05 +0300 Subject: [PATCH] Respawing team event fix (#1758) * fix * Another logic * Another logic * Delete RespawningTeam.cs * again * and again * done * some fixes * finally * remove useless --------- Co-authored-by: joker-119 --- .../EventArgs/Server/RespawningTeamEventArgs.cs | 17 +++++++++++++++-- .../Patches/Events/Server/RespawningTeam.cs | 11 +++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs b/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs index bf394553af..dbcd75b93b 100644 --- a/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs +++ b/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs @@ -23,6 +23,7 @@ namespace Exiled.Events.EventArgs.Server public class RespawningTeamEventArgs : IDeniableEvent { private SpawnableTeamType nextKnownTeam; + private int maximumRespawnAmount; /// /// Initializes a new instance of the class. @@ -58,7 +59,19 @@ public RespawningTeamEventArgs(List players, int maxRespawn, SpawnableTe /// /// Gets or sets the maximum amount of respawnable players. /// - public int MaximumRespawnAmount { get; set; } + public int MaximumRespawnAmount + { + get => maximumRespawnAmount; + set + { + if (value < maximumRespawnAmount) + { + Players.RemoveRange(value, Players.Count - value); + } + + maximumRespawnAmount = value; + } + } /// /// Gets or sets a value indicating what the next respawnable team is. @@ -98,4 +111,4 @@ public SpawnableTeamHandlerBase SpawnableTeam /// public Queue SpawnQueue { get; set; } } -} \ No newline at end of file +} diff --git a/Exiled.Events/Patches/Events/Server/RespawningTeam.cs b/Exiled.Events/Patches/Events/Server/RespawningTeam.cs index 7ae60c890a..6eafa71a6f 100644 --- a/Exiled.Events/Patches/Events/Server/RespawningTeam.cs +++ b/Exiled.Events/Patches/Events/Server/RespawningTeam.cs @@ -13,13 +13,11 @@ namespace Exiled.Events.Patches.Events.Server using System.Reflection.Emit; using API.Features.Pools; - using Exiled.Events.EventArgs.Server; using Exiled.Events.Handlers; - using HarmonyLib; - using Respawning; + using Respawning.NamingRules; using static HarmonyLib.AccessTools; @@ -36,8 +34,8 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); - int offset = -2; - int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stloc_3) + offset; + int offset = -3; + int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(UnitNamingRule), nameof(UnitNamingRule.TryGetNamingRule)))) + offset; LocalBuilder ev = generator.DeclareLocal(typeof(RespawningTeamEventArgs)); @@ -101,7 +99,8 @@ private static IEnumerable Transpiler(IEnumerable