From 96ecc2498d6cb23689b3ff8ee7e8d5a9c6f84d25 Mon Sep 17 00:00:00 2001
From: Yamato <66829532+louis1706@users.noreply.github.com>
Date: Wed, 28 Aug 2024 08:23:42 +0200
Subject: [PATCH] `RecontainedWhenNoScps` feature (#16)
---
EXILED/Exiled.Events/Config.cs | 8 ++-
.../Events/Player/ActivatingWorkstation.cs | 2 +-
.../Events/Player/ChangingDangerState.cs | 2 +-
.../Patches/Events/Scp096/AddingTarget.cs | 2 +-
.../Patches/Events/Scp096/CalmingDown.cs | 2 +-
.../Patches/Events/Scp173/BlinkingRequest.cs | 2 +-
.../Patches/Events/Server/AddingUnitName.cs | 2 +-
.../Patches/Generic/ParseVisionInformation.cs | 2 +-
.../Patches/Generic/Scp079Recontain.cs | 54 +++++++++++++++++++
9 files changed, 68 insertions(+), 8 deletions(-)
create mode 100644 EXILED/Exiled.Events/Patches/Generic/Scp079Recontain.cs
diff --git a/EXILED/Exiled.Events/Config.cs b/EXILED/Exiled.Events/Config.cs
index 006be02b2..b141cd17e 100644
--- a/EXILED/Exiled.Events/Config.cs
+++ b/EXILED/Exiled.Events/Config.cs
@@ -80,6 +80,12 @@ public sealed class Config : IConfig
[Description("Indicates whether thrown keycards can affect doors that don't require any permissions")]
public bool CanKeycardThrowAffectDoors { get; set; } = false;
+ ///
+ /// Gets or sets a value indicating whether the SCP079 will recontained if there are no SCPs left.
+ ///
+ [Description("Indicates whether the SCP079 will recontained if there are no SCPs left.")]
+ public bool RecontainScp079IfNoScpsLeft { get; set; } = true;
+
///
/// Gets or sets a value indicating whether configs has to be reloaded every time a round restarts.
///
@@ -90,7 +96,7 @@ public sealed class Config : IConfig
/// Gets or sets a value indicating whether translations has to be reloaded every time a round restarts.
///
[Description("Indicates whether translations has to be reloaded every round restart")]
- public bool ShouldReloadTranslationsAtRoundRestart { get; set; }
+ public bool ShouldReloadTranslationsAtRoundRestart { get; set; } = false;
///
/// Gets a value indicating whether bans should be logged or not.
diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ActivatingWorkstation.cs b/EXILED/Exiled.Events/Patches/Events/Player/ActivatingWorkstation.cs
index 4ee58f8ec..28edd3803 100644
--- a/EXILED/Exiled.Events/Patches/Events/Player/ActivatingWorkstation.cs
+++ b/EXILED/Exiled.Events/Patches/Events/Player/ActivatingWorkstation.cs
@@ -78,7 +78,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.Events.Patches.Generic.Scp079API
+{
+ using System.Collections.Generic;
+ using System.Reflection.Emit;
+
+ using API.Features.Pools;
+
+ using HarmonyLib;
+
+ using PlayerRoles.PlayableScps.Scp079;
+
+ using static HarmonyLib.AccessTools;
+
+ ///
+ /// Patches .
+ /// Adds the support.
+ ///
+ [HarmonyPatch(typeof(Scp079Recontainer), nameof(Scp079Recontainer.OnServerRoleChanged))]
+ internal class Scp079Recontain
+ {
+ private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator)
+ {
+ List newInstructions = ListPool.Pool.Get(instructions);
+
+ Label ret = generator.DefineLabel();
+
+ newInstructions.InsertRange(
+ 0,
+ new[]
+ {
+ // if (!Events.Instance.Config.ShouldScp079RecontainedWhenNoScps)
+ // return;
+ new CodeInstruction(OpCodes.Call, PropertyGetter(typeof(Exiled.Events.Events), nameof(Exiled.Events.Events.Instance))),
+ new(OpCodes.Callvirt, PropertyGetter(typeof(Exiled.Events.Events), nameof(Exiled.Events.Events.Config))),
+ new(OpCodes.Callvirt, PropertyGetter(typeof(Exiled.Events.Config), nameof(Exiled.Events.Config.RecontainScp079IfNoScpsLeft))),
+ new(OpCodes.Brfalse_S, ret),
+ });
+
+ newInstructions[newInstructions.Count - 1].labels.Add(ret);
+
+ for (int z = 0; z < newInstructions.Count; z++)
+ yield return newInstructions[z];
+
+ ListPool.Pool.Return(newInstructions);
+ }
+ }
+}
\ No newline at end of file