[+] Speed change

This commit is contained in:
Clansty 2024-09-28 17:35:59 +08:00
parent 27b8e6bd21
commit 3d79c939e9
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134

View File

@ -1,6 +1,11 @@
using AquaMai.Fix;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using AquaMai.Fix;
using AquaMai.Helpers;
using HarmonyLib;
using Manager;
using MelonLoader;
using Monitor;
using Process;
@ -13,6 +18,9 @@ public class PractiseMode
{
private static double repeatStart = -1;
private static double repeatEnd = -1;
private static float speed = 1;
private static List<CriAtomExPlayer> players = [];
private static MovieMaterialMai2 movie;
private static void SetRepeatEnd(double time)
{
@ -37,6 +45,45 @@ public class PractiseMode
repeatEnd = -1;
}
private static void SetSpeed()
{
foreach (var player in players)
{
player.SetPitch((float)(1200 * Math.Log(speed, 2)));
player.UpdateAll();
}
movie.player.SetSpeed(speed);
}
private static void SpeedUp()
{
speed += .05f;
if (speed > 2)
{
speed = 2;
}
SetSpeed();
}
private static void SpeedDown()
{
speed -= .05f;
if (speed < 0.5)
{
speed = 0.5f;
}
SetSpeed();
}
private static void SpeedReset()
{
speed = 1;
SetSpeed();
}
private class DebugWindow : MonoBehaviour
{
private GUIWindow window;
@ -52,6 +99,10 @@ public class PractiseMode
window.Button("循环开始", () => repeatStart = DebugFeature.CurrentPlayMsec);
window.Button("循环结束", () => SetRepeatEnd(DebugFeature.CurrentPlayMsec));
window.Button("循环解除", ClearRepeat);
window.SameLine(1, 1, 1);
window.Button("加速", SpeedUp);
window.Button("减速", SpeedDown);
window.Button("速度重置", SpeedReset);
}
private void OnGUI()
@ -62,6 +113,15 @@ public class PractiseMode
private static DebugWindow debugWin;
[HarmonyPatch(typeof(GameProcess), "OnStart")]
[HarmonyPostfix]
public static void GameProcessPostStart()
{
repeatStart = -1;
repeatEnd = -1;
speed = 1;
}
[HarmonyPatch(typeof(GameProcess), "OnUpdate")]
[HarmonyPostfix]
public static void GameProcessPostUpdate(GameProcess __instance, GameMonitor[] ____monitors)
@ -86,4 +146,40 @@ public class PractiseMode
}
}
}
[HarmonyPatch(typeof(NotesManager), "UpdateTimer")]
[HarmonyPostfix]
public static void NotesManagerPostUpdateTimer(bool ____isPlaying, Stopwatch ____stopwatch, ref float ____curMSec, ref float ____curMSecPre, float ____msecStartGap)
{
var num = 0d;
if (____isPlaying && ____stopwatch != null)
{
num = (double)____stopwatch.ElapsedTicks / Stopwatch.Frequency * 1000.0 * speed;
}
____curMSecPre = ____curMSec;
____curMSec = (float)num + ____msecStartGap;
}
[HarmonyPatch]
public static class PlayerObjCreate
{
public static MethodBase TargetMethod()
{
var type = typeof(SoundCtrl).GetNestedType("PlayerObj", BindingFlags.NonPublic);
return AccessTools.Method(type, "Create");
}
public static void Postfix(CriAtomExPlayer ___Player)
{
players.Add(___Player);
}
}
[HarmonyPatch(typeof(MovieController), "Awake")]
[HarmonyPostfix]
public static void MovieControllerPostAwake(MovieMaterialMai2 ____moviePlayers)
{
movie = ____moviePlayers;
}
}