Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DFUVR/DFUVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<Compile Include="MenuTransition.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sheath.cs" />
<Compile Include="SheathController.cs" />
<Compile Include="SheathCollision.cs" />
<Compile Include="SlotCollision.cs" />
<Compile Include="Slots.cs" />
Expand Down
23 changes: 15 additions & 8 deletions DFUVR/HandLabel.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine;
using UnityEngine.XR;

namespace DFUVR
{
public class HandLabel : MonoBehaviour
{
public bool rightHand;
public bool isMainHand;
public XRNode xrHandNode;
public InputDevice inputDevice;
public KeyCode grabButton;

public void Init(bool isMainHand, XRNode xrHandNode, InputDevice inputDevice, KeyCode grabButton)
{
this.isMainHand = isMainHand;
this.xrHandNode = xrHandNode;
this.inputDevice = inputDevice;
this.grabButton = grabButton;
}

void Start()
{
Plugin.LoggerInstance.LogInfo("added Handlabel");
}

}
}
6 changes: 3 additions & 3 deletions DFUVR/HandObjectLoadList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ private HandObjectLoadList(string assetBundlePath, Action<GameObject> postAction
new HandObjectLoadList("AssetBundles/weapons", null, typeof(WeaponCollision), typeof(MeshCollider), new[] { WeaponTypes.LongBlade, WeaponTypes.LongBlade_Magic }, "Sword", Vector3.zero, Quaternion.identity, Vector3.zero, Quaternion.identity, true, true, true),
new HandObjectLoadList("AssetBundles/weapons", null, typeof(WeaponCollision), typeof(MeshCollider), new[] { WeaponTypes.Dagger, WeaponTypes.Dagger_Magic }, "Steel_Dagger_512", Vector3.zero, Quaternion.Euler(0, 90, 90), Vector3.zero, Quaternion.Euler(0, 90, 90), true),
new HandObjectLoadList("AssetBundles/weapons", null, typeof(WeaponCollision), typeof(MeshCollider), new[] { WeaponTypes.Battleaxe, WeaponTypes.Battleaxe_Magic }, "MM_Axe_01_01_lod2", Vector3.zero, Quaternion.Euler(0, -90, 90), Vector3.zero, Quaternion.Euler(0, 180, 180)),
new HandObjectLoadList("AssetBundles/weapons", null, null, null, new[] { WeaponTypes.None }, "Sheath", Vector3.zero, Quaternion.identity, Vector3.zero, Quaternion.identity, true),
new HandObjectLoadList("AssetBundles/weapons", null, typeof(WeaponCollision), typeof(MeshCollider), new[] { WeaponTypes.Mace, WeaponTypes.Mace_Magic }, "mace", new Vector3(0, 0, 0.1f), Quaternion.Euler(90, 0, 0), new Vector3(0, 0, 0.1f), Quaternion.Euler(90, 0, 0)),
new HandObjectLoadList("AssetBundles/weapons", null, typeof(WeaponCollision), typeof(MeshCollider), new[] { WeaponTypes.Flail, WeaponTypes.Flail_Magic }, "mace", new Vector3(0, 0, 0.1f), Quaternion.Euler(90, 0, 0), new Vector3(0, 0, 0.1f), Quaternion.Euler(90, 0, 0)),
new HandObjectLoadList("AssetBundles/weapons", null, typeof(WeaponCollision), typeof(BoxCollider), new[] { WeaponTypes.Warhammer, WeaponTypes.Warhammer_Magic }, "Warhammer_1", Vector3.zero, Quaternion.Euler(0, 0, 90), Vector3.zero, Quaternion.identity),
Expand Down Expand Up @@ -575,9 +574,10 @@ public static void LoadAllHandObjects(Dictionary<WeaponTypes, HandObject> handOb
}
}
// this is for accessing by name later
else if (!string.IsNullOrEmpty(handObjectLoad.assetName))
if (!string.IsNullOrEmpty(handObjectLoad.assetName))
{
handObjectDictionaryByName.Add(handObjectLoad.assetName, new HandObject(handObjectLoad, gameObject));
if (!handObjectDictionaryByName.ContainsKey(handObjectLoad.assetName))
handObjectDictionaryByName.Add(handObjectLoad.assetName, new HandObject(handObjectLoad, gameObject));
}

handObjectLoad.postAction?.Invoke(gameObject);
Expand Down
257 changes: 212 additions & 45 deletions DFUVR/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,28 +562,47 @@ static void Prefix(InputManager __instance)
//ControllerPatch.flag = false;
//float input = Input.GetAxis("Axis5");
//float input = Input.GetAxis(Var.rThumbStickVertical);

// toggle skybox
if (Input.GetKeyDown(Var.acceptButton))
{
Var.skyboxToggle = !Var.skyboxToggle;
Plugin.LoggerInstance.LogInfo(Var.skyboxToggle);
}
var rightHand = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);

Vector2 rThumbStick;
rightHand.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primary2DAxis, out rThumbStick);

