Skip to content

Commit

Permalink
Update to v1.2.4
Browse files Browse the repository at this point in the history
Update to v1.2.4
  • Loading branch information
DaXcess authored Jun 1, 2024
2 parents 1722f98 + bf5eceb commit 2425346
Show file tree
Hide file tree
Showing 22 changed files with 873 additions and 477 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# 1.2.4

**Bug Fixes**:
- Fixed some of the doors on Artiface not using the new VR interactions
- Leaving the game while spectating will no longer prevent spectating to work in the next game
- Fixed some issues on the main menu when certain mods are active

**Additions**:
- Added VR motion controls to the knife (you can now stabby stab)
- Added VR interactions to the big doors on Artiface

**Changes**:
- Reworked the OpenXR loader, which will now attempt every runtime instead of only the default/preconfigured runtime
- Moved startup logic to a prefix, fixing an issue where occasionally the camera would be black when loading in

**Removals**:
- Removed detection for `UnityExplorer`
- Removed ghost girl from the main/pause menus

# 1.2.3

**Bug Fixes**:
Expand Down
2 changes: 1 addition & 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.3</Version>
<Version>1.2.4</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
<Title>LethalCompanyVR</Title>
Expand Down
Binary file modified Resources/lethalcompanyvr
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/Assets/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static bool LoadAssets()
keyboard = assetBundle.LoadAsset<GameObject>("NonNativeKeyboard");
settingsPanel = assetBundle.LoadAsset<GameObject>("Panel");
volumeManager = assetBundle.LoadAsset<GameObject>("Volume Manager");
enemyPrefab = assetBundle.LoadAsset<GameObject>("DressGirl");
enemyPrefab = assetBundle.LoadAsset<GameObject>("Flowerman");
spectatorLight = assetBundle.LoadAsset<GameObject>("Spectator Light");
spectatorGhost = assetBundle.LoadAsset<GameObject>("SpectatorGhost");

Expand Down
4 changes: 3 additions & 1 deletion Source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Config(ConfigFile file)
public ConfigEntry<bool> EnableDynamicResolution { get; } = file.Bind("Performance", "EnableDynamicResolution", false, "Whether or not dynamic resolution should be enabled. Required for most of these settings to have an effect.");
public ConfigEntry<DynamicResUpscaleFilter> DynamicResolutionUpscaleFilter { get; } = file.Bind("Performance", "DynamicResolutionUpscaleFilter", DynamicResUpscaleFilter.EdgeAdaptiveScalingUpres, new ConfigDescription("The filter/algorithm that will be used to perform dynamic resolution upscaling. Defaulted to FSR (Edge Adaptive Scaling).", new AcceptableValueEnum<DynamicResUpscaleFilter>()));
public ConfigEntry<float> DynamicResolutionPercentage { get; } = file.Bind("Performance", "DynamicResolutionPercentage", 80f, new ConfigDescription("The percentage of resolution to scale the game down to. The lower the value, the harder the upscale filter has to work which will result in quality loss.", new AcceptableValueRange<float>(0, 100)));
public ConfigEntry<bool> EnableDLSS { get; } = file.Bind("Performance", "EnableDLSS", false, "(Not recommended!) Enable DLSS support for the game. Requires dynamic resolution to be enabled. DLSS will override the upscale filter used.");
public ConfigEntry<bool> EnableDLSS { get; } = file.Bind("Performance", "EnableDLSS", false, "[DEPRECATED] DLSS support will be removed in a future release!");
public ConfigEntry<float> CameraResolution { get; } = file.Bind("Performance", "CameraResolution", 0.75f, new ConfigDescription("This setting configures the resolution scale of the game, lower values are more performant, but will make the game look worse. From around 0.8 the difference is negligible (on a Quest 2, with dynamic resolution disabled).", new AcceptableValueRange<float>(0.05f, 1f)));
public ConfigEntry<bool> DisableVolumetrics { get; } = file.Bind("Performance", "DisableVolumetrics", false, "Disables volumetrics in the game, which significantly improves performance, but removes all fog and may be considered cheating.");

Expand Down Expand Up @@ -61,6 +61,8 @@ public class Config(ConfigFile file)
public ConfigEntry<bool> DisableBreakerBoxInteraction { get; } = file.Bind("Interaction", "DisableBreakerBoxInteraction", false, "Disabled needing to physically open the breaker box and flip the switches with your finger.");
public ConfigEntry<bool> DisableDoorInteraction { get; } = file.Bind("Interaction", "DisableDoorInteraction", false, "Disable needing to physically open and close doors by interacting with the door handles. Will also disable the need to use keys and lockpickers physically on the door handle.");

public ConfigEntry<bool> DisableHangarLeverInteraction { get; } = file.Bind("Interaction", "DisableHangarLeverInteraction", false, "Disable needing to physically pull the lever for the big doors on Artiface");

