Skip to content

Commit

Permalink
Bunch of fixes and small features
Browse files Browse the repository at this point in the history
- Added config option to enable a popup asking for VR on startup
- Rewrote serialization for DNet
- Added a camera watchdog that detects when no XR rendering camera is active
- Fixed door interactors not changing size of somebody else interacts with them
  • Loading branch information
DaXcess committed Mar 16, 2024
1 parent 8d16c6c commit fe31f1d
Show file tree
Hide file tree
Showing 24 changed files with 479 additions and 285 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.2.0
# 1.2.0

## Settings Menu

Expand Down
2 changes: 1 addition & 1 deletion COMPILING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Compiling
# Compiling

## Initial setup

Expand Down
2 changes: 1 addition & 1 deletion Docs/API/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Table of contents
# Table of contents

1. [Adding LCVR as a dependency](#adding-lcvr-as-a-dependency)
2. [Checking if VR is active](#checking-if-vr-is-active)
Expand Down
2 changes: 1 addition & 1 deletion Docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Documentation
# Documentation

This directory will store all the documentation for thunderstore pages and the LCVR API
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lethal Company VR Mod
# Lethal Company VR Mod

<!-- Shields idea shamelessly stolen from Evaisa's LethalLib -->

Expand Down
Binary file modified Resources/lethalcompanyvr
Binary file not shown.
14 changes: 6 additions & 8 deletions Source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Config(ConfigFile file)
// General configuration

public ConfigEntry<bool> DisableVR { get; } = file.Bind("General", "DisableVR", false, "Disables the main functionality of this mod, can be used if you want to play without VR while keeping the mod installed.");

public ConfigEntry<bool> AskOnStartup { get; } = file.Bind("General", "AskOnStartup", false, "When enabled, shows a popup on game launch where you are asked whether or not you want to play in VR. If DisableVR is set to true, this popup will not show.");
public ConfigEntry<bool> IntroScreenSeen { get; } = file.Bind("General", "IntroScreenSeen", false, "Whether the VR intro screen has been displayed before. This configuration option should be set automatically.");
public ConfigEntry<bool> EnableHelmetVisor { get; } = file.Bind("General", "EnableHelmetVisor", false, "Enables the first person helmet visor and helmet. This will restrict your field of view, but looks more immersive.");

Expand All @@ -19,7 +21,7 @@ public class Config(ConfigFile file)
public ConfigEntry<bool> EnableDynamicResolution { get; } = file.Bind("Performance", "EnableDynamicResolution", false, "Whether or not dynamic resolution should be enabled. Required for most of these settings to have an effect.");
public ConfigEntry<DynamicResUpscaleFilter> DynamicResolutionUpscaleFilter { get; } = file.Bind("Performance", "DynamicResolutionUpscaleFilter", DynamicResUpscaleFilter.EdgeAdaptiveScalingUpres, new ConfigDescription("The filter/algorithm that will be used to perform dynamic resolution upscaling. Defaulted to FSR (Edge Adaptive Scaling).", new AcceptableValueEnum<DynamicResUpscaleFilter>()));
public ConfigEntry<float> DynamicResolutionPercentage { get; } = file.Bind("Performance", "DynamicResolutionPercentage", 80f, new ConfigDescription("The percentage of resolution to scale the game down to. The lower the value, the harder the upscale filter has to work which will result in quality loss.", new AcceptableValueRange<float>(0, 100)));
public ConfigEntry<bool> EnableDLSS { get; } = file.Bind("Performance", "EnableDLSS", false, "Enable DLSS support for the game. Required dynamic resolution to be enabled. DLSS will override the upscale filter used.");
public ConfigEntry<bool> EnableDLSS { get; } = file.Bind("Performance", "EnableDLSS", false, "(Not recommended!) Enable DLSS support for the game. Requires dynamic resolution to be enabled. DLSS will override the upscale filter used.");
public ConfigEntry<float> CameraResolution { get; } = file.Bind("Performance", "CameraResolution", 0.75f, new ConfigDescription("This setting configures the resolution scale of the game, lower values are more performant, but will make the game look worse. From around 0.8 the difference is negligible (on a Quest 2, with dynamic resolution disabled).", new AcceptableValueRange<float>(0.05f, 1f)));
public ConfigEntry<bool> DisableVolumetrics { get; } = file.Bind("Performance", "DisableVolumetrics", false, "Disables volumetrics in the game, which significantly improves performance, but removes all fog and may be considered cheating.");

Expand Down Expand Up @@ -75,14 +77,10 @@ public enum TurnProviderOption
}
}

