public override void OnApplicationStart()
        {
            if (instance != null)
            {
                MelonLogger.LogError("There's already an instance of Double-Tap Runner. Remove the duplicate dll files");
                MelonLogger.LogError("Not Guaranteed to work with multiple instances at all");
                return;
            }

            instance = this;

            // Default settings
            activeSettings = new Settings
            {
                Enabled            = true,
                SpeedMultiplier    = 2f,
                DoubleClickTime    = .5f,
                Forward            = KeyCode.W,
                Backward           = KeyCode.S,
                Left               = KeyCode.A,
                Right              = KeyCode.D,
                AxisDeadZone       = .1f,
                AxisClickThreshold = .6f
            };

            MelonPrefs.RegisterCategory(SettingsCategory, "Double-Tap Runner");
            MelonPrefs.RegisterBool(SettingsCategory, nameof(Settings.Enabled), activeSettings.Enabled, "Enabled");
            MelonPrefs.RegisterFloat(SettingsCategory, nameof(Settings.SpeedMultiplier), activeSettings.SpeedMultiplier, "Speed Multiplier");
            MelonPrefs.RegisterFloat(SettingsCategory, nameof(Settings.DoubleClickTime), activeSettings.DoubleClickTime, "Double Click Time");

            MelonPrefs.RegisterString(SettingsCategory, nameof(Settings.Forward), Enum.GetName(typeof(KeyCode), activeSettings.Forward), "Desktop Forward");
            MelonPrefs.RegisterString(SettingsCategory, nameof(Settings.Backward), Enum.GetName(typeof(KeyCode), activeSettings.Backward), "Desktop Backward");
            MelonPrefs.RegisterString(SettingsCategory, nameof(Settings.Left), Enum.GetName(typeof(KeyCode), activeSettings.Left), "Desktop Left");
            MelonPrefs.RegisterString(SettingsCategory, nameof(Settings.Right), Enum.GetName(typeof(KeyCode), activeSettings.Right), "Desktop Right");

            MelonPrefs.RegisterFloat(SettingsCategory, nameof(Settings.AxisDeadZone), activeSettings.AxisDeadZone, "Axis Dead Zone");
            MelonPrefs.RegisterFloat(SettingsCategory, nameof(Settings.AxisClickThreshold), activeSettings.AxisClickThreshold, "Axis Click Threshold");
            ApplySettings();

            try
            {
                // way more mod friendly but might mean more updates... oh well, not really hard to find. "Fade to" and check params
                MethodInfo fadeToMethod = typeof(VRCUiManager).GetMethod(
                    nameof(VRCUiManager.Method_Public_Void_String_Single_Action_0),
                    BindingFlags.Public | BindingFlags.Instance);
                harmonyInstance.Patch(
                    fadeToMethod,
                    null,
                    new HarmonyMethod(typeof(DoubleTapper).GetMethod(nameof(JoinedRoomPatch), BindingFlags.NonPublic | BindingFlags.Static)));
            }
            catch (Exception e)
            {
                modLoadedCorrectly = false;
                MelonLogger.LogError("Failed to patch into FadeTo: " + e);
            }

            try
            {
                MethodInfo leaveRoomMethod = typeof(NetworkManager).GetMethod(nameof(NetworkManager.OnLeftRoom), BindingFlags.Public | BindingFlags.Instance);
                harmonyInstance.Patch(
                    leaveRoomMethod,
                    new HarmonyMethod(typeof(DoubleTapper).GetMethod(nameof(LeftRoomPrefix), BindingFlags.NonPublic | BindingFlags.Static)));
            }
            catch (Exception e)
            {
                modLoadedCorrectly = false;
                MelonLogger.LogError("Failed to patch into OnLeftRoom: " + e);
            }

            if (!modLoadedCorrectly)
            {
                MelonLogger.LogError("Didn't load in correctly, not guaranteed to fully work so i'll shutdown this mod");
            }
        }
Пример #2
0
        public override void OnApplicationStart()
        {
            if (instance != null)
            {
                MelonLogger.Error("There's already an instance of Double-Tap Runner. Remove the duplicate dll files");
                MelonLogger.Error("Not Guaranteed to work with multiple instances at all");
                return;
            }

            instance = this;

            // Default settings
            activeSettings = new Settings
            {
                Enabled            = true,
                SpeedMultiplier    = 2f,
                DoubleClickTime    = .5f,
                Forward            = KeyCode.W,
                Backward           = KeyCode.S,
                Left               = KeyCode.A,
                Right              = KeyCode.D,
                AxisDeadZone       = .1f,
                AxisClickThreshold = .6f
            };

            settingsCategory = MelonPreferences.CreateCategory("DoubleTapRunner", "Double-Tap Runner");
            settingsCategory.CreateEntry(nameof(Settings.Enabled), activeSettings.Enabled, "Enabled");
            settingsCategory.CreateEntry(nameof(Settings.SpeedMultiplier), activeSettings.SpeedMultiplier, "Speed Multiplier");
            settingsCategory.CreateEntry(nameof(Settings.DoubleClickTime), activeSettings.DoubleClickTime, "Double Click Time");

            settingsCategory.CreateEntry(nameof(Settings.Forward), Enum.GetName(typeof(KeyCode), activeSettings.Forward), "Desktop Forward");
            settingsCategory.CreateEntry(

                nameof(Settings.Backward),
                Enum.GetName(typeof(KeyCode), activeSettings.Backward),
                "Desktop Backward");
            settingsCategory.CreateEntry(nameof(Settings.Left), Enum.GetName(typeof(KeyCode), activeSettings.Left), "Desktop Left");
            settingsCategory.CreateEntry(nameof(Settings.Right), Enum.GetName(typeof(KeyCode), activeSettings.Right), "Desktop Right");

            settingsCategory.CreateEntry(nameof(Settings.AxisDeadZone), activeSettings.AxisDeadZone, "Axis Dead Zone");
            settingsCategory.CreateEntry(nameof(Settings.AxisClickThreshold), activeSettings.AxisClickThreshold, "Axis Click Threshold");
            ApplySettings();

            VRChatUtilityKit.Utilities.VRCUtils.OnEmmWorldCheckCompleted += allowed => worldAllowed = allowed;

            try
            {
                MethodInfo leaveRoomMethod = typeof(NetworkManager).GetMethod(nameof(NetworkManager.OnLeftRoom), BindingFlags.Public | BindingFlags.Instance);
                HarmonyInstance.Patch(
                    leaveRoomMethod,
                    new HarmonyMethod(typeof(DoubleTapper).GetMethod(nameof(LeftRoomPrefix), BindingFlags.NonPublic | BindingFlags.Static)));
            }
            catch (Exception e)
            {
                modLoadedCorrectly = false;
                MelonLogger.Error("Failed to patch into OnLeftRoom: " + e);
            }

            if (!modLoadedCorrectly)
            {
                MelonLogger.Error("Didn't load in correctly, not guaranteed to fully work so i'll shutdown this mod");
            }
        }