diff --git a/EXILED/Exiled.Events/Config.cs b/EXILED/Exiled.Events/Config.cs index fd244f699..8f90d158b 100644 --- a/EXILED/Exiled.Events/Config.cs +++ b/EXILED/Exiled.Events/Config.cs @@ -50,6 +50,12 @@ public sealed class Config : IConfig [Description("Indicates whether tutorial is affected by SCP-079 scan.")] public bool TutorialNotAffectedByScp079Scan { get; set; } = false; + /// + /// Gets or sets a value indicating whether the last human glowing effect is enabled. + /// + [Description("Indicates whether the last human glowing effect is enabled")] + public bool CanLastHumanGlow { get; set; } = true; + /// /// Gets or sets a value indicating whether flashbangs flash original thrower. /// diff --git a/EXILED/Exiled.Events/Patches/Generic/LastTargetGlowing.cs b/EXILED/Exiled.Events/Patches/Generic/LastTargetGlowing.cs new file mode 100644 index 000000000..d0fda2056 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Generic/LastTargetGlowing.cs @@ -0,0 +1,64 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Generic +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using Exiled.API.Features; + using Exiled.API.Features.Pools; + + using HarmonyLib; + + using PlayerRoles.PlayableScps.HumanTracker; + + using UnityEngine; + + using static HarmonyLib.AccessTools; + + using ExiledEvents = Exiled.Events.Events; + + /// + /// Patches setter to implement . + /// + [HarmonyPatch(typeof(LastHumanTracker), nameof(LastHumanTracker.Network_lastTargetPos), MethodType.Setter)] + public class LastTargetGlowing + { + private static readonly Vector3? FakePosition = new(999f, 999f, 999f); + + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label continueLabel = generator.DefineLabel(); + + newInstructions[0].labels.Add(continueLabel); + + newInstructions.InsertRange( + 0, + new CodeInstruction[] + { + // if (!ExiledEvents.Instance.Config.LastHumanGlowing) + // goto continueLabel; + new(OpCodes.Call, PropertyGetter(typeof(ExiledEvents), nameof(ExiledEvents.Instance))), + new(OpCodes.Callvirt, PropertyGetter(typeof(Plugin), nameof(Plugin.Config))), + new(OpCodes.Callvirt, PropertyGetter(typeof(Config), nameof(Config.CanLastHumanGlow))), + new(OpCodes.Brtrue_S, continueLabel), + + // value = FakeVector; + new(OpCodes.Ldsfld, AccessTools.Field(typeof(LastTargetGlowing), nameof(FakePosition))), + new(OpCodes.Starg_S, 1), + }); + + for (int z = 0; z < newInstructions.Count; ++z) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +}