Created
July 25, 2026 23:17
-
-
Save GRAYgoose124/37cc74bd5931d7f725a67adbed60abd9 to your computer and use it in GitHub Desktop.
DoubleTime.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using FMOD; | |
| using FMOD.Studio; | |
| using HarmonyLib; | |
| using RiftOfTheNecroManager; | |
| using RhythmRift; | |
| using Shared.RhythmEngine; | |
| namespace ModMod; | |
| public static class DoubleTime | |
| { | |
| public const string Name = "DoubleTime"; | |
| public static double Multiplier = 2.0; | |
| private static bool _hadApplied; | |
| public static bool IsOn => Modifier.IsEnabled(Name); | |
| public static double EffectiveMultiplier() => IsOn ? Multiplier : 1.0; | |
| public static bool TryMapKey(int alphaDigit, out double multiplier) | |
| { | |
| if (alphaDigit == 0) | |
| { | |
| multiplier = 2.0; | |
| return true; | |
| } | |
| if (alphaDigit >= 1 && alphaDigit <= 9) | |
| { | |
| multiplier = 1.0 + alphaDigit * 0.1; | |
| return true; | |
| } | |
| multiplier = 1.0; | |
| return false; | |
| } | |
| public static bool TrySetFromKey(int alphaDigit) | |
| { | |
| if (!IsOn) | |
| return false; | |
| if (!TryMapKey(alphaDigit, out var m)) | |
| return false; | |
| Multiplier = m; | |
| return true; | |
| } | |
| public static void ApplyToStage(RRStageController stage) | |
| { | |
| if (stage == null) | |
| return; | |
| BeatmapPlayer player = stage.BeatmapPlayer; | |
| if (player == null) | |
| return; | |
| if (IsOn) | |
| { | |
| double rate = Multiplier; | |
| player._activeSpeedAdjustment = rate; | |
| if (stage._enemyController != null) | |
| stage._enemyController.SongSpeedMultiplier = (float)rate; | |
| _hadApplied = true; | |
| return; | |
| } | |
| if (_hadApplied && player._activeSpeedAdjustment >= 1.05) | |
| { | |
| player._activeSpeedAdjustment = 1.0; | |
| if (stage._enemyController != null) | |
| stage._enemyController.SongSpeedMultiplier = 1f; | |
| } | |
| _hadApplied = false; | |
| } | |
| public static void ApplyAudioPitch(BeatmapPlayer player) | |
| { | |
| if (player == null) | |
| return; | |
| EventInstance inst = player._musicInstance; | |
| if (!inst.isValid()) | |
| return; | |
| float pitch = IsOn ? (float)Multiplier : 1f; | |
| RESULT result = inst.setPitch(pitch); | |
| if (result != RESULT.OK) | |
| Log.Warning($"DoubleTime setPitch({pitch}) failed: {result}"); | |
| } | |
| [HarmonyPatch(typeof(RRStageController), nameof(RRStageController.BeginPlay))] | |
| [HarmonyPrefix] | |
| public static void BeginPlayPrefix(RRStageController __instance) | |
| { | |
| ApplyToStage(__instance); | |
| } | |
| [HarmonyPatch(typeof(RRStageController), nameof(RRStageController.ProcessPracticeModePayload))] | |
| [HarmonyPostfix] | |
| public static void PracticePayloadPostfix(RRStageController __instance) | |
| { | |
| ApplyToStage(__instance); | |
| } | |
| [HarmonyPatch(typeof(BeatmapPlayer), nameof(BeatmapPlayer.BeginPlay))] | |
| [HarmonyPostfix] | |
| public static void BeatmapBeginPlayPostfix(BeatmapPlayer __instance) | |
| { | |
| ApplyAudioPitch(__instance); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment