Skip to content

Commit

Permalink
Merge pull request #4 from MDMods/development
Browse files Browse the repository at this point in the history
Bump version to 4.0.2
  • Loading branch information
SB15-MD authored Feb 28, 2024
2 parents dafd427 + ac95cbc commit f22cdc1
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install .NET Core
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x

Expand All @@ -34,7 +34,7 @@ jobs:
dotnet build "/p:MelonNET6=./dependencies;WORKER=GitHub" CustomAlbums.sln
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: CustomAlbums.dll
path: ./Output/Debug/CustomAlbums.dll
14 changes: 7 additions & 7 deletions CustomAlbums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
<WorkingDirectory>$(OutputPath)</WorkingDirectory>
</PropertyGroup>
<ItemGroup>
<InputAssemblies Include="$(OutputPath)/$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)/NAudio.Core.dll" />
<InputAssemblies Include="$(OutputPath)/NAudio.Vorbis.dll" />
<InputAssemblies Include="$(OutputPath)/NLayer.dll" />
<InputAssemblies Include="$(OutputPath)/NVorbis.dll" />
<InputAssemblies Include="$(OutputPath)/SixLabors.ImageSharp.dll" />
<InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)\NAudio.Core.dll" />
<InputAssemblies Include="$(OutputPath)\NAudio.Vorbis.dll" />
<InputAssemblies Include="$(OutputPath)\NLayer.dll" />
<InputAssemblies Include="$(OutputPath)\NVorbis.dll" />
<InputAssemblies Include="$(OutputPath)\SixLabors.ImageSharp.dll" />
<IlRepackLibs Include="$(OutputPath)" />
<IlRepackLibs Include="$(MelonNET6)" />
</ItemGroup>
<ILRepack
LibraryPath="@(IlRepackLibs)"
OutputFile="$(OutputPath)/$(AssemblyName).dll"
OutputFile="$(OutputPath)\$(AssemblyName).dll"
InputAssemblies="@(InputAssemblies)"
Parallel="true"/>
</Target>
Expand Down
5 changes: 4 additions & 1 deletion Data/Album.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public Album(string path, int index)
public AudioClip Music => this.GetAudio();
public AudioClip Demo => this.GetAudio("demo");
public Dictionary<int, Sheet> Sheets { get; } = new();
public string AlbumName =>
IsPackaged ? $"album_{System.IO.Path.GetFileNameWithoutExtension(Path)}" : $"album_{System.IO.Path.GetFileName(Path)}_folder";

public bool HasFile(string name)
{
Expand All @@ -73,7 +75,8 @@ public bool HasFile(string name)
}
catch (IOException)
{
// this is expected in the case of deleting an album
// This is expected in the case of deleting an album
return false;
}
}

Expand Down
1 change: 1 addition & 0 deletions Data/CustomAlbumsSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class CustomAlbumsSave
{
public string SelectedAlbum { get; set; } = string.Empty;
public HashSet<string> UnlockedMasters { get; set; } = new();
public HashSet<string> Collections { get; set; } = new();
public HashSet<string> Hides { get; set; } = new();
public Queue<string> History { get; set; } = new();
Expand Down
3 changes: 2 additions & 1 deletion Data/Sheet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using CustomAlbums.Managers;
using CustomAlbums.Utilities;
using Il2CppAssets.Scripts.Database;
using Il2CppAssets.Scripts.GameCore;
Expand All @@ -15,7 +16,7 @@ public Sheet(string md5, Album parentAlbum, int difficulty)
Md5 = md5;
ParentAlbum = parentAlbum;
Difficulty = difficulty;
MapName = $"album_{Path.GetFileNameWithoutExtension(parentAlbum.Path)}_map{difficulty}";
MapName = $"{parentAlbum.AlbumName}_map{difficulty}";
}