public ConfigEntry<bool> DisableMuffleInteraction { get; } = file.Bind("Interaction", "DisableMuffleInteraction", false, "Disables the self-muffling feature, which makes it so that holding your hand in front of your mouth will no longer make you inaudible to enemies.");
public ConfigEntry<bool> DisableFaceInteractions { get; } = file.Bind("Interaction", "DisableFaceInteractions", false, "Disables the functionality to hold certain items up to your face to use them.");

Expand Down
32 changes: 5 additions & 27 deletions Source/EntryPoint.cs → Source/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,20 @@

namespace LCVR;

[LCVRPatch]
[HarmonyPatch]
internal class VREntryPoint
{
/// <summary>
/// The entrypoint for when you join a game
/// </summary>
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
private static void OnGameEntered()
{
StartOfRound.Instance.StartCoroutine(Start());
}

private static IEnumerator Start()
{
Logger.Log("Hello from VR!");

yield return new WaitUntil(() => StartOfRound.Instance.activeCamera != null);
}
}

[LCVRPatch(LCVRPatchTarget.Universal)]
[HarmonyPatch]
internal class UniversalEntryPoint
internal static class Entrypoint
{
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Start))]
[HarmonyPrefix]
private static void OnGameEntered()
{
StartOfRound.Instance.StartCoroutine(Start());
}

private static IEnumerator Start()
{
Logger.Log("Hello from universal!");
Logger.Log("Hello game, I am going to initialize now!");

yield return new WaitUntil(() => StartOfRound.Instance.activeCamera != null);

Expand All @@ -53,7 +31,7 @@ private static IEnumerator Start()
yield return DNet.Initialize();
}

[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.OnDestroy))]
[HarmonyPostfix]
private static void OnGameLeave()
{
Expand Down
86 changes: 86 additions & 0 deletions Source/Items/VRKnife.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Linq;
using LCVR.Assets;
using LCVR.Player;
using UnityEngine;

namespace LCVR.Items;

public class VRKnife : VRItem<KnifeItem>
{
private GameObject interactionTarget;
private GameObject knifeCollider;

private Vector3 previous;
private float attackTimer;

public float Speed { get; private set; }
private Vector3 Position => VRSession.Instance.LocalPlayer.transform.InverseTransformPoint(transform.position);

private new void Awake()
{
base.Awake();

if (!IsLocal)
return;

interactionTarget = Instantiate(AssetManager.interactable, VRSession.Instance.MainCamera.transform);
interactionTarget.transform.localPosition = new Vector3(0, 0, 0.5f);
interactionTarget.transform.localScale = Vector3.one * 0.3f;
interactionTarget.AddComponent<KnifeInteractor>();
interactionTarget.AddComponent<Rigidbody>().isKinematic = true;

knifeCollider = Instantiate(AssetManager.interactable, transform);
knifeCollider.transform.localPosition = new Vector3(0, 0, 7.25f);
knifeCollider.transform.localScale = new Vector3(1.2f, 3, 12.9f);

previous = Position;
}

protected override void OnUpdate()
{
if (!IsLocal)
return;

Speed = (Position - previous).magnitude / Time.deltaTime;
previous = Position;
}

private void OnDestroy()
{
Destroy(interactionTarget);
Destroy(knifeCollider);
}

internal void Attack()
{
if (Time.realtimeSinceStartup < attackTimer)
return;

attackTimer = Time.realtimeSinceStartup + 0.15f;
item.ItemActivate(true);
}

internal static RaycastHit[] GetKnifeHits(KnifeItem knife)
{
var tf = knife.transform;

var forwardHits = UnityEngine.Physics.SphereCastAll(tf.position, 0.3f, tf.forward, 0.75f, knife.knifeMask,
QueryTriggerInteraction.Collide);
var upHits = UnityEngine.Physics.SphereCastAll(tf.position, 0.3f, -tf.up, 0.75f, knife.knifeMask,
QueryTriggerInteraction.Collide);

RaycastHit[] allHits = [..forwardHits, ..upHits];

return allHits.GroupBy(x => x.collider).Select(x => x.First()).ToArray();
}
}

public class KnifeInteractor : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
var knife = other.GetComponentInParent<VRKnife>();
if (knife?.Speed > 6)
knife.Attack();
}
}
8 changes: 4 additions & 4 deletions Source/Items/VRShovelItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ internal class VRShovelItem : VRItem<Shovel>
private readonly Queue<Vector3> positions = new();
private Vector3 lastPosition = Vector3.zero;

private bool isHitting = false;
private bool hasSwung = false;
private float lastActionTime = 0;
private float timeNotReeledUp = 0;
private bool isHitting;
private bool hasSwung;
private float lastActionTime;
private float timeNotReeledUp;

