From 510fdf2f28876dd499a341042631969cbe1d8da1 Mon Sep 17 00:00:00 2001 From: sky Date: Sat, 3 Aug 2024 14:57:05 +0200 Subject: [PATCH 1/7] Fix Armor Drop from https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/230 --- .../Patches/Generic/ArmorDropPatch.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs diff --git a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs b/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs new file mode 100644 index 000000000..0e0d76a6c --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs @@ -0,0 +1,52 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Generic +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using Exiled.API.Features.Pools; + using HarmonyLib; + using InventorySystem; + using InventorySystem.Items; + using InventorySystem.Items.Armor; + + using static HarmonyLib.AccessTools; + + /// + /// Patches . + /// + [HarmonyPatch(typeof(BodyArmorUtils), nameof(BodyArmorUtils.RemoveEverythingExceedingLimits))] + internal static class ArmorDropPatch + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label continueLabel = generator.DefineLabel(); + int continueIndex = newInstructions.FindIndex(x => x.Is(OpCodes.Call, Method(typeof(Dictionary.Enumerator), nameof(Dictionary.Enumerator.MoveNext)))) - 1; + newInstructions[continueIndex].WithLabels(continueLabel); + + int index = newInstructions.FindIndex(x => x.Is(OpCodes.Ldc_I4_S, 9)); + + newInstructions.InsertRange(index, new CodeInstruction[] + { + new(OpCodes.Ldloca_S, 4), + new(OpCodes.Call, PropertyGetter(typeof(KeyValuePair), nameof(KeyValuePair.Value))), + new(OpCodes.Ldfld, Field(typeof(ItemBase), nameof(ItemBase.Category))), + new(OpCodes.Ldc_I4_0), + new(OpCodes.Beq_S, continueLabel), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From bdfef66fbb67f4122202c11da6c8788d0e12b379 Mon Sep 17 00:00:00 2001 From: sky Date: Sat, 3 Aug 2024 16:26:28 +0200 Subject: [PATCH 2/7] add comments --- EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs b/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs index 0e0d76a6c..3125031d5 100644 --- a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs +++ b/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs @@ -32,10 +32,13 @@ private static IEnumerable Transpiler(IEnumerable x.Is(OpCodes.Call, Method(typeof(Dictionary.Enumerator), nameof(Dictionary.Enumerator.MoveNext)))) - 1; newInstructions[continueIndex].WithLabels(continueLabel); + // before: if (keyValuePair.Value.Category != ItemCategory.Armor) + // after: if (keyValuePair.Value.Category != ItemCategory.Armor && keyValuePair.Value.Category != ItemCategory.None) int index = newInstructions.FindIndex(x => x.Is(OpCodes.Ldc_I4_S, 9)); newInstructions.InsertRange(index, new CodeInstruction[] { + // && keyValuePair.Value.Category != ItemCategory.None) new(OpCodes.Ldloca_S, 4), new(OpCodes.Call, PropertyGetter(typeof(KeyValuePair), nameof(KeyValuePair.Value))), new(OpCodes.Ldfld, Field(typeof(ItemBase), nameof(ItemBase.Category))), From 866ce48f0a5c11557d7d8535389195c112d19824 Mon Sep 17 00:00:00 2001 From: sky Date: Sat, 3 Aug 2024 19:58:00 +0200 Subject: [PATCH 3/7] fix scp173 and adding bug report link to summary class fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/143 --- .../Patches/Generic/ArmorDropPatch.cs | 2 +- .../Patches/Generic/Scp173FirstKillPatch.cs | 55 +++++++++++++++++++ .../Patches/Generic/Scp173SecondKillPatch.cs | 54 ++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs create mode 100644 EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs diff --git a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs b/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs index 3125031d5..f02a9b8b2 100644 --- a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs +++ b/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs @@ -19,7 +19,7 @@ namespace Exiled.Events.Patches.Generic using static HarmonyLib.AccessTools; /// - /// Patches . + /// Patches to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/230 bug. /// [HarmonyPatch(typeof(BodyArmorUtils), nameof(BodyArmorUtils.RemoveEverythingExceedingLimits))] internal static class ArmorDropPatch diff --git a/EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs b/EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs new file mode 100644 index 000000000..fddda38f6 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Generic +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Pools; + using CustomPlayerEffects; + using HarmonyLib; + using PlayerRoles.PlayableScps.Scp173; + using UnityEngine; + + using static HarmonyLib.AccessTools; + + /// + /// Patches to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/143 bug. + /// + [HarmonyPatch(typeof(Scp173SnapAbility), nameof(Scp173SnapAbility.TryHitTarget))] + internal static class Scp173FirstKillPatch + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label continueLabel = generator.DefineLabel(); + + int index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldc_I4_0); + newInstructions[index].WithLabels(continueLabel); + + // TODO: NRE ON LEFT CLICK (KICK PLAYER) - DO NOT PUSH + newInstructions.InsertRange(index, new CodeInstruction[] + { + // if (hub.playerEffectController.GetEffect().IsEnabled) return false; + new(OpCodes.Ldarg_1), + new(OpCodes.Ldfld, Field(typeof(ReferenceHub), nameof(ReferenceHub.playerEffectsController))), + new(OpCodes.Callvirt, Method(typeof(PlayerEffectsController), nameof(PlayerEffectsController.GetEffect), generics: new[] { typeof(SpawnProtected) })), + new(OpCodes.Callvirt, PropertyGetter(typeof(StatusEffectBase), nameof(StatusEffectBase.IsEnabled))), + new(OpCodes.Brfalse_S, continueLabel), + new(OpCodes.Ldc_I4_0), + new(OpCodes.Ret), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} diff --git a/EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs b/EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs new file mode 100644 index 000000000..71ba20528 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs @@ -0,0 +1,54 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Generic +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Pools; + using CustomPlayerEffects; + using HarmonyLib; + using Mirror; + using PlayerRoles.PlayableScps.Scp173; + + using static HarmonyLib.AccessTools; + + /// + /// Patches to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/143 bug. + /// + [HarmonyPatch(typeof(Scp173TeleportAbility), nameof(Scp173TeleportAbility.ServerProcessCmd))] + internal static class Scp173SecondKillPatch + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label returnLabel = generator.DefineLabel(); + + newInstructions[newInstructions.Count - 1].WithLabels(returnLabel); + + int offset = -5; + int index = newInstructions.FindIndex(x => x.Is(OpCodes.Callvirt, Method(typeof(MovementTracer), nameof(MovementTracer.GenerateBounds)))) + offset; + + newInstructions.InsertRange(index, new[] + { + // if (hub.playerEffectController.GetEffect().IsEnabled) return; + new CodeInstruction(OpCodes.Ldloc_S, 5).MoveLabelsFrom(newInstructions[index]), + new(OpCodes.Ldfld, Field(typeof(ReferenceHub), nameof(ReferenceHub.playerEffectsController))), + new(OpCodes.Callvirt, Method(typeof(PlayerEffectsController), nameof(PlayerEffectsController.GetEffect), generics: new[] { typeof(SpawnProtected) })), + new(OpCodes.Callvirt, PropertyGetter(typeof(StatusEffectBase), nameof(StatusEffectBase.IsEnabled))), + new(OpCodes.Brtrue_S, returnLabel), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} From f7f5986d371b2575ec19746d6bf4f143e692443c Mon Sep 17 00:00:00 2001 From: sky Date: Tue, 6 Aug 2024 13:09:41 +0200 Subject: [PATCH 4/7] Moved patches and fixed Scp173FirstKillPatch --- .../Patches/{Generic => Fixes}/ArmorDropPatch.cs | 2 +- .../Patches/{Generic => Fixes}/Scp173FirstKillPatch.cs | 8 ++++---- .../Patches/{Generic => Fixes}/Scp173SecondKillPatch.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename EXILED/Exiled.Events/Patches/{Generic => Fixes}/ArmorDropPatch.cs (98%) rename EXILED/Exiled.Events/Patches/{Generic => Fixes}/Scp173FirstKillPatch.cs (87%) rename EXILED/Exiled.Events/Patches/{Generic => Fixes}/Scp173SecondKillPatch.cs (98%) diff --git a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs b/EXILED/Exiled.Events/Patches/Fixes/ArmorDropPatch.cs similarity index 98% rename from EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs rename to EXILED/Exiled.Events/Patches/Fixes/ArmorDropPatch.cs index f02a9b8b2..a924f6808 100644 --- a/EXILED/Exiled.Events/Patches/Generic/ArmorDropPatch.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/ArmorDropPatch.cs @@ -5,7 +5,7 @@ // // ----------------------------------------------------------------------- -namespace Exiled.Events.Patches.Generic +namespace Exiled.Events.Patches.Fixes { using System.Collections.Generic; using System.Reflection.Emit; diff --git a/EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs b/EXILED/Exiled.Events/Patches/Fixes/Scp173FirstKillPatch.cs similarity index 87% rename from EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs rename to EXILED/Exiled.Events/Patches/Fixes/Scp173FirstKillPatch.cs index fddda38f6..f66d35058 100644 --- a/EXILED/Exiled.Events/Patches/Generic/Scp173FirstKillPatch.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/Scp173FirstKillPatch.cs @@ -5,7 +5,7 @@ // // ----------------------------------------------------------------------- -namespace Exiled.Events.Patches.Generic +namespace Exiled.Events.Patches.Fixes { using System.Collections.Generic; using System.Reflection.Emit; @@ -33,11 +33,11 @@ private static IEnumerable Transpiler(IEnumerable x.opcode == OpCodes.Ldc_I4_0); newInstructions[index].WithLabels(continueLabel); - // TODO: NRE ON LEFT CLICK (KICK PLAYER) - DO NOT PUSH newInstructions.InsertRange(index, new CodeInstruction[] { - // if (hub.playerEffectController.GetEffect().IsEnabled) return false; - new(OpCodes.Ldarg_1), + // if (hitboxIdentity.TargetHub.playerEffectController.GetEffect().IsEnabled) return false; + new(OpCodes.Ldloc_2), + new(OpCodes.Callvirt, PropertyGetter(typeof(HitboxIdentity), nameof(HitboxIdentity.TargetHub))), new(OpCodes.Ldfld, Field(typeof(ReferenceHub), nameof(ReferenceHub.playerEffectsController))), new(OpCodes.Callvirt, Method(typeof(PlayerEffectsController), nameof(PlayerEffectsController.GetEffect), generics: new[] { typeof(SpawnProtected) })), new(OpCodes.Callvirt, PropertyGetter(typeof(StatusEffectBase), nameof(StatusEffectBase.IsEnabled))), diff --git a/EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs b/EXILED/Exiled.Events/Patches/Fixes/Scp173SecondKillPatch.cs similarity index 98% rename from EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs rename to EXILED/Exiled.Events/Patches/Fixes/Scp173SecondKillPatch.cs index 71ba20528..2b6dcb028 100644 --- a/EXILED/Exiled.Events/Patches/Generic/Scp173SecondKillPatch.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/Scp173SecondKillPatch.cs @@ -5,7 +5,7 @@ // // ----------------------------------------------------------------------- -namespace Exiled.Events.Patches.Generic +namespace Exiled.Events.Patches.Fixes { using System.Collections.Generic; using System.Reflection.Emit; From 52b98588237ad3d94b685c2967adf50fc2343b11 Mon Sep 17 00:00:00 2001 From: sky Date: Tue, 6 Aug 2024 14:04:09 +0200 Subject: [PATCH 5/7] Add Slowness Fix Avoid values more than 100 for effect slowness to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/378 --- .../Patches/Fixes/SlownessFix.cs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs index e2e69b756..1d37361f9 100644 --- a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs @@ -10,6 +10,7 @@ namespace Exiled.Events.Patches.Fixes using System.Collections.Generic; using System.Reflection.Emit; + using CustomPlayerEffects; using Exiled.API.Features.Pools; using HarmonyLib; using PlayerRoles.FirstPersonControl; @@ -62,4 +63,40 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } } -} + + /// + /// Patches to avoid values more than 100 for effect Slowness. Fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/378. + /// + [HarmonyPatch(typeof(StatusEffectBase), nameof(StatusEffectBase.ForceIntensity))] + #pragma warning disable SA1402 // File may only contain a single type + internal class SlownessValueFix + #pragma warning restore SA1402 // File may only contain a single type + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label continueLabel = generator.DefineLabel(); + + newInstructions[0].WithLabels(continueLabel); + + newInstructions.InsertRange(0, new CodeInstruction[] + { + new(OpCodes.Ldarg_0), + new(OpCodes.Isinst, typeof(Slowness)), + new(OpCodes.Brfalse_S, continueLabel), + new(OpCodes.Ldarg_1), + new(OpCodes.Ldc_I4_S, 100), + new(OpCodes.Cgt), + new(OpCodes.Brfalse_S, continueLabel), + new(OpCodes.Ldc_I4_S, 100), + new(OpCodes.Starg_S, 1), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From 772b7656646c233d52337475fc6acf83380fae6e Mon Sep 17 00:00:00 2001 From: sky Date: Tue, 6 Aug 2024 16:37:29 +0200 Subject: [PATCH 6/7] skill issue --- .../Patches/Fixes/SlownessFix.cs | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs index 1d37361f9..5edf50849 100644 --- a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs @@ -63,40 +63,4 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } } - - /// - /// Patches to avoid values more than 100 for effect Slowness. Fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/378. - /// - [HarmonyPatch(typeof(StatusEffectBase), nameof(StatusEffectBase.ForceIntensity))] - #pragma warning disable SA1402 // File may only contain a single type - internal class SlownessValueFix - #pragma warning restore SA1402 // File may only contain a single type - { - private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) - { - List newInstructions = ListPool.Pool.Get(instructions); - - Label continueLabel = generator.DefineLabel(); - - newInstructions[0].WithLabels(continueLabel); - - newInstructions.InsertRange(0, new CodeInstruction[] - { - new(OpCodes.Ldarg_0), - new(OpCodes.Isinst, typeof(Slowness)), - new(OpCodes.Brfalse_S, continueLabel), - new(OpCodes.Ldarg_1), - new(OpCodes.Ldc_I4_S, 100), - new(OpCodes.Cgt), - new(OpCodes.Brfalse_S, continueLabel), - new(OpCodes.Ldc_I4_S, 100), - new(OpCodes.Starg_S, 1), - }); - - for (int z = 0; z < newInstructions.Count; z++) - yield return newInstructions[z]; - - ListPool.Pool.Return(newInstructions); - } - } } \ No newline at end of file From 618dfd961163f8e54fe11ea49cf52366e71cd2af Mon Sep 17 00:00:00 2001 From: sky Date: Tue, 6 Aug 2024 16:39:59 +0200 Subject: [PATCH 7/7] skill issue (again= --- EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs index 5edf50849..5a05c31a0 100644 --- a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs @@ -10,7 +10,6 @@ namespace Exiled.Events.Patches.Fixes using System.Collections.Generic; using System.Reflection.Emit; - using CustomPlayerEffects; using Exiled.API.Features.Pools; using HarmonyLib; using PlayerRoles.FirstPersonControl;