Skip to content

Commit

Permalink
More bugfixes and additions
Browse files Browse the repository at this point in the history
- Fixed some custom camera bugs
- Made the ship door translucent while spectating
- Disabled more M+K legacy input stuff
- Made doors easier to close by increasing hitbox size when opened and adding a small delay
  • Loading branch information
DaXcess committed Mar 2, 2024
1 parent 48538b3 commit 00a688f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 25 deletions.
Binary file modified Resources/lethalcompanyvr
Binary file not shown.
6 changes: 6 additions & 0 deletions Source/Assets/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ internal static class AssetManager
public static Material splashMaterial;
public static Material defaultRayMat;
public static Material alwaysOnTopMat;
public static Material transparentHangarShipDoor1;
public static Material transparentHangarShipDoor2;

public static InputActionAsset defaultInputActions;
public static InputActionAsset nullInputActions;

public static RuntimeAnimatorController localVrMetarig;
public static RuntimeAnimatorController remoteVrMetarig;
Expand Down Expand Up @@ -55,10 +58,13 @@ public static bool LoadAssets()
spectatorLight = assetBundle.LoadAsset<GameObject>("Spectator Light");

defaultInputActions = assetBundle.LoadAsset<InputActionAsset>("XR Input Actions");
nullInputActions = assetBundle.LoadAsset<InputActionAsset>("NullPlayerActions");

splashMaterial = assetBundle.LoadAsset<Material>("Splash");
defaultRayMat = assetBundle.LoadAsset<Material>("Default Ray");
alwaysOnTopMat = assetBundle.LoadAsset<Material>("Always On Top");
transparentHangarShipDoor1 = assetBundle.LoadAsset<Material>("HangarShipDoor1");
transparentHangarShipDoor2 = assetBundle.LoadAsset<Material>("HangarShipDoor2");

githubImage = assetBundle.LoadAsset<Sprite>("Github");
kofiImage = assetBundle.LoadAsset<Sprite>("Ko-Fi");
Expand Down
18 changes: 18 additions & 0 deletions Source/Patches/InputPatches.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using HarmonyLib;
using LCVR.Input;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using LCVR.Assets;
using UnityEngine.InputSystem;
using static HarmonyLib.AccessTools;

Expand All @@ -12,12 +14,28 @@ namespace LCVR.Patches;
[HarmonyPatch]
public class InputPatches
{
/// <summary>
/// Reload the bindings when the in-game player settings get loaded
/// </summary>
[HarmonyPatch(typeof(IngamePlayerSettings), nameof(IngamePlayerSettings.LoadSettingsFromPrefs))]
[HarmonyPostfix]
private static void OnLoadSettings()
{
Actions.Instance.Reload();
}

/// <summary>
/// Disable Lethal Company's legacy inputs
/// </summary>
[HarmonyPatch(typeof(PlayerActions), MethodType.Constructor)]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.MatchForward(false, new CodeMatch(OpCodes.Ldstr))
.SetOperandAndAdvance(AssetManager.nullInputActions.ToJson())
.InstructionEnumeration();
}
}

[LCVRPatch]
Expand Down
20 changes: 18 additions & 2 deletions Source/Physics/Interactions/Door.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using HarmonyLib;
using LCVR.Assets;
Expand Down Expand Up @@ -55,12 +56,27 @@ public bool OnButtonPress(VRInteractor interactor)
if (Time.realtimeSinceStartup - lastInteraction < 0.5f)
return false;

door.OpenOrCloseDoor(VRSession.Instance.LocalPlayer.PlayerController);
StartCoroutine(delayedToggleDoor(door.isDoorOpened ? 0.2f : 0f));
lastInteraction = Time.realtimeSinceStartup;

return true;
}

private IEnumerator delayedToggleDoor(float wait = 0f)
{
yield return new WaitForSeconds(wait);

ToggleDoor();
}

private void ToggleDoor()
{
var wasOpened = door.isDoorOpened;
door.OpenOrCloseDoor(VRSession.Instance.LocalPlayer.PlayerController);

transform.localScale *= wasOpened ? 0.25f : 4f;
}

