From d04aa2dd869c1f02a6f19b0c72ceba2855cf2530 Mon Sep 17 00:00:00 2001 From: Pespiri Date: Tue, 28 Jan 2020 22:38:53 +0100 Subject: [PATCH 1/6] Updated for BSIPA4 --- CustomWalls/CustomWalls.csproj | 5 +- CustomWalls/Plugin.cs | 58 +++++++++++-------- CustomWalls/Settings/Configuration.cs | 27 +++------ .../Settings/Utilities/PluginConfig.cs | 2 +- CustomWalls/Utilities/Utils.cs | 6 +- CustomWalls/manifest.json | 1 - 6 files changed, 46 insertions(+), 53 deletions(-) diff --git a/CustomWalls/CustomWalls.csproj b/CustomWalls/CustomWalls.csproj index 6bc6dc6..7cb0487 100644 --- a/CustomWalls/CustomWalls.csproj +++ b/CustomWalls/CustomWalls.csproj @@ -60,8 +60,8 @@ $(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll False - - $(BeatSaberDir)\Libs\SemVer.1.2.0.0.dll + + $(BeatSaberDir)\Libs\SemVer.1.2.2.0.dll False @@ -127,5 +127,4 @@ copy "$(TargetPath)" "$(BeatSaberDir)\Plugins" - \ No newline at end of file diff --git a/CustomWalls/Plugin.cs b/CustomWalls/Plugin.cs index 546c7a9..774aa7c 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,36 @@ public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgPr } } + [OnEnable] public void OnEnable() => Load(); + [OnDisable] public void OnDisable() => Unload(); + [OnExit] 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 +73,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/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/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..b9686bc 100644 --- a/CustomWalls/manifest.json +++ b/CustomWalls/manifest.json @@ -10,7 +10,6 @@ "name": "CustomWalls", "version": "1.2.0", "dependsOn": { - "BSIPA": "^3.13.4", "BeatSaberMarkupLanguage": "^1.1.0", "BS Utils": "^1.4.0" }, From f4af3919fb61ae7ef8482858914abb930340cdba Mon Sep 17 00:00:00 2001 From: Pespiri Date: Thu, 27 Feb 2020 01:39:39 +0100 Subject: [PATCH 2/6] Updated for Beat Saber 1.8.0b1 --- CustomWalls/CustomWalls.csproj | 8 ++++++-- CustomWalls/Properties/AssemblyInfo.cs | 4 ++-- CustomWalls/Settings/UI/MaterialDetailsViewController.cs | 1 + CustomWalls/manifest.json | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CustomWalls/CustomWalls.csproj b/CustomWalls/CustomWalls.csproj index 7cb0487..6af7d55 100644 --- a/CustomWalls/CustomWalls.csproj +++ b/CustomWalls/CustomWalls.csproj @@ -48,12 +48,16 @@ $(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 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/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/manifest.json b/CustomWalls/manifest.json index b9686bc..08b7ba2 100644 --- a/CustomWalls/manifest.json +++ b/CustomWalls/manifest.json @@ -5,10 +5,10 @@ "#![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": { "BeatSaberMarkupLanguage": "^1.1.0", "BS Utils": "^1.4.0" From 1381b66dff02e76aa552debf5be45cddce4b075a Mon Sep 17 00:00:00 2001 From: Pespiri Date: Thu, 27 Feb 2020 02:07:24 +0100 Subject: [PATCH 3/6] Updated references --- CustomWalls/CustomWalls.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CustomWalls/CustomWalls.csproj b/CustomWalls/CustomWalls.csproj index 6af7d55..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 @@ -64,8 +64,8 @@ $(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll False - - $(BeatSaberDir)\Libs\SemVer.1.2.2.0.dll + + $(BeatSaberDir)\Libs\SemVer.dll False From a81d2a2ce8e002f66aa4727a062d294a161c9d4d Mon Sep 17 00:00:00 2001 From: Pespiri Date: Sat, 29 Feb 2020 02:27:54 +0100 Subject: [PATCH 4/6] Updated for Harmony2 --- CustomWalls/HarmonyPatches/CustomMaterialsPatches.cs | 6 +++--- CustomWalls/HarmonyPatches/Patches/WallPatch.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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; From 80cad3141d8bb7ee71adda9fc47cd010ce33c31d Mon Sep 17 00:00:00 2001 From: Pespiri Date: Sat, 29 Feb 2020 03:17:25 +0100 Subject: [PATCH 5/6] Cleanup --- CustomWalls/Plugin.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/CustomWalls/Plugin.cs b/CustomWalls/Plugin.cs index 774aa7c..f62786e 100644 --- a/CustomWalls/Plugin.cs +++ b/CustomWalls/Plugin.cs @@ -37,8 +37,6 @@ public void Init(IPALogger logger, Config config, PluginMetadata metadata) public void OnEnable() => Load(); [OnDisable] public void OnDisable() => Unload(); - [OnExit] - public void OnApplicationQuit() => Unload(); private void OnGameSceneLoaded() { From 96775ac284d20f2ada268f86ba1b928811adf10c Mon Sep 17 00:00:00 2001 From: Pespiri Date: Thu, 26 Mar 2020 17:28:53 +0100 Subject: [PATCH 6/6] Changed error description behaviour --- CustomWalls/Data/CustomMaterial.cs | 19 +++++++++------- .../UI/MaterialPreviewViewController.cs | 22 ++++++++++++++++++- .../Settings/UI/MaterialsFlowCoordinator.cs | 12 ++++++++-- .../Settings/UI/Views/materialPreview.bsml | 3 +++ 4 files changed, 45 insertions(+), 11 deletions(-) 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/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