Skip to content

Commit

Permalink
RecontainedWhenNoScps feature (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Aug 28, 2024
1 parent 532fdfb commit 96ecc24
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 8 deletions.
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 RecontainScp079IfNoScpsLeft { get; set; } = true;

/// <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.RecontainScp079IfNoScpsLeft" /> 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.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<CodeInstruction>.Pool.Return(newInstructions);
}
}
}

0 comments on commit 96ecc24

Please sign in to comment.