SHA256
165 lines
6.2 KiB
C#
165 lines
6.2 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using ADOFAIRenderer.Core;
|
|
using ADOFAIRenderer.Util.Audio;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace ADOFAIRenderer.Patch.Engine;
|
|
|
|
public static class RenderEnvironmentPatches
|
|
{
|
|
private static double TimeSpent => RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.RenderFPS;
|
|
|
|
[HarmonyPatch(typeof(Time), "time", MethodType.Getter)]
|
|
public static class TimePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref float __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = (float)(TimeSpent + RenderManager.Instance.timeBase);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Time), "timeAsDouble", MethodType.Getter)]
|
|
public static class TimeAsDoublePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref double __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = TimeSpent + RenderManager.Instance.timeBase;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Time), "unscaledTime", MethodType.Getter)]
|
|
public static class UnscaledTimePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref float __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = (float)(TimeSpent + RenderManager.Instance.unscaledTimeBase);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Time), "unscaledTimeAsDouble", MethodType.Getter)]
|
|
public static class UnscaledTimeAsDoublePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref double __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = TimeSpent + RenderManager.Instance.unscaledTimeBase;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(AudioSettings), "dspTime", MethodType.Getter)]
|
|
public static class DspTimePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref double __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = TimeSpent + RenderManager.Instance.dspTimeBase;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(AudioSource), "PlayScheduled")]
|
|
public static class PlayScheduledPatch
|
|
{
|
|
// ReSharper disable once InconsistentNaming
|
|
public static bool Prefix(AudioSource __instance, double time)
|
|
{
|
|
return !RenderManager.IsActive;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Time), "frameCount", MethodType.Getter)]
|
|
public static class FrameCountPatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref int __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = (int)(RenderManager.Instance.frameCount + RenderManager.Instance.frameCountBase);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Time), "deltaTime", MethodType.Getter)]
|
|
public static class DeltaTimePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref float __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = (float)(1 / RenderManager.Instance.Configuration.RenderFPS);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Time), "unscaledDeltaTime", MethodType.Getter)]
|
|
public static class UnscaledDeltaTimePatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref float __result)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderContext.TimePatch) return true;
|
|
__result = (float)(1 / RenderManager.Instance.Configuration.RenderFPS);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Screen), "width", MethodType.Getter)]
|
|
public static class ScreenWidthPatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref int __result)
|
|
{
|
|
if (!RenderManager.IsActive || !RenderContext.ScreenPatch || !RenderManager.Instance) return true;
|
|
__result = RenderManager.Instance.Configuration.RenderWidth;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Screen), "height", MethodType.Getter)]
|
|
public static class ScreenHeightPatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(ref int __result)
|
|
{
|
|
if (!RenderManager.IsActive || !RenderContext.ScreenPatch || !RenderManager.Instance) return true;
|
|
__result = RenderManager.Instance.Configuration.RenderHeight;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(AudioSource), "GetSpectrumData", typeof(float[]), typeof(int), typeof(FFTWindow))]
|
|
public static class GetSpectrumDataPatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool Prefix(AudioSource __instance, float[] samples, int channel, FFTWindow window)
|
|
{
|
|
if (!RenderManager.IsCapturingActive || !RenderManager.Instance.Configuration.AdvancedConfig.ProcessAudio) return true;
|
|
AudioSpectrumGenerator.GetSpectrumData(samples, channel, window);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(AudioManager), "FindOrLoadAudioClipExternal", typeof(string), typeof(bool), typeof(float), typeof(bool))]
|
|
public static class FindOrLoadAudioClipExternalPatch
|
|
{
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static void Prefix(ref bool stream)
|
|
{
|
|
if (RenderManager.Instance && RenderManager.Instance.stage >= RenderStage.Load && RenderManager.Instance.Configuration.AdvancedConfig.ProcessAudio)
|
|
stream = false;
|
|
}
|
|
}
|
|
} |