Skip to content

Commit

Permalink
Merge pull request #16 from MDMods/md-4.8.0
Browse files Browse the repository at this point in the history
Muse Dash 4.8.0
  • Loading branch information
ALLMarvelous authored Sep 29, 2024
2 parents 9e44f69 + 97304b1 commit c8b17ac
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 37 deletions.
38 changes: 30 additions & 8 deletions Data/Album.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CustomAlbums.Data
{
public class Album
{
private readonly Logger _logger = new(nameof(Album));
private static readonly Logger Logger = new(nameof(Album));

public Album(string path, int index)
{
Expand All @@ -17,7 +17,7 @@ public Album(string path, int index)
// Load album from directory
if (!File.Exists($"{path}\\info.json"))
{
_logger.Error($"Could not find info.json at: {path}\\info.json");
Logger.Error($"Could not find info.json at: {path}\\info.json");
throw new FileNotFoundException();
}

Expand All @@ -31,7 +31,7 @@ public Album(string path, int index)
var info = zip.GetEntry("info.json");
if (info == null)
{
_logger.Error($"Could not find info.json in package: {path}");
Logger.Error($"Could not find info.json in package: {path}");
throw new FileNotFoundException();
}

Expand All @@ -41,7 +41,7 @@ public Album(string path, int index)
}
else
{
_logger.Error($"Could not find album at: {path}");
Logger.Error($"Could not find album at: {path}");
throw new FileNotFoundException();
}

Expand Down Expand Up @@ -97,18 +97,40 @@ public Stream OpenFileStreamIfPossible(string file)
return entry.Open().ToMemoryStream();
}

_logger.Error($"Could not find file in package: {file}");
Logger.Error($"Could not find file in package: {file}");
throw new FileNotFoundException();
}

var path = $"{Path}\\{file}";
if (File.Exists(path))
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

_logger.Error($"Could not find file: {path}");
Logger.Error($"Could not find file: {path}");
throw new FileNotFoundException();
}

public Stream OpenNullableStream(string file)
{
if (IsPackaged)
{
using var zip = ZipFile.OpenRead(Path);
var entry = zip.GetEntry(file);

if (entry != null)
{
return entry.Open().ToMemoryStream();
}

return null;
}

var path = $"{Path}\\{file}";
if (File.Exists(path))
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

return null;
}

public MemoryStream OpenMemoryStream(string file)
{
if (IsPackaged)
Expand All @@ -121,15 +143,15 @@ public MemoryStream OpenMemoryStream(string file)
return entry.Open().ToMemoryStream();
}

_logger.Error($"Could not find file in package: {file}");
Logger.Error($"Could not find file in package: {file}");
throw new FileNotFoundException();
}

var path = $"{Path}\\{file}";
if (File.Exists(path))
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite).ToMemoryStream();

_logger.Error($"Could not find file: {path}");
Logger.Error($"Could not find file: {path}");
throw new FileNotFoundException();
}
private void GetSheets()
Expand Down
13 changes: 13 additions & 0 deletions Data/Setlist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomAlbums.Data
{
public class Setlist
{
public string Title { get; set; }
}
}
4 changes: 2 additions & 2 deletions Data/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CustomAlbums.Data
{
public class Sheet
{
private readonly Logger _logger = new(nameof(Sheet));
private static readonly Logger Logger = new(nameof(Sheet));

public Sheet(Album parentAlbum, int difficulty)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public StageInfo GetStage()
var talkFile = Json.Deserialize<JsonObject>(talkStream);
if (talkFile.TryGetPropertyValue("version", out var node) && node?.GetValue<int>() == 2)
{
_logger.Msg("Version 2 talk file!");
Logger.Msg("Version 2 talk file!");
TalkFileVersion2 = true;
}

Expand Down
6 changes: 6 additions & 0 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ public override void OnFixedUpdate()
// TODO: Actually write HotReload
// HotReloadManager.FixedUpdate();
}

public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
base.OnSceneWasLoaded(buildIndex, sceneName);
MusicStageCellPatch.CurrentScene = sceneName;
}
}
}
3 changes: 3 additions & 0 deletions Managers/AlbumManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CustomAlbums.Data;
using CustomAlbums.ModExtensions;
using CustomAlbums.Utilities;
using Il2CppPeroTools2.Resources;
using UnityEngine;
Expand All @@ -25,6 +26,7 @@ public static class AlbumManager

private static readonly Logger Logger = new(nameof(AlbumManager));
internal static readonly FileSystemWatcher AlbumWatcher = new();
internal static Events.LoadAlbumEvent OnAlbumLoaded;

private static int MaxCount { get; set; }
public static Dictionary<string, Album> LoadedAlbums { get; } = new();
Expand All @@ -48,6 +50,7 @@ public static Album LoadOne(string path)
HideFlags.DontUnloadUnusedAsset;

