Skip to content

Commit

Permalink
add try catch for GetMovie() in movieloader
Browse files Browse the repository at this point in the history
  • Loading branch information
ck2739046 committed Feb 11, 2025
1 parent e43e312 commit e9c7ceb
Showing 1 changed file with 46 additions and 43 deletions.
89 changes: 46 additions & 43 deletions AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,61 @@ public static void LoadMusicPostfix(List<string> ____targetDirs)
[HarmonyPatch(typeof(TrackStartProcess), "OnStart")]
public static async void GetMovie() {

movieInfo = ("", "", null, ""); // reset
var music = Singleton<DataManager>.Instance.GetMusic(GameManager.SelectMusicID[0]);
if (music is null) return;
var musicID = $"{music.movieName.id:000000}";

// Load source movie
if (loadSourceMovie) {
var moviePath = Singleton<OptionDataManager>.Instance.GetMovieDataPath($"{musicID}") + ".dat";
if (!moviePath.Contains("dummy")) {
movieInfo = ("sourceMovie", "", null, musicID);
return;
try {

movieInfo = ("", "", null, ""); // reset
var music = Singleton<DataManager>.Instance.GetMusic(GameManager.SelectMusicID[0]);
if (music is null) return;
var musicID = $"{music.movieName.id:000000}";

// Load source movie
if (loadSourceMovie) {
var moviePath = Singleton<OptionDataManager>.Instance.GetMovieDataPath($"{musicID}") + ".dat";
if (!moviePath.Contains("dummy")) {
movieInfo = ("sourceMovie", "", null, musicID);
return;
}
}
}

// Load localasset mp4 bga
if (loadMp4Movie) {
var resolvedDir = FileSystem.ResolvePath(movieAssetsDir);
if (!optionFileMap.TryGetValue($"{musicID}.mp4", out var mp4Path)) {
mp4Path = Path.Combine(resolvedDir, $"{musicID}.mp4");
// Load localasset mp4 bga
if (loadMp4Movie) {
var resolvedDir = FileSystem.ResolvePath(movieAssetsDir);
if (!optionFileMap.TryGetValue($"{musicID}.mp4", out var mp4Path)) {
mp4Path = Path.Combine(resolvedDir, $"{musicID}.mp4");
}
if (File.Exists(mp4Path)) {
movieInfo = ("mp4Movie", mp4Path, null, musicID);
return;
}
}
if (File.Exists(mp4Path)) {
movieInfo = ("mp4Movie", mp4Path, null, musicID);
return;
}
}

// Load jacket
if (jacketAsMovie) {
// 尝试从game或LocalAssets获取jacket
var jacket = LoadLocalImages.GetJacketTexture2D(music.movieName.id);
if (jacket is null) {
var filename = $"Jacket/UI_Jacket_{musicID}.png";
jacket = AssetManager.Instance().GetJacketTexture2D(filename);
// Load jacket
if (jacketAsMovie) {
// 尝试从game或LocalAssets获取jacket
var jacket = LoadLocalImages.GetJacketTexture2D(music.movieName.id);
if (jacket is null) {
MelonLogger.Msg($"[MovieLoader] No jacket for {musicID}");
var filename = $"Jacket/UI_Jacket_{musicID}.png";
jacket = AssetManager.Instance().GetJacketTexture2D(filename);
if (jacket is null) {
MelonLogger.Msg($"[MovieLoader] No jacket for {musicID}");
return;
}
}
// 如果未开启后处理,直接返回jacket
if (!jacketPostProcess) {
movieInfo = ("jacket", "", jacket, musicID);
return;
}
// 异步调用后处理函数
movieInfo = ("jacket_processing", "", jacket, musicID); // 标记为开始后处理
jacket = await JacketPostProcess(jacket);
if (jacket is null) {
MelonLogger.Msg($"[MovieLoader] post-process return null for {musicID}");
return;
}
}
// 如果未开启后处理,直接返回jacket
if (!jacketPostProcess) {
movieInfo = ("jacket", "", jacket, musicID);
return;
}
// 异步调用后处理函数
movieInfo = ("jacket_processing", "", jacket, musicID); // 标记为开始后处理
jacket = await JacketPostProcess(jacket);
if (jacket is null) {
MelonLogger.Msg($"[MovieLoader] post-process return null for {musicID}");
return;
}
movieInfo = ("jacket", "", jacket, musicID);
}
} catch (System.Exception e) {MelonLogger.Msg($"[MovieLoader] GetMovie() error: {e}");}
}

private static async Task<Texture2D> JacketPostProcess(Texture2D jacket) {
Expand Down

0 comments on commit e9c7ceb

Please sign in to comment.