private new void Awake()
{
Expand Down
78 changes: 70 additions & 8 deletions Source/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Security;

namespace LCVR;

Expand Down Expand Up @@ -41,25 +43,59 @@ internal static class Native
public static readonly IntPtr HKEY_LOCAL_MACHINE = new(0x80000002);

[DllImport("Advapi32.dll", EntryPoint = "RegOpenKeyExA", CharSet = CharSet.Ansi)]
public static extern int RegOpenKeyEx(IntPtr hKey, [In] string lpSubKey, int ulOptions, int samDesired, out IntPtr phkResult);
public static extern int RegOpenKeyEx(IntPtr hKey, [In] string lpSubKey, int ulOptions, int samDesired,
out IntPtr phkResult);

[DllImport("advapi32.dll", CharSet = CharSet.Ansi)]
public static extern int RegQueryValueEx(IntPtr hKey, string lpValueName, int lpReserved, out uint lpType, StringBuilder lpData, ref uint lpcbData);
public static extern int RegQueryValueEx(IntPtr hKey, string lpValueName, int lpReserved, out uint lpType,
StringBuilder lpData, ref uint lpcbData);

[DllImport("advapi32.dll", CharSet = CharSet.Ansi)]
public static extern int RegQueryInfoKey(IntPtr hKey, StringBuilder lpClass, IntPtr lpcbClass, IntPtr lpReserved, out uint lpcSubKeys, out uint lpcbMaxSubKeyLen, out uint lpcbMaxClassLen, out uint lpcValues, out uint lpcbMaxValueNameLen, out uint lpcbMaxValueLen, IntPtr lpSecurityDescriptor, IntPtr lpftLastWriteTime);
public static extern int RegQueryInfoKey(IntPtr hKey, StringBuilder lpClass, IntPtr lpcbClass, IntPtr lpReserved,
out uint lpcSubKeys, out uint lpcbMaxSubKeyLen, out uint lpcbMaxClassLen, out uint lpcValues,
out uint lpcbMaxValueNameLen, out uint lpcbMaxValueLen, IntPtr lpSecurityDescriptor, IntPtr lpftLastWriteTime);

[DllImport("advapi32.dll", EntryPoint = "RegEnumValueA", CharSet = CharSet.Ansi)]
public static extern int RegEnumValue(IntPtr hKey, uint dwIndex, StringBuilder lpValueName, ref uint lpcchValueName, IntPtr lpReserved, IntPtr lpType, IntPtr lpData, IntPtr lpcbData);
public static extern int RegEnumValue(IntPtr hKey, uint dwIndex, StringBuilder lpValueName, ref uint lpcchValueName,
IntPtr lpReserved, IntPtr lpType, IntPtr lpData, IntPtr lpcbData);

[DllImport("advapi32.dll")]
public static extern int RegCloseKey(IntPtr hKey);

[DllImport("Shlwapi.dll", CharSet = CharSet.Ansi)]
public static extern int ShellMessageBox(IntPtr hAppInst, IntPtr hWnd, string lpcText, string lpcTitle, uint fuStyle);
public static extern int ShellMessageBox(IntPtr hAppInst, IntPtr hWnd, string lpcText, string lpcTitle,
uint fuStyle);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetCurrentProcess();

[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool OpenProcessToken(IntPtr hProcess, uint dwAccess, out IntPtr hToken);

[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool GetTokenInformation(IntPtr hToken, uint tokenInformationClass, IntPtr lpData,
uint tokenInformationLength, out uint returnLength);

[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr handle);

public static bool RegOpenSubKey(ref IntPtr hKey, string lpSubKey, int samDesired)
{
var result = RegOpenKeyEx(hKey, lpSubKey, 0, samDesired, out var hNewKey) == 0;
if (!result)
return false;

RegCloseKey(hKey);
hKey = hNewKey;

return true;
}

private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

private static string GetWindowText(IntPtr hWnd)
{
int size = GetWindowTextLength(hWnd);
Expand All @@ -79,7 +115,7 @@ private static IEnumerable<IntPtr> FindWindows(EnumWindowsProc filter)
IntPtr found = IntPtr.Zero;
List<IntPtr> windows = [];

EnumWindows(delegate (IntPtr wnd, IntPtr param)
EnumWindows(delegate(IntPtr wnd, IntPtr param)
{
if (filter(wnd, param))
{
Expand All @@ -96,7 +132,7 @@ public static void BringGameWindowToFront()
{
var currentPid = GetCurrentProcessId();

var gameWindows = FindWindows(delegate (IntPtr hWnd, IntPtr lParam)
var gameWindows = FindWindows(delegate(IntPtr hWnd, IntPtr lParam)
{
GetWindowThreadProcessId(hWnd, out var pid);

Expand All @@ -119,4 +155,30 @@ public static void BringGameWindowToFront()
BringWindowToTop(targetWindow);
AttachThreadInput(foregroundPid, currentThreadId, false);
}

public static bool IsElevated()
{
var hToken = IntPtr.Zero;
var data = IntPtr.Zero;

try
{
if (!OpenProcessToken(GetCurrentProcess(), 0x0008, out hToken))
return false;

data = Marshal.AllocHGlobal(4);
if (!GetTokenInformation(hToken, 20, data, 4, out _))
return false;

return Marshal.ReadIntPtr(data).ToInt32() != 0;
}
finally
{
if (hToken != IntPtr.Zero)
CloseHandle(hToken);

if (data != IntPtr.Zero)
Marshal.FreeHGlobal(data);
}
}
}
Loading

0 comments on commit 2425346

Please sign in to comment.