mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-15 12:37:28 +08:00
[+] Use the png jacket as bga
This commit is contained in:
@@ -5,7 +5,6 @@ using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
using MelonLoader;
|
||||
|
||||
namespace AquaMai.UX
|
||||
{
|
||||
@@ -27,26 +26,49 @@ namespace AquaMai.UX
|
||||
}
|
||||
|
||||
var id = matches[0].Groups[1].Value;
|
||||
foreach (var ext in new[] { ".jpg", ".png", ".webp", ".bmp", ".gif" })
|
||||
{
|
||||
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext)))
|
||||
{
|
||||
filename = id + ext;
|
||||
}
|
||||
}
|
||||
|
||||
var localPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", filename);
|
||||
if (File.Exists(localPath))
|
||||
var texture = GetJacketTexture2D(id);
|
||||
if (texture is null)
|
||||
{
|
||||
__result = new Texture2D(1, 1);
|
||||
ImageConversion.LoadImage(__result, File.ReadAllBytes(localPath));
|
||||
__result = __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = __instance.LoadAsset<Texture2D>($"Jacket/UI_Jacket_{id}.png");
|
||||
__result = texture;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GetJacketPath(string id)
|
||||
{
|
||||
foreach (var ext in new[] { ".jpg", ".png", ".webp", ".bmp", ".gif" })
|
||||
{
|
||||
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext)))
|
||||
{
|
||||
return Path.Combine(Environment.CurrentDirectory, "LocalAssets", id + ext);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Texture2D GetJacketTexture2D(string id)
|
||||
{
|
||||
var path = GetJacketPath(id);
|
||||
if (path == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var texture = new Texture2D(1, 1);
|
||||
texture.LoadImage(File.ReadAllBytes(path));
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Texture2D GetJacketTexture2D(int id)
|
||||
{
|
||||
return GetJacketTexture2D($"{id:000000}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
AquaMai/UX/LoadLocalBga.cs
Normal file
43
AquaMai/UX/LoadLocalBga.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MAI2.Util;
|
||||
using Manager;
|
||||
using MelonLoader;
|
||||
using Monitor.Game;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AquaMai.UX;
|
||||
|
||||
public class LoadLocalBga
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(GameCtrl), "IsReady")]
|
||||
public static void LoadLocalBgaAwake(GameObject ____movieMaskObj)
|
||||
{
|
||||
var components = ____movieMaskObj.GetComponentsInChildren<Component>(false);
|
||||
var movie = components.FirstOrDefault(it => it.name == "Movie");
|
||||
if (movie is null) return;
|
||||
|
||||
var music = Singleton<DataManager>.Instance.GetMusic(GameManager.SelectMusicID[0]);
|
||||
var moviePath = string.Format(Singleton<OptionDataManager>.Instance.GetMovieDataPath($"{music.movieName.id:000000}") + ".dat");
|
||||
if (!moviePath.Contains("dummy")) return;
|
||||
|
||||
var jacket = LoadJacketPng.GetJacketTexture2D(music.movieName.id);
|
||||
if (jacket is null)
|
||||
{
|
||||
MelonLogger.Msg("No jacket found for music " + music);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If I create a new RawImage component, the jacket will be not be displayed
|
||||
// I think it will be difficult to make it work with RawImage
|
||||
// So I change the material that plays video to default sprite material
|
||||
// The original player is actually a sprite renderer and plays video with a custom material
|
||||
var sprite = movie.GetComponent<SpriteRenderer>();
|
||||
sprite.sprite = Sprite.Create(jacket, new Rect(0, 0, jacket.width, jacket.height), new Vector2(0.5f, 0.5f));
|
||||
sprite.material = new Material(Shader.Find("Sprites/Default"));
|
||||
}
|
||||
|
||||
// movie.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user