diff --git a/NAK_CVR_Mods.sln b/NAK_CVR_Mods.sln index c11c1f5..0e7f92a 100644 --- a/NAK_CVR_Mods.sln +++ b/NAK_CVR_Mods.sln @@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShadowCloneFallback", "Shad EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StopClosingMyMenuOnWorldLoad", "StopClosingMyMenuOnWorldLoad\StopClosingMyMenuOnWorldLoad.csproj", "{9FA83514-13F8-412C-9790-C2B750E0E7E7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwitchToDesktopOnSteamVRExit", "SwitchToDesktopOnSteamVRExit\SwitchToDesktopOnSteamVRExit.csproj", "{F7F4B840-6FF5-46C4-AAFD-95362D1D666C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -129,6 +131,10 @@ Global {9FA83514-13F8-412C-9790-C2B750E0E7E7}.Debug|Any CPU.Build.0 = Debug|Any CPU {9FA83514-13F8-412C-9790-C2B750E0E7E7}.Release|Any CPU.ActiveCfg = Release|Any CPU {9FA83514-13F8-412C-9790-C2B750E0E7E7}.Release|Any CPU.Build.0 = Release|Any CPU + {F7F4B840-6FF5-46C4-AAFD-95362D1D666C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7F4B840-6FF5-46C4-AAFD-95362D1D666C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7F4B840-6FF5-46C4-AAFD-95362D1D666C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7F4B840-6FF5-46C4-AAFD-95362D1D666C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SwitchToDesktopOnSteamVRExit/Main.cs b/SwitchToDesktopOnSteamVRExit/Main.cs new file mode 100644 index 0000000..7868071 --- /dev/null +++ b/SwitchToDesktopOnSteamVRExit/Main.cs @@ -0,0 +1,40 @@ +using System.Reflection; +using ABI_RC.Systems.VRModeSwitch; +using HarmonyLib; +using MelonLoader; +using Valve.VR; + +namespace NAK.SwitchToDesktopOnSteamVRExit; + +public class SwitchToDesktopOnSteamVRExit : MelonMod +{ + private const string SettingsCategory = nameof(SwitchToDesktopOnSteamVRExit); + + private static readonly MelonPreferences_Category Category = + MelonPreferences.CreateCategory(SettingsCategory); + + private static readonly MelonPreferences_Entry EntryEnabled = + Category.CreateEntry("Enabled", true, description: "Toggle SwitchToDesktopOnSteamVRExit entirely."); + + public override void OnInitializeMelon() + { + HarmonyInstance.Patch( + typeof(SteamVR_Behaviour).GetMethod("OnQuit"), + new HarmonyMethod(typeof(SwitchToDesktopOnSteamVRExit).GetMethod(nameof(Prefix_SteamVR_Behaviour_OnQuit), + BindingFlags.NonPublic | BindingFlags.Static)) + ); + } + + private static bool Prefix_SteamVR_Behaviour_OnQuit() + { + if (!EntryEnabled.Value) + return true; + + // If we don't switch fast enough, SteamVR will force close. + // World Transition might cause issues. Might need to override. + if (VRModeSwitchManager.Instance != null) + VRModeSwitchManager.Instance.AttemptSwitch(); + + return false; + } +} \ No newline at end of file diff --git a/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs b/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..774756d --- /dev/null +++ b/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using NAK.SwitchToDesktopOnSteamVRExit.Properties; +using MelonLoader; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.SwitchToDesktopOnSteamVRExit))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.SwitchToDesktopOnSteamVRExit))] + +[assembly: MelonInfo( + typeof(NAK.SwitchToDesktopOnSteamVRExit.SwitchToDesktopOnSteamVRExit), + nameof(NAK.SwitchToDesktopOnSteamVRExit), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/SwitchToDesktopOnSteamVRExit" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.SwitchToDesktopOnSteamVRExit.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.0"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/SwitchToDesktopOnSteamVRExit/README.md b/SwitchToDesktopOnSteamVRExit/README.md new file mode 100644 index 0000000..f3dfb86 --- /dev/null +++ b/SwitchToDesktopOnSteamVRExit/README.md @@ -0,0 +1,17 @@ +# SwitchToDesktopOnSteamVRExit + +Simple mod that initiates a VR Switch to Desktop when SteamVR is exited. By default, this is enabled, but can be disabled in the mod settings. + +Same behaviour the original DesktopVRSwitch mod provided before the VR Switch functionality became native. + +--- + +Here is the block of text where I tell you this mod is not affiliated with or endorsed by ABI. +https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games + +> This mod is an independent creation not affiliated with, supported by, or approved by Alpha Blend Interactive. + +> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use. + +> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive. +**** \ No newline at end of file diff --git a/SwitchToDesktopOnSteamVRExit/SwitchToDesktopOnSteamVRExit.csproj b/SwitchToDesktopOnSteamVRExit/SwitchToDesktopOnSteamVRExit.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/SwitchToDesktopOnSteamVRExit/SwitchToDesktopOnSteamVRExit.csproj @@ -0,0 +1,2 @@ + + diff --git a/SwitchToDesktopOnSteamVRExit/format.json b/SwitchToDesktopOnSteamVRExit/format.json new file mode 100644 index 0000000..f535ff8 --- /dev/null +++ b/SwitchToDesktopOnSteamVRExit/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "SwitchToDesktopOnSteamVRExit", + "modversion": "1.0.0", + "gameversion": "2024r175", + "loaderversion": "0.6.1", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Simple mod that initiates a VR Switch to Desktop when SteamVR is exited. By default, this is enabled, but can be disabled in the mod settings.", + "searchtags": [ + "steamvr", + "vrswitch", + "desktopvrswitch", + "exit" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r26/SwitchToDesktopOnSteamVRExit.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/SwitchToDesktopOnSteamVRExit/", + "changelog": "- Initial Release", + "embedcolor": "#3498db" +} \ No newline at end of file