From 052f36c8786f530135014bac399543b300bab273 Mon Sep 17 00:00:00 2001 From: xNexusACS <83370388+xNexusACS@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:56:57 +0100 Subject: [PATCH] Fix some patches & RespawnedTeamEventArgs partial fix --- .../Server/RespawnedTeamEventArgs.cs | 5 +- Exiled.Events/Events.cs | 9 ++-- Exiled.Events/Handlers/Server.cs | 4 +- .../AddRespawnTargetMultiplierConfig.cs | 54 ------------------- Exiled.Events/Patches/Generic/LiftList.cs | 10 ++-- .../Patches/Generic/PickupControlPatch.cs | 4 +- Exiled.Events/Patches/Generic/TargetOffset.cs | 2 +- Exiled.Events/Patches/Generic/TeleportList.cs | 22 +++++--- 8 files changed, 30 insertions(+), 80 deletions(-) delete mode 100644 Exiled.Events/Patches/Generic/AddRespawnTargetMultiplierConfig.cs diff --git a/Exiled.Events/EventArgs/Server/RespawnedTeamEventArgs.cs b/Exiled.Events/EventArgs/Server/RespawnedTeamEventArgs.cs index 6af48698ec..b48f565d4b 100644 --- a/Exiled.Events/EventArgs/Server/RespawnedTeamEventArgs.cs +++ b/Exiled.Events/EventArgs/Server/RespawnedTeamEventArgs.cs @@ -13,6 +13,7 @@ namespace Exiled.Events.EventArgs.Server using Exiled.API.Features; using Exiled.Events.EventArgs.Interfaces; using Respawning; + using Respawning.Waves; /// /// Contains all information after a team has spawned. @@ -24,7 +25,7 @@ public class RespawnedTeamEventArgs : IExiledEvent /// /// /// - public RespawnedTeamEventArgs(SpawnableTeamType team, IEnumerable hubs) + public RespawnedTeamEventArgs(SpawnableWaveBase team, IEnumerable hubs) { Players = hubs.Select(Player.Get); Team = team; @@ -38,6 +39,6 @@ public RespawnedTeamEventArgs(SpawnableTeamType team, IEnumerable /// /// Gets the spawned team. /// - public SpawnableTeamType Team { get; } + public SpawnableWaveBase Team { get; } } } \ No newline at end of file diff --git a/Exiled.Events/Events.cs b/Exiled.Events/Events.cs index ed5b939b28..ba61519c7f 100644 --- a/Exiled.Events/Events.cs +++ b/Exiled.Events/Events.cs @@ -17,7 +17,6 @@ namespace Exiled.Events using CentralAuth; using Exiled.API.Interfaces; using Exiled.Events.Features; - using HarmonyLib; using InventorySystem.Items.Pickups; using InventorySystem.Items.Usables; using PlayerRoles.Ragdolls; @@ -62,7 +61,7 @@ public override void OnEnabled() PlayerAuthenticationManager.OnInstanceModeChanged -= RoleAssigner.CheckLateJoin; SceneManager.sceneUnloaded += Handlers.Internal.SceneUnloaded.OnSceneUnloaded; - MapGeneration.SeedSynchronizer.OnMapGenerated += Handlers.Internal.MapGenerated.OnMapGenerated; + MapGeneration.SeedSynchronizer.OnGenerationFinished += Handlers.Internal.MapGenerated.OnMapGenerated; UsableItemsController.ServerOnUsingCompleted += Handlers.Internal.Round.OnServerOnUsingCompleted; Handlers.Server.WaitingForPlayers += Handlers.Internal.Round.OnWaitingForPlayers; Handlers.Server.RestartingRound += Handlers.Internal.Round.OnRestartingRound; @@ -77,7 +76,7 @@ public override void OnEnabled() InventorySystem.InventoryExtensions.OnItemAdded += Handlers.Player.OnItemAdded; InventorySystem.InventoryExtensions.OnItemRemoved += Handlers.Player.OnItemRemoved; - RespawnManager.ServerOnRespawned += Handlers.Server.OnRespawnedTeam; + WaveManager.OnWaveSpawned += Handlers.Server.OnRespawnedTeam; RagdollManager.OnRagdollSpawned += Handlers.Internal.RagdollList.OnSpawnedRagdoll; RagdollManager.OnRagdollRemoved += Handlers.Internal.RagdollList.OnRemovedRagdoll; @@ -110,7 +109,7 @@ public override void OnDisabled() Unpatch(); SceneManager.sceneUnloaded -= Handlers.Internal.SceneUnloaded.OnSceneUnloaded; - MapGeneration.SeedSynchronizer.OnMapGenerated -= Handlers.Internal.MapGenerated.OnMapGenerated; + MapGeneration.SeedSynchronizer.OnGenerationFinished -= Handlers.Internal.MapGenerated.OnMapGenerated; UsableItemsController.ServerOnUsingCompleted -= Handlers.Internal.Round.OnServerOnUsingCompleted; Handlers.Server.WaitingForPlayers -= Handlers.Internal.Round.OnWaitingForPlayers; @@ -126,7 +125,7 @@ public override void OnDisabled() InventorySystem.InventoryExtensions.OnItemAdded -= Handlers.Player.OnItemAdded; InventorySystem.InventoryExtensions.OnItemRemoved -= Handlers.Player.OnItemRemoved; - RespawnManager.ServerOnRespawned -= Handlers.Server.OnRespawnedTeam; + WaveManager.OnWaveSpawned -= Handlers.Server.OnRespawnedTeam; RagdollManager.OnRagdollSpawned -= Handlers.Internal.RagdollList.OnSpawnedRagdoll; RagdollManager.OnRagdollRemoved -= Handlers.Internal.RagdollList.OnRemovedRagdoll; diff --git a/Exiled.Events/Handlers/Server.cs b/Exiled.Events/Handlers/Server.cs index 9d97876290..14bd3cb5c6 100644 --- a/Exiled.Events/Handlers/Server.cs +++ b/Exiled.Events/Handlers/Server.cs @@ -10,10 +10,10 @@ namespace Exiled.Events.Handlers using System.Collections.Generic; using Respawning; + using Respawning.Waves; #pragma warning disable SA1623 // Property summary documentation should match accessors - using Exiled.Events.EventArgs.Player; using Exiled.Events.EventArgs.Server; using Exiled.Events.Features; @@ -197,7 +197,7 @@ public static class Server /// /// /// - public static void OnRespawnedTeam(SpawnableTeamType teamType, List hubs) => RespawnedTeam.InvokeSafely(new RespawnedTeamEventArgs(teamType, hubs)); + public static void OnRespawnedTeam(SpawnableWaveBase teamType, List hubs) => RespawnedTeam.InvokeSafely(new RespawnedTeamEventArgs(teamType, hubs)); /// /// Called before adding an unit name. diff --git a/Exiled.Events/Patches/Generic/AddRespawnTargetMultiplierConfig.cs b/Exiled.Events/Patches/Generic/AddRespawnTargetMultiplierConfig.cs deleted file mode 100644 index 0054fd3a30..0000000000 --- a/Exiled.Events/Patches/Generic/AddRespawnTargetMultiplierConfig.cs +++ /dev/null @@ -1,54 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Exiled Team. All rights reserved. -// Licensed under the CC BY-SA 3.0 license. -// -// ----------------------------------------------------------------------- - -namespace Exiled.Events.Patches.Generic.Scp079API -{ - using System.Collections.Generic; - using System.Reflection.Emit; - - using API.Features.Core.Generic.Pools; - using HarmonyLib; - - using static HarmonyLib.AccessTools; - - using Scp049Role = API.Features.Roles.Scp049Role; - - /// - /// Patches . - /// Adds the as NW config. - /// - [HarmonyPatch(typeof(RoundSummary), nameof(RoundSummary.ServerOnRespawned))] - internal class AddRespawnTargetMultiplierConfig - { - private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) - { - List newInstructions = ListPool.Pool.Get(instructions); - - // replace "this.ChaosTargetCount += (int)((double)respawnedPlayers.Count * 0.75);" - // with " this.ChaosTargetCount += (int)((double)respawnedPlayers.Count * ConfigFile.ServerConfig.GetDouble("respawn_target_multiplier", 0.75);" - int offset = 0; - int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldc_R8) + offset; - newInstructions.RemoveAt(index); - - newInstructions.InsertRange( - index, - new CodeInstruction[] - { - // ConfigFile.ServerConfig.GetDouble("respawn_target_multiplier", 0.75); - new(OpCodes.Ldsfld, Field(typeof(GameCore.ConfigFile), nameof(GameCore.ConfigFile.ServerConfig))), - new(OpCodes.Ldstr, "respawn_target_multiplier"), - new(OpCodes.Ldc_R8, RoundSummary.RespawnTargetMultiplier), - new(OpCodes.Call, Method(typeof(YamlConfig), nameof(YamlConfig.GetDouble))), - }); - - 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.Events/Patches/Generic/LiftList.cs b/Exiled.Events/Patches/Generic/LiftList.cs index 397a305c40..ade3c06a0c 100644 --- a/Exiled.Events/Patches/Generic/LiftList.cs +++ b/Exiled.Events/Patches/Generic/LiftList.cs @@ -7,26 +7,24 @@ namespace Exiled.Events.Patches.Generic { - using System.Collections.Generic; - using API.Features; using HarmonyLib; using Interactables.Interobjects; /// - /// Patches . + /// Patches . /// - [HarmonyPatch(typeof(ElevatorManager), nameof(ElevatorManager.RefreshChambers))] + [HarmonyPatch(typeof(ElevatorManager), nameof(ElevatorManager.SpawnAllChambers))] internal class LiftList { private static void Postfix() { Lift.ElevatorChamberToLift.Clear(); - foreach (KeyValuePair lift in ElevatorManager.SpawnedChambers) + foreach (ElevatorChamber lift in ElevatorChamber.AllChambers) { - Lift.Get(lift.Value); + Lift.Get(lift); } } } diff --git a/Exiled.Events/Patches/Generic/PickupControlPatch.cs b/Exiled.Events/Patches/Generic/PickupControlPatch.cs index bcb689f8ab..7a97064497 100644 --- a/Exiled.Events/Patches/Generic/PickupControlPatch.cs +++ b/Exiled.Events/Patches/Generic/PickupControlPatch.cs @@ -30,9 +30,9 @@ namespace Exiled.Events.Patches.Generic #pragma warning disable SA1402 /// File may only contain a single type. /// - /// Patches to save scale for pickups and control property. + /// Patches to save scale for pickups and control property. /// - [HarmonyPatch(typeof(InventoryExtensions), nameof(InventoryExtensions.ServerCreatePickup), typeof(ItemBase), typeof(PickupSyncInfo), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(Action))] + [HarmonyPatch(typeof(InventoryExtensions), nameof(InventoryExtensions.ServerCreatePickup), typeof(ItemBase), typeof(PickupSyncInfo?), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(Action))] internal static class PickupControlPatch { private static IEnumerable Transpiler( diff --git a/Exiled.Events/Patches/Generic/TargetOffset.cs b/Exiled.Events/Patches/Generic/TargetOffset.cs index a3435ff42e..41931cb586 100644 --- a/Exiled.Events/Patches/Generic/TargetOffset.cs +++ b/Exiled.Events/Patches/Generic/TargetOffset.cs @@ -28,7 +28,7 @@ internal static class TargetOffset private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { static bool IsField(CodeInstruction instruction) => instruction.opcode == OpCodes.Ldfld - && (FieldInfo)instruction.operand == Field(typeof(RoundSummary), nameof(RoundSummary._chaosTargetCount)); + && (FieldInfo)instruction.operand == Field(typeof(RoundSummary), nameof(RoundSummary._extraTargets)); List newInstructions = ListPool.Pool.Get(instructions); diff --git a/Exiled.Events/Patches/Generic/TeleportList.cs b/Exiled.Events/Patches/Generic/TeleportList.cs index d15d9d2673..22fa479102 100644 --- a/Exiled.Events/Patches/Generic/TeleportList.cs +++ b/Exiled.Events/Patches/Generic/TeleportList.cs @@ -7,20 +7,26 @@ namespace Exiled.Events.Patches.Generic { +#pragma warning disable SA1313 +#pragma warning disable SA1402 using API.Features; using HarmonyLib; - using MapGeneration; /// - /// Patches . + /// Patches . /// - [HarmonyPatch(typeof(ImageGenerator), nameof(ImageGenerator.GenerateMap))] + [HarmonyPatch(typeof(PocketDimensionTeleport), nameof(PocketDimensionTeleport.Awake))] internal class TeleportList { - private static void Prefix() - { - Map.TeleportsValue.Clear(); - Map.TeleportsValue.AddRange(UnityEngine.Object.FindObjectsOfType()); - } + private static void Postfix(PocketDimensionTeleport __instance) => Map.TeleportsValue.Add(__instance); + } + + /// + /// Patches . + /// + [HarmonyPatch(typeof(PocketDimensionTeleport), nameof(PocketDimensionTeleport.OnDestroy))] + internal class TeleportListRemove + { + private static void Postfix(PocketDimensionTeleport __instance) => Map.TeleportsValue.Remove(__instance); } } \ No newline at end of file