Logger.Msg($"Loaded {albumName}: {album.Info.Name}");
OnAlbumLoaded?.Invoke(typeof(AlbumManager), new AlbumEventArgs(album));
return album;
}
catch (Exception ex)
Expand Down
9 changes: 3 additions & 6 deletions Managers/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,12 @@ internal static void SaveScore(string uid, int musicDifficulty, int score, float
var albumName = album.AlbumName;

// Create new album save
if (!SaveData.Highest.ContainsKey(albumName))
SaveData.Highest.Add(albumName, new Dictionary<int, CustomChartSave>());
SaveData.Highest.TryAdd(albumName, new Dictionary<int, CustomChartSave>());

var currChartScore = SaveData.Highest[albumName];

// Create new save data if the difficulty doesn't exist
if (!currChartScore.ContainsKey(musicDifficulty))
currChartScore.Add(musicDifficulty, new CustomChartSave());
currChartScore.TryAdd(musicDifficulty, new CustomChartSave());

// Set previous score for PnlVictory logic
var newScore = currChartScore[musicDifficulty];
Expand All @@ -221,8 +219,7 @@ internal static void SaveScore(string uid, int musicDifficulty, int score, float
if (miss != 0) return;

// If there were no misses then add the chart/difficulty to the FullCombo list
if (!SaveData.FullCombo.ContainsKey(albumName))
SaveData.FullCombo.Add(albumName, new List<int>());
SaveData.FullCombo.TryAdd(albumName, new List<int>());

if (!SaveData.FullCombo[albumName].Contains(musicDifficulty))
SaveData.FullCombo[albumName].Add(musicDifficulty);
Expand Down
14 changes: 14 additions & 0 deletions ModExtensions/AlbumEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CustomAlbums.Data;

namespace CustomAlbums.ModExtensions
{
public class AlbumEventArgs : EventArgs
{
public Album Album;

public AlbumEventArgs(Album album)
{
Album = album;
}
}
}
14 changes: 14 additions & 0 deletions ModExtensions/AssetEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace CustomAlbums.ModExtensions
{
public class AssetEventArgs : EventArgs
{
public string AssetName;
public IntPtr AssetPtr;

public AssetEventArgs(string assetName, IntPtr assetPtr)
{
AssetName = assetName;
AssetPtr = assetPtr;
}
}
}
25 changes: 25 additions & 0 deletions ModExtensions/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CustomAlbums.Managers;
using CustomAlbums.Patches;

namespace CustomAlbums.ModExtensions
{
public static class Events
{
public delegate void LoadAssetEvent(object s, AssetEventArgs e);

public static event LoadAssetEvent OnAssetLoaded
{
add => AssetPatch.OnAssetLoaded += value;
remove => AssetPatch.OnAssetLoaded -= value;
}

public delegate void LoadAlbumEvent(object s, AlbumEventArgs e);

public static event LoadAlbumEvent OnAlbumLoaded
{
add => AlbumManager.OnAlbumLoaded += value;
remove => AlbumManager.OnAlbumLoaded -= value;
}

}
}
7 changes: 2 additions & 5 deletions Patches/AnalyticsPatch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CustomAlbums.Managers;
using HarmonyLib;
using Il2CppAssets.Scripts.Database;
using Il2CppAssets.Scripts.Structs.Modules;
using Il2CppPeroPeroGames.DataStatistics;
using System.Reflection;
using UnityEngine;
Expand Down Expand Up @@ -102,10 +101,8 @@ internal class GetSearchResultInfoPatch
private static bool Prefix(MusicInfo musicInfo)
{
var runCond = !musicInfo.uid.StartsWith($"{AlbumManager.Uid}-");
if (runCond) return true;

Logger.Msg("Blocking custom album from being added to search analytics.");
return false;
if (!runCond) Logger.Msg("Blocking custom album from being added to search analytics.");
return runCond;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Patches/AnimatedCoverPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ internal static class MusicStageCellPatch
{
private static readonly Logger Logger = new(nameof(MusicStageCellPatch));
private static readonly LinkedList<MusicStageCell> Cells = new();
internal static string CurrentScene { get; set; }

public static void AnimateCoversUpdate()
{
if (CurrentScene is not "UISystem_PC") return;
var dbMusicTag = GlobalDataBase.dbMusicTag;

if (dbMusicTag == null) return;
Expand Down
4 changes: 4 additions & 0 deletions Patches/AssetPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json.Nodes;
using CustomAlbums.Data;
using CustomAlbums.Managers;
using CustomAlbums.ModExtensions;
using CustomAlbums.Utilities;
using HarmonyLib;
using Il2CppAssets.Scripts.Database;
Expand Down Expand Up @@ -31,6 +32,7 @@ internal class AssetPatch

private static int _latestAlbumNum;
private static bool _doneLoadingAlbumsFlag;
internal static Events.LoadAssetEvent OnAssetLoaded;

/// <summary>
/// Binds the asset to a new key, while removing the old asset.
Expand Down Expand Up @@ -291,6 +293,8 @@ private static IntPtr LoadFromNamePatch(IntPtr instance, IntPtr assetNamePtr, In

Logger.Msg($"Loading {assetName}!");

OnAssetLoaded?.Invoke(typeof(AssetPatch), new AssetEventArgs(assetName, assetPtr));

if (assetName.StartsWith("ALBUM") && assetName[5..].TryParseAsInt(out var albumNum) &&
albumNum != AlbumManager.Uid + 1)
{
Expand Down
Loading

0 comments on commit c8b17ac

Please sign in to comment.