Files
ADOFAIRenderer/Patch/RenderEnvironmentPatches.cs
T

143 lines
5.8 KiB
C#

using System.Diagnostics.CodeAnalysis;
using ADOFAIRenderer.Component;
using HarmonyLib;
using UnityEngine;
namespace ADOFAIRenderer.Patch
{
public static class RenderEnvironmentPatches
{
private const bool RenderPatch = true;
[HarmonyPatch(typeof(Time), "time", MethodType.Getter)]
public static class TimePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref float __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = (float)(RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + RenderMod.TimeBase);
return false;
}
}
[HarmonyPatch(typeof(Time), "timeAsDouble", MethodType.Getter)]
public static class TimeAsDoublePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref double __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + RenderMod.TimeBase;
return false;
}
}
[HarmonyPatch(typeof(Time), "unscaledTime", MethodType.Getter)]
public static class UnscaledTimePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref float __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = (float)(RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + RenderMod.UnscaledTimeBase);
return false;
}
}
[HarmonyPatch(typeof(Time), "unscaledTimeAsDouble", MethodType.Getter)]
public static class UnscaledTimeAsDoublePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref double __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + RenderMod.UnscaledTimeBase;
return false;
}
}
[HarmonyPatch(typeof(AudioSettings), "dspTime", MethodType.Getter)]
public static class DspTimePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref double __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + RenderMod.DspTimeBase;
return false;
}
}
[HarmonyPatch(typeof(AudioSource), "PlayScheduled")]
public static class PlayScheduledPatch
{
// ReSharper disable once InconsistentNaming
public static bool Prefix(AudioSource __instance, double time)
{
return !RenderMod.IsRendering || !RenderPatch;
}
}
[HarmonyPatch(typeof(Time), "frameCount", MethodType.Getter)]
public static class FrameCountPatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref int __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = (int)(RenderManager.Instance.frameCount + RenderMod.FrameCountBase);
return false;
}
}
[HarmonyPatch(typeof(Time), "deltaTime", MethodType.Getter)]
public static class DeltaTimePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref float __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = (float)(1 / RenderManager.Instance.Configuration.TargetFPS);
return false;
}
}
[HarmonyPatch(typeof(Time), "unscaledDeltaTime", MethodType.Getter)]
public static class UnscaledDeltaTimePatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref float __result)
{
if (!RenderMod.IsCapturing || !RenderPatch || !RenderManager.Instance) return true;
__result = (float)(1 / RenderManager.Instance.Configuration.TargetFPS);
return false;
}
}
[HarmonyPatch(typeof(Screen), "width", MethodType.Getter)]
public static class ScreenWidthPatch
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static bool Prefix(ref int __result)
{
if (!RenderMod.IsRendering || !RenderPatch || !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 (!RenderMod.IsRendering || !RenderPatch || !RenderManager.Instance) return true;
__result = RenderManager.Instance.Configuration.RenderHeight;
return false;
}
}
}
}