SHA256
Refactor scnGamePatch
This commit is contained in:
1 file changed
+17
-6
@@ -2,6 +2,7 @@ using System.IO;
|
|||||||
using ADOFAIRenderer.Core;
|
using ADOFAIRenderer.Core;
|
||||||
using ADOFAIRenderer.Util;
|
using ADOFAIRenderer.Util;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ADOFAIRenderer.Patch.Game
|
namespace ADOFAIRenderer.Patch.Game
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,7 @@ namespace ADOFAIRenderer.Patch.Game
|
|||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch("UpdateVideo")]
|
[HarmonyPatch("UpdateVideo")]
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
public static bool Prefix(scnGame __instance)
|
public static bool Prefix(scnGame __instance)
|
||||||
{
|
{
|
||||||
// Only replace when rendering is active
|
// Only replace when rendering is active
|
||||||
@@ -20,7 +22,7 @@ namespace ADOFAIRenderer.Patch.Game
|
|||||||
var oldPlayer = __instance.videoBG.gameObject.GetComponent<FFmpegVideoBGPlayer>();
|
var oldPlayer = __instance.videoBG.gameObject.GetComponent<FFmpegVideoBGPlayer>();
|
||||||
if (oldPlayer != null)
|
if (oldPlayer != null)
|
||||||
{
|
{
|
||||||
UnityEngine.Object.Destroy(oldPlayer);
|
Object.Destroy(oldPlayer);
|
||||||
}
|
}
|
||||||
// Re-enable native player component
|
// Re-enable native player component
|
||||||
__instance.videoBG.enabled = true;
|
__instance.videoBG.enabled = true;
|
||||||
@@ -45,13 +47,23 @@ namespace ADOFAIRenderer.Patch.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Custom level video path
|
// 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))
|
if (!File.Exists(videoPath))
|
||||||
{
|
{
|
||||||
return true; // Let the original print error
|
return true; // Let the original print error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable native VideoPlayer component (to prevent it from attempting real-time playback and sync errors)
|
// 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;
|
__instance.videoBG.enabled = false;
|
||||||
|
|
||||||
// Add or retrieve our custom FFmpeg video background player
|
// Add or retrieve our custom FFmpeg video background player
|
||||||
@@ -61,11 +73,10 @@ namespace ADOFAIRenderer.Patch.Game
|
|||||||
player = __instance.videoBG.gameObject.AddComponent<FFmpegVideoBGPlayer>();
|
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.
|
// Initialize player. If targetTexture is null (CameraFarPlane mode), it will build a quad in front of targetCamera.
|
||||||
// We initialize the player with the target RenderTexture.
|
player.Init(videoPath, __instance.videoBG.targetTexture, isLooping, targetCamera, __instance.videoBG.gameObject);
|
||||||
player.Init(videoPath, __instance.videoBG.targetTexture, isLooping);
|
|
||||||
|
|
||||||
return false; // Skip original UpdateVideo
|
return false; // Skip original UpdateVideo
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user