Skip to content

Commit

Permalink
Merge pull request #134 from Kylemc1413/fix/1.34.4
Browse files Browse the repository at this point in the history
Update for game v1.35.0
  • Loading branch information
Meivyn authored Mar 16, 2024
2 parents 7745b93 + b28f446 commit aa49c45
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 410 deletions.
17 changes: 10 additions & 7 deletions source/SongCore/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public static class Collections
private static readonly List<string> _capabilities = new List<string>();
private static readonly List<BeatmapCharacteristicSO> _customCharacteristics = new List<BeatmapCharacteristicSO>();

internal static readonly string DataPath = Path.Combine(UnityGame.UserDataPath, "SongCore", "SongCoreExtraData.dat");
internal static readonly string DataPath = Path.Combine(UnityGame.UserDataPath, nameof(SongCore), "SongCoreExtraData.dat");
internal static readonly ConcurrentDictionary<string, string> LevelHashDictionary = new ConcurrentDictionary<string, string>();
internal static readonly ConcurrentDictionary<string, List<string>> HashLevelDictionary = new ConcurrentDictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
internal static readonly ConcurrentDictionary<string, string> LevelPathDictionary = new ConcurrentDictionary<string, string>();

internal static CustomBeatmapLevelPack? WipLevelPack;
internal static BeatmapLevelPack? WipLevelPack;
internal static ConcurrentDictionary<string, ExtraSongData> CustomSongsData = new ConcurrentDictionary<string, ExtraSongData>();

public static ReadOnlyCollection<string> capabilities => _capabilities.AsReadOnly();
Expand Down Expand Up @@ -61,18 +62,18 @@ internal static void AddExtraSongData(string hash, string path, string rawSongDa
return null;
}

public static ExtraSongData.DifficultyData? RetrieveDifficultyData(IDifficultyBeatmap beatmap)
public static ExtraSongData.DifficultyData? RetrieveDifficultyData(BeatmapLevel beatmapLevel, BeatmapKey beatmapKey)
{
ExtraSongData? songData = null;

if (beatmap.level is CustomPreviewBeatmapLevel customLevel)
if (!beatmapLevel.hasPrecalculatedData)
{
songData = RetrieveExtraSongData(Hashing.GetCustomLevelHash(customLevel));
songData = RetrieveExtraSongData(Hashing.GetCustomLevelHash(beatmapLevel));
}

var diffData = songData?._difficulties.FirstOrDefault(x =>
x._difficulty == beatmap.difficulty && (x._beatmapCharacteristicName == beatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.characteristicNameLocalizationKey ||
x._beatmapCharacteristicName == beatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName));
x._difficulty == beatmapKey.difficulty && (x._beatmapCharacteristicName == beatmapKey.beatmapCharacteristic.characteristicNameLocalizationKey ||
x._beatmapCharacteristicName == beatmapKey.beatmapCharacteristic.serializedName));

return diffData;
}
Expand Down Expand Up @@ -123,6 +124,8 @@ public static void RegisterCapability(string capability)
newChar._containsRotationEvents = containsRotationEvents;
newChar._sortingOrder = sortingOrder;

newChar.name = serializedName + "BeatmapCharacteristic";

