LevelSelectionPatch.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using HarmonyLib;
  2. using SongCore.Utilities;
  3. using System.Diagnostics;
  4. using TMPro;
  5. using IPA;
  6. using System.Threading;
  7. namespace SongCore.HarmonyPatches
  8. {
  9. [HarmonyPatch(typeof(LevelCollectionViewController))]
  10. [HarmonyPatch("HandleLevelCollectionTableViewDidSelectLevel", MethodType.Normal)]
  11. class LevelPackLevelsSelectedPatch
  12. {
  13. // public static OverrideClasses.CustomLevel previouslySelectedSong = null;
  14. static void Prefix(LevelCollectionTableView tableView, IPreviewBeatmapLevel level)
  15. {
  16. if (level is CustomPreviewBeatmapLevel)
  17. {
  18. var customLevel = level as CustomPreviewBeatmapLevel;
  19. if (customLevel != null)
  20. {
  21. // Logging.Log(Utilities.Hashing.GetCustomLevelHash(customLevel));
  22. SongCore.Collections.AddSong(Utilities.Hashing.GetCustomLevelHash(customLevel), customLevel.customLevelPath);
  23. SongCore.Collections.SaveExtraSongData();
  24. }
  25. }
  26. }
  27. }
  28. }
  29. [HarmonyPatch(typeof(LevelListTableCell))]
  30. [HarmonyPatch("SetDataFromLevelAsync", MethodType.Normal)]
  31. public class LevelListTableCellSetDataFromLevel
  32. {
  33. static void Postfix(IPreviewBeatmapLevel level, bool isFavorite, ref TextMeshProUGUI ____songAuthorText, TextMeshProUGUI ____songDurationText)
  34. {
  35. if (!(level is CustomPreviewBeatmapLevel))
  36. return;
  37. var customLevel = level as CustomPreviewBeatmapLevel;
  38. /* Plan B
  39. 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(); });
  40. */
  41. ____songAuthorText.richText = true;
  42. if (!string.IsNullOrWhiteSpace(customLevel.levelAuthorName))
  43. ____songAuthorText.text = customLevel.songAuthorName + " <size=80%>[" + customLevel.levelAuthorName.Replace(@"<", "<\u200B").Replace(@">", ">\u200B") + "]</size>";
  44. }
  45. }
  46. /*
  47. [HarmonyPatch(typeof(LevelCollectionViewController))]
  48. [HarmonyPatch("RefreshLevelsAvailability", MethodType.Normal)]
  49. class LevelPackLevelsSelectedPatch
  50. {
  51. // public static OverrideClasses.CustomLevel previouslySelectedSong = null;
  52. static bool Prefix(IBeatmapLevelPack ____pack)
  53. {
  54. // Logging.logger.Info(____pack.packID);
  55. if (____pack.packID.Contains(CustomLevelLoader.kCustomLevelPackPrefixId))
  56. return false;
  57. else
  58. return true;
  59. }
  60. }
  61. */