diff --git a/DFUVR/Plugin.cs b/DFUVR/Plugin.cs index 72fb932..a496467 100644 --- a/DFUVR/Plugin.cs +++ b/DFUVR/Plugin.cs @@ -1017,33 +1017,51 @@ static void Postfix(WeaponManager __instance) [HarmonyPatch(typeof(WeaponManager), "ToggleSheath")] public class CorrectWeaponPatch : MonoBehaviour { - [HarmonyPrefix] - static void Prefix(WeaponManager __instance) + [HarmonyPostfix] + internal static void Postfix(WeaponManager __instance) { if (Var.weaponObject != null) Destroy(Var.weaponObject); - if (__instance.ScreenWeapon == null) + DaggerfallUnityItem rightHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightHand); + //DaggerfallUnityItem daggerfallUnityItem = playerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand); + + if (rightHandItem == null) { Var.currentWeaponName = null; + + Var.sheathObject.GetComponent().enabled = true; + Hands.rHand.SetActive(true); + Hands.lHand.SetActive(true); return; } - Var.currentWeaponName = __instance.ScreenWeapon.SpecificWeapon?.LongName ?? ""; + Var.currentWeaponName = rightHandItem.LongName ?? ""; HandObject currentHandObject = null; - if (__instance.ScreenWeapon.WeaponType != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentWeaponName)) + if (rightHandItem.GetWeaponType() != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentWeaponName)) currentHandObject = Var.handObjectsByName[Var.currentWeaponName]; else - currentHandObject = Var.handObjects[__instance.ScreenWeapon.WeaponType]; + currentHandObject = Var.handObjects[rightHandItem.GetWeaponType()]; GameObject tempObject = currentHandObject.gameObject; Var.weaponObject = Instantiate(tempObject); Var.weaponObject.GetComponent().enabled = true; - // if it is unsheathing if (__instance.Sheathed) + { + Var.weaponObject.GetComponent().enabled = false; + Var.weaponObject.transform.SetParent(Var.sheathObject.transform); + + Var.weaponObject.transform.localPosition = currentHandObject.sheatedPositionOffset; + Var.weaponObject.transform.localRotation = currentHandObject.sheatedRotationOffset; + Var.sheathObject.GetComponent().enabled = currentHandObject.renderSheated; + + Hands.rHand.SetActive(true); + Hands.lHand.SetActive(true); + } + else { Var.sheathObject.GetComponent().enabled = true; @@ -1059,18 +1077,18 @@ static void Prefix(WeaponManager __instance) Hands.rHand.SetActive(false); Hands.lHand.SetActive(false); } - else - { - Var.weaponObject.GetComponent().enabled = false; - Var.weaponObject.transform.SetParent(Var.sheathObject.transform); - - Var.weaponObject.transform.localPosition = currentHandObject.sheatedPositionOffset; - Var.weaponObject.transform.localRotation = currentHandObject.sheatedRotationOffset; - Var.sheathObject.GetComponent().enabled = currentHandObject.renderSheated; + } + } - Hands.rHand.SetActive(true); - Hands.lHand.SetActive(true); - } + [HarmonyPatch(typeof(WeaponManager), "ApplyWeapon")] + public class ApplyWeaponPatch : MonoBehaviour + { + [HarmonyPostfix] + static void Postfix(WeaponManager __instance) + { + DaggerfallUnityItem rightHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightHand); + if (rightHandItem == null || rightHandItem.LongName != Var.currentWeaponName) + CorrectWeaponPatch.Postfix(__instance); } }