diff --git a/ImmersiveHud/Hud_Update_Patch.cs b/ImmersiveHud/Hud_Update_Patch.cs index 2158de7..5457dd0 100644 --- a/ImmersiveHud/Hud_Update_Patch.cs +++ b/ImmersiveHud/Hud_Update_Patch.cs @@ -1,11 +1,15 @@ using UnityEngine; using HarmonyLib; - +using System; +using System.Reflection; + namespace ImmersiveHud { [HarmonyPatch(typeof(Hud), "Update")] public class Hud_Update_Patch : ImmersiveHud - { + { + private static MethodInfo _GetRightItemMethod = AccessTools.Method(typeof(Humanoid), "GetRightItem"); + private static MethodInfo _GetLeftItemMethod = AccessTools.Method(typeof(Humanoid), "GetLeftItem"); public static void updateHudElementTransparency(HudElement hudElement) { float lerpedAlpha; @@ -33,8 +37,8 @@ public static void getPlayerData(Transform hud, Player player) getPlayerTotalFoodValue(player); - ItemDrop.ItemData playerItemEquippedLeft = player.GetLeftItem(); - ItemDrop.ItemData playerItemEquippedRight = player.GetRightItem(); + ItemDrop.ItemData playerItemEquippedLeft = _GetLeftItemMethod.Invoke(player, Array.Empty()) as ItemDrop.ItemData; + ItemDrop.ItemData playerItemEquippedRight = _GetRightItemMethod.Invoke(player, Array.Empty()) as ItemDrop.ItemData; if (playerItemEquippedLeft != null || playerItemEquippedRight != null) playerHasItemEquipped = true; diff --git a/ImmersiveHud/Player_Update_Patch.cs b/ImmersiveHud/Player_Update_Patch.cs index d90e1f7..235fdda 100644 --- a/ImmersiveHud/Player_Update_Patch.cs +++ b/ImmersiveHud/Player_Update_Patch.cs @@ -1,18 +1,21 @@ using UnityEngine; using HarmonyLib; using System.Reflection; - +using System; + namespace ImmersiveHud { [HarmonyPatch(typeof(Player), "Update")] public class Player_Update_Patch : ImmersiveHud - { + { + private static MethodInfo _GetRightItemMethod = AccessTools.Method(typeof(Humanoid), "GetRightItem"); + private static MethodInfo _GetLeftItemMethod = AccessTools.Method(typeof(Humanoid), "GetLeftItem"); private static void Prefix(Player __instance) { if (!__instance) return; - ItemDrop.ItemData playerItemEquippedLeft = __instance.GetLeftItem(); - ItemDrop.ItemData playerItemEquippedRight = __instance.GetRightItem(); + ItemDrop.ItemData playerItemEquippedLeft = _GetLeftItemMethod.Invoke(__instance, Array.Empty()) as ItemDrop.ItemData; + ItemDrop.ItemData playerItemEquippedRight = _GetRightItemMethod.Invoke(__instance, Array.Empty()) as ItemDrop.ItemData; if (playerItemEquippedLeft != null && (playerItemEquippedLeft.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Bow)) {