From e0ec78a64e1138fce0fa9c5642da4b88a135d474 Mon Sep 17 00:00:00 2001 From: drojf Date: Thu, 15 Sep 2022 20:25:04 +1000 Subject: [PATCH] Play .ogv file if .mp4 file missing on Windows - Required to fix video playback on Proton/Wine on ch1-8 (see https://github.com/07th-mod/higurashi-assembly/issues/78) - Note: ch9 (rei) implements video playback differently, so these changes should not be applied to ch9 --- MOD.Scripts.Core.Movie/AVProMovieRenderer.cs | 2 +- MOD.Scripts.Core.Movie/MovieInfo.cs | 12 ++++- .../TextureMovieRenderer.cs | 2 +- MOD.Scripts.Core.State/StateMovie.cs | 47 ++++++++++++++----- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/MOD.Scripts.Core.Movie/AVProMovieRenderer.cs b/MOD.Scripts.Core.Movie/AVProMovieRenderer.cs index edf309f7..f040b0b1 100644 --- a/MOD.Scripts.Core.Movie/AVProMovieRenderer.cs +++ b/MOD.Scripts.Core.Movie/AVProMovieRenderer.cs @@ -57,7 +57,7 @@ public void Init(MovieInfo movieInfo) mediaPlayer.m_AutoOpen = true; mediaPlayer.m_AutoStart = true; mediaPlayer.m_Volume = movieInfo.Volume; - mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, movieInfo.Path + ".mp4"); + mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, movieInfo.PathWithExt); MODApplyToMaterial mODApplyToMaterial = base.gameObject.AddComponent(); mODApplyToMaterial._material = movieInfo.Layer.MODMaterial; mODApplyToMaterial._texturePropertyName = "_Primary"; diff --git a/MOD.Scripts.Core.Movie/MovieInfo.cs b/MOD.Scripts.Core.Movie/MovieInfo.cs index f1cc220f..682205bd 100644 --- a/MOD.Scripts.Core.Movie/MovieInfo.cs +++ b/MOD.Scripts.Core.Movie/MovieInfo.cs @@ -8,6 +8,13 @@ namespace MOD.Scripts.Core.Movie { public class MovieInfo { + public static string GetPathFromNameWithExt(string name, string ext) + { + return System.IO.Path.Combine(Application.streamingAssetsPath, "movies/" + name + ext); + } + + private readonly string Ext; + public string Name { get; @@ -16,13 +23,14 @@ public string Name public float Volume => Math.Min(1f, 1.55f * GameSystem.Instance.AudioController.BGMVolume); - public string Path => "file:///" + System.IO.Path.Combine(Application.streamingAssetsPath, "movies/" + Name); + public string PathWithExt => "file:///" + GetPathFromNameWithExt(Name, Ext); public Layer Layer => GameSystem.Instance.SceneController.MODActiveScene.BackgroundLayer; - public MovieInfo(string name) + public MovieInfo(string name, string ext) { Name = name; + Ext = ext; } } } diff --git a/MOD.Scripts.Core.Movie/TextureMovieRenderer.cs b/MOD.Scripts.Core.Movie/TextureMovieRenderer.cs index a374714c..7faed381 100644 --- a/MOD.Scripts.Core.Movie/TextureMovieRenderer.cs +++ b/MOD.Scripts.Core.Movie/TextureMovieRenderer.cs @@ -80,7 +80,7 @@ public TextureMovieRenderer() public void Init(MovieInfo movieInfo) { this.movieInfo = movieInfo; - www = new WWW(movieInfo.Path + ".ogv"); + www = new WWW(movieInfo.PathWithExt); audioSource = base.gameObject.AddComponent(); audioSource.volume = this.movieInfo.Volume; base.enabled = true; diff --git a/MOD.Scripts.Core.State/StateMovie.cs b/MOD.Scripts.Core.State/StateMovie.cs index 3895526a..77937b30 100644 --- a/MOD.Scripts.Core.State/StateMovie.cs +++ b/MOD.Scripts.Core.State/StateMovie.cs @@ -1,12 +1,17 @@ using Assets.Scripts.Core; using Assets.Scripts.Core.State; using MOD.Scripts.Core.Movie; +using MOD.Scripts.UI; +using System.IO; using UnityEngine; namespace MOD.Scripts.Core.State { public class StateMovie : IGameState { + const string windowsMovieExtension = ".mp4"; + const string linuxMovieExtension = ".ogv"; + private bool isLeaving; private IMovieRenderer MovieEntity; @@ -17,10 +22,39 @@ public class StateMovie : IGameState public StateMovie(string moviename) { - movieInfo = new MovieInfo(moviename); + // Windows and Wine/Proton will both show up as WindowsPlayer + bool isWindowsOrWine = Application.platform == RuntimePlatform.WindowsPlayer; + + // Only play the .mp4 file with AVProVideo on Windows-like Platforms, if the file exists + // On Wine, it is expected that only the Linux .ogv video file is installed, as playing using AVProVideo/.mp4 files on Wine is not supported + bool windowsPlaybackMode = isWindowsOrWine && File.Exists(MovieInfo.GetPathFromNameWithExt(moviename, windowsMovieExtension)); + + // The below just shows a message if no video file found to play (it does not affect playback behavior) + if (!windowsPlaybackMode && !File.Exists(MovieInfo.GetPathFromNameWithExt(moviename, linuxMovieExtension))) + { + string movieFiles = $"{moviename}{linuxMovieExtension}"; + if(isWindowsOrWine) + { + movieFiles = $"{moviename}{windowsMovieExtension} or " + movieFiles; + } + + string errorMessage = $"ERROR: Movie file {movieFiles} not found"; + Debug.Log(errorMessage); + MODToaster.Show(errorMessage, toastDuration:10); + } + + movieInfo = new MovieInfo(moviename, windowsPlaybackMode ? windowsMovieExtension : linuxMovieExtension); gameObject = new GameObject(); SetupBackgroundLayerForVideo(); - MovieEntity = CreateMovieRenderer(); + + if(windowsPlaybackMode) + { + MovieEntity = gameObject.AddComponent(); + } + else + { + MovieEntity = gameObject.AddComponent(); + } MovieEntity.Init(movieInfo); } @@ -76,15 +110,6 @@ public void Leave() } } - private IMovieRenderer CreateMovieRenderer() - { - if (Application.platform == RuntimePlatform.WindowsPlayer) - { - return gameObject.AddComponent(); - } - return gameObject.AddComponent(); - } - private void SetupBackgroundLayerForVideo() { movieInfo.Layer.ReleaseTextures();