diff --git a/EXILED/Exiled.Events/Patches/Events/Server/CompletingObjective.cs b/EXILED/Exiled.Events/Patches/Events/Server/CompletingObjective.cs index cf9f9aacbe..7da7da50e1 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/CompletingObjective.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/CompletingObjective.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) ExMod Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -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; @@ -30,7 +36,7 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); - Label returnLabel = generator.DefineLabel(); + Label retModLabel = generator.DefineLabel(); newInstructions.InsertRange(0, new CodeInstruction[] { @@ -48,17 +54,37 @@ private static IEnumerable Transpiler(IEnumerable.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()) + { + if (wave.TargetFaction == footprintObjective.ObjectiveFootprint.AchievingPlayer.RoleType.GetFaction() && wave.ReceiveObjectiveRewards) + { + wave.Timer.AddTime(-footprintObjective.ObjectiveFootprint.TimeReward); + } + } + } + } } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Fixes/FixGeneratorActivatedObjective.cs b/EXILED/Exiled.Events/Patches/Fixes/FixGeneratorActivatedObjective.cs new file mode 100644 index 0000000000..ca481137ed --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Fixes/FixGeneratorActivatedObjective.cs @@ -0,0 +1,58 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +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; + + /// + /// Patches 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). + /// + [HarmonyPatch(typeof(GeneratorActivatedObjective), nameof(GeneratorActivatedObjective.OnGeneratorEngaged))] + internal class FixGeneratorActivatedObjective + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.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.Pool.Return(newInstructions); + } + } +}