diff --git a/CustomWalls/CustomWalls.csproj b/CustomWalls/CustomWalls.csproj index 6bc6dc6..837b543 100644 --- a/CustomWalls/CustomWalls.csproj +++ b/CustomWalls/CustomWalls.csproj @@ -32,8 +32,8 @@ false - - $(BeatSaberDir)\Libs\0Harmony.1.2.0.1.dll + + $(BeatSaberDir)\Libs\0Harmony.dll False @@ -48,20 +48,24 @@ $(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll False + + $(BeatSaberDir)\Beat Saber_Data\Managed\HMRendering.dll + False + $(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\MainAssembly.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll False $(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll False - - $(BeatSaberDir)\Libs\SemVer.1.2.0.0.dll + + $(BeatSaberDir)\Libs\SemVer.dll False @@ -127,5 +131,4 @@ copy "$(TargetPath)" "$(BeatSaberDir)\Plugins" - \ No newline at end of file diff --git a/CustomWalls/Data/CustomMaterial.cs b/CustomWalls/Data/CustomMaterial.cs index 8dcdddb..195f6f8 100644 --- a/CustomWalls/Data/CustomMaterial.cs +++ b/CustomWalls/Data/CustomMaterial.cs @@ -13,6 +13,7 @@ public class CustomMaterial public MaterialDescriptor Descriptor { get; } public GameObject GameObject { get; } public Renderer MaterialRenderer { get; } + public string ErrorMessage { get; } = string.Empty; public CustomMaterial(string fileName) { @@ -37,13 +38,14 @@ public CustomMaterial(string fileName) { MaterialName = "Invalid Wall (Delete it!)", AuthorName = fileName, - Description = $"File: '{fileName}'" + + Icon = Utils.GetErrorIcon() + }; + + ErrorMessage = $"File: '{fileName}'" + "\n\nThis file failed to load." + "\n\nThis may have been caused by having duplicated files," + " another wall with the same name already exists or that the custom wall is simply just broken." + - "\n\nThe best thing is probably just to delete it!", - Icon = Utils.GetErrorIcon() - }; + "\n\nThe best thing is probably just to delete it!"; FileName = "DefaultMaterials"; } @@ -82,13 +84,14 @@ public CustomMaterial(byte[] materialObject, string name) { MaterialName = "Internal Error (Report it!)", AuthorName = $@"internalResource\{name}", - Description = $@"File: 'internalResource\\{name}'" + + Icon = Utils.GetErrorIcon() + }; + + ErrorMessage = $@"File: 'internalResource\\{name}'" + "\n\nAn internal asset has failed to load." + "\n\nThis shouldn't have happened and should be reported!" + " Remember to include the log related to this incident." + - "\n\nDiscord: Pespiri#5919", - Icon = Utils.GetErrorIcon() - }; + "\n\nDiscord: Pespiri#5919"; FileName = "DefaultMaterials"; } diff --git a/CustomWalls/HarmonyPatches/CustomMaterialsPatches.cs b/CustomWalls/HarmonyPatches/CustomMaterialsPatches.cs index b434a3e..da775a0 100644 --- a/CustomWalls/HarmonyPatches/CustomMaterialsPatches.cs +++ b/CustomWalls/HarmonyPatches/CustomMaterialsPatches.cs @@ -1,4 +1,4 @@ -using Harmony; +using HarmonyLib; using System.Reflection; namespace CustomWalls.HarmonyPatches @@ -8,7 +8,7 @@ namespace CustomWalls.HarmonyPatches /// public class CustomMaterialsPatches { - private static HarmonyInstance instance; + private static Harmony instance; public static bool IsPatched { get; private set; } public const string InstanceId = "com.pespiri.beatsaber.pixiedust"; @@ -19,7 +19,7 @@ internal static void ApplyHarmonyPatches() { if (instance == null) { - instance = HarmonyInstance.Create(InstanceId); + instance = new Harmony(InstanceId); } instance.PatchAll(Assembly.GetExecutingAssembly()); diff --git a/CustomWalls/HarmonyPatches/Patches/WallPatch.cs b/CustomWalls/HarmonyPatches/Patches/WallPatch.cs index 0ac42ef..86b3afe 100644 --- a/CustomWalls/HarmonyPatches/Patches/WallPatch.cs +++ b/CustomWalls/HarmonyPatches/Patches/WallPatch.cs @@ -2,7 +2,7 @@ using CustomWalls.Data; using CustomWalls.Settings; using CustomWalls.Utilities; -using Harmony; +using HarmonyLib; using System; using UnityEngine; diff --git a/CustomWalls/Plugin.cs b/CustomWalls/Plugin.cs index 546c7a9..f62786e 100644 --- a/CustomWalls/Plugin.cs +++ b/CustomWalls/Plugin.cs @@ -10,21 +10,22 @@ using System.IO; using System.Linq; using UnityEngine; -using UnityEngine.SceneManagement; using IPALogger = IPA.Logging.Logger; namespace CustomWalls { - public class Plugin : IBeatSaberPlugin, IDisablablePlugin + [Plugin(RuntimeOptions.DynamicInit)] + public class Plugin { public static string PluginName => "CustomWalls"; public static SemVer.Version PluginVersion { get; private set; } = new SemVer.Version("0.0.0"); - public static string PluginAssetPath => Path.Combine(BeatSaber.InstallPath, "CustomWalls"); + public static string PluginAssetPath => Path.Combine(UnityGame.InstallPath, "CustomWalls"); - public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgProvider, PluginLoader.PluginMetadata metadata) + [Init] + public void Init(IPALogger logger, Config config, PluginMetadata metadata) { Logger.log = logger; - Configuration.Init(cfgProvider); + Configuration.Init(config); if (metadata?.Version != null) { @@ -32,41 +33,34 @@ public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgPr } } + [OnEnable] public void OnEnable() => Load(); + [OnDisable] public void OnDisable() => Unload(); - public void OnApplicationQuit() => Unload(); - public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) + private void OnGameSceneLoaded() { - if (nextScene.name == "GameCore") - { - MaterialUtils.CurrentColorManager = Resources.FindObjectsOfTypeAll().LastOrDefault(); + MaterialUtils.CurrentColorManager = Resources.FindObjectsOfTypeAll().LastOrDefault(); - CustomMaterial customMaterial = MaterialAssetLoader.CustomMaterialObjects[MaterialAssetLoader.SelectedMaterial]; - if (customMaterial.Descriptor.DisablesScore - || Configuration.UserDisabledScores) - { - ScoreUtility.DisableScoreSubmission("Material"); - } - else if (ScoreUtility.ScoreIsBlocked) - { - ScoreUtility.EnableScoreSubmission("Material"); - } + CustomMaterial customMaterial = MaterialAssetLoader.CustomMaterialObjects[MaterialAssetLoader.SelectedMaterial]; + if (customMaterial.Descriptor.DisablesScore + || Configuration.UserDisabledScores) + { + ScoreUtility.DisableScoreSubmission("Material"); + } + else if (ScoreUtility.ScoreIsBlocked) + { + ScoreUtility.EnableScoreSubmission("Material"); } } - public void OnApplicationStart() { } - public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { } - public void OnSceneUnloaded(Scene scene) { } - public void OnUpdate() { } - public void OnFixedUpdate() { } - private void Load() { Configuration.Load(); MaterialAssetLoader.Load(); CustomMaterialsPatches.ApplyHarmonyPatches(); SettingsUI.CreateMenu(); + AddEvents(); Logger.log.Info($"{PluginName} v.{PluginVersion} has started."); } @@ -77,6 +71,18 @@ private void Unload() CustomMaterialsPatches.RemoveHarmonyPatches(); Configuration.Save(); MaterialAssetLoader.Clear(); + RemoveEvents(); + } + + private void AddEvents() + { + RemoveEvents(); + BS_Utils.Utilities.BSEvents.gameSceneLoaded += OnGameSceneLoaded; + } + + private void RemoveEvents() + { + BS_Utils.Utilities.BSEvents.gameSceneLoaded -= OnGameSceneLoaded; } } } diff --git a/CustomWalls/Properties/AssemblyInfo.cs b/CustomWalls/Properties/AssemblyInfo.cs index 0a25eba..d450d47 100644 --- a/CustomWalls/Properties/AssemblyInfo.cs +++ b/CustomWalls/Properties/AssemblyInfo.cs @@ -28,5 +28,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/CustomWalls/Settings/Configuration.cs b/CustomWalls/Settings/Configuration.cs index a3372d5..0098dce 100644 --- a/CustomWalls/Settings/Configuration.cs +++ b/CustomWalls/Settings/Configuration.cs @@ -1,44 +1,31 @@ using CustomWalls.Settings.Utilities; using IPA.Config; -using IPA.Utilities; +using IPA.Config.Stores; namespace CustomWalls.Settings { public class Configuration { - private static Ref config; - private static IConfigProvider configProvider; - public static string CurrentlySelectedMaterial { get; internal set; } public static bool EnableObstacleFrame { get; internal set; } public static bool UserDisabledScores { get; internal set; } - internal static void Init(IConfigProvider cfgProvider) + internal static void Init(Config config) { - configProvider = cfgProvider; - config = cfgProvider.MakeLink((p, v) => - { - if (v.Value == null || v.Value.RegenerateConfig) - { - p.Store(v.Value = new PluginConfig() { RegenerateConfig = false }); - } - config = v; - }); + PluginConfig.Instance = config.Generated(); } internal static void Load() { - CurrentlySelectedMaterial = config.Value.SelectedWallMaterial; - EnableObstacleFrame = config.Value.EnableObstacleFrame; + CurrentlySelectedMaterial = PluginConfig.Instance.SelectedWallMaterial; + EnableObstacleFrame = PluginConfig.Instance.EnableObstacleFrame; } internal static void Save() { - config.Value.SelectedWallMaterial = CurrentlySelectedMaterial; - config.Value.EnableObstacleFrame = EnableObstacleFrame; - - configProvider.Store(config.Value); + PluginConfig.Instance.SelectedWallMaterial = CurrentlySelectedMaterial; + PluginConfig.Instance.EnableObstacleFrame = EnableObstacleFrame; } } } diff --git a/CustomWalls/Settings/UI/MaterialDetailsViewController.cs b/CustomWalls/Settings/UI/MaterialDetailsViewController.cs index 47fd66b..2265cdc 100644 --- a/CustomWalls/Settings/UI/MaterialDetailsViewController.cs +++ b/CustomWalls/Settings/UI/MaterialDetailsViewController.cs @@ -2,6 +2,7 @@ using BeatSaberMarkupLanguage.ViewControllers; using CustomWalls.Data; using CustomWalls.Utilities; +using HMUI; using TMPro; namespace CustomWalls.Settings.UI diff --git a/CustomWalls/Settings/UI/MaterialPreviewViewController.cs b/CustomWalls/Settings/UI/MaterialPreviewViewController.cs index 4bb1a04..0d3201f 100644 --- a/CustomWalls/Settings/UI/MaterialPreviewViewController.cs +++ b/CustomWalls/Settings/UI/MaterialPreviewViewController.cs @@ -1,9 +1,29 @@ -using BeatSaberMarkupLanguage.ViewControllers; +using BeatSaberMarkupLanguage.Attributes; +using BeatSaberMarkupLanguage.ViewControllers; +using CustomWalls.Data; +using CustomWalls.Utilities; +using HMUI; namespace CustomWalls.Settings.UI { internal class MaterialPreviewViewController : BSMLResourceViewController { public override string ResourceName => "CustomWalls.Settings.UI.Views.materialPreview.bsml"; + + [UIComponent("error-description")] + public TextPageScrollView errorDescription; + + public void OnMaterialWasChanged(CustomMaterial customMaterial) + { + if (!string.IsNullOrWhiteSpace(customMaterial?.ErrorMessage)) + { + errorDescription.gameObject.SetActive(true); + errorDescription.SetText($"{customMaterial.Descriptor?.MaterialName}:\n\n{Utils.SafeUnescape(customMaterial.ErrorMessage)}"); + } + else + { + errorDescription.gameObject.SetActive(false); + } + } } } diff --git a/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs b/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs index d3b1228..dacf9b7 100644 --- a/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs +++ b/CustomWalls/Settings/UI/MaterialsFlowCoordinator.cs @@ -25,7 +25,16 @@ public void Awake() if (!materialsListView) { materialsListView = BeatSaberUI.CreateViewController(); - materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged; + + if (materialsDescriptionView) + { + materialsListView.customMaterialChanged += materialsDescriptionView.OnMaterialWasChanged; + } + + if (materialsPreviewView) + { + materialsListView.customMaterialChanged += materialsPreviewView.OnMaterialWasChanged; + } } } @@ -48,7 +57,6 @@ protected override void DidActivate(bool firstActivation, ActivationType activat protected override void BackButtonWasPressed(ViewController topViewController) { - // Dismiss ourselves BeatSaberUI.MainFlowCoordinator.DismissFlowCoordinator(this, null, false); } } diff --git a/CustomWalls/Settings/UI/Views/materialPreview.bsml b/CustomWalls/Settings/UI/Views/materialPreview.bsml index f5607f6..47c7e7b 100644 --- a/CustomWalls/Settings/UI/Views/materialPreview.bsml +++ b/CustomWalls/Settings/UI/Views/materialPreview.bsml @@ -2,4 +2,7 @@ + + + \ No newline at end of file diff --git a/CustomWalls/Settings/Utilities/PluginConfig.cs b/CustomWalls/Settings/Utilities/PluginConfig.cs index 5d08616..d6bae82 100644 --- a/CustomWalls/Settings/Utilities/PluginConfig.cs +++ b/CustomWalls/Settings/Utilities/PluginConfig.cs @@ -2,7 +2,7 @@ { public class PluginConfig { - public bool RegenerateConfig = true; + public static PluginConfig Instance { get; set; } public string SelectedWallMaterial; public bool EnableObstacleFrame = true; diff --git a/CustomWalls/Utilities/Utils.cs b/CustomWalls/Utilities/Utils.cs index 16d8288..979ed6a 100644 --- a/CustomWalls/Utilities/Utils.cs +++ b/CustomWalls/Utilities/Utils.cs @@ -172,10 +172,10 @@ public static bool IsPluginEnabled(string pluginName) { if (IsPluginPresent(pluginName)) { - PluginLoader.PluginInfo pluginInfo = PluginManager.GetPluginFromId(pluginName); - if (pluginInfo?.Metadata != null) + PluginMetadata metadata = PluginManager.GetPluginFromId(pluginName); + if (metadata != null) { - return PluginManager.IsEnabled(pluginInfo.Metadata); + return PluginManager.IsEnabled(metadata); } } diff --git a/CustomWalls/manifest.json b/CustomWalls/manifest.json index 7838ce0..08b7ba2 100644 --- a/CustomWalls/manifest.json +++ b/CustomWalls/manifest.json @@ -5,12 +5,11 @@ "#![CustomWalls.Resources.description.md]", "Change the all the materials!" ], - "gameVersion": "1.6.2", + "gameVersion": "1.8.0", "id": "CustomWalls", "name": "CustomWalls", - "version": "1.2.0", + "version": "1.3.0", "dependsOn": { - "BSIPA": "^3.13.4", "BeatSaberMarkupLanguage": "^1.1.0", "BS Utils": "^1.4.0" },