forked from ExMod-Team/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
EXILED/Exiled.Events/EventArgs/Warhead/DeadmanSwitchInitiatingEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="DeadmanSwitchInitiatingEventArgs.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.Events.EventArgs.Warhead | ||
{ | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before detonating the warhead. | ||
/// </summary> | ||
public class DeadmanSwitchInitiatingEventArgs : IDeniableEvent | ||
{ | ||
/// <inheritdoc/> | ||
public bool IsAllowed { get; set; } = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
EXILED/Exiled.Events/Patches/Events/Warhead/DeadmanSwitchStart.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="DeadmanSwitchStart.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.Events.Patches.Events.Warhead | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
|
||
using API.Features.Pools; | ||
using Exiled.Events.Attributes; | ||
using Exiled.Events.EventArgs.Warhead; | ||
using Handlers; | ||
using HarmonyLib; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
/// <summary> | ||
/// Patches <see cref="AlphaWarheadController.Detonate" /> | ||
/// to add <see cref="Exiled.API.Features.Warhead.DisableDeadmanSwitch"/> and <see cref="Warhead.DeadmanSwitchInitiating"/> events. | ||
/// </summary> | ||
[EventPatch(typeof(Warhead), nameof(Warhead.DeadmanSwitchInitiating))] | ||
[HarmonyPatch(typeof(DeadmanSwitch), nameof(DeadmanSwitch.InitiateProtocol))] | ||
internal static class DeadmanSwitchStart | ||
{ | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
||
Label retLabel = generator.DefineLabel(); | ||
LocalBuilder ev = generator.DeclareLocal(typeof(DetonatingEventArgs)); | ||
|
||
newInstructions.InsertRange(0, new CodeInstruction[] | ||
{ | ||
// if (Exiled.API.Features.Warhead.DisableDeadmanSwitch) | ||
// return; | ||
new(OpCodes.Call, PropertyGetter(typeof(Exiled.API.Features.Warhead), nameof(Exiled.API.Features.Warhead.DisableDeadmanSwitch))), | ||
new(OpCodes.Brtrue_S, retLabel), | ||
|
||
// DeadmanSwitchInitiatingEventArgs ev = new(); | ||
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(DeadmanSwitchInitiatingEventArgs))[0]), | ||
new(OpCodes.Dup), | ||
|
||
// Handlers.Warhead.OnDeadmanSwitchInitiating(ev); | ||
new(OpCodes.Call, Method(typeof(Warhead), nameof(Warhead.OnDeadmanSwitchInitiating))), | ||
|
||
// if (ev.IsAllowed) | ||
// goto retLabel; | ||
new(OpCodes.Callvirt, PropertyGetter(typeof(DeadmanSwitchInitiatingEventArgs), nameof(DeadmanSwitchInitiatingEventArgs.IsAllowed))), | ||
new(OpCodes.Brfalse_S, retLabel), | ||
}); | ||
|
||
newInstructions[newInstructions.Count - 1].labels.Add(retLabel); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |