mirror of https://github.com/hykilpikonna/AquaDX
[O] better polyfill load
parent
74e39c437d
commit
24ecaab570
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MAI2.Util;
|
using MAI2.Util;
|
||||||
|
@ -11,70 +10,76 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace AquaMai.Fix;
|
namespace AquaMai.Fix;
|
||||||
|
|
||||||
[HarmonyPatch]
|
|
||||||
public class DebugFeature
|
public class DebugFeature
|
||||||
{
|
{
|
||||||
public static bool IsPatchingSkipped { get; private set; }
|
public static bool IsPolyfill { get; private set; }
|
||||||
private static bool isPause;
|
private static GameProcess _gameProcess;
|
||||||
private static double timer;
|
private static MovieController _gameMovie;
|
||||||
|
private static GameMonitor[] _monitors;
|
||||||
|
private static object _debugFeatureOriginal;
|
||||||
|
|
||||||
public static IEnumerable<MethodBase> TargetMethods()
|
[HarmonyPatch(typeof(GameProcess), "OnStart")]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Init(GameProcess __instance, MovieController ____gameMovie, GameMonitor[] ____monitors)
|
||||||
{
|
{
|
||||||
var original = typeof(GameProcess).GetField("debugFeature", BindingFlags.NonPublic | BindingFlags.Instance);
|
_gameProcess = __instance;
|
||||||
if (original is not null)
|
_gameMovie = ____gameMovie;
|
||||||
{
|
_monitors = ____monitors;
|
||||||
MelonLogger.Msg("[DebugFeature] Skipped because already included");
|
|
||||||
IsPatchingSkipped = true;
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [AccessTools.Method(typeof(GameProcess), "OnUpdate")];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Postfix(GameProcess __instance, byte ____sequence, MovieController ____gameMovie, GameMonitor[] ____monitors)
|
public static void DoCustomPatch(HarmonyLib.Harmony h)
|
||||||
{
|
{
|
||||||
if (____sequence != 4) return;
|
var original = typeof(GameProcess).GetField("debugFeature", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
// GameSequence.Play
|
if (original is null)
|
||||||
if (!isPause)
|
|
||||||
{
|
{
|
||||||
timer += GameManager.GetGameMSecAddD();
|
MelonLogger.Msg(" > [DebugFeature] Running Polyfill");
|
||||||
|
IsPolyfill = true;
|
||||||
|
h.PatchAll(typeof(PolyFill));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MelonLogger.Msg(" > [DebugFeature] Already included");
|
||||||
|
h.PatchAll(typeof(GetOriginal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetPause(bool pause)
|
||||||
|
{
|
||||||
|
if (IsPolyfill)
|
||||||
|
{
|
||||||
|
PolyFill.isPause = pause;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var debugFeatureClass = typeof(GameProcess).GetNestedType("DebugFeature", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
debugFeatureClass?.GetField("_debugPause", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(_debugFeatureOriginal, pause);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.Home))
|
SoundManager.PauseMusic(pause);
|
||||||
|
_gameMovie.Pause(pause);
|
||||||
|
NotesManager.Pause(pause);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
private static class GetOriginal
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(GameProcess), "OnStart")]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Postfix(object ___debugFeature)
|
||||||
{
|
{
|
||||||
GameManager.AutoPlay = (GameManager.AutoPlayMode)((int)(GameManager.AutoPlay + 1) % Enum.GetNames(typeof(GameManager.AutoPlayMode)).Length);
|
_debugFeatureOriginal = ___debugFeature;
|
||||||
}
|
}
|
||||||
else if (Input.GetKeyDown(KeyCode.Return))
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
private static class PolyFill
|
||||||
|
{
|
||||||
|
public static bool isPause;
|
||||||
|
public static double timer;
|
||||||
|
|
||||||
|
public static void DebugTimeSkip(int addMsec)
|
||||||
{
|
{
|
||||||
isPause = !isPause;
|
_gameMovie.Pause(pauseFlag: true);
|
||||||
SoundManager.PauseMusic(isPause);
|
|
||||||
____gameMovie.Pause(isPause);
|
|
||||||
NotesManager.Pause(isPause);
|
|
||||||
}
|
|
||||||
else if (DebugInput.GetKeyDown(KeyCode.LeftArrow) || DebugInput.GetKeyDown(KeyCode.RightArrow))
|
|
||||||
{
|
|
||||||
var num23 = 0;
|
|
||||||
if (DebugInput.GetKeyDown(KeyCode.LeftArrow))
|
|
||||||
{
|
|
||||||
num23 = -1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DebugInput.GetKeyDown(KeyCode.RightArrow))
|
|
||||||
{
|
|
||||||
num23 = 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
int addMsec = ((!DebugInput.GetKey(KeyCode.LeftShift) && !DebugInput.GetKey(KeyCode.RightShift)) ? ((!DebugInput.GetKey(KeyCode.LeftControl) && !DebugInput.GetKey(KeyCode.RightControl)) ? num23 : (num23 * 10)) : (num23 * 5));
|
|
||||||
Singleton<GamePlayManager>.Instance.Initialize();
|
|
||||||
DebugTimeSkip(addMsec);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
void DebugTimeSkip(int addMsec)
|
|
||||||
{
|
|
||||||
____gameMovie.Pause(pauseFlag: true);
|
|
||||||
NotesManager.Pause(true);
|
NotesManager.Pause(true);
|
||||||
if (addMsec >= 0)
|
if (addMsec >= 0)
|
||||||
{
|
{
|
||||||
|
@ -85,11 +90,11 @@ public class DebugFeature
|
||||||
timer = timer + addMsec >= 0.0 ? timer + addMsec : 0.0;
|
timer = timer + addMsec >= 0.0 ? timer + addMsec : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
____gameMovie.SetSeekFrame(timer);
|
_gameMovie.SetSeekFrame(timer);
|
||||||
SoundManager.SeekMusic((int)timer);
|
SoundManager.SeekMusic((int)timer);
|
||||||
for (int i = 0; i < ____monitors.Length; i++)
|
for (int i = 0; i < _monitors.Length; i++)
|
||||||
{
|
{
|
||||||
____monitors[i].Seek((int)timer);
|
_monitors[i].Seek((int)timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// magic number, dont know why
|
// magic number, dont know why
|
||||||
|
@ -98,14 +103,55 @@ public class DebugFeature
|
||||||
if (!isPause)
|
if (!isPause)
|
||||||
{
|
{
|
||||||
SoundManager.PauseMusic(pause: false);
|
SoundManager.PauseMusic(pause: false);
|
||||||
____gameMovie.Pause(pauseFlag: false);
|
_gameMovie.Pause(pauseFlag: false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
____gameMovie.Pause(pauseFlag: true);
|
_gameMovie.Pause(pauseFlag: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
__instance.UpdateNotes();
|
_gameProcess.UpdateNotes();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(GameProcess), "OnUpdate")]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Postfix(byte ____sequence)
|
||||||
|
{
|
||||||
|
if (____sequence != 4) return;
|
||||||
|
// GameSequence.Play
|
||||||
|
if (!isPause)
|
||||||
|
{
|
||||||
|
timer += GameManager.GetGameMSecAddD();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.Home))
|
||||||
|
{
|
||||||
|
GameManager.AutoPlay = (GameManager.AutoPlayMode)((int)(GameManager.AutoPlay + 1) % Enum.GetNames(typeof(GameManager.AutoPlayMode)).Length);
|
||||||
|
}
|
||||||
|
else if (Input.GetKeyDown(KeyCode.Return))
|
||||||
|
{
|
||||||
|
isPause = !isPause;
|
||||||
|
SoundManager.PauseMusic(isPause);
|
||||||
|
_gameMovie.Pause(isPause);
|
||||||
|
NotesManager.Pause(isPause);
|
||||||
|
}
|
||||||
|
else if (DebugInput.GetKeyDown(KeyCode.LeftArrow) || DebugInput.GetKeyDown(KeyCode.RightArrow))
|
||||||
|
{
|
||||||
|
var num23 = 0;
|
||||||
|
if (DebugInput.GetKeyDown(KeyCode.LeftArrow))
|
||||||
|
{
|
||||||
|
num23 = -1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DebugInput.GetKeyDown(KeyCode.RightArrow))
|
||||||
|
{
|
||||||
|
num23 = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addMsec = ((!DebugInput.GetKey(KeyCode.LeftShift) && !DebugInput.GetKey(KeyCode.RightShift)) ? ((!DebugInput.GetKey(KeyCode.LeftControl) && !DebugInput.GetKey(KeyCode.RightControl)) ? num23 : (num23 * 10)) : (num23 * 5));
|
||||||
|
Singleton<GamePlayManager>.Instance.Initialize();
|
||||||
|
DebugTimeSkip(addMsec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using AquaMai.Fix;
|
using AquaMai.Fix;
|
||||||
using AquaMai.Helpers;
|
using AquaMai.Helpers;
|
||||||
|
@ -35,6 +36,9 @@ namespace AquaMai
|
||||||
{
|
{
|
||||||
Patch(nested);
|
Patch(nested);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var customMethod = type.GetMethod("DoCustomPatch", BindingFlags.Public | BindingFlags.Static);
|
||||||
|
customMethod?.Invoke(null, [HarmonyInstance]);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue