From c8d8fd50ab1d7987b17639a203af0a31bbe218a9 Mon Sep 17 00:00:00 2001 From: VALERA771 <72030575+VALERA771@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:51:31 +0300 Subject: [PATCH] New game update (#310) * fixes * all is fixed * fix no.2 * Update EXILED/Exiled.API/Extensions/RoleExtensions.cs Co-authored-by: Bolton <48883340+BoltonDev@users.noreply.github.com> * Update EXILED/Exiled.Events/Patches/Events/Server/SelectingRespawnTeam.cs Co-authored-by: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com> * Update EXILED/Exiled.Events/Patches/Events/Server/SelectingRespawnTeam.cs * team reborn --------- Co-authored-by: Bolton <48883340+BoltonDev@users.noreply.github.com> Co-authored-by: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com> --- .../Exiled.API/Extensions/RoleExtensions.cs | 14 +---- EXILED/Exiled.API/Features/Player.cs | 2 +- EXILED/Exiled.API/Features/Respawn.cs | 52 ++-------------- EXILED/Exiled.API/Features/Roles/HumanRole.cs | 11 +--- EXILED/Exiled.API/Features/Waves/TimedWave.cs | 54 +++++++++++------ EXILED/Exiled.API/Features/Waves/WaveTimer.cs | 4 +- .../Map/AnnouncingChaosEntranceEventArgs.cs | 38 ++++++++++++ .../Map/AnnouncingNtfEntranceEventArgs.cs | 2 +- .../Server/RespawningTeamEventArgs.cs | 10 ++-- .../Server/SelectingRespawnTeamEventArgs.cs | 24 +++++--- EXILED/Exiled.Events/Events.cs | 2 +- EXILED/Exiled.Events/Handlers/Map.cs | 11 ++++ .../Events/Map/AnnouncingChaosEntrance.cs | 59 +++++++++++++++++++ .../Events/Map/AnnouncingNtfEntrance.cs | 31 +++++----- .../Patches/Events/Server/AddingUnitName.cs | 7 +-- .../Events/Server/SelectingRespawnTeam.cs | 26 +++++--- 16 files changed, 211 insertions(+), 136 deletions(-) create mode 100644 EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs create mode 100644 EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs diff --git a/EXILED/Exiled.API/Extensions/RoleExtensions.cs b/EXILED/Exiled.API/Extensions/RoleExtensions.cs index 445edb88c..369910654 100644 --- a/EXILED/Exiled.API/Extensions/RoleExtensions.cs +++ b/EXILED/Exiled.API/Extensions/RoleExtensions.cs @@ -256,19 +256,7 @@ public static Dictionary GetStartingAmmo(this RoleTypeId roleT }; /// - /// Gets the associated with the provided . - /// - /// A member of the enum. - /// associated with the provided . - public static Faction GetFaction(this SpawnableTeamType spawnableTeamType) => spawnableTeamType switch - { - SpawnableTeamType.ChaosInsurgency => Faction.FoundationEnemy, - SpawnableTeamType.NineTailedFox => Faction.FoundationStaff, - _ => Faction.Unclassified, - }; - - /// - /// Tries to get the associated with the provided and . + /// Tries to get the associated with the provided and . /// /// A member of the enum. /// The to return. diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index 6df9948db..b76a88753 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -831,7 +831,7 @@ public bool IsGodModeEnabled /// /// Gets the player's unit name. /// - public string UnitName => Role.Base is PlayerRoles.HumanRole humanRole ? UnitNameMessageHandler.GetReceived(humanRole.AssignedSpawnableTeam, humanRole.UnitNameId) : string.Empty; + public string UnitName => Role is HumanRole humanRole ? humanRole.UnitName : string.Empty; /// /// Gets or sets the player's unit id. diff --git a/EXILED/Exiled.API/Features/Respawn.cs b/EXILED/Exiled.API/Features/Respawn.cs index a7590dfd2..82282435c 100644 --- a/EXILED/Exiled.API/Features/Respawn.cs +++ b/EXILED/Exiled.API/Features/Respawn.cs @@ -72,21 +72,15 @@ public static GameObject ChaosVan /// This returns SpawnableFaction.None unless a respawn has already started. public static SpawnableFaction NextKnownSpawnableFaction => WaveManager._nextWave is not null ? WaveManager._nextWave.GetSpawnableFaction() : SpawnableFaction.None; - /// - /// Gets the next known that will spawn. - /// - /// This returns SpawnableFaction.None unless a respawn has already started. - public static SpawnableTeamType NextKnownTeam => NextKnownSpawnableFaction.GetFaction().GetSpawnableTeam(); - /// /// Gets the current state of the . /// - public static WaveManager.WaveQueueState CurrentState => WaveManager.State; + public static WaveQueueState CurrentState => WaveManager.State; /// /// Gets a value indicating whether the respawn process for a is currently in progress.. /// - public static bool IsSpawning => WaveManager.State == WaveManager.WaveQueueState.WaveSpawning; + public static bool IsSpawning => WaveManager.State == WaveQueueState.WaveSpawning; /// /// Gets or sets a value indicating whether spawn protection is enabled. @@ -165,18 +159,6 @@ public static bool TryGetWaveBases(Faction faction, out IEnumerable - /// Tries to get an of . - /// - /// A determining which waves to search for. - /// The containing found 's if there are any, otherwise null. - /// true if was successfully found. Otherwise, false. - /// - public static bool TryGetWaveBases(SpawnableTeamType spawnableTeamType, out IEnumerable spawnableWaveBases) - { - return TryGetWaveBases(spawnableTeamType.GetFaction(), out spawnableWaveBases); - } - /// /// Advances the respawn timer for s. /// @@ -193,22 +175,6 @@ public static bool TryGetWaveBases(SpawnableTeamType spawnableTeamType, out IEnu /// This advances the timer for both the normal and mini wave. public static void AdvanceTimer(Faction faction, TimeSpan time) => AdvanceTimer(faction, (float)time.TotalSeconds); - /// - /// Advances the respawn timer for s. - /// - /// The whose 's timers are to be advanced. - /// Number of seconds to advance the timers by. - /// This advances the timer for both the normal and mini wave. - public static void AdvanceTimer(SpawnableTeamType spawnableTeamType, float seconds) => AdvanceTimer(spawnableTeamType.GetFaction(), seconds); - - /// - /// Advances the respawn timer for s. - /// - /// The whose 's timers are to be advanced. - /// A representing the amount of time to advance the timers by. - /// This advances the timer for both the normal and mini wave. - public static void AdvanceTimer(SpawnableTeamType spawnableTeamType, TimeSpan time) => AdvanceTimer(spawnableTeamType.GetFaction(), time); - /// /// Advances the respawn timer for s. /// @@ -243,7 +209,7 @@ public static void PlayEffect(SpawnableWaveBase wave) } /// - /// Summons the chopper. + /// Summons the NTF chopper. /// public static void SummonNtfChopper() { @@ -252,7 +218,7 @@ public static void SummonNtfChopper() } /// - /// Summons the van. + /// Summons the Chaos Insurgency van. /// /// This will also trigger Music effect. /// @@ -360,16 +326,6 @@ public static bool SetTokens(SpawnableFaction spawnableFaction, int amount) return false; } - /// - /// Starts the spawn sequence of the given . - /// - /// The whose wave to spawn. - /// Whether the wave should be a mini wave or not. - public static void ForceWave(SpawnableTeamType spawnableTeamType, bool isMini = false) - { - ForceWave(spawnableTeamType.GetFaction(), isMini); - } - /// /// Starts the spawn sequence of the given . /// diff --git a/EXILED/Exiled.API/Features/Roles/HumanRole.cs b/EXILED/Exiled.API/Features/Roles/HumanRole.cs index 830f7844e..8a238a3e7 100644 --- a/EXILED/Exiled.API/Features/Roles/HumanRole.cs +++ b/EXILED/Exiled.API/Features/Roles/HumanRole.cs @@ -32,19 +32,10 @@ internal HumanRole(HumanGameRole baseRole) /// public override RoleTypeId Type => Base.RoleTypeId; - /// - /// Gets or sets the . - /// - public SpawnableTeamType SpawnableTeamType - { - get => Base.AssignedSpawnableTeam; - set => Base.AssignedSpawnableTeam = value; - } - /// /// Gets the player's unit name. /// - public string UnitName => UnitNameMessageHandler.GetReceived(Base.AssignedSpawnableTeam, Base.UnitNameId); + public string UnitName => NamingRulesManager.ClientFetchReceived(Team, UnitNameId); /// /// Gets or sets the . diff --git a/EXILED/Exiled.API/Features/Waves/TimedWave.cs b/EXILED/Exiled.API/Features/Waves/TimedWave.cs index fe33d1418..ca668ca84 100644 --- a/EXILED/Exiled.API/Features/Waves/TimedWave.cs +++ b/EXILED/Exiled.API/Features/Waves/TimedWave.cs @@ -8,13 +8,12 @@ namespace Exiled.API.Features.Waves { using System.Collections.Generic; - using System.Linq; + using Exiled.API.Enums; using PlayerRoles; - using Respawning; - + using Respawning.Announcements; using Respawning.Waves; /// @@ -55,13 +54,30 @@ public class TimedWave /// /// Gets the team of this wave. /// - public SpawnableTeamType Team => timedWave.TargetFaction.GetSpawnableTeam(); + public Team Team => timedWave.TargetFaction.GetSpawnableTeam(); + + /// + /// Gets the spawnable faction for this wave. + /// + public SpawnableFaction SpawnableFaction => Faction switch + { + Faction.FoundationStaff when IsMiniWave => SpawnableFaction.NtfMiniWave, + Faction.FoundationStaff => SpawnableFaction.NtfWave, + Faction.FoundationEnemy when IsMiniWave => SpawnableFaction.ChaosMiniWave, + _ => SpawnableFaction.ChaosWave + }; /// /// Gets the maximum amount of people that can spawn in this wave. /// public int MaxAmount => timedWave.MaxWaveSize; + /// + /// Gets the for this wave. + /// + /// Wave must implement . + public WaveAnnouncementBase Announcement => timedWave is IAnnouncedWave announcedWave ? announcedWave.Announcement : null; + /// /// Get the timed waves for the specified faction. /// @@ -88,28 +104,22 @@ public static bool TryGetTimedWaves(Faction faction, out List waves) } /// - /// Get the timed wave for the specified team. + /// Get the timed waves for the specified faction. /// - /// - /// The team to get the wave for. - /// - /// - /// The waves if found. - /// - /// - /// A value indicating whether the wave were found. - /// - public static bool TryGetTimedWaves(SpawnableTeamType team, out List waves) + /// The faction to get the waves for. + /// The waves if found. + /// A value indicating whether the wave were found. + public static bool TryGetTimedWaves(Team team, out List waves) { - if (team == SpawnableTeamType.None) + List spawnableWaveBases = WaveManager.Waves.Where(w => w is TimeBasedWave wave && wave.TargetFaction.GetSpawnableTeam() == team).ToList(); + if(!spawnableWaveBases.Any()) { waves = null; return false; } - Faction faction = team == SpawnableTeamType.NineTailedFox ? Faction.FoundationStaff : Faction.FoundationEnemy; - - return TryGetTimedWaves(faction, out waves); + waves = spawnableWaveBases.Select(w => new TimedWave((TimeBasedWave)w)).ToList(); + return true; } /// @@ -175,5 +185,11 @@ public static List GetTimedWaves() /// The amount of people to populate. /// public void PopulateQueue(Queue queue, int amount) => timedWave.PopulateQueue(queue, amount); + + /// + /// Plays the announcement for this wave. + /// + /// Wave must implement . + public void PlayAnnouncement() => Announcement?.PlayAnnouncement(); } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Waves/WaveTimer.cs b/EXILED/Exiled.API/Features/Waves/WaveTimer.cs index 279eba75d..3f20b3447 100644 --- a/EXILED/Exiled.API/Features/Waves/WaveTimer.cs +++ b/EXILED/Exiled.API/Features/Waves/WaveTimer.cs @@ -109,12 +109,12 @@ public static bool TryGetWaveTimers(Faction faction, out List waves) } /// - /// Gets the wave timers for the specified team. + /// Get the wave timers for the specified faction. /// /// The team. /// The waves, if any. /// A bool indicating if waves were found. - public static bool TryGetWaveTimers(SpawnableTeamType team, out List waves) + public static bool TryGetWaveTimers(Team team, out List waves) { if (!TimedWave.TryGetTimedWaves(team, out List timedWaves)) { diff --git a/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs new file mode 100644 index 000000000..58e6d66ba --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Map +{ + using Exiled.API.Features.Waves; + using Exiled.Events.EventArgs.Interfaces; + using Respawning.Announcements; + + /// + /// Contains all information before Chaos wave entrance. + /// + public class AnnouncingChaosEntranceEventArgs : IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public AnnouncingChaosEntranceEventArgs(WaveAnnouncementBase announcement, bool isAllowed = true) + { + Wave = TimedWave.GetTimedWaves().Find(x => x.Announcement == announcement); + IsAllowed = isAllowed; + } + + /// + /// Gets the entering wave. + /// + public TimedWave Wave { get; } + + /// + public bool IsAllowed { get; set; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Map/AnnouncingNtfEntranceEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingNtfEntranceEventArgs.cs index f961a19de..508e471b6 100644 --- a/EXILED/Exiled.Events/EventArgs/Map/AnnouncingNtfEntranceEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingNtfEntranceEventArgs.cs @@ -55,6 +55,6 @@ public AnnouncingNtfEntranceEventArgs(int scpsLeft, string unitName, int unitNum /// /// Gets or sets a value indicating whether the NTF spawn will be announced by C.A.S.S.I.E. /// - public bool IsAllowed { get; set; } + public bool IsAllowed { get; set; } // TODO possibly not working } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs index 963d06351..e65bdbf03 100644 --- a/EXILED/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs @@ -10,14 +10,14 @@ namespace Exiled.Events.EventArgs.Server using System.Collections.Generic; using Exiled.API.Features; + using Exiled.API.Features.Waves; using Exiled.Events.EventArgs.Interfaces; using PlayerRoles; using Respawning; using Respawning.Waves; /// - /// Contains all information before spawning a wave of or - /// . + /// Contains all information before spawning a wave. /// public class RespawningTeamEventArgs : IDeniableEvent { @@ -40,7 +40,7 @@ public RespawningTeamEventArgs(List players, int maxRespawn, SpawnableWa Players = players; MaximumRespawnAmount = maxRespawn; SpawnQueue = WaveSpawner.SpawnQueue; - Wave = wave; + Wave = new TimedWave((TimeBasedWave)wave); IsAllowed = true; } @@ -70,12 +70,12 @@ public int MaximumRespawnAmount /// /// Gets or sets a value indicating what the next wave is. /// - public SpawnableWaveBase Wave { get; set; } + public TimedWave Wave { get; set; } /// /// Gets a value indicating what the next respawnable team is. /// - public SpawnableTeamType NextKnownTeam => Wave.TargetFaction.GetSpawnableTeam(); + public Faction NextKnownTeam => Wave.Faction; /// /// Gets or sets a value indicating whether the spawn can occur. diff --git a/EXILED/Exiled.Events/EventArgs/Server/SelectingRespawnTeamEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Server/SelectingRespawnTeamEventArgs.cs index e4c87e6b2..f2b531194 100644 --- a/EXILED/Exiled.Events/EventArgs/Server/SelectingRespawnTeamEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Server/SelectingRespawnTeamEventArgs.cs @@ -7,26 +7,36 @@ namespace Exiled.Events.EventArgs.Server { + using Exiled.API.Enums; + using Exiled.API.Features.Waves; using Exiled.Events.EventArgs.Interfaces; - using Respawning; + using Respawning.Waves; /// /// Contains all information before selecting the team to respawn next. /// - public class SelectingRespawnTeamEventArgs : IExiledEvent + public class SelectingRespawnTeamEventArgs : IDeniableEvent { /// /// Initializes a new instance of the class. /// - /// The used as the starting value for this event. - public SelectingRespawnTeamEventArgs(SpawnableTeamType type) + /// . + public SelectingRespawnTeamEventArgs(SpawnableWaveBase wave) { - Team = type; + Wave = new TimedWave((TimeBasedWave)wave); } /// - /// Gets or sets that represents the team chosen to spawn. + /// Gets that represents the team chosen to spawn. /// - public SpawnableTeamType Team { get; set; } + public SpawnableFaction Team => Wave.SpawnableFaction; + + /// + /// Gets or sets that is selected. + /// + public TimedWave Wave { get; set; } + + /// + public bool IsAllowed { get; set; } } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Events.cs b/EXILED/Exiled.Events/Events.cs index f68d6527f..9b67f7192 100644 --- a/EXILED/Exiled.Events/Events.cs +++ b/EXILED/Exiled.Events/Events.cs @@ -14,9 +14,9 @@ namespace Exiled.Events using API.Features; using CentralAuth; using Exiled.Events.Features; + using HarmonyLib; using InventorySystem.Items.Pickups; using InventorySystem.Items.Usables; - using PlayerRoles.Ragdolls; using PlayerRoles.RoleAssign; using PluginAPI.Events; diff --git a/EXILED/Exiled.Events/Handlers/Map.cs b/EXILED/Exiled.Events/Handlers/Map.cs index c617ba5e8..3036d4ede 100644 --- a/EXILED/Exiled.Events/Handlers/Map.cs +++ b/EXILED/Exiled.Events/Handlers/Map.cs @@ -40,6 +40,11 @@ public static class Map /// public static Event AnnouncingNtfEntrance { get; set; } = new(); + /// + /// Invoked before announcing the Chaos entrance. + /// + public static Event AnnouncingChaosEntrance { get; set; } = new(); + /// /// Invoked before a has been activated. /// @@ -134,6 +139,12 @@ public static class Map /// The instance. public static void OnAnnouncingNtfEntrance(AnnouncingNtfEntranceEventArgs ev) => AnnouncingNtfEntrance.InvokeSafely(ev); + /// + /// Called before announcing the Chaos entrance. + /// + /// The instance. + public static void OnAnnouncingChaosEntrance(AnnouncingChaosEntranceEventArgs ev) => AnnouncingChaosEntrance.InvokeSafely(ev); + /// /// Called before a has been activated. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs new file mode 100644 index 000000000..16176c8d3 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs @@ -0,0 +1,59 @@ +// ----------------------------------------------------------------------- +// +// 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 Respawning.Announcements; + + using static HarmonyLib.AccessTools; + + /// + /// Patches and + /// to add event. + /// + [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.AnnouncingChaosEntrance))] + [HarmonyPatch(typeof(ChaosWaveAnnouncement), nameof(ChaosWaveAnnouncement.CreateAnnouncementString))] + [HarmonyPatch(typeof(ChaosMiniwaveAnnouncement), nameof(ChaosMiniwaveAnnouncement.CreateAnnouncementString))] + internal static class AnnouncingChaosEntrance + { + private static IEnumerable Transpiler(IEnumerable instruction, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instruction); + + Label returnLabel = generator.DefineLabel(); + + newInstructions.InsertRange(0, new CodeInstruction[] + { + new(OpCodes.Ldarg_0), + + new(OpCodes.Ldc_I4_1), + + new(OpCodes.Newobj, GetDeclaredConstructors(typeof(AnnouncingChaosEntranceEventArgs))[0]), + new(OpCodes.Dup), + + new(OpCodes.Call, Method(typeof(Handlers.Map), nameof(Handlers.Map.OnAnnouncingChaosEntrance))), + + new(OpCodes.Callvirt, PropertyGetter(typeof(AnnouncingChaosEntranceEventArgs), nameof(AnnouncingChaosEntranceEventArgs.IsAllowed))), + new(OpCodes.Brfalse_S, returnLabel), + }); + + newInstructions[newInstructions.Count - 1].labels.Add(returnLabel); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs index 558362a9b..24d20d821 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs @@ -14,21 +14,20 @@ namespace Exiled.Events.Patches.Events.Map using API.Features.Pools; using Exiled.Events.Attributes; using Exiled.Events.EventArgs.Map; - using Handlers; - using HarmonyLib; - + using Respawning.Announcements; using Respawning.NamingRules; using static HarmonyLib.AccessTools; /// - /// Patch the . + /// Patch the and . /// Adds the event. /// [EventPatch(typeof(Map), nameof(Map.AnnouncingNtfEntrance))] - [HarmonyPatch(typeof(NineTailedFoxNamingRule), nameof(NineTailedFoxNamingRule.PlayEntranceAnnouncement))] + [HarmonyPatch(typeof(NtfWaveAnnouncement), nameof(NtfWaveAnnouncement.CreateAnnouncementString))] + [HarmonyPatch(typeof(NtfMiniwaveAnnouncement), nameof(NtfMiniwaveAnnouncement.CreateAnnouncementString))] internal static class AnnouncingNtfEntrance { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) @@ -40,8 +39,8 @@ private static IEnumerable Transpiler(IEnumerable instruction.opcode == OpCodes.Stloc_1) + offset; + int offset = 1; + int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stloc_3) + offset; // int scpsLeft = ReferenceHub.GetAllHubs().Values.Count(x => x.characterClassManager.CurRole.team == Team.SCP && x.characterClassManager.CurClass != RoleTypeId.Scp0492); // string unitNameClear = Regex.Replace(unitName, "<[^>]*?>", string.Empty); @@ -58,13 +57,13 @@ private static IEnumerable Transpiler(IEnumerable x.characterClassManager.CurRole.team == Team.SCP && x.characterClassManager.CurClass != RoleTypeId.Scp0492); - new CodeInstruction(OpCodes.Ldloc_1), + new(OpCodes.Ldloc_3), // string[] unitInformation = unitNameClear.Split('-'); - new(OpCodes.Ldarg_1), + new(OpCodes.Ldloc_1), new(OpCodes.Ldstr, "<[^>]*?>"), new(OpCodes.Ldsfld, Field(typeof(string), nameof(string.Empty))), new(OpCodes.Call, Method(typeof(Regex), nameof(Regex.Replace), new System.Type[] { typeof(string), typeof(string), typeof(string) })), @@ -100,7 +99,6 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable - /// Patches . + /// Patches . /// Adds the event. /// [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.AddingUnitName))] - [HarmonyPatch(typeof(UnitNameMessageHandler), nameof(UnitNameMessageHandler.SendNew))] + [HarmonyPatch(typeof(NamingRulesManager), nameof(NamingRulesManager.ServerGenerateName))] internal static class AddingUnitName { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) diff --git a/EXILED/Exiled.Events/Patches/Events/Server/SelectingRespawnTeam.cs b/EXILED/Exiled.Events/Patches/Events/Server/SelectingRespawnTeam.cs index b416a51f6..78bca7891 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/SelectingRespawnTeam.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/SelectingRespawnTeam.cs @@ -27,8 +27,7 @@ namespace Exiled.Events.Patches.Events.Server /// Patches to add the event. /// [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.SelectingRespawnTeam))] - - // [HarmonyPatch(typeof(WaveManager), nameof(RespawnManager.Update))] TODO Idk which method to patch + [HarmonyPatch(typeof(WaveManager), nameof(WaveManager.InitiateRespawn))] internal static class SelectingRespawnTeam { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) @@ -36,26 +35,35 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); LocalBuilder ev = generator.DeclareLocal(typeof(SelectingRespawnTeamEventArgs)); - const int offset = 1; - int index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Stloc_1) + offset; + Label returnLabel = generator.DefineLabel(); + + int index = newInstructions.FindIndex(i => i.opcode == OpCodes.Ldc_I4_1); newInstructions.InsertRange(index, new[] { // SelectingRespawnTeamEventArgs ev = new(dominatingTeam); - new CodeInstruction(OpCodes.Ldloc_1), + new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]), new(OpCodes.Newobj, GetDeclaredConstructors(typeof(SelectingRespawnTeamEventArgs))[0]), new(OpCodes.Dup), + new(OpCodes.Dup), new(OpCodes.Stloc_S, ev), // Handlers.Server.OnSelectingRespawnTeam(ev); new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server.OnSelectingRespawnTeam))), - // dominatingTeam = ev.Team; - new(OpCodes.Ldloc, ev), - new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(SelectingRespawnTeamEventArgs), nameof(SelectingRespawnTeamEventArgs.Team))), - new(OpCodes.Stloc_1), + // if (!ev.IsAllowed) + // return; + new(OpCodes.Callvirt, PropertyGetter(typeof(SelectingRespawnTeamEventArgs), nameof(SelectingRespawnTeamEventArgs.IsAllowed))), + new(OpCodes.Brfalse_S, returnLabel), + + // SpawnableWaveBase = ev.Wave; + new(OpCodes.Ldloc_S, ev), + new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(SelectingRespawnTeamEventArgs), nameof(SelectingRespawnTeamEventArgs.Wave))), + new(OpCodes.Starg_S, 0), }); + newInstructions[newInstructions.Count - 1].labels.Add(returnLabel); + for (int z = 0; z < newInstructions.Count; z++) yield return newInstructions[z];