// adjust sheath position
{
//Var.sphereObject.transform.localPosition=Vector3.zero;
if (Var.leftHand != null)
Var.sheathOffset = Var.leftHand.transform.position;

if (Var.mainHandSphereSheathObject != null)
{
Var.mainHandSphereSheathObject.transform.position = Var.sheathOffset;

if (Var.offHandSphereSheathObject != null)
{
Vector3 localPos = Var.mainHandSphereSheathObject.transform.localPosition;
localPos.x = -localPos.x;
Var.offHandSphereSheathObject.transform.localPosition = localPos;
//Var.offHandSphereSheathObject.transform.position = Var.sheathOffset;
}
}
}

// adjust height offset
{
var rightHand = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);

float inputX1 = rThumbStick.x;
float inputY1 = rThumbStick.y;
Vector2 rThumbStick;
rightHand.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primary2DAxis, out rThumbStick);

float input = rThumbStick.y;
float input = rThumbStick.y;
Var.heightOffset += input / 100;

Var.heightOffset += input / 100;
//Var.sphereObject.transform.localPosition=Vector3.zero;
Var.sheathOffset = Var.leftHand.transform.position;
Var.sphereObject.transform.position = Var.sheathOffset;
GameObject vrparent = GameObject.Find("VRParent");
vrparent.transform.localPosition = new Vector3(vrparent.transform.localPosition.x, (float)Var.heightOffset, vrparent.transform.localPosition.z);
GameObject vrparent = GameObject.Find("VRParent");
vrparent.transform.localPosition = new Vector3(vrparent.transform.localPosition.x, (float)Var.heightOffset, vrparent.transform.localPosition.z);
}
}
if (Input.GetKeyDown(Var.left2Button))
{
Expand Down Expand Up @@ -1017,60 +1036,208 @@ 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)
if (GameManager.Instance == null)
{
Plugin.LoggerInstance.LogError("GameManager is null");
return;
}
if (GameManager.Instance.PlayerEntity == null)
{
Var.currentWeaponName = null;
Plugin.LoggerInstance.LogError("PlayerEntity is null");
return;
}
if (GameManager.Instance.PlayerEntity.ItemEquipTable == null)
{
Plugin.LoggerInstance.LogError("ItemEquipTable is null");
return;
}

if (Var.leftWeaponObject != null)
Destroy(Var.leftWeaponObject);
if (Var.rightWeaponObject != null)
Destroy(Var.rightWeaponObject);

Var.currentWeaponName = __instance.ScreenWeapon.SpecificWeapon?.LongName ?? "";
DaggerfallUnityItem leftHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand);
DaggerfallUnityItem rightHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightHand);

HandObject currentHandObject = null;
if (__instance.ScreenWeapon.WeaponType != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentWeaponName))
currentHandObject = Var.handObjectsByName[Var.currentWeaponName];
if (leftHandItem == null)
Var.currentLeftWeaponName = "rHandClosed";
else
currentHandObject = Var.handObjects[__instance.ScreenWeapon.WeaponType];
Var.currentLeftWeaponName = leftHandItem.LongName;

GameObject tempObject = currentHandObject.gameObject;
if (rightHandItem == null)
Var.currentRightWeaponName = "rHandClosed";
else
Var.currentRightWeaponName = rightHandItem.LongName;

Var.weaponObject = Instantiate(tempObject);
Var.weaponObject.GetComponent<Collider>().enabled = true;
HandObject currentLeftHandObject = null;
if (Var.currentLeftWeaponName != null)
{
var weaponType = leftHandItem?.GetWeaponType() ?? WeaponTypes.Melee;

// if it is unsheathing
if (__instance.Sheathed)
if (weaponType != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentLeftWeaponName))
currentLeftHandObject = Var.handObjectsByName[Var.currentLeftWeaponName];
else
currentLeftHandObject = Var.handObjects[weaponType];
if (currentLeftHandObject == null)
{
Plugin.LoggerInstance.LogError("Current left hand object is null");
return;
}

Var.leftWeaponObject = Instantiate(currentLeftHandObject.gameObject);
if (Var.leftWeaponObject == null)
{
Plugin.LoggerInstance.LogError("Left weapon object is null after instantiation");
return;
}

Collider collider = Var.leftWeaponObject.GetComponent<Collider>();
if (collider != null)
collider.enabled = true;

WeaponCollision weaponCollision = Var.leftWeaponObject.GetComponent<WeaponCollision>();
if (weaponCollision != null && leftHandItem != null)
weaponCollision.item = leftHandItem;
}

HandObject currentRightHandObject = null;
if (Var.currentRightWeaponName != null)
{
Var.sheathObject.GetComponent<MeshRenderer>().enabled = true;
var weaponType = rightHandItem?.GetWeaponType() ?? WeaponTypes.Melee;

if (Var.leftHanded)
Var.weaponObject.transform.SetParent(Var.leftHand.transform);
if (weaponType != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentRightWeaponName))
currentRightHandObject = Var.handObjectsByName[Var.currentRightWeaponName];
else
Var.weaponObject.transform.SetParent(Var.rightHand.transform);
currentRightHandObject = Var.handObjects[weaponType];
if (currentRightHandObject == null)
{
Plugin.LoggerInstance.LogError("Current right hand object is null");
return;
}

