diff --git a/TABGVR/Native.cs b/TABGVR/Native.cs
new file mode 100644
index 0000000..9d772d5
--- /dev/null
+++ b/TABGVR/Native.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace TABGVR;
+
+public static class Native
+{
+ [DllImport("shlwapi.dll", CharSet = CharSet.Ansi)]
+ public static extern int ShellMessageBox(IntPtr hAppInst, IntPtr hWnd, string lpcText, string lpcTitle,
+ uint fuStyle);
+}
\ No newline at end of file
diff --git a/TABGVR/Network/NetKinematics.cs b/TABGVR/Network/NetKinematics.cs
index dad83ae..66cb3f6 100644
--- a/TABGVR/Network/NetKinematics.cs
+++ b/TABGVR/Network/NetKinematics.cs
@@ -9,6 +9,8 @@ public class NetKinematics : MonoBehaviour
NetworkPlayer netPlayer;
private Holding holding;
+ private bool isSetUp;
+
///
/// Sets up joint for kinematics
///
@@ -23,20 +25,27 @@ private void Setup(Rigidbody joint)
joint.isKinematic = false;
arm.GetComponent().isKinematic = false;
+
+ isSetUp = true;
}
private void Start()
{
netPlayer = GetComponent();
holding = GetComponent();
-
- Setup(holding.leftHand);
- Setup(holding.rightHand);
}
private void FixedUpdate()
{
if (!NetworkStoreList.NetworkStores.TryGetValue(netPlayer.Index, out var store)) return;
+
+ if (!isSetUp)
+ {
+ // ReSharper disable once Unity.PerformanceCriticalCodeInvocation
+ Setup(holding.leftHand);
+ // ReSharper disable once Unity.PerformanceCriticalCodeInvocation
+ Setup(holding.rightHand);
+ }
var leftHandPosition = store.LeftHandPosition - store.HmdPosition + netPlayer.m_Camera.position;
var rightHandPosition = store.RightHandPosition - store.HmdPosition + netPlayer.m_Camera.position;
diff --git a/TABGVR/PatchAttributes/FlatscreenPatchAttribute.cs b/TABGVR/PatchAttributes/FlatscreenPatchAttribute.cs
new file mode 100644
index 0000000..b685197
--- /dev/null
+++ b/TABGVR/PatchAttributes/FlatscreenPatchAttribute.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace TABGVR.PatchAttributes;
+
+[AttributeUsage(AttributeTargets.Class)]
+public class FlatscreenPatchAttribute : Attribute
+{
+}
\ No newline at end of file
diff --git a/TABGVR/PatchAttributes/VRPatchAttribute.cs b/TABGVR/PatchAttributes/VRPatchAttribute.cs
new file mode 100644
index 0000000..81b4540
--- /dev/null
+++ b/TABGVR/PatchAttributes/VRPatchAttribute.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace TABGVR.PatchAttributes;
+
+[AttributeUsage(AttributeTargets.Class)]
+public class VRPatchAttribute : Attribute
+{
+}
\ No newline at end of file
diff --git a/TABGVR/Patches/CameraPatches/CameraMovementPatch.cs b/TABGVR/Patches/CameraPatches/CameraMovementPatch.cs
index e74877e..ff3fecb 100644
--- a/TABGVR/Patches/CameraPatches/CameraMovementPatch.cs
+++ b/TABGVR/Patches/CameraPatches/CameraMovementPatch.cs
@@ -2,10 +2,12 @@
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;
+using TABGVR.PatchAttributes;
namespace TABGVR.Patches.CameraPatches;
[HarmonyPatch(typeof(CameraMovement))]
+[VRPatch]
public class CameraMovementPatch
{
[HarmonyPatch(nameof(CameraMovement.LateUpdate))]
diff --git a/TABGVR/Patches/CameraPatches/CameraPatch.cs b/TABGVR/Patches/CameraPatches/CameraPatch.cs
index f80d2a5..2fd3561 100644
--- a/TABGVR/Patches/CameraPatches/CameraPatch.cs
+++ b/TABGVR/Patches/CameraPatches/CameraPatch.cs
@@ -1,6 +1,7 @@
using DeepSky.Haze;
using HarmonyLib;
using HighlightingSystem;
+using TABGVR.PatchAttributes;
using TABGVR.Player;
using UnityEngine;
using UnityEngine.Animations;
@@ -10,6 +11,7 @@
namespace TABGVR.Patches.CameraPatches;
[HarmonyPatch(typeof(PlayerCamera))]
+[VRPatch]
public class CameraPatch
{
///
diff --git a/TABGVR/Patches/FlatscreenKinematicsHelperPatch.cs b/TABGVR/Patches/FlatscreenKinematicsHelperPatch.cs
new file mode 100644
index 0000000..d9dfbab
--- /dev/null
+++ b/TABGVR/Patches/FlatscreenKinematicsHelperPatch.cs
@@ -0,0 +1,21 @@
+using HarmonyLib;
+using Landfall.Network;
+using TABGVR.Network;
+using TABGVR.PatchAttributes;
+using UnityEngine.SceneManagement;
+
+namespace TABGVR.Patches;
+
+[HarmonyPatch(typeof(Holding), nameof(Holding.Start))]
+[FlatscreenPatch]
+public class FlatscreenKinematicsHelperPatch
+{
+ private static void Postfix(Holding __instance)
+ {
+ if (__instance.m_player == global::Player.localPlayer) return;
+ if (!PhotonServerConnector.IsNetworkMatch) return;
+ if (SceneManager.GetActiveScene().name == "MainMenu") return;
+
+ __instance.gameObject.AddComponent();
+ }
+}
\ No newline at end of file
diff --git a/TABGVR/Patches/Interactions/KinematicsPatch.cs b/TABGVR/Patches/Interactions/KinematicsPatch.cs
index f18bcab..6f0bb76 100644
--- a/TABGVR/Patches/Interactions/KinematicsPatch.cs
+++ b/TABGVR/Patches/Interactions/KinematicsPatch.cs
@@ -5,6 +5,7 @@
using Landfall.Network;
using TABGVR.Input;
using TABGVR.Network;
+using TABGVR.PatchAttributes;
using TABGVR.Player;
using TABGVR.Player.Mundanities;
using TABGVR.Util;
@@ -17,6 +18,7 @@
namespace TABGVR.Patches.Interactions;
[HarmonyPatch(typeof(Holding))]
+[VRPatch]
internal class KinematicsPatch
{
internal static bool GripAvailable;
diff --git a/TABGVR/Patches/Interactions/ShootHapticPatch.cs b/TABGVR/Patches/Interactions/ShootHapticPatch.cs
index 15b5f76..212f7cc 100644
--- a/TABGVR/Patches/Interactions/ShootHapticPatch.cs
+++ b/TABGVR/Patches/Interactions/ShootHapticPatch.cs
@@ -1,11 +1,13 @@
using System;
using HarmonyLib;
using TABGVR.Input;
+using TABGVR.PatchAttributes;
using TABGVR.Player;
namespace TABGVR.Patches.Interactions;
[HarmonyPatch(typeof(Weapon), nameof(Weapon.Awake))]
+[VRPatch]
public class ShootHapticPatch
{
private const float Amplitude = 0.8f;
diff --git a/TABGVR/Patches/Interactions/SwapWeaponPatch.cs b/TABGVR/Patches/Interactions/SwapWeaponPatch.cs
index 7290fb6..ac7013c 100644
--- a/TABGVR/Patches/Interactions/SwapWeaponPatch.cs
+++ b/TABGVR/Patches/Interactions/SwapWeaponPatch.cs
@@ -3,11 +3,13 @@
using HarmonyLib;
using TABGInput;
using TABGVR.Input;
+using TABGVR.PatchAttributes;
using TABGVR.Player;
namespace TABGVR.Patches.Interactions;
[HarmonyPatch(typeof(InteractionHandler), nameof(InteractionHandler.StartPickup), MethodType.Enumerator)]
+[VRPatch]
public static class SwapWeaponPatch
{
[HarmonyTranspiler]
diff --git a/TABGVR/Patches/Interactions/ThrowingPatch.cs b/TABGVR/Patches/Interactions/ThrowingPatch.cs
index a141d35..a8d187b 100644
--- a/TABGVR/Patches/Interactions/ThrowingPatch.cs
+++ b/TABGVR/Patches/Interactions/ThrowingPatch.cs
@@ -10,12 +10,14 @@
using System.Collections.Generic;
using System.Reflection.Emit;
using HarmonyLib;
+// using TABGVR.PatchAttributes;
using TABGVR.Player;
namespace TABGVR.Patches.Interactions;
// [HarmonyPatch(typeof(InteractionHandler), nameof(InteractionHandler.Throwing), MethodType.Enumerator)]
// [HarmonyDebug]
+// [VRPatch]
public static class ThrowingPatch
{
public static IEnumerable Transpiler(IEnumerable instructions) =>
diff --git a/TABGVR/Patches/Networking/NetworkEventPatch.cs b/TABGVR/Patches/Networking/NetworkEventPatch.cs
index 7e23608..0d43b6b 100644
--- a/TABGVR/Patches/Networking/NetworkEventPatch.cs
+++ b/TABGVR/Patches/Networking/NetworkEventPatch.cs
@@ -3,11 +3,13 @@
using HarmonyLib;
using Landfall.Network;
using TABGVR.Network;
+using TABGVR.PatchAttributes;
using UnityEngine;
namespace TABGVR.Patches.Networking;
[HarmonyPatch(typeof(ServerConnector), nameof(ServerConnector.OnEvent))]
+[VRPatch, FlatscreenPatch]
public class NetworkEventPatch
{
public static bool Interrogated = false;
@@ -24,6 +26,7 @@ public static bool Prefix(ClientPackage clientPackage)
switch (clientPackage.Code)
{
case (EventCode)PacketCodes.Interrogate: // Interrogate
+ if (!Plugin.VREnabled.Value) return false; // flatscreen players aren't allowed to respond to interrogations
ServerConnector.m_ServerHandler.SendMessageToServer((EventCode)PacketCodes.Interrogate, [], true);
Interrogated = true;
return false;
diff --git a/TABGVR/Patches/PlayerPatch.cs b/TABGVR/Patches/PlayerPatch.cs
index 23a84a4..1f3b0da 100644
--- a/TABGVR/Patches/PlayerPatch.cs
+++ b/TABGVR/Patches/PlayerPatch.cs
@@ -1,5 +1,6 @@
using HarmonyLib;
using TABGVR.Input;
+using TABGVR.PatchAttributes;
using TABGVR.Player;
using UnityEngine;
using UnityEngine.SpatialTracking;
@@ -7,6 +8,7 @@
namespace TABGVR.Patches;
[HarmonyPatch(typeof(global::Player))]
+[VRPatch]
public class PlayerPatch
{
public static VRControls CurrentVRControls;
diff --git a/TABGVR/Patches/UI/DraggedItemPatch.cs b/TABGVR/Patches/UI/DraggedItemPatch.cs
index bdfd8c5..17b0e42 100644
--- a/TABGVR/Patches/UI/DraggedItemPatch.cs
+++ b/TABGVR/Patches/UI/DraggedItemPatch.cs
@@ -2,6 +2,7 @@
using System.Reflection.Emit;
using HarmonyLib;
using Landfall.TABG.UI;
+using TABGVR.PatchAttributes;
using TABGVR.Util;
using UnityEngine;
@@ -11,6 +12,7 @@ namespace TABGVR.Patches.UI;
#if DEBUG
[HarmonyDebug]
#endif
+[VRPatch]
public class DraggedItemPatch
{
public static IEnumerable Transpiler(IEnumerable instructions)
diff --git a/TABGVR/Patches/UI/InventoryUIManagerUpdatePatch.cs b/TABGVR/Patches/UI/InventoryUIManagerUpdatePatch.cs
index b80576b..fcee97e 100644
--- a/TABGVR/Patches/UI/InventoryUIManagerUpdatePatch.cs
+++ b/TABGVR/Patches/UI/InventoryUIManagerUpdatePatch.cs
@@ -3,10 +3,12 @@
using HarmonyLib;
using Landfall.TABG.UI;
using TABGVR.Input;
+using TABGVR.PatchAttributes;
namespace TABGVR.Patches.UI;
[HarmonyPatch(typeof(InventoryUIManager), nameof(InventoryUIManager.Update))]
+[VRPatch]
public class InventoryUIManagerUpdatePatch
{
///
diff --git a/TABGVR/Patches/UI/InventoryUIPatch.cs b/TABGVR/Patches/UI/InventoryUIPatch.cs
index 47d1092..905f692 100644
--- a/TABGVR/Patches/UI/InventoryUIPatch.cs
+++ b/TABGVR/Patches/UI/InventoryUIPatch.cs
@@ -1,4 +1,5 @@
using HarmonyLib;
+using TABGVR.PatchAttributes;
using TABGVR.Util;
using UnityEngine;
using UnityEngine.UI;
@@ -6,6 +7,7 @@
namespace TABGVR.Patches.UI;
[HarmonyPatch(typeof(InventoryUI), nameof(InventoryUI.Start))]
+[VRPatch]
public static class InventoryUIPatch
{
///
diff --git a/TABGVR/Patches/UI/MainMenuCameraPatch.cs b/TABGVR/Patches/UI/MainMenuCameraPatch.cs
index 5f0b161..1a1db58 100644
--- a/TABGVR/Patches/UI/MainMenuCameraPatch.cs
+++ b/TABGVR/Patches/UI/MainMenuCameraPatch.cs
@@ -1,5 +1,6 @@
using DeepSky.Haze;
using HarmonyLib;
+using TABGVR.PatchAttributes;
using TABGVR.Player;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
@@ -8,6 +9,7 @@
namespace TABGVR.Patches.UI;
[HarmonyPatch(typeof(CameraIdleMovement), nameof(CameraIdleMovement.Start))]
+[VRPatch]
public static class MainMenuCameraPatch
{
public static void Postfix(CameraIdleMovement __instance)
diff --git a/TABGVR/Patches/UI/MainMenuPatch.cs b/TABGVR/Patches/UI/MainMenuPatch.cs
index edae211..cf1603b 100644
--- a/TABGVR/Patches/UI/MainMenuPatch.cs
+++ b/TABGVR/Patches/UI/MainMenuPatch.cs
@@ -1,5 +1,6 @@
using HarmonyLib;
using Landfall.TABG.UI.MainMenu;
+using TABGVR.PatchAttributes;
using TABGVR.Util;
using UnityEngine;
using UnityEngine.UI;
@@ -7,6 +8,7 @@
namespace TABGVR.Patches.UI;
[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))]
+[VRPatch]
public static class MainMenuPatch
{
public static void Postfix(MainMenuManager __instance)
diff --git a/TABGVR/Plugin.cs b/TABGVR/Plugin.cs
index 763912c..08f9cc9 100644
--- a/TABGVR/Plugin.cs
+++ b/TABGVR/Plugin.cs
@@ -1,7 +1,12 @@
-using BepInEx;
+using System;
+using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
+using TABGVR.PatchAttributes;
using TABGVR.Patches.Misc;
using TABGVR.Player;
using TABGVR.Util;
@@ -19,26 +24,60 @@ public class Plugin : BaseUnityPlugin
internal new static ManualLogSource Logger;
public static ConfigEntry SnapTurnEnabled;
+ public static ConfigEntry AskOnStartup;
+ public static ConfigEntry VREnabled;
private void Awake()
{
SnapTurnEnabled = Config.Bind("Input", "SnapTurn", true, "Use snap turn instead of smooth turn.");
-
+ AskOnStartup = Config.Bind("Input", "AskOnStartup", true, "Ask to use VR mode on startup.");
+ VREnabled = Config.Bind("Input", "VREnabled", true,
+ "If enabled, will always use VR mode if AskOnStartup is false.");
+
Logger = base.Logger;
Logger.LogInfo("TABGVR plugin loaded.");
AntiCheatBypass.Bypass();
- XRLoader.LoadXR();
-
Harmony harmony = new(MyPluginInfo.PLUGIN_GUID);
-
+
#if DEBUG
HarmonyFileLog.Enabled = true;
#endif
-
- harmony.PatchAll();
+
+ if (AskOnStartup.Value)
+ switch (Native.ShellMessageBox(IntPtr.Zero, IntPtr.Zero,
+ "Would you like to launch TABG in VR?\n\nMake sure your headset is connected and your launcher (Oculus Dash or SteamVR) is configured as the default OpenXR API.\nLaunching without VR will still let you see VR players' hand movements.",
+ "TABGVR", 0x1043))
+ {
+ case 2:
+ Process.GetCurrentProcess().Kill();
+ break;
+ case 7:
+ VREnabled.Value = false;
+ break;
+ case 6:
+ VREnabled.Value = true;
+ break;
+ }
+
+ var allTypes = Assembly.GetExecutingAssembly().GetTypes();
+
+ if (VREnabled.Value)
+ {
+ // patch vr types
+ foreach (var type in allTypes.Where(type => type.IsDefined(typeof(VRPatchAttribute))))
+ harmony.PatchAll(type);
+
+ XRLoader.LoadXR();
+ }
+ else
+ {
+ // patch flatscreen types
+ foreach (var type in allTypes.Where(type => type.IsDefined(typeof(FlatscreenPatchAttribute))))
+ harmony.PatchAll(type);
+ }
SceneManager.sceneLoaded += (_, _) => Controllers.Setup();
SceneManager.sceneUnloaded += (_) =>