Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions EXILED/Exiled.Events/Patches/Events/Server/CompletingObjective.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="CompletingObjective.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
Expand All @@ -8,13 +8,19 @@
namespace Exiled.Events.Patches.Events.Server
{
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;

using Exiled.API.Features.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Map;
using Exiled.Events.EventArgs.Server;
using Exiled.Events.Patches.Events.Map;
using HarmonyLib;
using PlayerRoles;
using Respawning;
using Respawning.Objectives;
using Respawning.Waves;

using static HarmonyLib.AccessTools;

Expand All @@ -30,7 +36,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label returnLabel = generator.DefineLabel();
Label retModLabel = generator.DefineLabel();

newInstructions.InsertRange(0, new CodeInstruction[]
{
Expand All @@ -48,17 +54,37 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server.OnCompletingObjective))),

// if (!ev.IsAllowed)
// return;
// return;
new(OpCodes.Callvirt, PropertyGetter(typeof(CompletingObjectiveEventArgs), nameof(CompletingObjectiveEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, returnLabel),
new(OpCodes.Brfalse_S, retModLabel),
});

newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
newInstructions.InsertRange(newInstructions.Count, new CodeInstruction[]
{
// faction
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(retModLabel),
new (OpCodes.Call, Method(typeof(CompletingObjective), nameof(RevertAllValue))),
});

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}

private static void RevertAllValue(FactionObjectiveBase factionObjectiveBase)
{
if (factionObjectiveBase is IFootprintObjective footprintObjective)
{
FactionInfluenceManager.Remove(footprintObjective.ObjectiveFootprint.AchievingPlayer.RoleType.GetFaction(), -footprintObjective.ObjectiveFootprint.InfluenceReward);
foreach (TimeBasedWave wave in WaveManager.Waves.Cast<TimeBasedWave>())
{
if (wave.TargetFaction == footprintObjective.ObjectiveFootprint.AchievingPlayer.RoleType.GetFaction() && wave.ReceiveObjectiveRewards)
{
wave.Timer.AddTime(-footprintObjective.ObjectiveFootprint.TimeReward);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// -----------------------------------------------------------------------
// <copyright file="FixGeneratorActivatedObjective.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Fixes
{
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features.Pools;
using Footprinting;
using HarmonyLib;
using InventorySystem;
using InventorySystem.Items.Firearms.Ammo;
using InventorySystem.Items.Pickups;
using Respawning.Objectives;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="GeneratorActivatedObjective.OnGeneratorEngaged"/> delegate.
/// Fix than LabAPI get an incorect value for when Scp079 is not prevent and than any change on timer for LabAPI will not be affected.
/// Reported at NW (https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/2184).
/// </summary>
[HarmonyPatch(typeof(GeneratorActivatedObjective), nameof(GeneratorActivatedObjective.OnGeneratorEngaged))]
internal class FixGeneratorActivatedObjective
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);
Label jump = generator.DefineLabel();
int offset = 1;
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stloc_2) + offset;

newInstructions[index].labels.Add(jump);

newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldloc_0),
new(OpCodes.Brtrue_S, jump),
new(OpCodes.Ldc_R4, 0f),
new(OpCodes.Stloc_2),
});

offset = 0;
index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldloc_0) + offset;
newInstructions.RemoveRange(index, 2);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
Loading