internal class AcceptableValueEnum<T> : AcceptableValueBase where T : notnull, Enum
internal class AcceptableValueEnum<T>() : AcceptableValueBase(typeof(T))
where T : notnull, Enum
{
private readonly string[] names;

public AcceptableValueEnum() : base(typeof(T))
{
names = Enum.GetNames(typeof(T));
}
private readonly string[] names = Enum.GetNames(typeof(T));

public override object Clamp(object value) => value;
public override bool IsValid(object value) => true;
Expand Down
54 changes: 54 additions & 0 deletions Source/Experiments/CameraWatchdog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

namespace LCVR.Experiments;

/// <summary>
/// This behaviour attempts to detect when the XR rendering is failing due to no active XR cameras being present in
/// the scene. If this is the case, it will log warnings into the console.
/// </summary>
public class CameraWatchdog : MonoBehaviour
{
private static Camera ActiveCamera => Camera.allCameras.FirstOrDefault(cam => cam.targetTexture == null);

private int cameraMisses;

private void Awake()
{
StartCoroutine(checkForActiveCameraLoop());
}

private IEnumerator checkForActiveCameraLoop()
{
while (true)
{
var activeCamera = ActiveCamera;
cameraMisses = Mathf.Clamp(cameraMisses, 0, 5);

if (cameraMisses > 5)
{
Logger.LogWarning("[CameraWatchdog] Unresponsive XR rendering setup detected!");
Logger.LogWarning($"[CameraWatchdog] Current active camera: {(activeCamera ? activeCamera : "<NONE>")}");
}

yield return new WaitForSeconds(2f);

if (activeCamera is null)
{
cameraMisses++;
continue;
}

var hdCamera = activeCamera.GetComponent<HDAdditionalCameraData>();
if (hdCamera.xrRendering)
{
cameraMisses--;
continue;
}

cameraMisses++;
}
}
}
20 changes: 10 additions & 10 deletions Source/Input/FingerCurler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ internal DNet.Fingers GetCurls()
{
return new DNet.Fingers()
{
thumb = thumbFinger.curl,
index = indexFinger.curl,
middle = middleFinger.curl,
ring = ringFinger.curl,
pinky = pinkyFinger.curl,
thumb = (byte)(thumbFinger.curl * 255f),
index = (byte)(indexFinger.curl * 255f),
middle = (byte)(middleFinger.curl * 255f),
ring = (byte)(ringFinger.curl * 255f),
pinky = (byte)(pinkyFinger.curl * 255f),
};
}

internal void SetCurls(DNet.Fingers fingers)
{
thumbFinger.curl = fingers.thumb;
indexFinger.curl = fingers.index;
middleFinger.curl = fingers.middle;
ringFinger.curl = fingers.ring;
pinkyFinger.curl = fingers.pinky;
thumbFinger.curl = fingers.thumb / 255f;
indexFinger.curl = fingers.index / 255f;
middleFinger.curl = fingers.middle / 255f;
ringFinger.curl = fingers.ring / 255f;
pinkyFinger.curl = fingers.pinky / 255f;
}

public virtual void Update()
Expand Down
17 changes: 6 additions & 11 deletions Source/Items/VRItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,32 @@ public abstract class VRItem<T> : MonoBehaviour where T : GrabbableObject
/// <summary>
/// Keep receiving updates even when the item is pocketed
/// </summary>
protected bool UpdateWhenPocketed { get; set; } = false;
protected bool UpdateWhenPocketed { get; set; }

/// <summary>
/// Prevents the game from running LateUpdate calls on this item, which mess with the position and rotation of the object
/// </summary>
public bool CancelGameUpdate { get; protected set; } = false;
public bool CancelGameUpdate { get; protected set; }

protected bool IsLocal
{
get => _isLocal;
}

private bool _isLocal = false;
protected bool IsLocal { get; private set; }

protected virtual void Awake()
{
item = GetComponent<T>();
player = item.playerHeldBy;
networkPlayer = player.GetComponent<VRNetPlayer>();
_isLocal = networkPlayer == null;
IsLocal = networkPlayer == null;

itemCache.Add(item, this);

Logger.LogDebug($"VRItem[{GetType().Name}] (IsLocal: {_isLocal}) instantiated for item '{item.itemProperties.itemName}'");
Logger.LogDebug($"VRItem[{GetType().Name}] (IsLocal: {IsLocal}) instantiated for item '{item.itemProperties.itemName}'");
}

protected virtual void LateUpdate()
{
if (item.playerHeldBy != player || (!UpdateWhenPocketed && item.isPocketed) || !item.isHeld)
{
Logger.LogDebug($"VRItem[{GetType().Name}] (IsLocal: {_isLocal}) is being destroyed");
Logger.LogDebug($"VRItem[{GetType().Name}] (IsLocal: {IsLocal}) is being destroyed");
itemCache.Remove(item);

Destroy(this);
Expand Down
3 changes: 3 additions & 0 deletions Source/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ internal static class Native
[DllImport("advapi32.dll")]
public static extern int RegCloseKey(IntPtr hKey);

[DllImport("Shlwapi.dll", CharSet = CharSet.Ansi)]
public static extern int ShellMessageBox(IntPtr hAppInst, IntPtr hWnd, string lpcText, string lpcTitle, uint fuStyle);

private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

private static string GetWindowText(IntPtr hWnd)
Expand Down
Loading

0 comments on commit fe31f1d

Please sign in to comment.