Skip to content

Commit

Permalink
Fix NW bugs (#32)
Browse files Browse the repository at this point in the history
* Fix Armor Drop

from https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/230

* add comments

* fix scp173 and adding bug report link to summary class

fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/143

* Moved patches and fixed Scp173FirstKillPatch

* Add Slowness Fix

Avoid values more than 100 for effect slowness to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/378

* skill issue

* skill issue (again=

---------

Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
  • Loading branch information
skyfr0676 and louis1706 authored Aug 6, 2024
1 parent a7354b7 commit 259cabb
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
55 changes: 55 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/ArmorDropPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// -----------------------------------------------------------------------
// <copyright file="ArmorDropPatch.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.Fixes
{
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;

/// <summary>
/// Patches <see cref="BodyArmorUtils.RemoveEverythingExceedingLimits(Inventory, BodyArmor, bool, bool)"/> to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/230 bug.
/// </summary>
[HarmonyPatch(typeof(BodyArmorUtils), nameof(BodyArmorUtils.RemoveEverythingExceedingLimits))]
internal static class ArmorDropPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label continueLabel = generator.DefineLabel();
int continueIndex = newInstructions.FindIndex(x => x.Is(OpCodes.Call, Method(typeof(Dictionary<ushort, ItemBase>.Enumerator), nameof(Dictionary<ushort, ItemBase>.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<ushort, ItemBase>), nameof(KeyValuePair<ushort, ItemBase>.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<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
55 changes: 55 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/Scp173FirstKillPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// -----------------------------------------------------------------------
// <copyright file="Scp173FirstKillPatch.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.Fixes
{
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;

/// <summary>
/// Patches <see cref="Scp173SnapAbility.TryHitTarget(Transform, out ReferenceHub)" /> to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/143 bug.
/// </summary>
[HarmonyPatch(typeof(Scp173SnapAbility), nameof(Scp173SnapAbility.TryHitTarget))]
internal static class Scp173FirstKillPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label continueLabel = generator.DefineLabel();

int index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldc_I4_0);
newInstructions[index].WithLabels(continueLabel);

newInstructions.InsertRange(index, new CodeInstruction[]
{
// if (hitboxIdentity.TargetHub.playerEffectController.GetEffect<SpawnProtected>().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))),
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<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
54 changes: 54 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/Scp173SecondKillPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="Scp173SecondKillPatch.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.Fixes
{
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;

/// <summary>
/// Patches <see cref="Scp173TeleportAbility.ServerProcessCmd(NetworkReader)" /> to fix https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/143 bug.
/// </summary>
[HarmonyPatch(typeof(Scp173TeleportAbility), nameof(Scp173TeleportAbility.ServerProcessCmd))]
internal static class Scp173SecondKillPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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<SpawnProtected>().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<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
}

0 comments on commit 259cabb

Please sign in to comment.