Skip to content

Commit

Permalink
Fix NW moment
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Aug 1, 2024
1 parent 92d023d commit 6f3bfef
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
11 changes: 1 addition & 10 deletions EXILED/Exiled.API/Features/Items/Jailbird.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,7 @@ public float GetDamage(JailbirdWearState wearState)
/// </summary>
/// <param name="wearState">The desired wear state to calculate the charge for.</param>
/// <returns>The charge value required to achieve the specified wear state.</returns>
public int GetCharge(JailbirdWearState wearState)
{
foreach (Keyframe keyframe in Base._deterioration._chargesToWearState.keys)
{
if (Base._deterioration.FloatToState(keyframe.value) == wearState)
return Mathf.RoundToInt(keyframe.time);
}

throw new Exception("Wear state not found in charges to wear state mapping.");
}
public int GetCharge(JailbirdWearState wearState) => (int)wearState;

/// <summary>
/// Breaks the Jailbird.
Expand Down
61 changes: 61 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/Jailbird914CoarseFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// -----------------------------------------------------------------------
// <copyright file="Jailbird914CoarseFix.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.Events.Player
{
#pragma warning disable IDE0060

using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features;
using API.Features.Pools;

using HarmonyLib;
using InventorySystem.Items.Jailbird;
using Mirror;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="JailbirdDeteriorationTracker.Setup(JailbirdItem, JailbirdHitreg)" />.
/// Bug reported to NW (https://trello.com/c/kyr3hV9B).
/// </summary>
[HarmonyPatch(typeof(JailbirdDeteriorationTracker), nameof(JailbirdDeteriorationTracker.Setup))]
internal static class Jailbird914CoarseFix
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int offset = -1;
int index = newInstructions.FindIndex(i => i.opcode == OpCodes.Blt_S) + offset;

List<Label> labels = newInstructions[index].ExtractLabels();

int offsetToRemove = 2;
int indexToRemove = newInstructions.FindIndex(i => i.opcode == OpCodes.Blt_S) + offsetToRemove;
int countToRemove = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Blt_S) - indexToRemove + offsetToRemove;

newInstructions.RemoveRange(indexToRemove, countToRemove);

newInstructions.InsertRange(
index,
new CodeInstruction[]
{
// JailbirdDeteriorationTracker.Scp914CoarseCharges = JailbirdWearState.AlmostBroken
new CodeInstruction(OpCodes.Ldc_I4_4).WithLabels(labels),
new(OpCodes.Call, PropertySetter(typeof(JailbirdDeteriorationTracker), nameof(JailbirdDeteriorationTracker.Scp914CoarseCharges))),
});

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

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

0 comments on commit 6f3bfef

Please sign in to comment.