Var.weaponObject.transform.localPosition = currentHandObject.unsheatedPositionOffset;
Var.weaponObject.transform.localRotation = currentHandObject.unsheatedRotationOffset;
Var.weaponObject.SetActive(true);
Var.rightWeaponObject = Instantiate(currentRightHandObject.gameObject);
if (Var.rightWeaponObject == null)
{
Plugin.LoggerInstance.LogError("Right weapon object is null after instantiation");
return;
}

Hands.rHand.SetActive(false);
Hands.lHand.SetActive(false);
Collider collider = Var.rightWeaponObject.GetComponent<Collider>();
if (collider != null)
collider.enabled = true;

WeaponCollision weaponCollision = Var.rightWeaponObject.GetComponent<WeaponCollision>();
if (weaponCollision != null && rightHandItem != null)
weaponCollision.item = rightHandItem;
}
else

if (__instance.Sheathed)
{
Var.weaponObject.GetComponent<Collider>().enabled = false;
Var.weaponObject.transform.SetParent(Var.sheathObject.transform);
if (Var.leftWeaponObject != null)
{
Collider collider = Var.leftWeaponObject.GetComponent<Collider>();
if (collider != null)
collider.enabled = false;

if (Var.offHandSheathObject != null)
Var.leftWeaponObject.transform.SetParent(Var.offHandSheathObject.transform);

Var.leftWeaponObject.transform.localPosition = currentLeftHandObject.sheatedPositionOffset;
Var.leftWeaponObject.transform.localRotation = currentLeftHandObject.sheatedRotationOffset;
}

Var.weaponObject.transform.localPosition = currentHandObject.sheatedPositionOffset;
Var.weaponObject.transform.localRotation = currentHandObject.sheatedRotationOffset;
Var.sheathObject.GetComponent<MeshRenderer>().enabled = currentHandObject.renderSheated;
if (Var.rightWeaponObject != null)
{
Collider collider = Var.rightWeaponObject.GetComponent<Collider>();
if (collider != null)
collider.enabled = false;

if (Var.mainHandSheathObject != null)
Var.rightWeaponObject.transform.SetParent(Var.mainHandSheathObject.transform);

Var.rightWeaponObject.transform.localPosition = currentRightHandObject.sheatedPositionOffset;
Var.rightWeaponObject.transform.localRotation = currentRightHandObject.sheatedRotationOffset;
}

if (Var.mainHandSheathObject != null)
{
MeshRenderer meshRenderer = Var.mainHandSheathObject.GetComponent<MeshRenderer>();
if (meshRenderer != null)
meshRenderer.enabled = currentRightHandObject.renderSheated;
}
if (Var.offHandSheathObject != null)
{
MeshRenderer meshRenderer = Var.offHandSheathObject.GetComponent<MeshRenderer>();
if (meshRenderer != null)
meshRenderer.enabled = currentLeftHandObject.renderSheated;
}

Hands.rHand.SetActive(true);
Hands.lHand.SetActive(true);
}
else
{
if (Var.mainHandSheathObject != null)
{
MeshRenderer meshRenderer = Var.mainHandSheathObject.GetComponent<MeshRenderer>();
if (meshRenderer != null)
meshRenderer.enabled = true;
}
if (Var.offHandSheathObject != null)
{
MeshRenderer meshRenderer = Var.offHandSheathObject.GetComponent<MeshRenderer>();
if (meshRenderer != null)
meshRenderer.enabled = true;
}

if (Var.leftWeaponObject != null)
{
Var.leftWeaponObject.transform.SetParent(Var.offHand.transform);

if (currentLeftHandObject != null)
{
Var.leftWeaponObject.transform.localPosition = currentLeftHandObject.unsheatedPositionOffset;
Var.leftWeaponObject.transform.localRotation = currentLeftHandObject.unsheatedRotationOffset;
}
Var.leftWeaponObject.SetActive(true);
}

if (Var.rightWeaponObject != null)
{
Var.rightWeaponObject.transform.SetParent(Var.mainHand.transform);

if (currentRightHandObject != null)
{
Var.rightWeaponObject.transform.localPosition = currentRightHandObject.unsheatedPositionOffset;
Var.rightWeaponObject.transform.localRotation = currentRightHandObject.unsheatedRotationOffset;
}
Var.rightWeaponObject.SetActive(true);
}

Hands.rHand.SetActive(false);
Hands.lHand.SetActive(false);
}
}
}

[HarmonyPatch(typeof(WeaponManager), "ApplyWeapon")]
public class ApplyWeaponPatch : MonoBehaviour
{
[HarmonyPostfix]
static void Postfix(WeaponManager __instance)
{
DaggerfallUnityItem leftHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand);
DaggerfallUnityItem rightHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightHand);

string leftName = leftHandItem?.LongName ?? "rHandClosed";
string rightName = rightHandItem?.LongName ?? "rHandClosed";

if (leftName != Var.currentLeftWeaponName || rightName != Var.currentRightWeaponName)
CorrectWeaponPatch.Postfix(__instance);
}
}

Expand Down
Loading