Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 4.1.1 update #12

Merged
merged 9 commits into from
Jul 23, 2024
4 changes: 2 additions & 2 deletions CustomAlbums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.26">
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.34.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="NLayer" Version="1.15.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
Expand Down
7 changes: 1 addition & 6 deletions Data/Album.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ private void GetSheets()
{
// Adds to the Sheets dictionary
foreach (var difficulty in Info.Difficulties.Keys.Where(difficulty => HasFile($"map{difficulty}.bms")))
{
using var stream = OpenMemoryStream($"map{difficulty}.bms");
var hash = stream.GetHash();

Sheets.Add(difficulty, new Sheet(hash, this, difficulty));
}
Sheets.Add(difficulty, new Sheet(this, difficulty));
}

public bool HasDifficulty(int difficulty) => Sheets.ContainsKey(difficulty);
Expand Down
2 changes: 2 additions & 0 deletions Data/Bms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public enum BmsId
SceneSwitchGrooveCoaster,
SceneSwitchTouhou,
SceneSwitchDjmax,
SceneSwitchMiku,
PItem,
Ghost,
Heart,
Expand Down Expand Up @@ -261,6 +262,7 @@ public enum ChannelType
["1T"] = BmsId.SceneSwitchGrooveCoaster,
["1U"] = BmsId.SceneSwitchTouhou,
["1V"] = BmsId.SceneSwitchDjmax,
["1X"] = BmsId.SceneSwitchMiku,
["20"] = BmsId.PItem,
["21"] = BmsId.Ghost,
["22"] = BmsId.Heart,
Expand Down
12 changes: 9 additions & 3 deletions Data/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ public class Sheet
{
private readonly Logger _logger = new(nameof(Sheet));

public Sheet(string md5, Album parentAlbum, int difficulty)
public Sheet(Album parentAlbum, int difficulty)
{
Md5 = md5;
ParentAlbum = parentAlbum;
Difficulty = difficulty;
MapName = $"{parentAlbum.AlbumName}_map{difficulty}";
}

public Album ParentAlbum { get; }
public string Md5 { get; }
public string MapName { get; }
public int Difficulty { get; }
public bool TalkFileVersion2 { get; set; }
public string Md5
{
get
{
using var stream = ParentAlbum.OpenMemoryStream($"map{Difficulty}.bms");
return stream.GetHash();
}
}

public StageInfo GetStage()
{
Expand Down
2 changes: 0 additions & 2 deletions Managers/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ internal static void SaveScore(string uid, int musicDifficulty, int score, float

if (!SaveData.FullCombo[albumName].Contains(musicDifficulty))
SaveData.FullCombo[albumName].Add(musicDifficulty);

SaveSaveFile();
}
}
}
2 changes: 1 addition & 1 deletion Patches/AssetPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ internal static void InitializeHandler()
AlbumManager.LoadedAlbums.TryGetValue(albumKey, out var album);
if (suffix.StartsWith("_map"))
{
newAsset = album?.Sheets[suffix[^1].ToString().ParseAsInt()].GetStage();
newAsset = album?.Sheets.GetValueOrDefault(suffix[^1].ToString().ParseAsInt())?.GetStage();
// Do not cache the StageInfos, this should be loaded into memory only when we need it
cache = false;
}
Expand Down
31 changes: 31 additions & 0 deletions Patches/SavePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Il2CppAssets.Scripts.PeroTools.Commons;
using Il2CppAssets.Scripts.PeroTools.Platforms.Steam;
using Il2CppAssets.Scripts.Structs;
using Il2CppAssets.Scripts.UI.Panels;
using Il2CppInterop.Common;
using Il2CppPeroPeroGames.DataStatistics;
using MelonLoader.NativeUtils;
Expand Down Expand Up @@ -227,6 +228,25 @@ private static void InjectCustomData()
DataHelper.selectedMusicUidFromInfoList = AlbumManager.LoadedAlbums.TryGetValue(SaveData.SelectedAlbum, out var album) ? album.Uid : "0-0";
}

// Dumb hack that fixes the chart appearing locked on game start even if it is unlocked
[HarmonyPatch(typeof(PnlStage), nameof(PnlStage.Start))]
internal class StartPatch
{
private static void Postfix(PnlStage __instance)
{
var uid = DataHelper.selectedMusicUid;
if (!DataHelper.selectedMusicUid?.StartsWith($"{AlbumManager.Uid}-") ?? true) return;

var album = AlbumManager.GetByUid(uid);

if (album == null || (!DataHelper.isUnlockAllMaster && !SaveData.UnlockedMasters.Contains(album!.AlbumName))) return;

__instance.difficulty3Lock.SetActive(false);
__instance.difficulty3Master.SetActive(true);
__instance.difficulty3.enabled = true;
}
}

[HarmonyPatch(typeof(PnlPreparation), nameof(PnlPreparation.OnEnable))]
internal class PnlPreparationEnablePatch
{
Expand Down Expand Up @@ -401,9 +421,20 @@ internal class SetScorePatch
{
private static void Postfix(PnlVictory __instance)
{
// Fix for DJMax scrolling text bug
if (__instance.m_CurControls.mainPnl.transform.parent.name is "Djmax")
{
var titleMask = __instance.m_CurControls.mainPnl.transform
.Find("PnlVictory_3D").Find("SongTittle").Find("ImgSongTittleMask");

var titleText = titleMask.Find("TxtSongTittle").gameObject;
if (!titleText.active) titleMask.Find("MaskPos").gameObject.SetActive(true);
}

if (!ModSettings.SavingEnabled || !GlobalDataBase.dbBattleStage.musicUid.StartsWith($"{AlbumManager.Uid}-")) return;

var albumName = AlbumManager.GetAlbumNameFromUid(GlobalDataBase.dbBattleStage.musicUid);

if (!SaveData.Highest.TryGetValue(albumName, out var highest))
return;

Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
[assembly: MelonInfo(typeof(CustomAlbums.Main), "CustomAlbums", "4.1.0", "Team Baller")]
[assembly: AssemblyVersion("4.1.1.0")]
[assembly: AssemblyFileVersion("4.1.1.0")]
[assembly: MelonInfo(typeof(CustomAlbums.Main), "CustomAlbums", "4.1.1", "Team Baller")]
[assembly: MelonGame("PeroPeroGames", "MuseDash")]
[assembly: MelonColor(255, 0, 255, 150)]
12 changes: 10 additions & 2 deletions Utilities/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace CustomAlbums.Utilities
{
internal static class StreamExtensions
{
private static readonly Logger Logger = new(nameof(StreamExtensions));
public static string GetHash(this Stream stream)
{
byte[] hash;
Expand All @@ -29,8 +30,15 @@ public static byte[] ReadFully(this MemoryStream stream)
public static MemoryStream ToMemoryStream(this Stream stream)
{
var ms = new MemoryStream();
stream.CopyTo(ms);
ms.Position = 0;
try
{
stream.CopyTo(ms);
ms.Position = 0;
}
catch (Exception ex)
{
Logger.Warning(ex.Message);
}

return ms;
}
Expand Down