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) return true; __result = (float)(RenderManager.FrameCount / RenderManager.Configuration.TargetFPS); 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) return true; __result = RenderManager.FrameCount / RenderManager.Configuration.TargetFPS; 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) return true; __result = (float)(RenderManager.FrameCount / RenderManager.Configuration.TargetFPS); 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) return true; __result = RenderManager.FrameCount / RenderManager.Configuration.TargetFPS; 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) return true; __result = RenderManager.FrameCount / RenderManager.Configuration.TargetFPS; 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) return true; __result = RenderManager.FrameCount; 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) return true; __result = (float)(1 / RenderManager.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) return true; __result = (float)(1 / RenderManager.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) return true; __result = RenderManager.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) return true; __result = RenderManager.Configuration.RenderHeight; return false; } } } }