public Album ParentAlbum { get; }
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<Private>false</Private>
<HintPath>$(MelonAssemblies)\Il2CppPeroString.dll</HintPath>
</Reference>
<Reference Include="Il2Cppcom.prpr.log, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>false</SpecificVersion>
<Private>false</Private>
<HintPath>$(MelonAssemblies)\Il2Cppcom.prpr.log.dll</HintPath>
</Reference>
<Reference Include="Il2CppGoogle.Protobuf, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>false</SpecificVersion>
<Private>false</Private>
Expand Down
19 changes: 4 additions & 15 deletions Managers/AlbumManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.IO.Enumeration;
using CustomAlbums.Data;
using Il2CppPeroTools2.Resources;
using UnityEngine;
Expand Down Expand Up @@ -32,15 +33,15 @@ public static class AlbumManager
public static Album LoadOne(string path)
{
MaxCount = Math.Max(LoadedAlbums.Count, MaxCount);
var fileName = Path.GetFileNameWithoutExtension(path);
var fileName = File.GetAttributes(path).HasFlag(FileAttributes.Directory) ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
if (LoadedAlbums.ContainsKey(fileName)) return null;

try
{
var album = new Album(path, MaxCount);
if (album.Info is null) return null;

var albumName = album.GetAlbumName();
var albumName = album.AlbumName;
LoadedAlbums.Add(albumName, album);

if (album.HasFile("cover.png") || album.HasFile("cover.gif"))
Expand Down Expand Up @@ -81,23 +82,11 @@ public static Album GetByUid(string uid)
{
return LoadedAlbums.FirstOrDefault(album => album.Value.Index == int.Parse(uid[4..], CultureInfo.InvariantCulture)).Value;
}

public static string GetAlbumName(this Album album)
{
return album.IsPackaged
? $"album_{Path.GetFileNameWithoutExtension(album.Path)}"
: $"album_{Path.GetFileNameWithoutExtension(album.Path)}_folder";
}

public static string GetAlbumNameFromUid(string uid)
{
var album = GetByUid(uid);
if (album is null) return string.Empty;
return album.IsPackaged
? $"album_{Path.GetFileNameWithoutExtension(album.Path)}"
: $"album_{Path.GetFileNameWithoutExtension(album.Path)}_folder";
return album is null ? string.Empty : album.AlbumName;
}

public static IEnumerable<string> GetAlbumUidsFromNames(this IEnumerable<string> albumNames)
{
return albumNames.Where(name => LoadedAlbums.ContainsKey(name))
Expand Down
2 changes: 1 addition & 1 deletion Managers/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static Coroutine CreateCoroutine(Il2CppSystem.Func<bool> update)
/// <returns></returns>
public static AudioClip GetAudio(this Album album, string name = "music")
{
var key = $"album_{Path.GetFileNameWithoutExtension(album.Path)}_{name}";
var key = $"{album.AlbumName}_{name}";
if (album.HasFile($"{name}.ogg"))
{
// Load music.ogg
Expand Down
22 changes: 11 additions & 11 deletions Managers/CoverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,34 @@ public static Sprite GetCover(this Album album)

public static unsafe AnimatedCover GetAnimatedCover(this Album album)
{
// early return statements
// Early return statements
if (!album.HasFile("cover.gif")) return null;
if (CachedAnimatedCovers.TryGetValue(album.Index, out var cached)) return cached;

Config.PreferContiguousImageBuffers = true;

// open and load the gif
// Open and load the gif
using var stream = album.OpenFileStream("cover.gif");
using var gif = Image.Load<Rgba32>(new DecoderOptions { Configuration = Config }, stream);

// for some reason Unity loads textures upside down?
// flip the frames
// For some reason Unity loads textures upside down?
// Flip the frames
gif.Mutate(c => c.Flip(FlipMode.Vertical));

var sprites = new Sprite[gif.Frames.Count];

for (var i = 0; i < gif.Frames.Count; i++)
{
// get frame data
// Get frame data
var frame = gif.Frames[i];
var width = frame.Width;
var height = frame.Width;

// get frame pixel data
// Get frame pixel data
//
// this should really be done with CopyPixelData and a byte array
// This should really be done with CopyPixelData and a byte array
// but that causes a 6MB+ copy of an array that slows things down by a bit
// the more efficient way is to retrieve an IntPtr that stores the data and pass that with a size instead
// The more efficient way is to retrieve an IntPtr that stores the data and pass that with a size instead
var getPixelDataResult = frame.DangerousTryGetSinglePixelMemory(out var memory);
if (!getPixelDataResult)
{
Expand All @@ -74,19 +74,19 @@ public static unsafe AnimatedCover GetAnimatedCover(this Album album)

using var handle = memory.Pin();

// create the textures
// Create the textures
var texture = new Texture2D(width, height, TextureFormat.RGBA32, false);
texture.LoadRawTextureData((IntPtr)handle.Pointer, memory.Length * sizeof(IntPtr));
texture.Apply(false);

// create the sprite with the given texture and add it to the sprites array
// Create the sprite with the given texture and add it to the sprites array
var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height),
new Vector2(0.5f, 0.5f));
sprite.hideFlags |= HideFlags.DontUnloadUnusedAsset;
sprites[i] = sprite;
}

// create and add cover to cache
// Create and add cover to cache
var cover = new AnimatedCover(sprites, gif.Frames.RootFrame.Metadata.GetGifMetadata().FrameDelay * 10);
CachedAnimatedCovers.Add(album.Index, cover);

Expand Down
1 change: 1 addition & 0 deletions Managers/HotReloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace CustomAlbums.Managers
{
// TODO: Fix all of this with album.AlbumName
internal static class HotReloadManager
{
private static readonly Logger Logger = new(nameof(HotReloadManager));
Expand Down
18 changes: 15 additions & 3 deletions Managers/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static void FixSaveFile()
var firstFullCombo = SaveData.FullCombo.FirstOrDefault();
var stringBuilder = new StringBuilder();

// if we need to fix the history
// If we need to fix the history
if (firstHistory != null && firstHistory.StartsWith("pkg_"))
{
var fixedQueue = new Queue<string>(SaveData.History.Count);
Expand Down Expand Up @@ -59,6 +59,15 @@ internal static void FixSaveFile()
SaveData.Highest = fixedDictionaryHighest;
}

if (!SaveData.UnlockedMasters.Any())
{
var unlockedHighest = SaveData.Highest.Where(kv =>
kv.Value.ContainsKey(3) && kv.Value.TryGetValue(2, out var chartSave) && chartSave.Evaluate >= 4).Select(kv => kv.Key);
var folderCharts = AlbumManager.LoadedAlbums.Where(kv => kv.Value.Sheets.ContainsKey(2) && kv.Value.Sheets.ContainsKey(3) && !kv.Value.IsPackaged).Select(kv => kv.Key);
var concat = unlockedHighest.Concat(folderCharts);
SaveData.UnlockedMasters.UnionWith(concat);
}

// If we don't need to fix the FullCombo then return
if (!firstFullCombo.Equals(default(KeyValuePair<string, List<int>>)) &&
!firstFullCombo.Key.StartsWith("pkg_")) return;
Expand Down Expand Up @@ -127,7 +136,7 @@ internal static void SaveScore(string uid, int musicDifficulty, int score, float
if (!ModSettings.SavingEnabled) return;

var album = AlbumManager.GetByUid(uid);
if (album is null) return;
if (!album?.IsPackaged ?? true) return;

var newEvaluate = evaluate switch
{
Expand All @@ -140,7 +149,7 @@ internal static void SaveScore(string uid, int musicDifficulty, int score, float
_ => 0
};

var albumName = album.GetAlbumName();
var albumName = album.AlbumName;

// Create new album save
if (!SaveData.Highest.ContainsKey(albumName))
Expand All @@ -165,6 +174,9 @@ internal static void SaveScore(string uid, int musicDifficulty, int score, float
newScore.AccuracyStr = string.Create(CultureInfo.InvariantCulture, $"{newScore.Accuracy / 100:P2}");
newScore.Clear++;

if (musicDifficulty is 2 && AlbumManager.LoadedAlbums[albumName].Sheets.ContainsKey(3) && newScore.Evaluate >= 4)
SaveData.UnlockedMasters.Add(albumName);

if (miss != 0) return;

// If there were no misses then add the chart/difficulty to the FullCombo list
Expand Down
3 changes: 3 additions & 0 deletions ModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ internal static class ModSettings
{
private static MelonPreferences_Entry<bool> _verboseLogging;
private static MelonPreferences_Entry<bool> _savingEnabled;
private static MelonPreferences_Entry<bool> _enableLogWriteToFile;
public static bool VerboseLogging => _verboseLogging.Value;
public static bool SavingEnabled => _savingEnabled.Value;
public static bool LoggingToFileEnabled => _enableLogWriteToFile.Value;


internal static void Register()
Expand All @@ -16,6 +18,7 @@ internal static void Register()

_verboseLogging = category.CreateEntry("VerboseLogging", false, "Verbose Logging");
_savingEnabled = category.CreateEntry("SavingEnabled", true, "Enable Saving");
_enableLogWriteToFile = category.CreateEntry("LogWriteToFile", false, "Enable Log Write to File");
}
}
}
12 changes: 1 addition & 11 deletions Patches/SavePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,7 @@ private static void InjectCustomData()
DataHelper.hides.AddManagedRange(SaveData.Hides.GetAlbumUidsFromNames());
DataHelper.history.AddManagedRange(SaveData.History.GetAlbumUidsFromNames());
DataHelper.collections.AddManagedRange(SaveData.Collections.GetAlbumUidsFromNames());

// Wild one-liner to get the UIDs that should have unlocked masters
//
// Logic: Get all the charts where there is a master difficulty (3), and if the value of hard difficulty exists (2), make sure that its evaluate is an S rank. If it is, add it to the list
// Once the list has been lazily created, select only the keys (album_{nameOfFile}) from that list, and then get the UIDs from those album names, adding it to the game's data list
DataHelper.unlockMasters.AddManagedRange(SaveData.Highest.Where(kv =>
kv.Value.ContainsKey(3) && kv.Value.TryGetValue(2, out var chartSave) && chartSave.Evaluate >= 4).Select(kv => kv.Key).GetAlbumUidsFromNames());
DataHelper.unlockMasters.AddManagedRange(SaveData.UnlockedMasters.GetAlbumUidsFromNames());

if (!SaveData.SelectedAlbum.StartsWith("album_")) return;
DataHelper.selectedAlbumUid = "music_package_999";
Expand Down Expand Up @@ -416,10 +410,6 @@ private static void Postfix(PnlVictory __instance)

// If the chart has been played then enable the "HI-SCORE" UI element
var difficulty = GlobalDataBase.s_DbBattleStage.m_MapDifficulty;
if (difficulty is 2 && AlbumManager.LoadedAlbums[albumName].Sheets.ContainsKey(3) && highest[2].Evaluate >= 4)
{
DataHelper.unlockMasters.Add(GlobalDataBase.dbBattleStage.musicUid);
}
__instance.m_CurControls.highScoreTitle.enabled = PreviousScore != "-";
__instance.m_CurControls.highScoreTxt.enabled = PreviousScore != "-";

Expand Down
22 changes: 22 additions & 0 deletions Patches/SilenceLogPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using HarmonyLib;
using Il2CppPeroTools2.Log;

namespace CustomAlbums.Patches
{
internal class SilenceLogPatch
{
/// <summary>
/// Disables log write-to-file if it is set in MelonPreferences (it is by default).
/// </summary>
[HarmonyPatch(typeof(PeroLogConfig), nameof(PeroLogConfig.instance), MethodType.Getter)]
internal class LoadConfigPatch
{
private static void Postfix(ref PeroLogConfig __result)
{
if (ModSettings.LoggingToFileEnabled) return;
__result.m_IsLogToFile = false;
}
}

}
}
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.0.1.0")]
[assembly: AssemblyFileVersion("4.0.1.0")]
[assembly: MelonInfo(typeof(CustomAlbums.Main), "CustomAlbums", "4.0.1", "Team Baller")]
[assembly: AssemblyVersion("4.0.2.0")]
[assembly: AssemblyFileVersion("4.0.2.0")]
[assembly: MelonInfo(typeof(CustomAlbums.Main), "CustomAlbums", "4.0.2", "Team Baller")]
[assembly: MelonGame("PeroPeroGames", "MuseDash")]
[assembly: MelonColor(255, 0, 255, 150)]
2 changes: 1 addition & 1 deletion Utilities/SaveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static JsonObject GetChartSaveDataFromUid(this CustomAlbumsSave save, str

if (album is null) return null;

var key = album!.GetAlbumName();
var key = album!.AlbumName;
return new JsonObject
{
{ nameof(save.Highest), JsonNode.Parse(JsonSerializer.Serialize(save.Highest.GetValueOrDefault(key))) },
Expand Down

0 comments on commit f22cdc1

Please sign in to comment.