@@ -28,22 +28,32 @@ namespace Exiled.Events.Patches.Events.Map
2828 [ HarmonyPatch ( typeof ( WaveAnnouncementBase ) , nameof ( WaveAnnouncementBase . PlayAnnouncement ) ) ]
2929 internal static class AnnouncingTeamEntrance
3030 {
31- private static IEnumerable < CodeInstruction > Transpiler ( IEnumerable < CodeInstruction > instruction , ILGenerator generator )
31+ private static IEnumerable < CodeInstruction > Transpiler ( IEnumerable < CodeInstruction > instructions , ILGenerator generator )
3232 {
33- List < CodeInstruction > newInstructions = ListPool < CodeInstruction > . Pool . Get ( instruction ) ;
33+ List < CodeInstruction > newInstructions = ListPool < CodeInstruction > . Pool . Get ( instructions ) ;
3434
3535 Label returnLabel = generator . DefineLabel ( ) ;
3636
37- int index = newInstructions . FindLastIndex ( i => i . opcode == OpCodes . Ldsfld ) ;
37+ // the instruction that sends subtitles is called before stringReturn is created (and thus checked) so we need to move it so that empty (or disallowed) message's subtitles are not sent.
38+ // this removes the Ldarg_0 and the CallVirt
39+ int index = newInstructions . FindIndex ( instruction => instruction . Calls ( Method ( typeof ( WaveAnnouncementBase ) , nameof ( WaveAnnouncementBase . SendSubtitles ) ) ) ) ;
40+ CodeInstruction sendSubtitlesInstruction = newInstructions [ index ] ;
41+ newInstructions . RemoveRange ( index - 1 , 2 ) ;
3842
39- newInstructions . InsertRange ( index , new CodeInstruction [ ]
43+ index = newInstructions . FindLastIndex ( i => i . opcode == OpCodes . Ldsfld ) ;
44+
45+ newInstructions . InsertRange ( index , new [ ]
4046 {
4147 // if (stringReturn == "")
4248 // return;
4349 new ( OpCodes . Ldloc_S , 4 ) ,
4450 new ( OpCodes . Ldstr , string . Empty ) ,
4551 new ( OpCodes . Ceq ) ,
4652 new ( OpCodes . Brtrue_S , returnLabel ) ,
53+
54+ // send subtitles before cassie message, but after our check.
55+ new ( OpCodes . Ldarg_0 ) ,
56+ sendSubtitlesInstruction ,
4757 } ) ;
4858
4959 newInstructions [ newInstructions . Count - 1 ] . labels . Add ( returnLabel ) ;
0 commit comments