Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions EXILED/Exiled.API/Features/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public static IEnumerable<Side> AliveSides
}
}

/// <summary>
/// Gets get the initial lobby Waiting Time.
/// </summary>
public static short InitialLobbyWaitingTime { get; } = ConfigFile.ServerConfig.GetShort("lobby_waiting_time", 20);

/// <summary>
/// Restarts the round with custom settings.
/// </summary>
Expand Down Expand Up @@ -258,5 +263,10 @@ public static bool EndRound(bool forceEnd = false)
/// Start the round.
/// </summary>
public static void Start() => CharacterClassManager.ForceRoundStart();

/// <summary>
/// Reset the CountDown from Config Value.
/// </summary>
public static void ResetCountDown() => LobbyWaitingTime = InitialLobbyWaitingTime;
}
}
11 changes: 2 additions & 9 deletions EXILED/Exiled.Events/EventArgs/Server/RoundStartingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

namespace Exiled.Events.EventArgs.Server
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Exiled.Events.EventArgs.Interfaces;

/// <summary>
Expand All @@ -30,10 +24,9 @@ public class RoundStartingEventArgs : IDeniableEvent
public RoundStartingEventArgs(short timeLeft, short originalTimeLeft, int topPlayer, int playerCount)
{
TimeLeft = timeLeft;
OriginalTimeLeft = originalTimeLeft;
OriginalTimeLeft = originalTimeLeft == -1 ? 1 : originalTimeLeft;
TopPlayer = topPlayer;
PlayerCount = playerCount;
IsAllowed = TimeLeft == -1;
}

/// <summary>
Expand All @@ -57,6 +50,6 @@ public RoundStartingEventArgs(short timeLeft, short originalTimeLeft, int topPla
public int PlayerCount { get; }

/// <inheritdoc/>
public bool IsAllowed { get; set; }
public bool IsAllowed { get; set; } = true;
}
}
39 changes: 30 additions & 9 deletions EXILED/Exiled.Events/Patches/Events/Server/RoundStarting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Exiled.Events.Patches.Events.Server
using System.Reflection;
using System.Reflection.Emit;

using Exiled.API.Features;
using Exiled.API.Features.Pools;
using Exiled.Events.EventArgs.Server;
using HarmonyLib;
Expand Down Expand Up @@ -52,17 +51,20 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
const string TopPlayer = "<topPlayers>5__4";

LocalBuilder ev = generator.DeclareLocal(typeof(RoundStartingEventArgs));
int offset = -4;
int index = newInstructions.FindLastIndex(x => x.Calls(Method(typeof(CharacterClassManager), nameof(CharacterClassManager.ForceRoundStart)))) + offset;
Label continueLabel = generator.DefineLabel();
Label checkSkip = generator.DefineLabel();

List<Label> labels = newInstructions[index].ExtractLabels();
Label skip = (Label)newInstructions[index + 3].operand;
newInstructions.RemoveRange(index, 4);
int index = newInstructions.FindLastIndex(x => x.Calls(Method(typeof(CharacterClassManager), nameof(CharacterClassManager.ForceRoundStart))));

// we will call ForceRoundStart ourselves to check its result
newInstructions.RemoveRange(index, 2);

newInstructions[index].labels.Add(continueLabel);

newInstructions.InsertRange(index, new[]
{
// this.TimeLeft
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
new CodeInstruction(OpCodes.Ldarg_0),
new(OpCodes.Ldfld, Field(PrivateType, TimeLeft)),

// this.OriginalTimeLeft
Expand Down Expand Up @@ -103,10 +105,29 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Stfld, Field(PrivateType, TopPlayer)),

// if (!ev.IsAllowed)
// skip;
// goto checkSkip; (checkSkip is where we see if we need to change timeLeft so the round doesn't start from stupid NW stuff)
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(RoundStartingEventArgs), nameof(RoundStartingEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, skip),
new(OpCodes.Brfalse_S, checkSkip),

// try start the round because it was allowed.
new(OpCodes.Call, Method(typeof(CharacterClassManager), nameof(CharacterClassManager.ForceRoundStart))),

// round has started, we don't care about timeLeft because of the Timer check later in the method.
new(OpCodes.Brtrue_S, continueLabel),

// if (timeLeft != -1)
// goto continueLabel; (timeLeft isn't -1, so we can just let the method execute)
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(checkSkip),
new(OpCodes.Ldfld, Field(PrivateType, TimeLeft)),

new(OpCodes.Ldc_I4_M1),
new(OpCodes.Bne_Un_S, continueLabel),

// timeLeft = 0; (so we delay round start 1s)
new(OpCodes.Ldarg_0),
new(OpCodes.Ldc_I4_0),
new(OpCodes.Stfld, Field(PrivateType, TimeLeft)),
});

for (int z = 0; z < newInstructions.Count; z++)
Expand Down
Loading