Skip to content

Commit

Permalink
Some reverts, new packaging logic and a deprecation
Browse files Browse the repository at this point in the history
- Reverted removal of "RestartRequired"
- Added package extraction and verification logic
- Moved initialization to a prefix to fix an issue
- Deprecated DLSS, it will be removed in a future release
  • Loading branch information
DaXcess committed May 30, 2024
1 parent f608441 commit e6b5f19
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 32 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
- Added VR interactions to the big doors on Artiface

**Changes**:
- Changed the mod package layout, dropping the `RuntimeDeps`
- Changed the mod package layout, dropping the `RuntimeDeps` in favor of `package`
- Reworked the OpenXR loader, which will now attempt every runtime instead of only the default/preconfigured runtime
- Game no longer needs to be restarted if the VR mod was installed for the first time
- Moved startup logic to a prefix, fixing an issue where occasionally the camera would be black when loading in

**Removals**:
- Removed detection for `UnityExplorer`
Expand Down
2 changes: 1 addition & 1 deletion Source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,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, "(Not recommended!) Enable DLSS support for the game. Requires dynamic resolution to be enabled. DLSS will override the upscale filter used.");
public ConfigEntry<bool> EnableDLSS { get; } = file.Bind("Performance", "EnableDLSS", false, "[DEPRECATED] DLSS support will be removed in a future release!");
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
32 changes: 5 additions & 27 deletions Source/EntryPoint.cs → Source/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,20 @@

namespace LCVR;

[LCVRPatch]
[HarmonyPatch]
internal class VREntryPoint
{
/// <summary>
/// The entrypoint for when you join a game
/// </summary>
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
private static void OnGameEntered()
{
StartOfRound.Instance.StartCoroutine(Start());
}

private static IEnumerator Start()
{
Logger.Log("Hello from VR!");

yield return new WaitUntil(() => StartOfRound.Instance.activeCamera != null);
}
}

[LCVRPatch(LCVRPatchTarget.Universal)]
[HarmonyPatch]
internal class UniversalEntryPoint
internal static class Entrypoint
{
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Start))]
[HarmonyPrefix]
private static void OnGameEntered()
{
StartOfRound.Instance.StartCoroutine(Start());
}

private static IEnumerator Start()
{
Logger.Log("Hello from universal!");
Logger.Log("Hello game, I am going to initialize now!");

yield return new WaitUntil(() => StartOfRound.Instance.activeCamera != null);

Expand All @@ -53,7 +31,7 @@ private static IEnumerator Start()
yield return DNet.Initialize();
}

[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.OnDestroy))]
[HarmonyPostfix]
private static void OnGameLeave()
{
Expand Down
25 changes: 25 additions & 0 deletions Source/Patches/UIPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,31 @@ private static void ForceNewInputSystem(XRUIInputModule __instance)
[HarmonyPatch]
internal static class UniversalUIPatches
{
/// <summary>
/// This function runs when the pre-init menu is shown
/// </summary>
[HarmonyPatch(typeof(PreInitSceneScript), nameof(PreInitSceneScript.Start))]
[HarmonyPostfix]
private static void OnPreInitMenuShown(PreInitSceneScript __instance)
{
if (!Plugin.Flags.HasFlag(Flags.RestartRequired))
return;

var canvas = __instance.launchSettingsPanelsContainer.GetComponentInParent<Canvas>().gameObject;
var textObject = Object.Instantiate(canvas.Find("GameObject/LANOrOnline/OnlineButton/Text (TMP) (1)"));
var text = textObject.GetComponent<TextMeshProUGUI>();

text.transform.parent = canvas.Find("GameObject").transform;
text.transform.localPosition = new Vector3(200, -170, 0);
text.transform.localScale = Vector3.one;
text.text = "VR Setup Complete!\nYou must restart your game to go into VR!\nIgnore this if you want to play without VR.";
text.autoSizeTextContainer = true;
text.color = new Color(0.9434f, 0.0434f, 0.0434f, 1);
text.alignment = TextAlignmentOptions.Center;
text.fontSize = 18;
text.raycastTarget = false;
}

#if DEBUG
internal static bool debugScreenSeen;
#endif
Expand Down
68 changes: 66 additions & 2 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
Expand Down Expand Up @@ -61,6 +62,16 @@ private void Awake()

Logger.LogInfo($"Plugin {PLUGIN_NAME} is starting...");

// Extract LCVR dependencies
if (!ExtractPackage(out var mustRestart))
{
Logger.LogError("Failed to extract LCVR dependencies, disabling mod");
return;
}

if (mustRestart)
Flags |= Flags.RestartRequired;

// Allow disabling VR via config and command line
var disableVr = Config.DisableVR.Value ||
Environment.GetCommandLineArgs().Contains("--disable-vr", StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -117,6 +128,7 @@ private void Awake()
if (!disableVr && InitializeVR())
{
Flags |= Flags.VR;
Flags &= ~Flags.RestartRequired;

StartCoroutine(HijackSplashScreen());
}
Expand All @@ -137,6 +149,53 @@ private bool VerifyGameVersion()
return GAME_ASSEMBLY_HASHES.Contains(shasum);
}

/// <summary>
/// Verifies and extracts the LCVR dependencies (if necessary), returning whether the game needs to restart
/// </summary>
private bool ExtractPackage(out bool mustRestart)
{
mustRestart = false;

try
{
var basePath = Path.Combine(Paths.GameRootPath, "Lethal Company_Data");
using var zip = ZipFile.OpenRead(Path.Combine(Info.Location, "package"));

foreach (var entry in zip.Entries.Where(entry =>
!entry.FullName.EndsWith('/') || !string.IsNullOrEmpty(entry.Name)))
{
var fullPath = Path.Combine(basePath, entry.FullName);
var directoryName = Path.GetDirectoryName(fullPath)!;

if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
mustRestart = true;
}

using var stream = entry.Open();
using var reader = new BinaryReader(stream);

var bytes = reader.ReadBytes((int)entry.Length);

// Check if file is up-to-date
if (File.Exists(fullPath) &&
Utils.ComputeHash(bytes).SequenceEqual(Utils.ComputeHash(File.ReadAllBytes(fullPath)))) continue;

File.WriteAllBytes(fullPath, bytes);

mustRestart = true;
}
}
catch (Exception ex)
{
Logger.LogError($"Failed to validate and extract LCVR package: {ex.Message}");
return false;
}

return true;
}

private bool InitializeVR()
{
Logger.LogInfo("Loading VR...");
Expand Down Expand Up @@ -170,6 +229,10 @@ private bool InitializeVR()
Config.DynamicResolutionPercentage.Value;
settings.supportMotionVectors = true;

if (Config.EnableDLSS.Value)
Logger.LogWarning(
"DLSS has been deprecated, and will be removed in a future release. Please switch over to the Dynamic Resolution and Camera Resolution configuration to enhance your performance.");

settings.xrSettings.occlusionMesh = false;
settings.xrSettings.singlePass = false;

Expand Down Expand Up @@ -209,6 +272,7 @@ private static IEnumerator HijackSplashScreen()
public enum Flags
{
VR = 1 << 0,
InvalidGameAssembly = 1 << 3,
InteractableDebug = 1 << 4,
RestartRequired = 1 << 1,
InvalidGameAssembly = 1 << 2,
InteractableDebug = 1 << 3,
}
1 change: 1 addition & 0 deletions Source/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using System;
using System.Collections;
using System.IO;
using GameNetcodeStuff;

namespace LCVR;
Expand Down

0 comments on commit e6b5f19

Please sign in to comment.