Skip to content

Commit

Permalink
Revamp compat system, new spectator feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Aug 1, 2024
1 parent a9d2ee8 commit 2a61d7f
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 79 deletions.
44 changes: 8 additions & 36 deletions Source/Compat.cs
Original file line number Diff line number Diff line change
@@ -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<string> DetectedMods = [];

public Compat(IEnumerable<PluginInfo> 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);
}
}
2 changes: 1 addition & 1 deletion Source/Compatibility/CullFactory/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LCVR.Compatibility.CullFactory;

[LCVRPatch(dependency: "CullFactory")]
[LCVRPatch(dependency: Compat.CullFactory)]
[HarmonyPatch]
internal static class Patches
{
Expand Down
5 changes: 4 additions & 1 deletion Source/Compatibility/Diversity/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LCVR.Compatibility.Diversity;

[LCVRPatch(dependency: "Diversity")]
[LCVRPatch(dependency: Compat.Diversity)]
[HarmonyPatch]
internal static class DiversityPatches
{
Expand All @@ -22,6 +22,9 @@ private static void OnLoadCustomPostProcess()
DisableGlitchCustomPass();
}

/// <summary>
/// Disables the glitch fullscreen pass, which is incompatible with Dynamic Resolution in VR
/// </summary>
private static void DisableGlitchCustomPass()
{
HUDManagerRevamp.Instance.fullscreenPass2.enabled = false;
Expand Down
2 changes: 1 addition & 1 deletion Source/Compatibility/Mimics/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LCVR.Compatibility.Mimics;

[LCVRPatch(dependency: "Mimics")]
[LCVRPatch(dependency: Compat.Mimics)]
[HarmonyPatch]
internal static class MimicUIPatches
{
Expand Down
5 changes: 4 additions & 1 deletion Source/Compatibility/MoreCompany/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

namespace LCVR.Compatibility.MoreCompany;

[LCVRPatch(dependency: "MoreCompany")]
[LCVRPatch(dependency: Compat.MoreCompany)]
[HarmonyPatch]
internal static class MoreCompanyUIPatches
{
/// <summary>
/// Not too sure why this was needed, probably had to do with me moving the UI around in the GameObject hierarchy
/// </summary>
[HarmonyPatch(typeof(CosmeticRegistry), nameof(CosmeticRegistry.UpdateCosmeticsOnDisplayGuy))]
[HarmonyPostfix]
private static void AfterUpdateCosmetics()
Expand Down
3 changes: 2 additions & 1 deletion Source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class Config(ConfigFile file)
public ConfigEntry<float> 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<float>(0.01f, 1f)));
public ConfigEntry<float> 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<float>(1, 5)));
public ConfigEntry<bool> 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<bool> 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<bool> DisableShipLeverInteraction { get; } = file.Bind("Interaction", "DisableShipLeverInteraction", false, "Disables the physical lever pull interaction on the ship lever.");
Expand Down
4 changes: 2 additions & 2 deletions Source/Patches/HarmonyPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
32 changes: 0 additions & 32 deletions Source/Patches/PlayerControllerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
/// When dropping items, use the hand rotation instead of the player rotation to determine which way the item
/// should face once on the ground
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.DiscardHeldObject))]
[HarmonyTranspiler]
[HarmonyDebug]
private static IEnumerable<CodeInstruction> DropItemWithHandRotation(IEnumerable<CodeInstruction> 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<PlayerControllerB, int>)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)]
Expand Down
2 changes: 1 addition & 1 deletion Source/Patches/UIPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()})");

Expand Down
14 changes: 14 additions & 0 deletions Source/UI/VRHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -426,6 +427,19 @@ public void ToggleSpectatorLight(bool? active = null)
if (spectatorLight is not { } light)
return;

var hdCamera = VRSession.Instance.MainCamera.GetComponent<HDAdditionalCameraData>();

// 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);
}

Expand Down

0 comments on commit 2a61d7f

Please sign in to comment.