[SwitchToDesktopOnSteamVRExit] Switched patch implementation because it did not work properly

This commit is contained in:
NotAKidoS 2024-04-23 16:53:00 -05:00
parent b42f72d082
commit e12da22513
2 changed files with 35 additions and 15 deletions

View file

@ -18,23 +18,41 @@ public class SwitchToDesktopOnSteamVRExit : MelonMod
public override void OnInitializeMelon() public override void OnInitializeMelon()
{ {
HarmonyInstance.Patch( ApplyPatches(typeof(SteamVRBehaviour_Patches));
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() private void ApplyPatches(Type type)
{ {
if (!EntryEnabled.Value) try
return true; {
HarmonyInstance.PatchAll(type);
// If we don't switch fast enough, SteamVR will force close. }
// World Transition might cause issues. Might need to override. catch (Exception e)
if (VRModeSwitchManager.Instance != null) {
VRModeSwitchManager.Instance.AttemptSwitch(); LoggerInstance.Msg($"Failed while patching {type.Name}!");
LoggerInstance.Error(e);
return false; }
} }
#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
} }

View file

@ -20,6 +20,8 @@ using System.Reflection;
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] [assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
[assembly: MelonColor(255, 52, 152, 219)]
[assembly: MelonAuthorColor(255, 158, 21, 32)]
[assembly: HarmonyDontPatchAll] [assembly: HarmonyDontPatchAll]
namespace NAK.SwitchToDesktopOnSteamVRExit.Properties; namespace NAK.SwitchToDesktopOnSteamVRExit.Properties;