Skip to content

Commit

Permalink
Merge pull request #130 from Kylemc1413/misc/optimization
Browse files Browse the repository at this point in the history
Couple of fixes for `Loader` and cleanup
  • Loading branch information
Meivyn authored Jan 21, 2024
2 parents d15f9e3 + c12c4d5 commit e4771cd
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 463 deletions.
2 changes: 0 additions & 2 deletions build/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.ComponentModel;
using System.Linq;
using Nuke.Common.Tooling;

[TypeConverter(typeof(TypeConverter<Configuration>))]
Expand Down
2 changes: 1 addition & 1 deletion source/SongCore/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void RegisterCapability(string capability)

newChar._icon = icon;
newChar._descriptionLocalizationKey = hintText;
newChar._serializedName= serializedName;
newChar._serializedName = serializedName;
newChar._characteristicNameLocalizationKey = characteristicName;
newChar._compoundIdPartName = compoundIdPartName;
newChar._requires360Movement = requires360Movement;
Expand Down
6 changes: 0 additions & 6 deletions source/SongCore/Data/SongData.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SongCore.Utilities;
using UnityEngine;
using UnityEngine.UI;
using static BloomPrePassBackgroundColorsGradientFromColorSchemeColors;

namespace SongCore.Data
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace SongCore.HarmonyPatches
[HarmonyPatch(typeof(AnnotatedBeatmapLevelCollectionCell), nameof(AnnotatedBeatmapLevelCollectionCell.RefreshAvailabilityAsync))]
internal class AnnotatedBeatmapLevelCollectionCell_RefreshAvailabilityAsync
{
private static void Postfix(AnnotatedBeatmapLevelCollectionCell __instance, IAnnotatedBeatmapLevelCollection ____annotatedBeatmapLevelCollection)
private static void Postfix(AnnotatedBeatmapLevelCollectionCell __instance)
{
if (____annotatedBeatmapLevelCollection is CustomBeatmapLevelPack)
if (__instance._annotatedBeatmapLevelCollection is CustomBeatmapLevelPack)
{
__instance.SetDownloadIconVisible(false);
}
Expand Down
116 changes: 0 additions & 116 deletions source/SongCore/HarmonyPatches/AprilFools.cs

This file was deleted.

27 changes: 10 additions & 17 deletions source/SongCore/HarmonyPatches/CosmeticCharacteristicsPatches.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using HMUI;
using IPA.Utilities;
using SongCore.Data;
using SongCore.Utilities;
using UnityEngine;
using static IPA.Logging.Logger;

namespace SongCore.HarmonyPatches
{
Expand Down Expand Up @@ -53,7 +47,7 @@ private static void Prefix(GameplayCoreInstaller __instance)
if (Plugin.Configuration.DisableOneSaberOverride)
return;

sceneSetupData = __instance.GetField<GameplayCoreSceneSetupData, GameplayCoreInstaller>("_sceneSetupData");
sceneSetupData = __instance._sceneSetupData;

var diffBeatmapLevel = sceneSetupData.difficultyBeatmap.level;
var level = diffBeatmapLevel is CustomBeatmapLevel ? diffBeatmapLevel as CustomPreviewBeatmapLevel : null;
Expand All @@ -68,7 +62,7 @@ private static void Prefix(GameplayCoreInstaller __instance)
if (diffData._oneSaber != null && !Plugin.Configuration.DisableOneSaberOverride)
{
numberOfColors = sceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.numberOfColors;
sceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.SetField("_numberOfColors", diffData._oneSaber.Value == true ? 1 : 2);
sceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic._numberOfColors = diffData._oneSaber.Value == true ? 1 : 2;
}

}
Expand All @@ -81,7 +75,7 @@ private static void Postfix(GameplayCoreInstaller __instance)

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

Expand All @@ -92,8 +86,7 @@ private static void Postfix(GameplayCoreInstaller __instance)
[HarmonyPatch(nameof(BeatmapCharacteristicSegmentedControlController.SetData), MethodType.Normal)]
internal class CosmeticCharacteristicsPatch
{
// public static OverrideClasses.CustomLevel previouslySelectedSong = null;
private static void Postfix(IReadOnlyList<IDifficultyBeatmapSet> difficultyBeatmapSets, BeatmapCharacteristicSO selectedBeatmapCharacteristic, ref List<BeatmapCharacteristicSO> ____beatmapCharacteristics, ref IconSegmentedControl ____segmentedControl)
private static void Postfix(BeatmapCharacteristicSegmentedControlController __instance, IReadOnlyList<IDifficultyBeatmapSet> difficultyBeatmapSets, BeatmapCharacteristicSO selectedBeatmapCharacteristic)
{
if (!Plugin.Configuration.DisplayCustomCharacteristics) return;

Expand All @@ -110,18 +103,18 @@ private static void Postfix(IReadOnlyList<IDifficultyBeatmapSet> difficultyBeatm

if (songData == null) return;
if (songData._characteristicDetails == null) return;
if (____segmentedControl == null) return;
if (__instance._segmentedControl == null) return;

if (songData._characteristicDetails.Length > 0)
{
var dataItems = ____segmentedControl.GetField<IconSegmentedControl.DataItem[], IconSegmentedControl>("_dataItems");
var dataItems = __instance._segmentedControl._dataItems;
List<IconSegmentedControl.DataItem> newDataItems = new List<IconSegmentedControl.DataItem>();

int i = 0;
int cell = 0;
foreach (var item in dataItems)
{
var characteristic = ____beatmapCharacteristics[i];
var characteristic = __instance._beatmapCharacteristics[i];
string serializedName = characteristic.serializedName;
ExtraSongData.CharacteristicDetails? detail = songData._characteristicDetails.Where(x => x._beatmapCharacteristicName == serializedName).FirstOrDefault();

Expand All @@ -139,13 +132,13 @@ private static void Postfix(IReadOnlyList<IDifficultyBeatmapSet> difficultyBeatm
}

if (characteristic == selectedBeatmapCharacteristic)
{
{
cell = i;
}
i++;
}
____segmentedControl.SetData(newDataItems.ToArray());
____segmentedControl.SelectCellWithNumber(cell);
__instance._segmentedControl.SetData(newDataItems.ToArray());
__instance._segmentedControl.SelectCellWithNumber(cell);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace SongCore.HarmonyPatches
[HarmonyPatch(nameof(BeatmapCharacteristicCollection.GetBeatmapCharacteristicBySerializedName), MethodType.Normal)]
internal class CustomCharacteristicsPatch
{
// public static OverrideClasses.CustomLevel previouslySelectedSong = null;
private static void Postfix(string serializedName, ref BeatmapCharacteristicSO __result)
{
if (__result == null)
Expand Down
47 changes: 7 additions & 40 deletions source/SongCore/HarmonyPatches/CustomSongColorsPatch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using IPA.Utilities;
using SongCore.Utilities;
using Utils = SongCore.Utilities.Utils;

Expand All @@ -12,55 +11,25 @@ internal class SceneTransitionPatch
{
private static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(StandardLevelScenesTransitionSetupDataSO), nameof(StandardLevelScenesTransitionSetupDataSO.Init),
new[]
{
typeof(string),
typeof(IDifficultyBeatmap),
typeof(IPreviewBeatmapLevel),
typeof(OverrideEnvironmentSettings),
typeof(ColorScheme),
typeof(ColorScheme),
typeof(GameplayModifiers),
typeof(PlayerSpecificSettings),
typeof(PracticeSettings),
typeof(string),
typeof(bool),
typeof(bool),
typeof(BeatmapDataCache),
typeof(RecordingToolManager.SetupData?)
});

yield return AccessTools.Method(typeof(MultiplayerLevelScenesTransitionSetupDataSO), nameof(MultiplayerLevelScenesTransitionSetupDataSO.Init),
new[]
{
typeof(string),
typeof(IPreviewBeatmapLevel),
typeof(BeatmapDifficulty),
typeof(BeatmapCharacteristicSO),
typeof(IDifficultyBeatmap),
typeof(ColorScheme),
typeof(GameplayModifiers),
typeof(PlayerSpecificSettings),
typeof(PracticeSettings),
typeof(bool)
});
yield return AccessTools.DeclaredMethod(typeof(StandardLevelScenesTransitionSetupDataSO), nameof(StandardLevelScenesTransitionSetupDataSO.Init));
yield return AccessTools.DeclaredMethod(typeof(MultiplayerLevelScenesTransitionSetupDataSO), nameof(MultiplayerLevelScenesTransitionSetupDataSO.Init));
}

private static void Prefix(ref IDifficultyBeatmap difficultyBeatmap, ref ColorScheme? overrideColorScheme)
{
if(overrideColorScheme != null)
// TODO: Remove this when it gets fixed.
if (overrideColorScheme != null)
{
if(overrideColorScheme._environmentColor0Boost.a == 0)
if (overrideColorScheme._environmentColor0Boost == default)
{
overrideColorScheme._environmentColor0Boost = overrideColorScheme._environmentColor0;
}
if (overrideColorScheme._environmentColor1Boost.a == 0)
if (overrideColorScheme._environmentColor1Boost == default)
{
overrideColorScheme._environmentColor1Boost = overrideColorScheme._environmentColor1;
}
}

if (difficultyBeatmap == null || !Plugin.Configuration.CustomSongNoteColors && !Plugin.Configuration.CustomSongEnvironmentColors && !Plugin.Configuration.CustomSongObstacleColors)
{
return;
Expand Down Expand Up @@ -113,8 +82,6 @@ private static void Prefix(ref IDifficultyBeatmap difficultyBeatmap, ref ColorSc
: Utils.ColorFromMapColor(songData._obstacleColor);
overrideColorScheme = new ColorScheme("SongCoreMapColorScheme", "SongCore Map Color Scheme", true, "SongCore Map Color Scheme", false, saberLeft, saberRight, envLeft,
envRight, envWhite, true, envLeftBoost, envRightBoost, envWhiteBoost, obstacle);
overrideColorScheme._environmentColorW = envWhite;
overrideColorScheme._environmentColorWBoost = envWhiteBoost;
}
}
}
12 changes: 4 additions & 8 deletions source/SongCore/HarmonyPatches/LevelSelectionPatch.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
using System.Globalization;
using HarmonyLib;
using TMPro;

namespace SongCore.HarmonyPatches
{
[HarmonyPatch(typeof(LevelListTableCell))]
[HarmonyPatch(nameof(LevelListTableCell.SetDataFromLevelAsync), MethodType.Normal)]
internal class LevelListTableCellSetDataFromLevel
{
private static void Postfix(IPreviewBeatmapLevel level, TextMeshProUGUI ____songAuthorText, TextMeshProUGUI ____songBpmText)
private static void Postfix(LevelListTableCell __instance, IPreviewBeatmapLevel level)
{
// Rounding BPM display for all maps, including official ones
____songBpmText.text = System.Math.Round(level.beatsPerMinute).ToString(CultureInfo.InvariantCulture);
__instance._songBpmText.text = System.Math.Round(level.beatsPerMinute).ToString(CultureInfo.InvariantCulture);

/* Plan B
IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew( async () => { var token = new CancellationTokenSource().Token; var audio = await level.GetPreviewAudioClipAsync(token); customLevel.SetField("_songDuration", audio.length); ____songDurationText.text = customLevel.songDuration.MinSecDurationText(); });
*/
if (!string.IsNullOrWhiteSpace(level.levelAuthorName))
{
____songAuthorText.richText = true;
__instance._songAuthorText.richText = true;
//Get PinkCore'd

string mapperColor = Plugin.Configuration.GreenMapperColor ? "89ff89" : "ff69b4";

____songAuthorText.text = $"<size=80%>{level.songAuthorName}</size> <size=90%>[<color=#{mapperColor}>{level.levelAuthorName.Replace(@"<", "<\u200B").Replace(@">", ">\u200B")}</color>]</size>";
__instance._songAuthorText.text = $"<size=80%>{level.songAuthorName}</size> <size=90%>[<color=#{mapperColor}>{level.levelAuthorName.Replace(@"<", "<\u200B").Replace(@">", ">\u200B")}</color>]</size>";
}
}
}
Expand Down
Loading

0 comments on commit e4771cd

Please sign in to comment.