if (_customCharacteristics.All(x => x.serializedName != newChar.serializedName))
{
_customCharacteristics.Add(newChar);
Expand Down
12 changes: 4 additions & 8 deletions source/SongCore/Data/SongFolderEntries.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SongCore.OverrideClasses;
using SongCore.OverrideClasses;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -34,10 +34,9 @@ public SongFolderEntry(string name, string path, FolderLevelPack pack, string im

public class SeperateSongFolder
{
public readonly ConcurrentDictionary<string, CustomPreviewBeatmapLevel> Levels = new ConcurrentDictionary<string, CustomPreviewBeatmapLevel>();
public readonly ConcurrentDictionary<string, BeatmapLevel> Levels = new ConcurrentDictionary<string, BeatmapLevel>();

public SongFolderEntry SongFolderEntry { get; private set; }
public SongCoreCustomLevelCollection LevelCollection { get; private set; } = null;
public SongCoreCustomBeatmapLevelPack LevelPack { get; private set; } = null;
public SeperateSongFolder? CacheFolder { get; private set; }

Expand All @@ -48,7 +47,6 @@ public SeperateSongFolder(SongFolderEntry folderEntry, SeperateSongFolder? cache

if (folderEntry.Pack == FolderLevelPack.NewPack)
{
LevelCollection = new SongCoreCustomLevelCollection(Levels.Values.ToArray());
var image = UI.BasicUI.FolderIcon!;

if (!string.IsNullOrEmpty(folderEntry.ImagePath))
Expand All @@ -67,7 +65,7 @@ public SeperateSongFolder(SongFolderEntry folderEntry, SeperateSongFolder? cache
}
}

LevelPack = new SongCoreCustomBeatmapLevelPack(CustomLevelLoader.kCustomLevelPackPrefixId + folderEntry.Name, folderEntry.Name, image, LevelCollection);
LevelPack = new SongCoreCustomBeatmapLevelPack(CustomLevelLoader.kCustomLevelPackPrefixId + folderEntry.Name, folderEntry.Name, image, Levels.Values.ToArray());
}
}

Expand All @@ -76,9 +74,7 @@ public SeperateSongFolder(SongFolderEntry folderEntry, UnityEngine.Sprite image)
SongFolderEntry = folderEntry;
if (folderEntry.Pack == FolderLevelPack.NewPack)
{
LevelCollection = new SongCoreCustomLevelCollection(Levels.Values.ToArray());

LevelPack = new SongCoreCustomBeatmapLevelPack(CustomLevelLoader.kCustomLevelPackPrefixId + folderEntry.Name, folderEntry.Name, image, LevelCollection);
LevelPack = new SongCoreCustomBeatmapLevelPack(CustomLevelLoader.kCustomLevelPackPrefixId + folderEntry.Name, folderEntry.Name, image, Levels.Values.ToArray());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using HarmonyLib;

/*
Expand All @@ -12,7 +13,7 @@ internal class AnnotatedBeatmapLevelCollectionCell_RefreshAvailabilityAsync
{
private static void Postfix(AnnotatedBeatmapLevelCollectionCell __instance)
{
if (__instance._annotatedBeatmapLevelCollection is CustomBeatmapLevelPack)
if (__instance._beatmapLevelPack.packID.StartsWith(CustomLevelLoader.kCustomLevelPackPrefixId, StringComparison.Ordinal))
{
__instance.SetDownloadIconVisible(false);
}
Expand Down
33 changes: 8 additions & 25 deletions source/SongCore/HarmonyPatches/BeatmapVersionDetectionPatch.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
using System;
using System.Text.RegularExpressions;
using HarmonyLib;
using JetBrains.Annotations;

namespace SongCore.HarmonyPatches
{
// This patch fixes the base game implementation, which fails with maps that have no version declared.
// Without this patch affected maps don't load when selected. It is also 100 times faster on average.
[HarmonyPatch(typeof(BeatmapSaveDataHelpers), nameof(BeatmapSaveDataHelpers.GetVersion))]
[UsedImplicitly]
/// <summary>
/// This patch fixes the base game implementation, which fails with maps that have no version declared.
/// Without this patch affected maps don't load when selected.
/// </summary>
[HarmonyPatch(typeof(BeatmapSaveDataHelpers.VersionSerializedData), nameof(BeatmapSaveDataHelpers.VersionSerializedData.v), MethodType.Getter)]
internal static class BeatmapVersionDetectionPatch
{
private static readonly Regex VersionRegex = new Regex(
@"""_?version""\s*:\s*""(?<version>[0-9]+\.[0-9]+\.?[0-9]?)""",
RegexOptions.Compiled | RegexOptions.CultureInvariant
);

private static readonly Version FallbackVersion = new Version("2.0.0");

[UsedImplicitly]
private static bool Prefix(string data, ref Version __result)
private static void Postfix(ref string? __result)
{
var truncatedText = data.Substring(0, 50);
var match = VersionRegex.Match(truncatedText);
if (!match.Success)
{
__result = FallbackVersion;
return false;
}

__result = new Version(match.Groups["version"].Value);
return false;
__result ??= BeatmapSaveDataHelpers.noVersion.ToString();
}
}
}
}
39 changes: 16 additions & 23 deletions source/SongCore/HarmonyPatches/CosmeticCharacteristicsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ private static bool Prefix()
if (Plugin.Configuration.DisableRotationSpawnLinesOverride)
return true;

var beatmap = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap;
if (beatmap == null)
var sceneSetupData = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData;
if (sceneSetupData.beatmapLevel == null)
return true;
var beatmapData = Collections.RetrieveDifficultyData(beatmap);
var beatmapData = Collections.RetrieveDifficultyData(sceneSetupData.beatmapLevel, sceneSetupData.beatmapKey);
if (beatmapData == null)
return true;
if (beatmapData._showRotationNoteSpawnLines == null)
Expand All @@ -49,24 +49,23 @@ private static void Prefix(GameplayCoreInstaller __instance)

sceneSetupData = __instance._sceneSetupData;

var diffBeatmapLevel = sceneSetupData.difficultyBeatmap.level;
var level = diffBeatmapLevel is CustomBeatmapLevel ? diffBeatmapLevel as CustomPreviewBeatmapLevel : null;
if (level == null)
var beatmapLevel = sceneSetupData.beatmapLevel;
if (beatmapLevel.hasPrecalculatedData)
{
diffData = null;
return;
}
diffData = Collections.RetrieveDifficultyData(sceneSetupData.difficultyBeatmap);
diffData = Collections.RetrieveDifficultyData(beatmapLevel, sceneSetupData.beatmapKey);
if (diffData == null)
return;
if (diffData._oneSaber != null && !Plugin.Configuration.DisableOneSaberOverride)
{
numberOfColors = sceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.numberOfColors;
sceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic._numberOfColors = diffData._oneSaber.Value == true ? 1 : 2;
numberOfColors = sceneSetupData.beatmapKey.beatmapCharacteristic.numberOfColors;
sceneSetupData.beatmapKey.beatmapCharacteristic._numberOfColors = diffData._oneSaber.Value == true ? 1 : 2;
}

}
private static void Postfix(GameplayCoreInstaller __instance)
private static void Postfix()
{
if (Plugin.Configuration.DisableOneSaberOverride)
return;
Expand All @@ -75,7 +74,7 @@ private static void Postfix(GameplayCoreInstaller __instance)

if (diffData._oneSaber != null && !Plugin.Configuration.DisableOneSaberOverride)
{
sceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic._numberOfColors = numberOfColors;
sceneSetupData.beatmapKey.beatmapCharacteristic._numberOfColors = numberOfColors;
}
}

Expand All @@ -86,19 +85,13 @@ private static void Postfix(GameplayCoreInstaller __instance)
[HarmonyPatch(nameof(BeatmapCharacteristicSegmentedControlController.SetData), MethodType.Normal)]
internal class CosmeticCharacteristicsPatch
{
private static void Postfix(BeatmapCharacteristicSegmentedControlController __instance, IReadOnlyList<IDifficultyBeatmapSet> difficultyBeatmapSets, BeatmapCharacteristicSO selectedBeatmapCharacteristic)
private static void Postfix(BeatmapCharacteristicSegmentedControlController __instance, BeatmapCharacteristicSO selectedBeatmapCharacteristic)
{
if (!Plugin.Configuration.DisplayCustomCharacteristics) return;

var diffBeatmapSetsBeatmaps = difficultyBeatmapSets.FirstOrDefault().difficultyBeatmaps;
if (diffBeatmapSetsBeatmaps == null) return;
var diffBeatmapItem = diffBeatmapSetsBeatmaps.FirstOrDefault();
if (diffBeatmapItem == null) return;
var diffBeatmapLevel = diffBeatmapItem.level;
var level = Object.FindObjectOfType<StandardLevelDetailViewController>()._beatmapLevel;

var level = diffBeatmapLevel is CustomBeatmapLevel ? diffBeatmapLevel as CustomPreviewBeatmapLevel : null;

if (level == null) return;
if (level.hasPrecalculatedData) return;
var songData = Collections.RetrieveExtraSongData(Hashing.GetCustomLevelHash(level));

if (songData == null) return;
Expand All @@ -121,9 +114,9 @@ private static void Postfix(BeatmapCharacteristicSegmentedControlController __in
if (detail != null)
{
Sprite sprite = characteristic.icon;
if (detail._characteristicIconFilePath != null)
sprite = Utilities.Utils.LoadSpriteFromFile(Path.Combine(level.customLevelPath, detail._characteristicIconFilePath)) ?? characteristic.icon;
string label = detail._characteristicLabel ?? Polyglot.Localization.Get(characteristic.descriptionLocalizationKey);
if (detail._characteristicIconFilePath != null && Collections.LevelPathDictionary.TryGetValue(level.levelID, out var customLevelPath))
sprite = Utilities.Utils.LoadSpriteFromFile(Path.Combine(customLevelPath, detail._characteristicIconFilePath)) ?? characteristic.icon;
string label = detail._characteristicLabel ?? BGLib.Polyglot.Localization.Get(characteristic.descriptionLocalizationKey);
newDataItems.Add(new IconSegmentedControl.DataItem(sprite, label));
}
else
Expand Down
Loading

0 comments on commit aa49c45

Please sign in to comment.