public void OnButtonRelease(VRInteractor _) { }
public void OnColliderEnter(VRInteractor _) { }
public void OnColliderExit(VRInteractor _) { }
Expand Down Expand Up @@ -168,7 +184,7 @@ private static void InitializeDoorInteractor(DoorLock __instance)
var interactableObject = GameObject.Instantiate(AssetManager.interactable, __instance.transform);
interactableObject.transform.localPosition = position;
interactableObject.transform.localEulerAngles = rotation;
interactableObject.transform.localScale = scale;
interactableObject.transform.localScale = scale * (__instance.isDoorOpened ? 4f : 1f);

var interactable = interactableObject.AddComponent<Door>();
interactable.door = __instance;
Expand Down
33 changes: 24 additions & 9 deletions Source/Player/Spectating/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HarmonyLib;
using LCVR.Patches;
using System.Collections;
using LCVR.Assets;
using UnityEngine;

namespace LCVR.Player.Spectating;
Expand Down Expand Up @@ -105,14 +106,25 @@ private static void OnPlayerDeath(PlayerControllerB __instance)
var shipDoorRight = shipDoorContainer.transform.Find("HangarDoorRight (1)");
var shipDoorWall = shipDoorContainer.transform.Find("Cube");

shipDoorLeft.GetComponent<MeshRenderer>().enabled = false;
shipDoorLeft.GetComponent<BoxCollider>().isTrigger = true;

shipDoorRight.GetComponent<MeshRenderer>().enabled = false;
shipDoorRight.GetComponent<BoxCollider>().isTrigger = true;

shipDoorWall.GetComponent<BoxCollider>().isTrigger = true;


// Make the ship doors transparent
var shipDoorLeftRenderer = shipDoorLeft.GetComponent<Renderer>();
var shipDoorRightRenderer = shipDoorRight.GetComponent<Renderer>();

shipDoorLeftRenderer.materials =
[AssetManager.transparentHangarShipDoor1, AssetManager.transparentHangarShipDoor2];
shipDoorRightRenderer.materials =
[AssetManager.transparentHangarShipDoor2, AssetManager.transparentHangarShipDoor1];

var color1 = AssetManager.transparentHangarShipDoor1.color;
var color2 = AssetManager.transparentHangarShipDoor2.color;

AssetManager.transparentHangarShipDoor1.color = new Color(color1.r, color1.g, color1.b, 0.25f);
AssetManager.transparentHangarShipDoor2.color = new Color(color2.r, color2.g, color2.b, 0.25f);

// Make sure all enemies are no longer targeting us
var enemies = Object.FindObjectsOfType<EnemyAI>();
foreach (var enemy in enemies)
Expand Down Expand Up @@ -202,13 +214,16 @@ private static void OnPlayerRevived()
var shipDoorRight = shipDoorContainer.transform.Find("HangarDoorRight (1)");
var shipDoorWall = shipDoorContainer.transform.Find("Cube");

shipDoorLeft.GetComponent<MeshRenderer>().enabled = true;
shipDoorLeft.GetComponent<BoxCollider>().isTrigger = false;

shipDoorRight.GetComponent<MeshRenderer>().enabled = true;
shipDoorRight.GetComponent<BoxCollider>().isTrigger = false;

shipDoorWall.GetComponent<BoxCollider>().isTrigger = false;

// Make the ship doors opaque again
var color1 = AssetManager.transparentHangarShipDoor1.color;
var color2 = AssetManager.transparentHangarShipDoor2.color;

AssetManager.transparentHangarShipDoor1.color = new Color(color1.r, color1.g, color1.b, 1f);
AssetManager.transparentHangarShipDoor2.color = new Color(color2.r, color2.g, color2.b, 1f);

VRSession.Instance.HUD.ToggleSpectatorLight(false);
}
Expand Down
28 changes: 18 additions & 10 deletions Source/Player/VRSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class VRSession : MonoBehaviour
#endregion

#region Custom Camera
private bool customCameraEnabled = false;
private bool customCameraEnabled;
private Camera customCamera;
private float customCameraLerpFactor;
#endregion
Expand Down Expand Up @@ -74,15 +74,16 @@ void Awake()
ChargeStation = ChargeStation.Create();
#endregion

