From c83ed608ad3e9a0e61e955174329e041a824f1df Mon Sep 17 00:00:00 2001 From: xLinka Date: Tue, 2 Jul 2024 13:59:28 +0100 Subject: [PATCH] gonna slip this in --- ProjectObsidian/Injection/Injection.cs | 53 ++++++++++++++++++++ ProjectObsidian/Injection/ShaderInjection.cs | 39 ++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 ProjectObsidian/Injection/Injection.cs create mode 100644 ProjectObsidian/Injection/ShaderInjection.cs diff --git a/ProjectObsidian/Injection/Injection.cs b/ProjectObsidian/Injection/Injection.cs new file mode 100644 index 0000000..69686e4 --- /dev/null +++ b/ProjectObsidian/Injection/Injection.cs @@ -0,0 +1,53 @@ +using System; +using System.Linq; +using System.Reflection; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux.Core; + +namespace Obsidian +{ + [ImplementableClass(true)] + internal static class ExecutionHook + { + // Fields for reflective access + private static Type? __connectorType; + private static Type? __connectorTypes; + + // Static constructor for initializing the hook + static ExecutionHook() + { + try + { + Engine.Current.OnReady += () => + { + ShaderInjection.AppendShaders(); + + }; + } + catch (Exception e) + { + UniLog.Log($"Exception thrown during initialization: {e}"); + } + } + + // Method to instantiate the connector + private static DummyConnector InstantiateConnector() => new DummyConnector(); + + // Dummy connector class implementing IConnector + private class DummyConnector : IConnector + { + public IImplementable? Owner { get; private set; } + + public void ApplyChanges() { } + + public void AssignOwner(IImplementable owner) => Owner = owner; + + public void Destroy(bool destroyingWorld) { } + + public void Initialize() { } + + public void RemoveOwner() => Owner = null; + } + } +} diff --git a/ProjectObsidian/Injection/ShaderInjection.cs b/ProjectObsidian/Injection/ShaderInjection.cs new file mode 100644 index 0000000..e9e297a --- /dev/null +++ b/ProjectObsidian/Injection/ShaderInjection.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using FrooxEngine; +using SkyFrost.Base; +using FrooxEngine.Store; +using System.IO; +namespace Obsidian.Shaders +{ + internal class ShaderInjection + { + + + private static readonly List Shaders = new() + { + + }; + public static string ExtractSignature(Uri uri) + { + if (uri.Scheme != "resdb") + { + throw new ArgumentException("Not a resdb URI"); + } + string path = uri.Segments[1]; + return Path.GetFileNameWithoutExtension(path); + } + + private static async Task RegisterShader(Uri uri) + { + var signature = ExtractSignature(uri); + var shaderExists = await Engine.Current.LocalDB.ReadVariableAsync(signature, false); + if (!shaderExists) await Engine.Current.LocalDB.WriteVariableAsync(signature, true); + } + + + public static void AppendShaders() => Task.WaitAll(Shaders.Select(shader => RegisterShader(shader)).ToArray()); + } +} \ No newline at end of file