Skip to content

Commit

Permalink
Merge pull request #232 from DaXcess/dev
Browse files Browse the repository at this point in the history
Update LCVR to v1.2.2
  • Loading branch information
DaXcess authored Apr 17, 2024
2 parents 26f412d + 974b4af commit 8b14d6d
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 34 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 1.2.2

**Game Version**:
- Added compatibility with V50 Patch 1

**Bug Fixes**:
- Fixed visual glitch where VR players would not appear to be sinking in mud
- Fixed visual glitch where VR players who died in water got the underwater filter applied sporadically

**Mod Compatibility**:
- Fixed lighting culling issues when CullFactory is installed

# 1.2.1

### V50 IS HERE
Expand Down
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
27 changes: 14 additions & 13 deletions Source/Networking/VRNetPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class VRNetPlayer : MonoBehaviour
{
private ChainIKConstraintData originalLeftArmConstraintData;
private ChainIKConstraintData originalRightArmConstraintData;

private GameObject playerGhost;
private Transform usernameBillboard;
private CanvasGroup usernameAlpha;
private TextMeshProUGUI usernameText;

private bool spectatorWasParentedToShip;

private Transform xrOrigin;
private Transform leftController;
private Transform rightController;
Expand All @@ -46,7 +46,7 @@ public class VRNetPlayer : MonoBehaviour

public PlayerControllerB PlayerController { get; private set; }
public Bones Bones { get; private set; }

public Transform LeftItemHolder { get; private set; }
public Transform RightItemHolder { get; private set; }

Expand Down Expand Up @@ -111,20 +111,20 @@ private void Awake()
usernameAlpha = playerGhost.GetComponentInChildren<CanvasGroup>();

playerGhost.GetComponentInChildren<SpectatorGhost>().player = this;

// Disable rendering ghost until player dies
foreach (var renderer in playerGhost.GetComponentsInChildren<MeshRenderer>())
{
renderer.enabled = false;
}

// Set username text
if (PlayerController.playerSteamId is 76561198438308784 or 76561199575858981)
{
usernameText.color = new Color(0, 1, 1, 1);
usernameText.fontStyle = FontStyles.Bold;
}

usernameText.text = $"<noparse>{PlayerController.playerUsername}</noparse>";
}

Expand Down Expand Up @@ -195,7 +195,8 @@ private void Update()
transform.position.z + (modelOffset.z * 1.5f) - (cameraPosAccounted.z * 1.5f)
);

Bones.Model.localPosition = transform.InverseTransformPoint(transform.position + modelOffset);
Bones.Model.localPosition = transform.InverseTransformPoint(transform.position + modelOffset) +
Vector3.down * (2.5f * PlayerController.sinkingValue);
}
else
{
Expand Down Expand Up @@ -236,7 +237,7 @@ private void LateUpdate()
{
rightFingerCurler?.Update();
}

// Rotate spectator username billboard
if (StartOfRound.Instance.localPlayerController.localVisorTargetPoint is not null)
{
Expand Down Expand Up @@ -265,7 +266,7 @@ public void HideSpectatorGhost()
{
renderer.enabled = false;
}

usernameAlpha.alpha = 0f;
}

Expand All @@ -279,7 +280,7 @@ public void ShowSpectatorNameBillboard()

usernameAlpha.alpha = 1f;
}

internal void UpdateTargetTransforms(DNet.Rig rig)
{
leftController.localPosition = rig.leftHandPosition;
Expand Down Expand Up @@ -321,7 +322,7 @@ internal void UpdateSpectatorTransforms(DNet.SpectatorRig rig)
}

spectatorWasParentedToShip = rig.parentedToShip;

head.localPosition = rig.headPosition;
head.eulerAngles = rig.headRotation;

Expand All @@ -343,7 +344,7 @@ internal void UpdateSpectatorTransforms(DNet.SpectatorRig rig)
void OnDestroy()
{
Destroy(playerGhost);

Bones.ResetToPrefabPositions();

Destroy(Bones.LeftArmRig.GetComponent<TwoBoneIKConstraint>());
Expand All @@ -357,4 +358,4 @@ void OnDestroy()

GetComponentInChildren<RigBuilder>().Build();
}
}
}
39 changes: 39 additions & 0 deletions Source/Patches/Spectating/EnvironmentPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,43 @@ private static bool PreventTeleportDeadPlayer(ShipTeleporter __instance, ref IEn
__result = Utils.NopRoutine();
return false;
}

/// <summary>
/// Prevent the spectator camera (which is not used) from triggering the underwater filter
/// </summary>
[HarmonyPatch(typeof(HUDManager), nameof(HUDManager.UnderwaterScreenFilters))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SpectatorCamDontTriggerWater(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.MatchForward(false, [new CodeMatch(OpCodes.Ldc_I4_1)])
.SetOpcodeAndAdvance(OpCodes.Ldc_I4_0)
.InstructionEnumeration();
}

/// <summary>
/// Allow dead players to still experience the underwater filter
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.SetFaceUnderwaterFilters))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> EnableDeadPlayerUnderwater(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.Advance(1)
.RemoveInstructions(4)
.InstructionEnumeration();
}

/// <summary>
/// Prevent dead players from dying again if they are underwater as a spectator
/// </summary>
[HarmonyPatch(typeof(PlayerControllerB), nameof(PlayerControllerB.SetFaceUnderwaterFilters))]
[HarmonyPostfix]
private static void UnderwaterPreventDeath(PlayerControllerB __instance)
{
if (!__instance.isPlayerDead)
return;

StartOfRound.Instance.drowningTimer = 1;
}
}
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 8b14d6d

Please sign in to comment.