mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
backport from experimental
This commit is contained in:
parent
8a3523539b
commit
5fd8e3d4d6
14 changed files with 686 additions and 560 deletions
|
@ -1,59 +1,36 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using MelonLoader;
|
||||
using MelonLoader;
|
||||
|
||||
//tell the game to change VRMode/DesktopMode for Steam/Discord presence
|
||||
//RichPresence.PopulatePresence();
|
||||
namespace NAK.Melons.DesktopVRSwitch;
|
||||
|
||||
//nvm that resets the RichPresence clock- i want people to know how long ive wasted staring at mirror
|
||||
|
||||
namespace DesktopVRSwitch;
|
||||
|
||||
public class DesktopVRSwitch : MelonMod
|
||||
public class DesktopVRSwitchMod : MelonMod
|
||||
{
|
||||
internal const string SettingsCategory = "DesktopVRSwitch";
|
||||
internal static MelonPreferences_Category m_categoryDesktopVRSwitch;
|
||||
internal static MelonPreferences_Entry<bool> m_entryTimedErrorCatch;
|
||||
internal static MelonPreferences_Entry<float> m_entryTimedErrorTimer;
|
||||
internal static MelonLogger.Instance Logger;
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
Logger = LoggerInstance;
|
||||
m_categoryDesktopVRSwitch = MelonPreferences.CreateCategory(SettingsCategory);
|
||||
m_entryTimedErrorCatch = m_categoryDesktopVRSwitch.CreateEntry<bool>("Timed Error Catch", true, description: "Attempt to switch back if an error is found after n seconds.");
|
||||
m_entryTimedErrorTimer = m_categoryDesktopVRSwitch.CreateEntry<float>("Timed Error Timer", 10f, description: "Amount of seconds to wait before assuming there was an error.");
|
||||
|
||||
m_categoryDesktopVRSwitch.SaveToFile(false);
|
||||
foreach (var setting in m_categoryDesktopVRSwitch.Entries)
|
||||
{
|
||||
setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
|
||||
}
|
||||
|
||||
//UIExpansionKit addon
|
||||
if (MelonMod.RegisteredMelons.Any(it => it.Info.Name == "UI Expansion Kit"))
|
||||
{
|
||||
MelonLogger.Msg("Initializing UIExpansionKit support.");
|
||||
UiExtensionsAddon.Init();
|
||||
}
|
||||
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
||||
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
|
||||
ApplyPatches(typeof(HarmonyPatches.CVRPickupObjectPatches));
|
||||
ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches));
|
||||
ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches));
|
||||
ApplyPatches(typeof(HarmonyPatches.IKSystemPatches));
|
||||
ApplyPatches(typeof(HarmonyPatches.MovementSystemPatches));
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator WaitForLocalPlayer()
|
||||
private void ApplyPatches(Type type)
|
||||
{
|
||||
while (PlayerSetup.Instance == null)
|
||||
yield return null;
|
||||
|
||||
PlayerSetup.Instance.gameObject.AddComponent<DesktopVRSwitchHelper>();
|
||||
|
||||
while (DesktopVRSwitchHelper.Instance == null)
|
||||
yield return null;
|
||||
|
||||
UpdateAllSettings();
|
||||
}
|
||||
|
||||
private void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();
|
||||
private void UpdateAllSettings()
|
||||
{
|
||||
if (!DesktopVRSwitchHelper.Instance) return;
|
||||
DesktopVRSwitchHelper.Instance.SettingTimedErrorCatch = m_entryTimedErrorCatch.Value;
|
||||
DesktopVRSwitchHelper.Instance.SettingTimedErrorTimer = m_entryTimedErrorTimer.Value;
|
||||
try
|
||||
{
|
||||
HarmonyInstance.PatchAll(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Msg($"Failed while patching {type.Name}!");
|
||||
Logger.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue