Skip to content
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
122 changes: 88 additions & 34 deletions DFUVR/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ public class PlayerDeathPatch : MonoBehaviour
{
static void Prefix(PlayerDeath __instance)
{
if (Var.weaponObject != null)
Destroy(Var.weaponObject);
if (Var.leftWeaponObject != null)
Destroy(Var.leftWeaponObject);
if (Var.rightWeaponObject != null)
Destroy(Var.rightWeaponObject);

Var.currentLeftWeaponName = null;
Var.currentRightWeaponName = null;

Var.currentWeaponName = null;
Hands.rHand.SetActive(true);
Hands.lHand.SetActive(true);
}
Expand Down Expand Up @@ -1035,59 +1039,104 @@ public class CorrectWeaponPatch : MonoBehaviour
[HarmonyPostfix]
internal static void Postfix(WeaponManager __instance)
{
if (Var.weaponObject != null)
Destroy(Var.weaponObject);
if (Var.leftWeaponObject != null)
Destroy(Var.leftWeaponObject);
if (Var.rightWeaponObject != null)
Destroy(Var.rightWeaponObject);

DaggerfallUnityItem leftHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand);
DaggerfallUnityItem rightHandItem = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightHand);
//DaggerfallUnityItem daggerfallUnityItem = playerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand);

if (leftHandItem == null)
Var.currentLeftWeaponName = "rHandClosed";
else
Var.currentLeftWeaponName = leftHandItem.LongName;

if (rightHandItem == null)
Var.currentRightWeaponName = "rHandClosed";
else
Var.currentRightWeaponName = rightHandItem.LongName;

HandObject currentLeftHandObject = null;
if (Var.currentLeftWeaponName != null)
{
Var.currentWeaponName = null;
var weaponType = leftHandItem?.GetWeaponType() ?? WeaponTypes.Melee;

Var.sheathObject.GetComponent<MeshRenderer>().enabled = true;
Hands.rHand.SetActive(true);
Hands.lHand.SetActive(true);
return;
if (weaponType != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentLeftWeaponName))
currentLeftHandObject = Var.handObjectsByName[Var.currentLeftWeaponName];
else
currentLeftHandObject = Var.handObjects[weaponType];

Var.leftWeaponObject = Instantiate(currentLeftHandObject.gameObject);
Var.leftWeaponObject.GetComponent<Collider>().enabled = true;

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

Var.currentWeaponName = rightHandItem.LongName ?? "";
HandObject currentRightHandObject = null;
if (Var.currentRightWeaponName != null)
{
var weaponType = rightHandItem?.GetWeaponType() ?? WeaponTypes.Melee;

HandObject currentHandObject = null;
if (rightHandItem.GetWeaponType() != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentWeaponName))
currentHandObject = Var.handObjectsByName[Var.currentWeaponName];
else
currentHandObject = Var.handObjects[rightHandItem.GetWeaponType()];
if (weaponType != WeaponTypes.Bow && Var.handObjectsByName.ContainsKey(Var.currentRightWeaponName))
currentRightHandObject = Var.handObjectsByName[Var.currentRightWeaponName];
else
currentRightHandObject = Var.handObjects[weaponType];

GameObject tempObject = currentHandObject.gameObject;
Var.rightWeaponObject = Instantiate(currentRightHandObject.gameObject);
Var.rightWeaponObject.GetComponent<Collider>().enabled = true;

Var.weaponObject = Instantiate(tempObject);
Var.weaponObject.GetComponent<Collider>().enabled = true;
WeaponCollision weaponCollision = Var.rightWeaponObject.GetComponent<WeaponCollision>();
if (weaponCollision != null && rightHandItem != null)
weaponCollision.item = rightHandItem;
}

