[+] Use the png jacket as bga

This commit is contained in:
Clansty 2024-06-26 03:11:56 +08:00
parent 8b72214780
commit 2946c51774
5 changed files with 86 additions and 15 deletions

View File

@ -13,6 +13,7 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<LangVersion>12</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
@ -281,6 +282,7 @@
<Compile Include="UX\ImmediateSave.cs" />
<Compile Include="UX\LoadJacketPng.cs" />
<Compile Include="UX\LoadAssetBundleWithoutManifest.cs" />
<Compile Include="UX\LoadLocalBga.cs" />
<Compile Include="UX\QuickSkip.cs" />
<Compile Include="UX\RandomBgm.cs" />
<Compile Include="UX\RunCommandOnEvents.cs" />

View File

@ -22,6 +22,9 @@ SkipToMusicSelection=false
CustomVersionString=""
# Load Jacket image from folder "LocalAssets" and filename "{MusicID}.png" for self-made charts
LoadJacketPng=true
# Use the png jacket above as BGA if BGA is not found for self-made charts
# Use together with `LoadJacketPng`
LoadLocalBga=true
# Press key "7" for 1 second to skip to next step or restart current song
QuickSkip=true
# Add ".ab" image resources without the need of rebuilding a manifest
@ -42,4 +45,4 @@ ImmediateSave=true
[Performance]
# Disable some useless delays to speed up the game boot process
ImproveLoadSpeed=false
ImproveLoadSpeed=false

View File

@ -29,6 +29,7 @@ namespace AquaMai
public bool ExtendTimer { get; set; }
public bool SkipEventInfo { get; set; }
public bool ImmediateSave { get; set; }
public bool LoadLocalBga { get; set; }
public string CustomVersionString { get; set; }
public string ExecOnIdle { get; set; }
public string ExecOnEntry { get; set; }

View File

@ -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}");
}
}
}
}

View 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);
}
}