Skip to content

Commit

Permalink
Bunch of 1.2.4 stuff
Browse files Browse the repository at this point in the history
- Reworked OpenXR loader
- Removed ghost girl from menus
- Removed UnityExplorer detection
  • Loading branch information
DaXcess committed May 28, 2024
1 parent 32d0db6 commit f608441
Show file tree
Hide file tree
Showing 12 changed files with 509 additions and 546 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
- Added VR motion controls to the knife (you can now stabby stab)
- Added VR interactions to the big doors on Artiface

**Changes**:
- Changed the mod package layout, dropping the `RuntimeDeps`
- Reworked the OpenXR loader, which will now attempt every runtime instead of only the default/preconfigured runtime
- Game no longer needs to be restarted if the VR mod was installed for the first time

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

# 1.2.3

**Bug Fixes**:
Expand Down
23 changes: 0 additions & 23 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,4 @@
<value>..\Resources\lethalcompanyvr;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitySubsystemsManifest" xml:space="preserve">
<value>{
"name": "OpenXR XR Plugin",
"version": "1.8.2",
"libraryName": "UnityOpenXR",
"displays": [
{
"id": "OpenXR Display"
}
],
"inputs": [
{
"id": "OpenXR Input"
}
]
}</value>
</data>
</root>
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
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 f608441

Please sign in to comment.