From 7935db13d42649571f531fad30d9747fba1cf81a Mon Sep 17 00:00:00 2001 From: Nytra <14206961+Nytra@users.noreply.github.com> Date: Thu, 28 Nov 2024 03:54:22 +0000 Subject: [PATCH 1/2] Add preliminary button to toggle core assembly in the Create New menu --- ProjectObsidian/Injection/Injection.cs | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ProjectObsidian/Injection/Injection.cs b/ProjectObsidian/Injection/Injection.cs index dcd5416..03ff7be 100644 --- a/ProjectObsidian/Injection/Injection.cs +++ b/ProjectObsidian/Injection/Injection.cs @@ -5,6 +5,7 @@ using FrooxEngine; using FrooxEngine.ProtoFlux.Core; using Obsidian.Shaders; +using System.Collections.Generic; namespace Obsidian { @@ -15,6 +16,9 @@ internal static class ExecutionHook private static Type? __connectorType; private static Type? __connectorTypes; + private static AssemblyTypeRegistry obsidianRegistry; + private static bool registered = true; + // Static constructor for initializing the hook static ExecutionHook() { @@ -22,8 +26,29 @@ static ExecutionHook() { Engine.Current.OnReady += () => { - ShaderInjection.AppendShaders(); - + ShaderInjection.AppendShaders(); + DevCreateNewForm.AddAction("Plugins", "Register/Unregister Obsidian Assembly", (Slot s) => + { + s.Destroy(); + var glob = (List)typeof(GlobalTypeRegistry).GetField("_coreAssemblies", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); + if (registered) + { + foreach (var thing in glob.ToList()) + { + if (thing.Assembly == Assembly.GetExecutingAssembly()) + { + obsidianRegistry = thing; + glob.Remove(thing); + } + } + registered = false; + } + else + { + glob.Add(obsidianRegistry); + registered = true; + } + }); }; } catch (Exception e) From 033123c5f547c268e16743c315e770006ace8e46 Mon Sep 17 00:00:00 2001 From: Nytra <14206961+Nytra@users.noreply.github.com> Date: Thu, 28 Nov 2024 04:55:54 +0000 Subject: [PATCH 2/2] Switch to plugin settings in dash --- ProjectObsidian/Injection/Injection.cs | 27 +------ ProjectObsidian/Settings/MIDI_Settings.cs | 1 - ProjectObsidian/Settings/PluginSettings.cs | 83 ++++++++++++++++++++++ 3 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 ProjectObsidian/Settings/PluginSettings.cs diff --git a/ProjectObsidian/Injection/Injection.cs b/ProjectObsidian/Injection/Injection.cs index 03ff7be..652909a 100644 --- a/ProjectObsidian/Injection/Injection.cs +++ b/ProjectObsidian/Injection/Injection.cs @@ -5,7 +5,6 @@ using FrooxEngine; using FrooxEngine.ProtoFlux.Core; using Obsidian.Shaders; -using System.Collections.Generic; namespace Obsidian { @@ -16,9 +15,6 @@ internal static class ExecutionHook private static Type? __connectorType; private static Type? __connectorTypes; - private static AssemblyTypeRegistry obsidianRegistry; - private static bool registered = true; - // Static constructor for initializing the hook static ExecutionHook() { @@ -27,28 +23,7 @@ static ExecutionHook() Engine.Current.OnReady += () => { ShaderInjection.AppendShaders(); - DevCreateNewForm.AddAction("Plugins", "Register/Unregister Obsidian Assembly", (Slot s) => - { - s.Destroy(); - var glob = (List)typeof(GlobalTypeRegistry).GetField("_coreAssemblies", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); - if (registered) - { - foreach (var thing in glob.ToList()) - { - if (thing.Assembly == Assembly.GetExecutingAssembly()) - { - obsidianRegistry = thing; - glob.Remove(thing); - } - } - registered = false; - } - else - { - glob.Add(obsidianRegistry); - registered = true; - } - }); + Settings.GetActiveSetting(); }; } catch (Exception e) diff --git a/ProjectObsidian/Settings/MIDI_Settings.cs b/ProjectObsidian/Settings/MIDI_Settings.cs index 0614e33..81704b4 100644 --- a/ProjectObsidian/Settings/MIDI_Settings.cs +++ b/ProjectObsidian/Settings/MIDI_Settings.cs @@ -88,7 +88,6 @@ protected override void OnStart() _localeData.LocaleCode = "en"; _localeData.Authors = new List() { "Nytra" }; _localeData.Messages = new Dictionary(); - _localeData.Messages.Add("Settings.Category.Obsidian", "Obsidian"); _localeData.Messages.Add("Settings.MIDI_Settings", "MIDI Settings"); _localeData.Messages.Add("Settings.MIDI_Settings.RefreshDeviceLists", "Refresh Devices"); _localeData.Messages.Add("Settings.MIDI_Settings.InputDevices", "Input Devices"); diff --git a/ProjectObsidian/Settings/PluginSettings.cs b/ProjectObsidian/Settings/PluginSettings.cs new file mode 100644 index 0000000..28f904a --- /dev/null +++ b/ProjectObsidian/Settings/PluginSettings.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FrooxEngine; +using Elements.Core; +using Elements.Assets; +using Commons.Music.Midi; +using System.Reflection; + +namespace Obsidian; + +[SettingCategory("Obsidian")] +public class PluginSettings : SettingComponent +{ + public override bool UserspaceOnly => true; + + [NonPersistent] + [SettingIndicatorProperty(null, null, null, null, false, 0L)] + public readonly Sync CoreAssemblyLoaded; + + private LocaleData _localeData; + + private static AssemblyTypeRegistry obsidianRegistry; + + protected override void OnStart() + { + base.OnStart(); + _localeData = new LocaleData(); + _localeData.LocaleCode = "en"; + _localeData.Authors = new List() { "Nytra" }; + _localeData.Messages = new Dictionary(); + _localeData.Messages.Add("Settings.Category.Obsidian", "Obsidian"); + _localeData.Messages.Add("Settings.PluginSettings", "Plugin Settings"); + _localeData.Messages.Add("Settings.PluginSettings.CoreAssemblyLoaded", "Core Assembly Loaded"); + _localeData.Messages.Add("Settings.PluginSettings.ToggleCoreAssembly", "Toggle Core Assembly"); + + CoreAssemblyLoaded.Value = true; + + // Sometimes the locale is null in here, so wait a bit I guess + + RunInUpdates(15, () => + { + UpdateLocale(); + Settings.RegisterValueChanges(UpdateLocale); + }); + } + + protected override void OnDispose() + { + base.OnDispose(); + Settings.UnregisterValueChanges(UpdateLocale); + } + + private void UpdateLocale(LocaleSettings settings = null) + { + this.GetCoreLocale()?.Asset?.Data.LoadDataAdditively(_localeData); + } + + [SettingProperty(null, null, null, false, 0L, null, null)] + [SyncMethod(typeof(Action), new string[] { })] + public void ToggleCoreAssembly() + { + UniLog.Log("Toggle pressed"); + var glob = (List)typeof(GlobalTypeRegistry).GetField("_coreAssemblies", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); + if (CoreAssemblyLoaded) + { + foreach (var thing in glob.ToList()) + { + if (thing.Assembly == Assembly.GetExecutingAssembly()) + { + obsidianRegistry = thing; + glob.Remove(thing); + } + } + CoreAssemblyLoaded.Value = false; + } + else + { + glob.Add(obsidianRegistry); + CoreAssemblyLoaded.Value = true; + } + } +} \ No newline at end of file