diff --git a/SwitchToDesktopOnSteamVRExit/Main.cs b/SwitchToDesktopOnSteamVRExit/Main.cs index 7868071..6d6c19f 100644 --- a/SwitchToDesktopOnSteamVRExit/Main.cs +++ b/SwitchToDesktopOnSteamVRExit/Main.cs @@ -18,23 +18,41 @@ public class SwitchToDesktopOnSteamVRExit : MelonMod 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)) - ); + ApplyPatches(typeof(SteamVRBehaviour_Patches)); } - private static bool Prefix_SteamVR_Behaviour_OnQuit() + private void ApplyPatches(Type type) { - 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; + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } } + + #region Patches + + private static class SteamVRBehaviour_Patches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(SteamVR_Behaviour), /*nameof(SteamVR_Behaviour.OnQuit)*/ "OnQuit")] + 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; + } + } + + #endregion Patches } \ No newline at end of file diff --git a/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs b/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs index 774756d..17d0013 100644 --- a/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs +++ b/SwitchToDesktopOnSteamVRExit/Properties/AssemblyInfo.cs @@ -20,6 +20,8 @@ using System.Reflection; [assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] [assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: MelonColor(255, 52, 152, 219)] +[assembly: MelonAuthorColor(255, 158, 21, 32)] [assembly: HarmonyDontPatchAll] namespace NAK.SwitchToDesktopOnSteamVRExit.Properties;