From 1fe545d3613ceb2790f2fbb718471222e0632138 Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 1 Aug 2024 00:19:16 +0200 Subject: [PATCH 1/4] Jailbird --- EXILED/Exiled.API/Features/Items/Jailbird.cs | 39 ++++++++++++++++++- .../Item/ChargingJailbirdEventArgs.cs | 11 ++++-- .../EventArgs/Item/SwingingEventArgs.cs | 9 ++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/EXILED/Exiled.API/Features/Items/Jailbird.cs b/EXILED/Exiled.API/Features/Items/Jailbird.cs index 9e508da11..d0fe13647 100644 --- a/EXILED/Exiled.API/Features/Items/Jailbird.cs +++ b/EXILED/Exiled.API/Features/Items/Jailbird.cs @@ -7,11 +7,14 @@ namespace Exiled.API.Features.Items { + using System; + using Exiled.API.Features.Pickups; using Exiled.API.Interfaces; using InventorySystem.Items.Autosync; using InventorySystem.Items.Jailbird; using Mirror; + using UnityEngine; using JailbirdPickup = Pickups.JailbirdPickup; @@ -114,12 +117,44 @@ public JailbirdWearState WearState get => Base._deterioration.WearState; set { - if (JailbirdDeteriorationTracker.ReceivedStates.ContainsKey(Serial)) - JailbirdDeteriorationTracker.ReceivedStates[Serial] = value; + TotalDamageDealt = GetDamage(value); + TotalCharges = GetCharge(value); Base._deterioration.RecheckUsage(); } } + /// + /// Calculates the damage corresponding to a given . + /// + /// The wear state to calculate damage for. + /// The amount of damage associated with the specified wear state. + public float GetDamage(JailbirdWearState wearState) + { + foreach (Keyframe keyframe in Base._deterioration._chargesToWearState.keys) + { + if (Base._deterioration.FloatToState(keyframe.value) == wearState) + return keyframe.time; + } + + throw new Exception("Wear state not found in charges to wear state mapping."); + } + + /// + /// Gets the charge needed to reach a specific . + /// + /// The desired wear state to calculate the charge for. + /// The charge value required to achieve the specified wear state. + 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."); + } + /// /// Breaks the Jailbird. /// diff --git a/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs index 1b17a1bb0..7678a8dc8 100644 --- a/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs @@ -25,7 +25,7 @@ public class ChargingJailbirdEventArgs : IPlayerEvent, IItemEvent, IDeniableEven public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swingItem, bool isAllowed = true) { Player = Player.Get(player); - Item = Item.Get(swingItem); + Jailbird = (Jailbird)Item.Get(swingItem); IsAllowed = isAllowed; } @@ -35,9 +35,14 @@ public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.Item public Player Player { get; } /// - /// Gets the that is being charged. This will always be a . + /// Gets the that is being charged. /// - public Item Item { get; } + public Jailbird Jailbird { get; } + + /// + /// Gets the that is being charged. + /// + public Item Item => Jailbird; /// /// Gets or sets a value indicating whether or not the Jailbird can be charged. diff --git a/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs index 17c0319b0..6c8f0fce8 100644 --- a/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs @@ -25,7 +25,7 @@ public class SwingingEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent public SwingingEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swingItem, bool isAllowed = true) { Player = Player.Get(player); - Item = Item.Get(swingItem); + Jailbird = (Jailbird)Item.Get(swingItem); IsAllowed = isAllowed; } @@ -34,10 +34,15 @@ public SwingingEventArgs(ReferenceHub player, InventorySystem.Items.ItemBase swi /// public Player Player { get; } + /// + /// Gets the that is being swung. + /// + public Jailbird Jailbird { get; } + /// /// Gets the that is being swung. /// - public Item Item { get; } + public Item Item => Jailbird; /// /// Gets or sets a value indicating whether or not the item can be swung. From bde11640f20c200fbf00da3ae346f05131e9b8f1 Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 1 Aug 2024 02:41:26 +0200 Subject: [PATCH 2/4] Fix --- EXILED/Exiled.API/Features/Items/Jailbird.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Items/Jailbird.cs b/EXILED/Exiled.API/Features/Items/Jailbird.cs index d0fe13647..d5c018b84 100644 --- a/EXILED/Exiled.API/Features/Items/Jailbird.cs +++ b/EXILED/Exiled.API/Features/Items/Jailbird.cs @@ -130,7 +130,7 @@ public JailbirdWearState WearState /// The amount of damage associated with the specified wear state. public float GetDamage(JailbirdWearState wearState) { - foreach (Keyframe keyframe in Base._deterioration._chargesToWearState.keys) + foreach (Keyframe keyframe in Base._deterioration._damageToWearState.keys) { if (Base._deterioration.FloatToState(keyframe.value) == wearState) return keyframe.time; From 92d023d41d25546d69a37091250e80898cb5f0b9 Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 1 Aug 2024 12:00:48 +0200 Subject: [PATCH 3/4] Exception --- EXILED/Exiled.API/Features/Items/Jailbird.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Items/Jailbird.cs b/EXILED/Exiled.API/Features/Items/Jailbird.cs index d5c018b84..22361f296 100644 --- a/EXILED/Exiled.API/Features/Items/Jailbird.cs +++ b/EXILED/Exiled.API/Features/Items/Jailbird.cs @@ -136,7 +136,7 @@ public float GetDamage(JailbirdWearState wearState) return keyframe.time; } - throw new Exception("Wear state not found in charges to wear state mapping."); + throw new Exception("Wear state not found in damage to wear state mapping."); } /// From 6f3bfefd8b1a6b7b048e64873ca96036a3574ec1 Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 1 Aug 2024 12:47:48 +0200 Subject: [PATCH 4/4] Fix NW moment --- EXILED/Exiled.API/Features/Items/Jailbird.cs | 11 +--- .../Patches/Fixes/Jailbird914CoarseFix.cs | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 EXILED/Exiled.Events/Patches/Fixes/Jailbird914CoarseFix.cs diff --git a/EXILED/Exiled.API/Features/Items/Jailbird.cs b/EXILED/Exiled.API/Features/Items/Jailbird.cs index 22361f296..2f8bfb524 100644 --- a/EXILED/Exiled.API/Features/Items/Jailbird.cs +++ b/EXILED/Exiled.API/Features/Items/Jailbird.cs @@ -144,16 +144,7 @@ public float GetDamage(JailbirdWearState wearState) /// /// The desired wear state to calculate the charge for. /// The charge value required to achieve the specified wear state. - 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; /// /// Breaks the Jailbird. diff --git a/EXILED/Exiled.Events/Patches/Fixes/Jailbird914CoarseFix.cs b/EXILED/Exiled.Events/Patches/Fixes/Jailbird914CoarseFix.cs new file mode 100644 index 000000000..680e40608 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Fixes/Jailbird914CoarseFix.cs @@ -0,0 +1,61 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +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; + + /// + /// Patches . + /// Bug reported to NW (https://trello.com/c/kyr3hV9B). + /// + [HarmonyPatch(typeof(JailbirdDeteriorationTracker), nameof(JailbirdDeteriorationTracker.Setup))] + internal static class Jailbird914CoarseFix + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + int offset = -1; + int index = newInstructions.FindIndex(i => i.opcode == OpCodes.Blt_S) + offset; + + List