Refactor scnGamePatch

This commit is contained in:
copecone committed 2026-06-21 23:07:47 +09:00
1 parent 606480d0db
commit 7da83227ed
1 file changed
+17 -6
+17 -6
View File
@@ -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<FFmpegVideoBGPlayer>();
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<Camera>();
}
}
__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<FFmpegVideoBGPlayer>();
}
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
}