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 (!RenderManager.IsCapturingActive || !RenderPatch || !RenderManager.Instance) return true; __result = (float)(RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + 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 || !RenderPatch || !RenderManager.Instance) return true; __result = RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + 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 || !RenderPatch || !RenderManager.Instance) return true; __result = (float)(RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + 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 || !RenderPatch || !RenderManager.Instance) return true; __result = RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + 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 || !RenderPatch || !RenderManager.Instance) return true; __result = RenderManager.Instance.frameCount / RenderManager.Instance.Configuration.TargetFPS + 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 || !RenderPatch; } } [HarmonyPatch(typeof(Time), "frameCount", MethodType.Getter)] public static class FrameCountPatch { [SuppressMessage("ReSharper", "InconsistentNaming")] public static bool Prefix(ref int __result) { if (!RenderManager.IsCapturingActive || !RenderPatch || !RenderManager.Instance) 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.Instance && (!RenderManager.IsCapturingActive || !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 (!RenderManager.IsCapturingActive || !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 (!RenderManager.IsActive || !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 (!RenderManager.IsActive || !RenderPatch || !RenderManager.Instance) return true; __result = RenderManager.Instance.Configuration.RenderHeight; return false; } } } }