Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecontainedWhenNoScps feature #16

Merged
merged 10 commits into from
Aug 28, 2024
8 changes: 7 additions & 1 deletion EXILED/Exiled.Events/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Gets or sets a value indicating whether the SCP079 will recontained if there are no SCPs left.
/// </summary>
[Description("Indicates whether the SCP079 will recontained if there are no SCPs left.")]
public bool ShouldRecontainScp079IfNoScpsLeft { get; set; } = true;
louis1706 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets a value indicating whether configs has to be reloaded every time a round restarts.
/// </summary>
Expand All @@ -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.
/// </summary>
[Description("Indicates whether translations has to be reloaded every round restart")]
public bool ShouldReloadTranslationsAtRoundRestart { get; set; }
public bool ShouldReloadTranslationsAtRoundRestart { get; set; } = false;

/// <summary>
/// Gets a value indicating whether bans should be logged or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, PropertySetter(typeof(WorkstationController), nameof(WorkstationController.NetworkStatus))),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Brfalse_S, returnLabel),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Events/Scp096/AddingTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Brfalse_S, returnLabel),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Events/Scp096/CalmingDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Starg_S, 1),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Brfalse, returnLabel),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Brfalse_S, returnLabel),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// otherwise the second check won't be executed
Label secondCheckPointer = generator.DefineLabel();

newInstructions[0].WithLabels(continueLabel);
newInstructions[0].labels.Add(continueLabel);

// if (referenceHub.roleManager.CurrentRole.RoleTypeId == RoleTypeId.Tutorial && !ExiledEvents.Instance.Config.CanTutorialTriggerScp096
// || Scp096Role.TurnedPlayers.Contains(Player.Get(referenceHub)))
Expand Down
54 changes: 54 additions & 0 deletions EXILED/Exiled.Events/Patches/Generic/Scp079Recontain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="Scp079Recontain.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.Generic.Scp079API
{
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features.Pools;

using HarmonyLib;

using PlayerRoles.PlayableScps.Scp079;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="Scp079Recontainer.OnServerRoleChanged(ReferenceHub, PlayerRoles.RoleTypeId, PlayerRoles.RoleChangeReason)"/>.
/// Adds the <see cref="Exiled.Events.Config.ShouldRecontainScp079IfNoScpsLeft" /> support.
/// </summary>
[HarmonyPatch(typeof(Scp079Recontainer), nameof(Scp079Recontainer.OnServerRoleChanged))]
internal class Scp079Recontain
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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.ShouldRecontainScp079IfNoScpsLeft))),
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<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
Loading