Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ValheimRaft V2 Support Fix #574

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions ValheimVRMod/Patches/EyeRotationPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ValheimVRMod.Utilities;
using System.Reflection;
using System.Collections.Generic;
using ValheimVRMod.Scripts;

namespace ValheimVRMod.Patches
{
Expand Down Expand Up @@ -289,14 +290,14 @@ static void Postfix(Player player)
{
var ship = player.GetStandingOnShip();
var movableBase = player.transform.parent;
if (ship || (movableBase && movableBase?.name == "MovableBase"))
if (ship || (movableBase && LayerUtils.IsModdedStructure(movableBase?.name)))
{
Transform referenceUp = null;
if (ship)
{
referenceUp = ship.transform;
}
else if (movableBase && movableBase?.name == "MovableBase")
else if (movableBase && LayerUtils.IsModdedStructure(movableBase?.name))
{
referenceUp = movableBase.transform;
}
Expand Down
3 changes: 2 additions & 1 deletion ValheimVRMod/Patches/HandBasedInteractionPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using static ValheimVRMod.Utilities.LogUtils;
using TMPro;
using ValheimVRMod.Scripts;

namespace ValheimVRMod.Patches
{
Expand Down Expand Up @@ -191,7 +192,7 @@ private static void UpdateHoverObject(Player instance, ref GameObject hoverRefer
hitPosition = hit.point;
if (hit.collider.GetComponent<Hoverable>() != null ||
!hit.collider.attachedRigidbody ||
hit.collider.attachedRigidbody.name == "MovableBase") // MovableBase is the gameobject name for Valheim Raft Mod object
LayerUtils.IsModdedStructure(hit.collider.attachedRigidbody.name)) // Added Compatibility to Valheim Raft Mod object
{
hoverReference = hit.collider.gameObject;
}
Expand Down
17 changes: 6 additions & 11 deletions ValheimVRMod/Scripts/BuildingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,12 @@ private void UpdateLine()
originalRayTraceTransform = pieceRaycast.transform;
if (modSupport)
{
if (IsModdedStructure(pieceRaycast.transform.name))
if (LayerUtils.IsModdedStructure(pieceRaycast.transform.name))
{
originalRayTraceMod = pieceRaycast.transform;
originalRayTraceTransform = pieceRaycast.collider.transform;
}
else if (pieceRaycast.transform && (SteamVR_Actions.laserPointers_LeftClick.GetStateDown(SteamVR_Input_Sources.RightHand) || !(Player.m_localPlayer.transform.parent && IsModdedStructure(Player.m_localPlayer.transform.parent.name))))
else if (pieceRaycast.transform && (SteamVR_Actions.laserPointers_LeftClick.GetStateDown(SteamVR_Input_Sources.RightHand) || !(Player.m_localPlayer.transform.parent && LayerUtils.IsModdedStructure(Player.m_localPlayer.transform.parent.name))))
{
originalRayTraceMod = null;
}
Expand All @@ -483,7 +483,7 @@ private void UpdateLine()
snapLine.enabled = true;
snapLine.positionCount = 2;
originalRayTraceTransform = null;
if (!(Player.m_localPlayer.transform.parent && IsModdedStructure(Player.m_localPlayer.transform.parent.name)))
if (!(Player.m_localPlayer.transform.parent && LayerUtils.IsModdedStructure(Player.m_localPlayer.transform.parent.name)))
{
originalRayTraceMod = null;
}
Expand Down Expand Up @@ -656,7 +656,7 @@ private void UpdateRefPosition(RaycastHit pieceRaycast, Vector3 direction)
if (modSupport)
{
var raft = pieceRaycast.transform;
if (IsModdedStructure(raft.name))
if (LayerUtils.IsModdedStructure(raft.name))
{
buildRefBox.transform.SetParent(raft);
}
Expand Down Expand Up @@ -693,7 +693,7 @@ public int TranslateRotation()
var forward = Vector3.forward;
if (modSupport)
{
if (rayTracedPiece && rayTracedPiece.transform.parent && IsModdedStructure(rayTracedPiece.transform.parent.name))
if (rayTracedPiece && rayTracedPiece.transform.parent && LayerUtils.IsModdedStructure(rayTracedPiece.transform.parent.name))
{
forward = rayTracedPiece.transform.parent.forward;
}
Expand Down Expand Up @@ -807,7 +807,7 @@ private void BuildSnapPoint()
firstSnapTransform = pieceRaycast.transform;
if (modSupport)
{
if (IsModdedStructure(firstSnapTransform.transform.name))
if (LayerUtils.IsModdedStructure(firstSnapTransform.transform.name))
{
lastSnapMod = pieceRaycast.transform;
firstSnapTransform = pieceRaycast.collider.transform;
Expand Down Expand Up @@ -1803,10 +1803,5 @@ public void RelativeEulerModRotate(GameObject ghost)
parentRotation = false;
}
}

public bool IsModdedStructure(string name)
{
return name == "MS_CustomShip(Clone)" || name == "MovableBase";
}
}
}
5 changes: 4 additions & 1 deletion ValheimVRMod/Utilities/LayerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ private static void checkLayer(int layer)
LogWarning("Layer " + layer + " is a named layer: " + layerString);
}
}

public static bool IsModdedStructure(string name)
{
return name == "MS_CustomShip(Clone)" || name == "MovableBase" || name == "ValheimVehicles_WaterVehicleShip(Clone)";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep good to keep both just incase people install older version or enable V1 fallback Raft for some reason.

}
}
}