diff --git a/ProjectObsidian/Injection/Injection.cs b/ProjectObsidian/Injection/Injection.cs index dcd5416..652909a 100644 --- a/ProjectObsidian/Injection/Injection.cs +++ b/ProjectObsidian/Injection/Injection.cs @@ -22,8 +22,8 @@ static ExecutionHook() { Engine.Current.OnReady += () => { - ShaderInjection.AppendShaders(); - + ShaderInjection.AppendShaders(); + 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