2024-09-28 17:35:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using AquaMai.Fix;
|
2024-09-28 16:30:19 +08:00
|
|
|
|
using AquaMai.Helpers;
|
|
|
|
|
using HarmonyLib;
|
2024-09-28 17:35:59 +08:00
|
|
|
|
using Manager;
|
2024-09-28 16:30:19 +08:00
|
|
|
|
using Monitor;
|
|
|
|
|
using Process;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UrGUI.GUIWindow;
|
|
|
|
|
|
|
|
|
|
namespace AquaMai.Utils;
|
|
|
|
|
|
|
|
|
|
public class PractiseMode
|
|
|
|
|
{
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static double repeatStart = -1;
|
|
|
|
|
public static double repeatEnd = -1;
|
|
|
|
|
public static float speed = 1;
|
2024-09-28 19:42:42 +08:00
|
|
|
|
private static CriAtomExPlayer player;
|
2024-09-28 17:35:59 +08:00
|
|
|
|
private static MovieMaterialMai2 movie;
|
2024-09-28 16:30:19 +08:00
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static void SetRepeatEnd(double time)
|
2024-09-28 16:30:19 +08:00
|
|
|
|
{
|
|
|
|
|
if (repeatStart == -1)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowMessage("Please set repeat start time first");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (time < repeatStart)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowMessage("Repeat end time cannot be less than repeat start time");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repeatEnd = time;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static void ClearRepeat()
|
2024-09-28 16:30:19 +08:00
|
|
|
|
{
|
|
|
|
|
repeatStart = -1;
|
|
|
|
|
repeatEnd = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static void SetSpeed()
|
2024-09-28 17:35:59 +08:00
|
|
|
|
{
|
2024-09-28 19:42:42 +08:00
|
|
|
|
player.SetPitch((float)(1200 * Math.Log(speed, 2)));
|
|
|
|
|
// player.SetDspTimeStretchRatio(1 / speed);
|
|
|
|
|
player.UpdateAll();
|
2024-09-28 17:35:59 +08:00
|
|
|
|
|
|
|
|
|
movie.player.SetSpeed(speed);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static void SpeedUp()
|
2024-09-28 17:35:59 +08:00
|
|
|
|
{
|
|
|
|
|
speed += .05f;
|
|
|
|
|
if (speed > 2)
|
|
|
|
|
{
|
|
|
|
|
speed = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static void SpeedDown()
|
2024-09-28 17:35:59 +08:00
|
|
|
|
{
|
|
|
|
|
speed -= .05f;
|
|
|
|
|
if (speed < 0.5)
|
|
|
|
|
{
|
|
|
|
|
speed = 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static void SpeedReset()
|
2024-09-28 17:35:59 +08:00
|
|
|
|
{
|
|
|
|
|
speed = 1;
|
|
|
|
|
SetSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 16:30:19 +08:00
|
|
|
|
private class DebugWindow : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private GUIWindow window;
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
window = GUIWindow.Begin("练习模式 测试");
|
|
|
|
|
window.Button("暂停", () => DebugFeature.Pause = !DebugFeature.Pause);
|
|
|
|
|
window.SameLine();
|
|
|
|
|
window.Button("向前", () => DebugFeature.Seek(-1000));
|
|
|
|
|
window.Button("向后", () => DebugFeature.Seek(1000));
|
|
|
|
|
window.SameLine(1, 1, 1);
|
|
|
|
|
window.Button("循环开始", () => repeatStart = DebugFeature.CurrentPlayMsec);
|
|
|
|
|
window.Button("循环结束", () => SetRepeatEnd(DebugFeature.CurrentPlayMsec));
|
|
|
|
|
window.Button("循环解除", ClearRepeat);
|
2024-09-28 17:35:59 +08:00
|
|
|
|
window.SameLine(1, 1, 1);
|
|
|
|
|
window.Button("加速", SpeedUp);
|
|
|
|
|
window.Button("减速", SpeedDown);
|
|
|
|
|
window.Button("速度重置", SpeedReset);
|
2024-09-28 16:30:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGUI()
|
|
|
|
|
{
|
|
|
|
|
window?.Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
public static PractiseModeUI ui;
|
2024-09-28 16:30:19 +08:00
|
|
|
|
|
2024-09-28 17:35:59 +08:00
|
|
|
|
[HarmonyPatch(typeof(GameProcess), "OnStart")]
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void GameProcessPostStart()
|
|
|
|
|
{
|
|
|
|
|
repeatStart = -1;
|
|
|
|
|
repeatEnd = -1;
|
|
|
|
|
speed = 1;
|
2024-09-28 23:06:06 +08:00
|
|
|
|
ui = null;
|
2024-09-28 19:42:42 +08:00
|
|
|
|
SetSpeed();
|
2024-09-28 17:35:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 23:06:06 +08:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(GenericProcess), "OnUpdate")]
|
|
|
|
|
public static void OnGenericProcessUpdate(GenericMonitor[] ____monitors)
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.F12))
|
|
|
|
|
{
|
|
|
|
|
____monitors[0].gameObject.AddComponent<DebugWindow>();
|
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyDown(KeyCode.F11))
|
|
|
|
|
{
|
|
|
|
|
____monitors[0].gameObject.AddComponent<PractiseModeUI>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 16:30:19 +08:00
|
|
|
|
[HarmonyPatch(typeof(GameProcess), "OnUpdate")]
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void GameProcessPostUpdate(GameProcess __instance, GameMonitor[] ____monitors)
|
|
|
|
|
{
|
2024-09-28 23:06:06 +08:00
|
|
|
|
if (InputManager.GetSystemInputPush(InputManager.SystemButtonSetting.ButtonTest) && ui is null)
|
2024-09-28 16:30:19 +08:00
|
|
|
|
{
|
2024-09-28 23:06:06 +08:00
|
|
|
|
ui = ____monitors[0].gameObject.AddComponent<PractiseModeUI>();
|
2024-09-28 16:30:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (repeatStart >= 0 && repeatEnd >= 0)
|
|
|
|
|
{
|
|
|
|
|
if (DebugFeature.CurrentPlayMsec >= repeatEnd)
|
|
|
|
|
{
|
|
|
|
|
DebugFeature.CurrentPlayMsec = repeatStart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-28 17:35:59 +08:00
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 19:42:42 +08:00
|
|
|
|
[HarmonyPatch(typeof(SoundCtrl), "Initialize")]
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void SoundCtrlPostInitialize(SoundCtrl.InitParam param, Dictionary<int, object> ____players)
|
2024-09-28 17:35:59 +08:00
|
|
|
|
{
|
2024-09-28 19:42:42 +08:00
|
|
|
|
var wrapper = ____players[2];
|
|
|
|
|
player = (CriAtomExPlayer)wrapper.GetType().GetField("Player").GetValue(wrapper);
|
|
|
|
|
// var pool = new CriAtomExStandardVoicePool(1, 8, 96000, true, 2);
|
|
|
|
|
// pool.AttachDspTimeStretch();
|
|
|
|
|
// player.SetVoicePoolIdentifier(pool.identifier);
|
|
|
|
|
|
|
|
|
|
// debug
|
|
|
|
|
// var wrapper1 = ____players[7];
|
|
|
|
|
// var player1 = (CriAtomExPlayer)wrapper1.GetType().GetField("Player").GetValue(wrapper1);
|
|
|
|
|
// var pool = new CriAtomExStandardVoicePool(1, 8, 96000, true, 2);
|
|
|
|
|
// pool.AttachDspTimeStretch();
|
|
|
|
|
// player1.SetVoicePoolIdentifier(pool.identifier);
|
|
|
|
|
// player1.SetDspTimeStretchRatio(2);
|
2024-09-28 17:35:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(MovieController), "Awake")]
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void MovieControllerPostAwake(MovieMaterialMai2 ____moviePlayers)
|
|
|
|
|
{
|
|
|
|
|
movie = ____moviePlayers;
|
|
|
|
|
}
|
2024-09-28 16:30:19 +08:00
|
|
|
|
}
|