Skip to content

Commit

Permalink
Respawing team event fix (#1758)
Browse files Browse the repository at this point in the history
* fix

* Another logic

* Another logic

* Delete RespawningTeam.cs

* again

* and again

* done

* some fixes

* finally

* remove useless

---------

Co-authored-by: joker-119 <[email protected]>
  • Loading branch information
VALERA771 and joker-119 authored May 10, 2023
1 parent 386e511 commit c806799
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
17 changes: 15 additions & 2 deletions Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Exiled.Events.EventArgs.Server
public class RespawningTeamEventArgs : IDeniableEvent
{
private SpawnableTeamType nextKnownTeam;
private int maximumRespawnAmount;

/// <summary>
/// Initializes a new instance of the <see cref="RespawningTeamEventArgs" /> class.
Expand Down Expand Up @@ -58,7 +59,19 @@ public RespawningTeamEventArgs(List<Player> players, int maxRespawn, SpawnableTe
/// <summary>
/// Gets or sets the maximum amount of respawnable players.
/// </summary>
public int MaximumRespawnAmount { get; set; }
public int MaximumRespawnAmount
{
get => maximumRespawnAmount;
set
{
if (value < maximumRespawnAmount)
{
Players.RemoveRange(value, Players.Count - value);
}

maximumRespawnAmount = value;
}
}

/// <summary>
/// Gets or sets a value indicating what the next respawnable team is.
Expand Down Expand Up @@ -98,4 +111,4 @@ public SpawnableTeamHandlerBase SpawnableTeam
/// </summary>
public Queue<RoleTypeId> SpawnQueue { get; set; }
}
}
}
11 changes: 5 additions & 6 deletions Exiled.Events/Patches/Events/Server/RespawningTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,8 +34,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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));

Expand Down Expand Up @@ -101,7 +99,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(RespawningTeam), nameof(GetHubs))),
new(OpCodes.Stloc_1),

new(OpCodes.Callvirt, PropertyGetter(typeof(RespawningTeamEventArgs), nameof(RespawningTeamEventArgs.SpawnQueue))),
// queueToFill = ev.SpawnQueue;
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(RespawningTeamEventArgs), nameof(RespawningTeamEventArgs.SpawnQueue))),
new(OpCodes.Stloc, 6),
});

Expand Down

0 comments on commit c806799

Please sign in to comment.