From 2c2de9bb63067817e435ac2b5dd43e09b9ec5c10 Mon Sep 17 00:00:00 2001 From: Clansty Date: Mon, 2 Dec 2024 12:20:38 +0800 Subject: [PATCH] load mp4 from StreamingAssets --- AquaMai.Mods/GameSystem/Assets/MovieLoader.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/AquaMai.Mods/GameSystem/Assets/MovieLoader.cs b/AquaMai.Mods/GameSystem/Assets/MovieLoader.cs index 7bfd87fc..87bf9349 100644 --- a/AquaMai.Mods/GameSystem/Assets/MovieLoader.cs +++ b/AquaMai.Mods/GameSystem/Assets/MovieLoader.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.IO; using AquaMai.Config.Attributes; using AquaMai.Core.Helpers; @@ -39,6 +39,23 @@ public class MovieLoader zh: "加载 MP4 文件的路径")] private static readonly string movieAssetsDir = "LocalAssets"; + private static readonly Dictionary optionFileMap = []; + + [HarmonyPrefix] + [HarmonyPatch(typeof(DataManager), "LoadMusicBase")] + public static void LoadMusicPostfix(List ____targetDirs) + { + foreach (var aDir in ____targetDirs) + { + if (!Directory.Exists(Path.Combine(aDir, "MovieData"))) continue; + var files = Directory.GetFiles(Path.Combine(aDir, "MovieData"), "*.mp4"); + foreach (var file in files) + { + optionFileMap[Path.GetFileName(file)] = file; + } + } + } + private static VideoPlayer[] _videoPlayers = new VideoPlayer[2]; [HarmonyPostfix] @@ -52,7 +69,11 @@ public class MovieLoader if (!moviePath.Contains("dummy")) return; var resolvedDir = FileSystem.ResolvePath(movieAssetsDir); - var mp4Path = Path.Combine(resolvedDir, $"{music.movieName.id:000000}.mp4"); + if (!optionFileMap.TryGetValue($"{music.movieName.id:000000}.mp4", out var mp4Path)) + { + mp4Path = Path.Combine(resolvedDir, $"{music.movieName.id:000000}.mp4"); + } + var mp4Exists = File.Exists(mp4Path); var jacket = LoadLocalImages.GetJacketTexture2D(music.movieName.id); if (!mp4Exists && jacket is null)