Skip to content

Commit

Permalink
V50 patch 1 and CullFactory fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Apr 17, 2024
1 parent 26f412d commit fade407
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 21 deletions.
3 changes: 2 additions & 1 deletion LCVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>LCVR</AssemblyName>
<Description>Collecting Scrap in VR</Description>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
<Title>LethalCompanyVR</Title>
Expand All @@ -28,6 +28,7 @@
<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="CullFactory" Version="1.0.4" />
<PackageReference Include="DissonanceVoip" Version="1.50.0-lc.1" />
<PackageReference Include="Diversity" Version="2.0.3" />
<PackageReference Include="LethalCompany" Version="1.50.0-beta.1" />
Expand Down
14 changes: 8 additions & 6 deletions Source/Compat.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx;

namespace LCVR;

public class Compat
{
private static readonly CompatibleMod[] ModCompatibilityList =
private readonly CompatibleMod[] ModCompatibilityList =
[
new("MoreCompany", "me.swipez.melonloader.morecompany"),
new("Mimics", "x753.Mimics"),
new("Diversity", "Chaos.Diversity"),
new CompatibleMod("MoreCompany", "me.swipez.melonloader.morecompany"),
new CompatibleMod("Mimics", "x753.Mimics"),
new CompatibleMod("Diversity", "Chaos.Diversity"),
new CompatibleMod("CullFactory", "com.fumiko.CullFactory")
];

private static readonly List<string> DetectedMods = [];
private readonly List<string> DetectedMods = [];

public Compat(BepInEx.PluginInfo[] plugins)
public Compat(IEnumerable<PluginInfo> plugins)
{
foreach (var plugin in plugins)
{
Expand Down
29 changes: 29 additions & 0 deletions Source/Compatibility/CullFactory/Patches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CullFactory.Data;
using HarmonyLib;
using LCVR.Patches;
using LCVR.Player;
using UnityEngine;

namespace LCVR.Compatibility.CullFactory;

[LCVRPatch(dependency: "CullFactory")]
[HarmonyPatch]
internal static class Patches
{
/// <summary>
/// Fix for CullFactory to include the VR helmet lights in the <see cref="DynamicObjects.allPlayerLights"/> array
/// </summary>
[HarmonyPatch(typeof(DynamicObjects), nameof(DynamicObjects.CollectAllPlayerLights))]
[HarmonyPostfix]
private static void OnCollectAllPlayerLights()
{
if (!VRSession.Instance)
return;

var clientId = VRSession.Instance.LocalPlayer.PlayerController.playerClientId;
var lights = DynamicObjects.allPlayerLights[clientId];
var cameraLights = VRSession.Instance.MainCamera.GetComponentsInChildren<Light>();

DynamicObjects.allPlayerLights[clientId] = [..lights, ..cameraLights];
}
}
8 changes: 4 additions & 4 deletions Source/Items/VRFlashlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ protected override void OnUpdate()
if (IsLocal)
return;

var isHoldingActiveFlashlight = (player.currentlyHeldObjectServer?.itemProperties.itemId == 1 || player.currentlyHeldObjectServer?.itemProperties.itemId == 6)
&& player.currentlyHeldObjectServer.isBeingUsed;
// currentlyHeldObjectServer is guaranteed to not be null at this point

var isHoldingActiveFlashlight =
player.currentlyHeldObjectServer is { isBeingUsed: true } and ({ itemProperties.itemId: 1 } or
{ itemProperties.itemId: 6 });
if (!item.isPocketed)
{
// Update flashlight offsets
Expand Down
6 changes: 3 additions & 3 deletions Source/Patches/Spectating/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private static void OnPlayerUpdate(PlayerControllerB __instance)
__instance.takingFallDamage = false;
}

[HarmonyPatch(typeof(PlayerControllerB), "ActivateItem_performed")]
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.ActivateItem_performed))]
[HarmonyPostfix]
private static void SpectateNextPlayer(PlayerControllerB __instance)
{
Expand Down Expand Up @@ -287,7 +287,7 @@ private static void HideSpectatingText()
/// <summary>
/// Toggle death screen UI by pressing the secondary use button
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), "ItemSecondaryUse_performed")]
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.ItemSecondaryUse_performed))]
[HarmonyPostfix]
private static void OnToggleDeathScreen(PlayerControllerB __instance)
{
Expand All @@ -300,7 +300,7 @@ private static void OnToggleDeathScreen(PlayerControllerB __instance)
/// <summary>
/// Toggle spectator light by pressing the tertiary use button
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), "Discard_performed")]
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.Discard_performed))]
[HarmonyPostfix]
private static void OnToggleSpectatorLight(PlayerControllerB __instance)
{
Expand Down
6 changes: 4 additions & 2 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ namespace LCVR;
#region Compatibility Dependencies
[BepInDependency("me.swipez.melonloader.morecompany", DependencyFlags.SoftDependency)]
[BepInDependency("x753.Mimics", DependencyFlags.SoftDependency)]
[BepInDependency("com.fumiko.CullFactory", DependencyFlags.SoftDependency)]
#endregion
public class Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "io.daxcess.lcvr";
public const string PLUGIN_NAME = "LCVR";
public const string PLUGIN_VERSION = "1.2.1";
public const string PLUGIN_VERSION = "1.2.2";

private readonly string[] GAME_ASSEMBLY_HASHES = [
"7CFABBA203022CC46EF309B0E651276CB59217AF6D38C34E2085E67957DBBCBD" // V50
"7CFABBA203022CC46EF309B0E651276CB59217AF6D38C34E2085E67957DBBCBD", // V50
"4C265CECBC1A075E52D9E1FA458C67AA25C087362B472DF66DF370B9A0676A67", // V50 Patch 1
];

public new static Config Config { get; private set; }
Expand Down
16 changes: 11 additions & 5 deletions Source/UI/VRHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ private void Awake()
// Set up a global light for spectators to be able to toggle
spectatorLight = Instantiate(AssetManager.spectatorLight, transform);
spectatorLight.SetActive(false);

// Prevents CullFactory from culling the light
spectatorLight.hideFlags |= HideFlags.DontSave;
}

private void LateUpdate()
Expand Down Expand Up @@ -385,14 +388,14 @@ public void HideHUD(bool hide)
inventory.SetActive(!hide);
}

public void ToggleDeathScreen(bool? enabled = null)
public void ToggleDeathScreen(bool? visible = null)
{
if (!deathScreen)
return;

if (enabled != null)
if (visible != null)
{
deathScreen.transform.localScale = Vector3.one * (enabled == true ? 1.1f : 0f);
deathScreen.transform.localScale = Vector3.one * (visible == true ? 1.1f : 0f);
return;
}

Expand All @@ -402,9 +405,12 @@ public void ToggleDeathScreen(bool? enabled = null)
deathScreen.transform.localScale = Vector3.one * 1.1f;
}

public void ToggleSpectatorLight(bool? enabled = null)
public void ToggleSpectatorLight(bool? active = null)
{
spectatorLight?.SetActive(enabled ?? !spectatorLight.activeSelf);
if (spectatorLight is not { } light)
return;

light.SetActive(active ?? !light.activeSelf);
}

/// <summary>
Expand Down

0 comments on commit fade407

Please sign in to comment.