From 7f6174465e0ad0efa2fb75af4e2683f58a898d98 Mon Sep 17 00:00:00 2001 From: tree <> Date: Sat, 7 Oct 2023 15:34:38 -0600 Subject: [PATCH] ImmersiveHud_fix --- ImmersiveHud/Hud_Update_Patch.cs | 12 ++++++++---- ImmersiveHud/Player_Update_Patch.cs | 11 +++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) 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)) {