-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RoundStartingEventArgs.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.Events.EventArgs.Server | ||
{ | ||
/// <summary> | ||
/// Contains nothing. | ||
/// </summary> | ||
public class RoundStartingEventArgs | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RoundStartingEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="isAllowed"> | ||
/// <inheritdoc cref="IsAllowed" /> | ||
/// </param> | ||
public RoundStartingEventArgs(bool isAllowed = true) | ||
{ | ||
IsAllowed = isAllowed; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the event can continue. | ||
/// </summary> | ||
public bool IsAllowed { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RoundStarting.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.Events.Patches.Events.Server | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
|
||
using API.Features.Pools; | ||
using Exiled.Events.Attributes; | ||
using Exiled.Events.EventArgs.Server; | ||
using Exiled.Events.Handlers; | ||
|
||
using GameCore; | ||
|
||
using HarmonyLib; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
/// <summary> | ||
/// Patch the <see cref="RoundStart.NetworkTimer" />. | ||
/// Adds the <see cref="Server.RoundStarting" /> event. | ||
/// </summary> | ||
[EventPatch(typeof(Server), nameof(Server.ReportingCheater))] | ||
[HarmonyPatch(typeof(RoundStart), nameof(RoundStart.NetworkTimer), MethodType.Setter)] | ||
internal static class RoundStarting | ||
{ | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
||
Label ret = generator.DefineLabel(); | ||
Label contlabel = generator.DefineLabel(); | ||
|
||
newInstructions[newInstructions.Count - 1].labels.Add(ret); | ||
LocalBuilder ev = generator.DeclareLocal(typeof(RoundStartingEventArgs)); | ||
|
||
newInstructions.InsertRange( | ||
0, | ||
new CodeInstruction[] | ||
{ | ||
// Getting a old value | ||
new CodeInstruction(OpCodes.Ldarg_1), | ||
// Getting a new value | ||
Check failure on line 48 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 48 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 48 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 48 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 48 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
|
||
new CodeInstruction(OpCodes.Ldc_I4, -1), | ||
// If the value is not equal, jump | ||
Check failure on line 50 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 50 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 50 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 50 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
Check failure on line 50 in Exiled.Events/Patches/Events/Server/RoundStarting.cs GitHub Actions / build
|
||
new CodeInstruction(OpCodes.Bne_Un, contlabel), | ||
|
||
// RoundStartingEventArgs ev = new | ||
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(RoundStartingEventArgs))[0]), | ||
new CodeInstruction(OpCodes.Dup), | ||
new CodeInstruction(OpCodes.Stloc_S, ev.LocalIndex), | ||
|
||
// Handlers.Server.OnRoundStarting(ev) | ||
new CodeInstruction(OpCodes.Call, Method(typeof(Server), nameof(Server.OnRoundStarting))), | ||
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex), | ||
|
||
// If isallowed = false | ||
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(RoundStartingEventArgs), nameof(RoundStartingEventArgs.IsAllowed))), | ||
new CodeInstruction(OpCodes.Brfalse_S, ret), | ||
|
||
// Empty opcode for jump | ||
new CodeInstruction(OpCodes.Nop).WithLabels(contlabel), | ||
}); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |