diff --git a/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs
index 58e6d66ba2..e0e7fb8931 100644
--- a/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs
+++ b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingChaosEntranceEventArgs.cs
@@ -7,6 +7,8 @@
namespace Exiled.Events.EventArgs.Map
{
+ using System.Text;
+
using Exiled.API.Features.Waves;
using Exiled.Events.EventArgs.Interfaces;
using Respawning.Announcements;
@@ -20,11 +22,11 @@ public class AnnouncingChaosEntranceEventArgs : IDeniableEvent
/// Initializes a new instance of the class.
///
///
- ///
- public AnnouncingChaosEntranceEventArgs(WaveAnnouncementBase announcement, bool isAllowed = true)
+ ///
+ public AnnouncingChaosEntranceEventArgs(WaveAnnouncementBase announcement, StringBuilder builder)
{
Wave = TimedWave.GetTimedWaves().Find(x => x.Announcement == announcement);
- IsAllowed = isAllowed;
+ Words = builder;
}
///
@@ -32,7 +34,13 @@ public AnnouncingChaosEntranceEventArgs(WaveAnnouncementBase announcement, bool
///
public TimedWave Wave { get; }
+ ///
+ /// Gets the of the words that C.A.S.S.I.E will say.
+ /// It doesn't affect the subtitle part that will be sent to the client.
+ ///
+ public StringBuilder Words { get; }
+
///
- public bool IsAllowed { get; set; }
+ public bool IsAllowed { get; set; } = true;
}
}
\ 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 508e471b61..40a9fd3151 100644
--- a/EXILED/Exiled.Events/EventArgs/Map/AnnouncingNtfEntranceEventArgs.cs
+++ b/EXILED/Exiled.Events/EventArgs/Map/AnnouncingNtfEntranceEventArgs.cs
@@ -7,7 +7,9 @@
namespace Exiled.Events.EventArgs.Map
{
+ using Exiled.API.Features.Waves;
using Interfaces;
+ using Respawning.Announcements;
///
/// Contains all information before C.A.S.S.I.E announces the NTF entrance.
@@ -17,26 +19,23 @@ public class AnnouncingNtfEntranceEventArgs : IDeniableEvent
///
/// Initializes a new instance of the class.
///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public AnnouncingNtfEntranceEventArgs(int scpsLeft, string unitName, int unitNumber, bool isAllowed = true)
+ ///
+ ///
+ ///
+ ///
+ public AnnouncingNtfEntranceEventArgs(WaveAnnouncementBase announcement, int scpsLeft, string unitName, int unitNumber)
{
+ Wave = TimedWave.GetTimedWaves().Find(x => x.Announcement == announcement);
ScpsLeft = scpsLeft;
UnitName = unitName;
UnitNumber = unitNumber;
- IsAllowed = isAllowed;
}
+ ///
+ /// Gets the entering wave.
+ ///
+ public TimedWave Wave { get; }
+
///
/// Gets or sets the number of SCPs left.
///
@@ -55,6 +54,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; } // TODO possibly not working
+ public bool IsAllowed { get; set; } = true;
}
}
\ No newline at end of file
diff --git a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs
index 16176c8d35..1bf2c9c02d 100644
--- a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs
+++ b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingChaosEntrance.cs
@@ -8,7 +8,9 @@
namespace Exiled.Events.Patches.Events.Map
{
using System.Collections.Generic;
+ using System.Reflection;
using System.Reflection.Emit;
+ using System.Text;
using Exiled.API.Features.Pools;
using Exiled.Events.Attributes;
@@ -23,32 +25,55 @@ namespace Exiled.Events.Patches.Events.Map
/// to add event.
///
[EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.AnnouncingChaosEntrance))]
- [HarmonyPatch(typeof(ChaosWaveAnnouncement), nameof(ChaosWaveAnnouncement.CreateAnnouncementString))]
- [HarmonyPatch(typeof(ChaosMiniwaveAnnouncement), nameof(ChaosMiniwaveAnnouncement.CreateAnnouncementString))]
+ [HarmonyPatch]
internal static class AnnouncingChaosEntrance
{
+ private static IEnumerable TargetMethods()
+ {
+ yield return Method(typeof(ChaosWaveAnnouncement), nameof(ChaosWaveAnnouncement.CreateAnnouncementString));
+ yield return Method(typeof(ChaosMiniwaveAnnouncement), nameof(ChaosMiniwaveAnnouncement.CreateAnnouncementString));
+ }
+
private static IEnumerable Transpiler(IEnumerable instruction, ILGenerator generator)
{
List newInstructions = ListPool.Pool.Get(instruction);
- Label returnLabel = generator.DefineLabel();
+ Label continueLabel = generator.DefineLabel();
+
+ LocalBuilder ev = generator.DeclareLocal(typeof(AnnouncingChaosEntranceEventArgs));
+
+ int index = newInstructions.FindIndex(i => i.opcode == OpCodes.Ldloca_S);
- newInstructions.InsertRange(0, new CodeInstruction[]
+ newInstructions.InsertRange(index, new[]
{
+ // WaveAnnouncementBase
new(OpCodes.Ldarg_0),
- new(OpCodes.Ldc_I4_1),
+ // builder
+ new(OpCodes.Ldarg_1),
+ // new AnnouncingChaosEntranceEventArgs(WaveAnnouncementBase, StringBuilder)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(AnnouncingChaosEntranceEventArgs))[0]),
new(OpCodes.Dup),
+ new(OpCodes.Dup),
+ new(OpCodes.Stloc_S, ev.LocalIndex),
+ // Map.OnAnnouncingChaosEntrance(ev)
new(OpCodes.Call, Method(typeof(Handlers.Map), nameof(Handlers.Map.OnAnnouncingChaosEntrance))),
+ // if (!ev.IsAllowed)
+ // builder.Clear();
+ // return;
new(OpCodes.Callvirt, PropertyGetter(typeof(AnnouncingChaosEntranceEventArgs), nameof(AnnouncingChaosEntranceEventArgs.IsAllowed))),
- new(OpCodes.Brfalse_S, returnLabel),
- });
+ new(OpCodes.Brtrue_S, continueLabel),
- newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
+ new(OpCodes.Ldarg_1),
+ new(OpCodes.Callvirt, Method(typeof(StringBuilder), nameof(StringBuilder.Clear))),
+ new(OpCodes.Pop),
+ new(OpCodes.Ret),
+
+ new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel),
+ });
for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
diff --git a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs
index 24d20d8216..f9663ecc7e 100644
--- a/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs
+++ b/EXILED/Exiled.Events/Patches/Events/Map/AnnouncingNtfEntrance.cs
@@ -8,6 +8,7 @@
namespace Exiled.Events.Patches.Events.Map
{
using System.Collections.Generic;
+ using System.Reflection;
using System.Reflection.Emit;
using System.Text.RegularExpressions;
@@ -26,10 +27,15 @@ namespace Exiled.Events.Patches.Events.Map
/// Adds the event.
///
[EventPatch(typeof(Map), nameof(Map.AnnouncingNtfEntrance))]
- [HarmonyPatch(typeof(NtfWaveAnnouncement), nameof(NtfWaveAnnouncement.CreateAnnouncementString))]
- [HarmonyPatch(typeof(NtfMiniwaveAnnouncement), nameof(NtfMiniwaveAnnouncement.CreateAnnouncementString))]
+ [HarmonyPatch]
internal static class AnnouncingNtfEntrance
{
+ private static IEnumerable TargetMethods()
+ {
+ yield return Method(typeof(NtfWaveAnnouncement), nameof(NtfWaveAnnouncement.CreateAnnouncementString));
+ yield return Method(typeof(NtfMiniwaveAnnouncement), nameof(NtfMiniwaveAnnouncement.CreateAnnouncementString));
+ }
+
private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator)
{
List newInstructions = ListPool.Pool.Get(instructions);
@@ -42,23 +48,13 @@ private static IEnumerable Transpiler(IEnumerable 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);
- // string[] unitInformation = unitNameClear.Split('-');
- //
- // AnnouncingNtfEntranceEventArgs ev = new(scpsLeft, unitInformation[0], int.Parse(unitInformation[1]));
- // Map.OnAnnouncingNtfEntrance(ev);
- //
- // if (!ev.IsAllowed)
- // return;
- //
- // unitName = $"{ev.UnitName}-{ev.UnitNumber};
- // cassieUnitName = this.GetCassieUnitName(unitName);
- // scpsLeft = ev.ScpsLeft;
newInstructions.InsertRange(
index,
new CodeInstruction[]
{
+ // WaveAnnouncementBase
+ new(OpCodes.Ldarg_0),
+
// int scpsLeft = ReferenceHub.GetAllHubs().Values.Count(x => x.characterClassManager.CurRole.team == Team.SCP && x.characterClassManager.CurClass != RoleTypeId.Scp0492);
new(OpCodes.Ldloc_3),
@@ -86,7 +82,6 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable
+// 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;
+ using System.Reflection.Emit;
+ using System.Text;
+
+ using Exiled.API.Features.Pools;
+ using Exiled.Events.Attributes;
+ using Exiled.Events.EventArgs.Map;
+ using HarmonyLib;
+ using Respawning.Announcements;
+
+ using static HarmonyLib.AccessTools;
+
+ ///
+ /// Patches to prevent cassie from playing empty string.
+ ///
+ [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.AnnouncingNtfEntrance))]
+ [EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.AnnouncingChaosEntrance))]
+ [HarmonyPatch(typeof(WaveAnnouncementBase), nameof(WaveAnnouncementBase.PlayAnnouncement))]
+ internal static class AnnouncingTeamEntrance
+ {
+ private static IEnumerable Transpiler(IEnumerable instruction, ILGenerator generator)
+ {
+ List newInstructions = ListPool.Pool.Get(instruction);
+
+ Label returnLabel = generator.DefineLabel();
+
+ int index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ldsfld);
+
+ newInstructions.InsertRange(index, new CodeInstruction[]
+ {
+ // if (stringReturn == "")
+ // return;
+ new(OpCodes.Ldloc_S, 4),
+ new(OpCodes.Ldstr, string.Empty),
+ new(OpCodes.Ceq),
+ new(OpCodes.Brtrue_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