if (__instance.Sheathed)
{
Var.weaponObject.GetComponent<Collider>().enabled = false;
Var.weaponObject.transform.SetParent(Var.sheathObject.transform);
if (Var.leftWeaponObject != null)
{
Var.leftWeaponObject.GetComponent<Collider>().enabled = false;
//Var.leftWeaponObject.transform.SetParent(Var.leftSheathObject.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)
{
Var.rightWeaponObject.GetComponent<Collider>().enabled = false;
Var.rightWeaponObject.transform.SetParent(Var.rightSheathObject.transform);
Var.rightWeaponObject.transform.localPosition = currentRightHandObject.sheatedPositionOffset;
Var.rightWeaponObject.transform.localRotation = currentRightHandObject.sheatedRotationOffset;
}

Var.rightSheathObject.GetComponent<MeshRenderer>().enabled = currentRightHandObject.renderSheated;

Hands.rHand.SetActive(true);
Hands.lHand.SetActive(true);
}
else
{
Var.sheathObject.GetComponent<MeshRenderer>().enabled = true;
Var.rightSheathObject.GetComponent<MeshRenderer>().enabled = true;

if (Var.leftHanded)
Var.weaponObject.transform.SetParent(Var.leftHand.transform);
else
Var.weaponObject.transform.SetParent(Var.rightHand.transform);
if (Var.leftWeaponObject != null)
{
Var.leftWeaponObject.transform.SetParent(Var.offHand.transform);

Var.weaponObject.transform.localPosition = currentHandObject.unsheatedPositionOffset;
Var.weaponObject.transform.localRotation = currentHandObject.unsheatedRotationOffset;
Var.weaponObject.SetActive(true);
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);

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

Hands.rHand.SetActive(false);
Hands.lHand.SetActive(false);
Expand All @@ -1101,8 +1150,13 @@ 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);
if (rightHandItem == null || rightHandItem.LongName != Var.currentWeaponName)

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

if (leftName != Var.currentLeftWeaponName || rightName != Var.currentRightWeaponName)
CorrectWeaponPatch.Postfix(__instance);
}
}
Expand Down
2 changes: 1 addition & 1 deletion DFUVR/Sheath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void Start()
//sheath.transform.localRotation = Quaternion.identity;

assetBundle.Unload(false);
Var.sheathObject=sheath;
Var.rightSheathObject=sheath;

//sphere.transform.localPosition = sphere.transform.parent.InverseTransformPoint(Var.sheathOffset);
sphere.transform.localPosition = Var.sheathOffset;
Expand Down
25 changes: 22 additions & 3 deletions DFUVR/Var.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,31 @@ public class Var : MonoBehaviour
public static GameObject VRParent;
public static GameObject debugSphere;

public static GameObject mainHand
{
get
{
return leftHanded ? leftHand : rightHand;
}
}
public static GameObject offHand
{
get
{
return leftHanded ? rightHand : leftHand;
}
}

public static Dictionary<WeaponTypes, HandObject> handObjects = new Dictionary<WeaponTypes, HandObject>();
public static Dictionary<string, HandObject> handObjectsByName = new Dictionary<string, HandObject>();
public static GameObject weaponObject;
public static string currentWeaponName;

public static GameObject sheathObject;
public static GameObject rightWeaponObject;
public static GameObject leftWeaponObject;
public static string currentRightWeaponName;
public static string currentLeftWeaponName;

public static GameObject rightSheathObject;
public static GameObject leftSheathObject;

public static int connectedJoysticks;

Expand Down
4 changes: 2 additions & 2 deletions DFUVR/WeaponCollision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace DFUVR
{
public class WeaponCollision : MonoBehaviour
{
public DaggerfallUnityItem item = null;
//public float velocityThreshold = 2.0f;

//private Rigidbody rb;
Expand Down Expand Up @@ -51,14 +52,13 @@ private void OnTriggerEnter(Collider other)
Vector3 hitDirection = other.transform.position - transform.position;
Transform hitTransform = other.transform;
WeaponManager weaponManager = GameObject.Find("PlayerAdvanced").GetComponent<WeaponManager>();
DaggerfallUnityItem currentRightHandWeapon = (DaggerfallUnityItem)AccessTools.Field(typeof(WeaponManager), "currentRightHandWeapon").GetValue(weaponManager);
hitDirection = hitDirection.normalized;
//Debug.Log("Hit Direction: " + hitDirection);

var playerId = GameManager.Instance.PlayerObject.GetInstanceID();
if (playerId != other.gameObject.GetInstanceID())
{
weaponManager.WeaponDamage(currentRightHandWeapon, false, false, hitTransform, hitTransform.localPosition, hitDirection);
weaponManager.WeaponDamage(item, false, false, hitTransform, hitTransform.localPosition, hitDirection);
hitSomething = true;
}
}
Expand Down