diff --git a/Patch/Game/scnGamePatch.cs b/Patch/Game/scnGamePatch.cs index 5d10a4a..a97ffb2 100644 --- a/Patch/Game/scnGamePatch.cs +++ b/Patch/Game/scnGamePatch.cs @@ -2,6 +2,7 @@ using System.IO; using ADOFAIRenderer.Core; using ADOFAIRenderer.Util; using HarmonyLib; +using UnityEngine; namespace ADOFAIRenderer.Patch.Game { @@ -11,6 +12,7 @@ namespace ADOFAIRenderer.Patch.Game { [HarmonyPrefix] [HarmonyPatch("UpdateVideo")] + // ReSharper disable once InconsistentNaming public static bool Prefix(scnGame __instance) { // Only replace when rendering is active @@ -20,7 +22,7 @@ namespace ADOFAIRenderer.Patch.Game var oldPlayer = __instance.videoBG.gameObject.GetComponent(); if (oldPlayer != null) { - UnityEngine.Object.Destroy(oldPlayer); + Object.Destroy(oldPlayer); } // Re-enable native player component __instance.videoBG.enabled = true; @@ -45,13 +47,23 @@ namespace ADOFAIRenderer.Patch.Game } // Custom level video path - string videoPath = Path.Combine(Path.GetDirectoryName(ADOBase.levelPath), text); + var videoPath = Path.Combine(Path.GetDirectoryName(ADOBase.levelPath) ?? "", text); if (!File.Exists(videoPath)) { return true; // Let the original print error } // Disable native VideoPlayer component (to prevent it from attempting real-time playback and sync errors) + var targetCamera = __instance.videoBG.targetCamera; + if (!targetCamera) + { + var camGo = GameObject.Find("BGStaticCam"); + if (camGo != null) + { + targetCamera = camGo.GetComponent(); + } + } + __instance.videoBG.enabled = false; // Add or retrieve our custom FFmpeg video background player @@ -61,11 +73,10 @@ namespace ADOFAIRenderer.Patch.Game player = __instance.videoBG.gameObject.AddComponent(); } - bool isLooping = __instance.levelData.miscSettings.GetBool("loopVideo"); + var isLooping = __instance.levelData.miscSettings.GetBool("loopVideo"); - // In custom levels, ADOFAI's videoBG targetTexture is pre-allocated by the game to render background filters. - // We initialize the player with the target RenderTexture. - player.Init(videoPath, __instance.videoBG.targetTexture, isLooping); + // Initialize player. If targetTexture is null (CameraFarPlane mode), it will build a quad in front of targetCamera. + player.Init(videoPath, __instance.videoBG.targetTexture, isLooping, targetCamera, __instance.videoBG.gameObject); return false; // Skip original UpdateVideo }