// Enable this line to show the interactors on the camera
#if DEBUG && false
playerGameplayCamera.cullingMask |= 1 << 11;
#endif
if (Plugin.Flags.HasFlag(Flags.InteractableDebug))
playerGameplayCamera.cullingMask |= 1 << 11;
}

void Update()
{
if (customCameraEnabled && !localPlayer.IsDead)
if (!InVR)
return;

if (customCameraEnabled)
{
customCamera.transform.position = playerGameplayCamera.transform.position;
customCamera.transform.rotation = Quaternion.Lerp(customCamera.transform.rotation, playerGameplayCamera.transform.rotation, customCameraLerpFactor);
Expand Down Expand Up @@ -199,8 +200,7 @@ private void InitializeVRSession()
#region Add keyboard to Terminal
var terminal = FindObjectOfType<Terminal>();

var terminalKeyboardObject = Instantiate(AssetManager.keyboard);
terminalKeyboardObject.transform.SetParent(terminal.transform.parent.parent, false);
var terminalKeyboardObject = Instantiate(AssetManager.keyboard, terminal.transform.parent);
terminalKeyboardObject.transform.localPosition = new Vector3(-0.584f, 0.333f, 0.791f);
terminalKeyboardObject.transform.localEulerAngles = new Vector3(0, 90, 90);
terminalKeyboardObject.transform.localScale = Vector3.one * 0.0009f;
Expand Down Expand Up @@ -347,9 +347,8 @@ private void InitializeCustomCamera()

children.Do(child => child.SetParent(null, true));

customCamera = Instantiate(playerGameplayCamera);
customCamera = Instantiate(playerGameplayCamera, transform);
customCamera.name = "Custom Camera";
customCamera.transform.SetParent(playerGameplayCamera.transform.parent, false);
customCamera.transform.localEulerAngles = Vector3.zero;
customCamera.transform.localPosition = Vector3.zero;
customCamera.transform.localScale = Vector3.one;
Expand All @@ -358,6 +357,9 @@ private void InitializeCustomCamera()
customCamera.depth++;
customCamera.stereoTargetEye = StereoTargetEyeMask.None;
customCamera.targetDisplay = 0;

// Prevent cloned camera from tracking HMD movement
Destroy(customCamera.GetComponent<TrackedPoseDriver>());

var hdDesktopCamera = customCamera.GetComponent<HDAdditionalCameraData>();
hdDesktopCamera.xrRendering = false;
Expand Down Expand Up @@ -390,6 +392,9 @@ public void OnPauseMenuOpened()
HUD.menuKeyboard.Close();
SwitchToUICamera();

if (customCameraEnabled)
customCamera.enabled = false;

LocalPlayer.PrimaryController.enabled = false;
}

Expand All @@ -400,6 +405,9 @@ public void OnPauseMenuClosed()
HUD.menuKeyboard.Close();
SwitchToGameCamera();

if (customCameraEnabled)
customCamera.enabled = true;

LocalPlayer.PrimaryController.enabled = true;
}

Expand Down
12 changes: 8 additions & 4 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ private void Awake()
if (disableVr)
Logger.LogWarning("VR has been disabled by config or the `--disable-vr` command line flag");

if (Environment.GetCommandLineArgs().Contains("--lcvr-debug-interactables"))
Flags |= Flags.InteractableDebug;

// Verify game assembly to detect compatible version
var allowUnverified = Environment.GetCommandLineArgs().Contains("--lcvr-skip-checksum");

Expand Down Expand Up @@ -436,8 +439,9 @@ private IEnumerator HijackSplashScreen()
[Flags]
public enum Flags
{
VR = 1,
RestartRequired = 2,
UnityExplorerDetected = 4,
InvalidGameAssembly = 8
VR = 1 << 0,
RestartRequired = 1 << 1,
UnityExplorerDetected = 1 << 2,
InvalidGameAssembly = 1 << 3,
InteractableDebug = 1 << 4,
}

0 comments on commit 00a688f

Please sign in to comment.