From 59e8eb68b156981b63a8ac3d94f07718e6a875b6 Mon Sep 17 00:00:00 2001 From: Loloppe Date: Sat, 14 Sep 2024 18:06:06 -0400 Subject: [PATCH] Fixed BSML Parsing --- Source/7_Utils/BSMLUtility.cs | 8 +++++--- Source/8_UI/ReeUIComponentV2.cs | 3 ++- Source/Plugin.cs | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/7_Utils/BSMLUtility.cs b/Source/7_Utils/BSMLUtility.cs index fcda0de6..792c2e9f 100644 --- a/Source/7_Utils/BSMLUtility.cs +++ b/Source/7_Utils/BSMLUtility.cs @@ -3,6 +3,7 @@ using UnityEngine; using BeatSaberMarkupLanguage.Attributes; using System.Reflection; +using System.Threading.Tasks; namespace BeatLeader.Utils { public static class BSMLUtility { @@ -14,10 +15,11 @@ public static Sprite LoadSprite(string location) { if (location.Length > 1 && location.StartsWith("#")) { string text = location.Substring(1); sprite = FindSpriteCached(text); - } else Utilities.GetData(location, (byte[] data) => { - sprite = Utilities.LoadSpriteRaw(data); + } else { + var task = Task.Run(async () => await Utilities.LoadSpriteFromAssemblyAsync(location)); + sprite = task.GetAwaiter().GetResult(); sprite.texture.wrapMode = TextureWrapMode.Clamp; - }); + } if (sprite == null) { throw new Exception($"Can not find sprite located at [{location}]!"); diff --git a/Source/8_UI/ReeUIComponentV2.cs b/Source/8_UI/ReeUIComponentV2.cs index f1293a27..96c79cbb 100644 --- a/Source/8_UI/ReeUIComponentV2.cs +++ b/Source/8_UI/ReeUIComponentV2.cs @@ -200,8 +200,9 @@ private void DisposeIfNeeded() { _state = State.Uninitialized; } - private void ParseSelfIfNeeded() { + private async void ParseSelfIfNeeded() { if (_state != State.Uninitialized) return; + await MainMenuAwaiter.WaitForMainMenuAsync(); _state = State.Parsing; BSMLParser.Instance.Parse(GetBsmlForType(GetType()), gameObject, ParseHost); Content = Transform.GetChild(0); diff --git a/Source/Plugin.cs b/Source/Plugin.cs index 4d835bda..a96069f8 100644 --- a/Source/Plugin.cs +++ b/Source/Plugin.cs @@ -1,13 +1,13 @@ using BeatLeader.DataManager; using BeatLeader.UI.BSML_Addons; using BeatLeader.Utils; +using BeatSaberMarkupLanguage.Util; using Hive.Versioning; using IPA; using IPA.Config; using IPA.Config.Stores; using IPA.Loader; using JetBrains.Annotations; -using UnityEngine; using IPALogger = IPA.Logging.Logger; namespace BeatLeader { @@ -53,11 +53,14 @@ private static void InitializeConfig(Config config) { [UsedImplicitly] public void OnApplicationStart() { ObserveEnabled(); - SettingsPanelUI.AddTab(); - BSMLAddonsLoader.LoadAddons(); + MainMenuAwaiter.MainMenuInitializing += MainMenuInit; InteropLoader.Init(); } + public static void MainMenuInit() { + SettingsPanelUI.AddTab(); + BSMLAddonsLoader.LoadAddons(); + } private static void ObserveEnabled() { PluginConfig.OnEnabledChangedEvent += OnEnabledChanged; OnEnabledChanged(PluginConfig.Enabled);