From af40286b8e713d17482c07c60f0a678e1e7784c3 Mon Sep 17 00:00:00 2001 From: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:57:14 -0500 Subject: [PATCH] Update RestartingRound.cs (#258) --- .../Patches/Events/Server/RestartingRound.cs | 66 ++++--------------- 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Server/RestartingRound.cs b/EXILED/Exiled.Events/Patches/Events/Server/RestartingRound.cs index 39dc587c1..ab4ef8b26 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/RestartingRound.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/RestartingRound.cs @@ -12,7 +12,10 @@ namespace Exiled.Events.Patches.Events.Server using System.Reflection.Emit; using API.Features.Pools; + using CustomPlayerEffects.Danger; + using Exiled.API.Enums; using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Player; using GameCore; using HarmonyLib; @@ -20,70 +23,23 @@ namespace Exiled.Events.Patches.Events.Server using RoundRestarting; using static HarmonyLib.AccessTools; + using static PlayerList; /// /// Patches . /// Adds the event. /// [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.RestartingRound))] - [HarmonyPatch(typeof(RoundRestart), nameof(RoundRestart.InitiateRoundRestart))] + [HarmonyPatch(typeof(RoundRestart), nameof(RoundRestart.IsRoundRestarting), MethodType.Setter)] internal static class RestartingRound { - private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + // TODO: Convert to transpiler and bring back old features + private static void Prefix(bool value) { - List newInstructions = ListPool.Pool.Get(instructions); + if (!value || value == RoundRestart.IsRoundRestarting) + return; - newInstructions.InsertRange( - 0, - new CodeInstruction[] - { - // Handlers.Server.OnRestartingRound() - new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server.OnRestartingRound))), - - // API.Features.Log.Debug("Round restarting", Loader.ShouldDebugBeShown) - new(OpCodes.Ldstr, "Round restarting"), - new(OpCodes.Call, Method(typeof(API.Features.Log), nameof(API.Features.Log.Debug), new[] { typeof(string) })), - }); - - const int offset = 1; - int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Brfalse); - - newInstructions.InsertRange( - index + offset, - new CodeInstruction[] - { - // if (ServerStatic.StopNextRound == ServerStatic.NextRoundAction.Restart) -> goto normal round restart - new(OpCodes.Call, PropertyGetter(typeof(ServerStatic), nameof(ServerStatic.StopNextRound))), - new(OpCodes.Ldc_I4_1), - new(OpCodes.Beq_S, newInstructions[index].operand), - - // if (ShouldServerRestart()) -> goto normal round restart - new(OpCodes.Call, Method(typeof(RestartingRound), nameof(ShouldServerRestart))), - new(OpCodes.Brtrue, newInstructions[index].operand), - }); - - for (int z = 0; z < newInstructions.Count; z++) - yield return newInstructions[z]; - - ListPool.Pool.Return(newInstructions); - } - - private static bool ShouldServerRestart() - { - bool flag = false; - - try - { - int num = ConfigFile.ServerConfig.GetInt("restart_after_rounds"); - - flag = num > 0 && RoundRestart.UptimeRounds >= num; - } - catch (Exception ex) - { - ServerConsole.AddLog("Failed to check the restart_after_rounds config value: " + ex.Message, ConsoleColor.Red); - } - - return flag; + Handlers.Server.OnRestartingRound(); } } -} \ No newline at end of file +}