From 2a61d7fb9a480b21a2fd3ba6b07d74dd28a33d96 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Thu, 1 Aug 2024 20:08:30 +0200 Subject: [PATCH] Revamp compat system, new spectator feature --- Source/Compat.cs | 44 ++++----------------- Source/Compatibility/CullFactory/Patches.cs | 2 +- Source/Compatibility/Diversity/Patches.cs | 5 ++- Source/Compatibility/Mimics/Patches.cs | 2 +- Source/Compatibility/MoreCompany/Patches.cs | 5 ++- Source/Config.cs | 3 +- Source/Patches/HarmonyPatcher.cs | 4 +- Source/Patches/PlayerControllerPatches.cs | 32 --------------- Source/Patches/UIPatches.cs | 2 +- Source/Plugin.cs | 3 -- Source/UI/VRHUD.cs | 14 +++++++ 11 files changed, 37 insertions(+), 79 deletions(-) diff --git a/Source/Compat.cs b/Source/Compat.cs index f73dbcc8..558b2ae5 100644 --- a/Source/Compat.cs +++ b/Source/Compat.cs @@ -1,44 +1,16 @@ -using System.Collections.Generic; -using System.Linq; -using BepInEx; +using BepInEx.Bootstrap; namespace LCVR; -public class Compat +public static class Compat { - private readonly CompatibleMod[] ModCompatibilityList = - [ - new CompatibleMod("MoreCompany", "me.swipez.melonloader.morecompany"), - new CompatibleMod("Mimics", "x753.Mimics"), - new CompatibleMod("Diversity", "Chaos.Diversity"), - new CompatibleMod("CullFactory", "com.fumiko.CullFactory") - ]; + public const string MoreCompany = "me.swipez.melonloader.morecompany"; + public const string Mimics = "x753.Mimics"; + public const string Diversity = "Chaos.Diversity"; + public const string CullFactory = "com.fumiko.CullFactory"; - private readonly List DetectedMods = []; - - public Compat(IEnumerable plugins) - { - foreach (var plugin in plugins) - { - var mod = ModCompatibilityList.FirstOrDefault((mod) => mod.Guid == plugin.Metadata.GUID); - - if (mod == null) - continue; - - Logger.LogInfo($"Found compatible mod {mod.Name}"); - - DetectedMods.Add(mod.Name); - } - } - - public bool IsLoaded(string modName) - { - return DetectedMods.Contains(modName); - } - - private class CompatibleMod(string name, string guid) + public static bool IsLoaded(string modId) { - public string Name { get; } = name; - public string Guid { get; } = guid; + return Chainloader.PluginInfos.ContainsKey(modId); } } diff --git a/Source/Compatibility/CullFactory/Patches.cs b/Source/Compatibility/CullFactory/Patches.cs index 80e41ff3..e6644d0a 100644 --- a/Source/Compatibility/CullFactory/Patches.cs +++ b/Source/Compatibility/CullFactory/Patches.cs @@ -6,7 +6,7 @@ namespace LCVR.Compatibility.CullFactory; -[LCVRPatch(dependency: "CullFactory")] +[LCVRPatch(dependency: Compat.CullFactory)] [HarmonyPatch] internal static class Patches { diff --git a/Source/Compatibility/Diversity/Patches.cs b/Source/Compatibility/Diversity/Patches.cs index 691d275f..d0f548fc 100644 --- a/Source/Compatibility/Diversity/Patches.cs +++ b/Source/Compatibility/Diversity/Patches.cs @@ -4,7 +4,7 @@ namespace LCVR.Compatibility.Diversity; -[LCVRPatch(dependency: "Diversity")] +[LCVRPatch(dependency: Compat.Diversity)] [HarmonyPatch] internal static class DiversityPatches { @@ -22,6 +22,9 @@ private static void OnLoadCustomPostProcess() DisableGlitchCustomPass(); } + /// + /// Disables the glitch fullscreen pass, which is incompatible with Dynamic Resolution in VR + /// private static void DisableGlitchCustomPass() { HUDManagerRevamp.Instance.fullscreenPass2.enabled = false; diff --git a/Source/Compatibility/Mimics/Patches.cs b/Source/Compatibility/Mimics/Patches.cs index f082056d..08a280b7 100644 --- a/Source/Compatibility/Mimics/Patches.cs +++ b/Source/Compatibility/Mimics/Patches.cs @@ -6,7 +6,7 @@ namespace LCVR.Compatibility.Mimics; -[LCVRPatch(dependency: "Mimics")] +[LCVRPatch(dependency: Compat.Mimics)] [HarmonyPatch] internal static class MimicUIPatches { diff --git a/Source/Compatibility/MoreCompany/Patches.cs b/Source/Compatibility/MoreCompany/Patches.cs index 1d00508b..925fd69c 100644 --- a/Source/Compatibility/MoreCompany/Patches.cs +++ b/Source/Compatibility/MoreCompany/Patches.cs @@ -8,10 +8,13 @@ namespace LCVR.Compatibility.MoreCompany; -[LCVRPatch(dependency: "MoreCompany")] +[LCVRPatch(dependency: Compat.MoreCompany)] [HarmonyPatch] internal static class MoreCompanyUIPatches { + /// + /// Not too sure why this was needed, probably had to do with me moving the UI around in the GameObject hierarchy + /// [HarmonyPatch(typeof(CosmeticRegistry), nameof(CosmeticRegistry.UpdateCosmeticsOnDisplayGuy))] [HarmonyPostfix] private static void AfterUpdateCosmetics() diff --git a/Source/Config.cs b/Source/Config.cs index c81ac349..163e47b2 100644 --- a/Source/Config.cs +++ b/Source/Config.cs @@ -45,7 +45,8 @@ public class Config(ConfigFile file) public ConfigEntry CustomCameraLerpFactor { get; } = file.Bind("Rendering", "CustomCameraLerpFactor", 0.1f, new ConfigDescription("The smoothing factor of the custom camera rotation. Higher values mean more static movement, lower values are more smooth.", new AcceptableValueRange(0.01f, 1f))); public ConfigEntry LODBias { get; } = file.Bind("Rendering", "LODBias", 2f, new ConfigDescription("The LOD bias is a multiplier that dictates when an LOD must reduce their quality. Higher values means that more detailed LODs will persist for longer.", new AcceptableValueRange(1, 5))); public ConfigEntry DisableLensDistortion { get; } = file.Bind("Rendering", "DisableLensDistortion", false, "Disables the warping effects that you experience when you are under water, use the TZP-inhalant and more."); - + public ConfigEntry SpectatorLightRemovesVolumetrics { get; } = file.Bind("Rendering", "SpectatorLightRemovesVolumetrics", false, "When spectating, also disable all volumetrics (fog) while the fullbright lighting is enabled for more visibility."); + // Interaction configuration public ConfigEntry DisableShipLeverInteraction { get; } = file.Bind("Interaction", "DisableShipLeverInteraction", false, "Disables the physical lever pull interaction on the ship lever."); diff --git a/Source/Patches/HarmonyPatcher.cs b/Source/Patches/HarmonyPatcher.cs index 1400ff78..763015f8 100644 --- a/Source/Patches/HarmonyPatcher.cs +++ b/Source/Patches/HarmonyPatcher.cs @@ -30,7 +30,7 @@ private static void Patch(Harmony patcher, LCVRPatchTarget target) if (attribute == null) return; - if (attribute.Dependency != null && !Plugin.Compatibility.IsLoaded(attribute.Dependency)) + if (attribute.Dependency != null && !Compat.IsLoaded(attribute.Dependency)) return; if (attribute.Target != target) @@ -48,7 +48,7 @@ private static void Patch(Harmony patcher, LCVRPatchTarget target) } } -[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] +[AttributeUsage(AttributeTargets.Class)] internal class LCVRPatchAttribute(LCVRPatchTarget target = LCVRPatchTarget.VROnly, string dependency = null) : Attribute { public LCVRPatchTarget Target { get; } = target; diff --git a/Source/Patches/PlayerControllerPatches.cs b/Source/Patches/PlayerControllerPatches.cs index d99ee38f..047a6705 100644 --- a/Source/Patches/PlayerControllerPatches.cs +++ b/Source/Patches/PlayerControllerPatches.cs @@ -335,38 +335,6 @@ [new CodeMatch(OpCodes.Call, Method(typeof(Bounds), nameof(Bounds.Contains), [ty Method(typeof(Vector3), "op_Addition", [typeof(Vector3), typeof(Vector3)]))) .InstructionEnumeration(); } - - /// - /// When dropping items, use the hand rotation instead of the player rotation to determine which way the item - /// should face once on the ground - /// - [HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.DiscardHeldObject))] - [HarmonyTranspiler] - [HarmonyDebug] - private static IEnumerable DropItemWithHandRotation(IEnumerable instructions, - MethodBase original) - { - return new CodeMatcher(instructions) - .End() - .MatchBack(false, - [ - new CodeMatch(OpCodes.Callvirt, PropertyGetter(typeof(Transform), nameof(Transform.localEulerAngles))) - ]) - .Advance(-1) - .RemoveInstructions(4) - .InsertAndAdvance( - new CodeInstruction(OpCodes.Call, ((Func)GetHandRotation).Method) - ).InstructionEnumeration(); - - static int GetHandRotation(PlayerControllerB player) - { - var item = player.currentlyHeldObjectServer; - var restOffset = Quaternion.Euler(item.itemProperties.restingRotation.x, 0, - item.itemProperties.restingRotation.z); - return (int)(item.transform.eulerAngles.y - item.itemProperties.floorYOffset - 90 + - restOffset.eulerAngles.y); - } - } } [LCVRPatch(LCVRPatchTarget.Universal)] diff --git a/Source/Patches/UIPatches.cs b/Source/Patches/UIPatches.cs index 53d2dd2e..b97d5497 100644 --- a/Source/Patches/UIPatches.cs +++ b/Source/Patches/UIPatches.cs @@ -57,7 +57,7 @@ private static void OnMainMenuShown(MenuManager __instance) InitMenuScene(canvas); - if (Plugin.Compatibility.IsLoaded("MoreCompany")) + if (Compat.IsLoaded(Compat.MoreCompany)) Compatibility.MoreCompany.MoreCompanyCompatibility.SetupMoreCompanyUI(); if (__instance.isInitScene) diff --git a/Source/Plugin.cs b/Source/Plugin.cs index aa899a31..8df80282 100644 --- a/Source/Plugin.cs +++ b/Source/Plugin.cs @@ -36,7 +36,6 @@ public class Plugin : BaseUnityPlugin ]; public new static Config Config { get; private set; } - public static Compat Compatibility { get; private set; } public static Flags Flags { get; private set; } = 0; private void Awake() @@ -51,9 +50,7 @@ private void Awake() // Plugin startup logic LCVR.Logger.SetSource(Logger); - Config = new Config(base.Config); - Compatibility = new Compat([.. Chainloader.PluginInfos.Values]); Logger.LogInfo($"Starting {PLUGIN_NAME} v{PLUGIN_VERSION} ({GetCommitHash()})"); diff --git a/Source/UI/VRHUD.cs b/Source/UI/VRHUD.cs index 33caf508..1fc6bc68 100644 --- a/Source/UI/VRHUD.cs +++ b/Source/UI/VRHUD.cs @@ -3,6 +3,7 @@ using Microsoft.MixedReality.Toolkit.Experimental.UI; using TMPro; using UnityEngine; +using UnityEngine.Rendering.HighDefinition; using UnityEngine.UI; using UnityEngine.XR.Interaction.Toolkit.UI; @@ -426,6 +427,19 @@ public void ToggleSpectatorLight(bool? active = null) if (spectatorLight is not { } light) return; + var hdCamera = VRSession.Instance.MainCamera.GetComponent(); + + // Don't disable volumetrics if it's already disabled, or if the user disabled the feature + if (!Plugin.Config.DisableVolumetrics.Value && Plugin.Config.SpectatorLightRemovesVolumetrics.Value) + { + var enable = active ?? !light.activeSelf; + + if (enable) + hdCamera.DisableQualitySetting(FrameSettingsField.Volumetrics); + else + hdCamera.EnableQualitySetting(FrameSettingsField.Volumetrics); + } + light.SetActive(active ?? !light.activeSelf); }